登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 想亮亮 于 2022-9-2 16:36 编辑
如题,本人初步接触Metpy库,尝试使用平流函数计算涡度平流,在metpy.calc.advection这句函数的使用上出现了问题。
具体过程是:模仿官方提供的例子:https://unidata.github.io/python-training/gallery/500hpa_vorticity_advection/
其中计算涡度平流的函数使用情况是这样的:
vort_adv = mpcalc.advection(avor, [uwnd_500, vwnd_500], (dx, dy), dim_order='yx') * 1e9当运行程序时提示不存在dim_order='yx'这一项参数。在查询后改成了:vort_adv = mpcalc.advection(avor,[u,v],dx=dx,dy=dy,x_dim=-1,y_dim=-2) * 1e9
但很奇怪的是算出的vort_adv的np.shape显示是(2,241,321),而我u,v,avor都是(241,321)的二维数组。
后面我又改成了:vort_adv = mpcalc.advection(avor,,[v],dx=dx,dy=dy,x_dim=-1,y_dim=-2) * 1e9
vort_adv的数组成了(1,241,321)
但如果是用vort_adv = mpcalc.advection(avor,u,v,dx=dx,dy=dy,x_dim=-1,y_dim=-2) * 1e9则会报错。
我觉得应该是小问题但不知道该怎么改了,求助各位大佬。另外我在和鲸社区在线跑了那个例子,显示的vort_adv是二维数组,但它那个已经是以前的函数(带dim_order的)。最后附上代码和函数例子。另外我试着降了metpy的版本,安装了1.0版也无法解决问题。from datetimeimport datetime importcartopy.crs as ccrs importcartopy.feature as cfeature importmatplotlib.gridspec as gridspec importmatplotlib.pylab as plt importmetpy.calc as mpcalc import metpy asmetpy from metpy.unitsimport units from netCDF4import num2date import numpy asnp importscipy.ndimage as ndimage from siphon.ncssimport NCSS import xarray asxr import netCDF4as nc fromcartopy.io.shapereader import Reader fromcartopy.mpl.ticker import LongitudeFormatter,LatitudeFormatter importscipy.ndimage as ndimage
filein ='20220726.nc' ds =xr.open_dataset(filein)
time =ds.variables['time'][10] level =ds.variables['level'][8] lat =ds.variables['latitude'][:] lon =ds.variables['longitude'][:] lons, lats =np.meshgrid(lon,lat) hgt =ds.variables['z'][10,8,:,:]*0.01#500hpa tmp =ds.variables['t'][10,8,:,:]-273.15#500hpa u = units('m/s')* ds.variables['u'][10,8,:,:]#500hpa v = units('m/s')* ds.variables['v'][10,8,:,:]#500hpa rh =ds.variables['r'][10,8,:,:]#500hpa Z_500 =ndimage.gaussian_filter(hgt, sigma=3, order=0)
dx,dy =mpcalc.lat_lon_grid_deltas(lon, lat) avor =mpcalc.vorticity(u,v,dx=dx, dy=dy) avor =ndimage.gaussian_filter(avor, sigma=3, order=0) * units('1/s') vort_adv =mpcalc.advection(avor,,[v],dx=dx,dy=dy,x_dim=-1,y_dim=-2) * 1e9 #vort_adv =ndimage.gaussian_filter(vort_adv, sigma=3, order=0) np.shape(vort_adv)
函数使用手册 官方例子 和鲸社区
大家救救孩子吧
|