【问题标题】:How to use vorticiy calculation in metpy version 1.0?如何在metpy 1.0版中使用vorticiy计算?
【发布时间】:2021-11-11 17:00:05
【问题描述】:

我想使用metpy.calc.vorticity。之前的结构是(u, v, dx, dy),现在改为(u, v, *, dx=None, dy=None, x_dim=- 1, y_dim=- 2)

  1. 新结构中的* 是什么?
  2. 当我使用(u, v)时,其他参数似乎是可选的,我遇到了ValueError: Must provide dx/dy arguments or input DataArray with latitude/longitude coordinates.
  3. 当我使用(u , v, dx, dy)时,我面对的是TypeError: too many positional arguments

但是,我的代码和数据中的geostrophic_wind(height,dx,dy,latitude) 没有问题,但涡度有什么问题? 我的部分代码如下:

PATH_nc = '/home/python_script/'
out_fff='gfs.t12z.pgrb2.0p50.f168'
ncfile = Dataset('{}{}.nc'.format(PATH_nc,out_fff))
lon = ncfile.variables['longitude'][:]
lon[lon < 0] = 360 + lon[lon < 0]
lat = ncfile.variables['latitude'][:]
dx, dy = mpcalc.lat_lon_grid_deltas(lon, lat)
long1, lat1 = np.meshgrid(lon, lat)
hght_850  = ncfile.variables['HGT_850mb'][:]
HGT_850  = gaussian_filter((hght_850)/10, sigma=  2)
height850 = ndimage.gaussian_filter(hght_850, sigma=1.5, order=0)
geo_wind_u_850, geo_wind_v_850 = mpcalc.geostrophic_wind(np.squeeze(height850)*units.m, dx, dy, lat1)
vwnd_700 =  units('m/s') *ncfile.variables['VGRD_700mb'][:]
avor700 = mpcalc.vorticity(np.squeeze(uwnd_700), np.squeeze(vwnd_700), dx, dy)

我希望编写我的代码中与问题相关的所有必要部分。 如有任何帮助,我将不胜感激。

【问题讨论】:

    标签: python metpy


    【解决方案1】:

    所以在vorticity的定义中:

    metpy.calc.vorticity(u, v, *, dx=None, dy=None, x_dim=-1, y_dim=-2)
    

    * 之后的所有内容都定义为keyword-only argument,这意味着函数参数/参数只能通过关键字传递。因为您当前的代码没有通过关键字传递dxdy,而是仅按位置传递,所以您得到的错误是:TypeError: too many positional arguments。解决方法是使用关键字参数传递dxdy

    avor700 = mpcalc.vorticity(np.squeeze(uwnd_700), np.squeeze(vwnd_700), dx=dx, dy=dy)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2020-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多