Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Wrong wind direction of vertcross

未关闭
#143 14 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
matplotlib, numpy, python

调研方向

使用 vertcross、interplevel 和 matplotlib.quiver 重现该示例,然后将剖面分量与 15 km 高度的水平风图进行比较。首先检查 vertcross 文档以及任何相关的测试或实现;当解释或纠正方向差异并记录一种经过验证的绘图方法后,即视为完成。

由索引模型根据 Issue 内容生成。

描述

support

Background

Hi, all,

I'm trying to plot the wind quiver on the crosssection. But, I find the wind direction is wrong. Here're the details.

Read data and vertcross

import numpy as np
from wrf import getvar, interplevel, ALL_TIMES, CoordPair, vertcross, to_np, latlon_coords
from netCDF4 import Dataset
import matplotlib.pyplot as plt

data_dir = '../data/wrfchem/wrfout/20200901/lnox_500/'
file = data_dir+'wrfout_d04_2020-09-01_05:00:00_subset'
ncfile = Dataset(file)

# set cross
start_lon = 118.6
end_lon = 119
start_lat = 32.1
end_lat = 31.7

start_point = CoordPair(lat=start_lat, lon=start_lon)
end_point = CoordPair(lat=end_lat, lon=end_lon)

# get vars
u = getvar(ncfile, 'ua')
v = getvar(ncfile, 'va')
w = getvar(ncfile, 'wa')
wspd = getvar(ncfile, 'uvmet_wspd_wdir')
dbz = getvar(ncfile, 'dbz')
z = getvar(ncfile, 'z', units='km')

# vertcross and subset to 0-17 km
cross_u = vertcross(u, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True).sel(vertical=slice(0, 17))
cross_v = vertcross(v, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True).sel(vertical=slice(0, 17))
cross_w = vertcross(w, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True).sel(vertical=slice(0, 17))
cross_dbz = vertcross(dbz, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True).sel(vertical=slice(0, 17))
cross_wspd = vertcross(wspd, z, wrfin=ncfile, start_point=start_point, end_point=end_point, latlon=True, meta=True).sel(vertical=slice(0, 17))

# get xlabels
coord_pairs = to_np(cross_dbz.coords["xy_loc"])
xticks = np.arange(coord_pairs.shape[0])
xlabels = [pair.latlon_str() for pair in to_np(coord_pairs)]

fig, ax = plt.subplots(figsize=(10, 6))
ax.set_xticks(xticks[::20])
ax.set_xticklabels(['(' +s.replace(',', '\n') + ')' for s in xlabels[::20]], fontsize=4) # rotation

# plot wind
xs = np.arange(0, cross_w.shape[-1], 1)
ys = to_np(cross_w.coords['vertical'])
step = 2

# plot dbz
m = ax.contourf(xs[::step],
                ys[::step],
                to_np(cross_dbz[::step, ::step]),
                cmap='Reds'
               )


q = ax.quiver(xs[::step],
              ys[::step],
              to_np(cross_u[::step, ::step]+cross_v[::step, ::step]),
              to_np(cross_w[::step, ::step])
             )

plt.colorbar(m, label='dBZ')
plt.savefig('./cross.jpg', dpi=300)

Result:
cross

Wind interpolated to 15 km

# Get the lat/lon coordinates
lats, lons = latlon_coords(u)

zlevel = 15  # km
u_zlevel = interplevel(u, z, zlevel)
v_zlevel = interplevel(v, z, zlevel)

step = 10

fig, ax = plt.subplots(figsize=(10, 6))
q = plt.quiver(to_np(lons[::step,::step]), to_np(lats[::step,::step]),
              to_np(u_zlevel[::step, ::step]), to_np(v_zlevel[::step, ::step])
             )

qk = plt.quiverkey(q, 1, 1.05, 10, r'$10 m/s}$', labelpos='E')
plt.plot([start_lon, end_lon], [start_lat, end_lat], '-r')
plt.title('Wind at 15 km level')
plt.savefig('./zlev.jpg', dpi=300)

zlev

Problem

As you can see, the wind at the 15 km level should blow from the start point to the endpoint.
But, the 15 km wind in the crosssection is the opposite.

Is there anything wrong with my method?
Thanks in advance!

主要语言
Python
星标
498
派生
178
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NCAR/wrf-python 的其他 Issue

查看 NCAR/wrf-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。