MetPy
MetPy copied to clipboard
Problem with calculating metpy.calc.geostrophic_wind
Hello everyone. I am trying to calculate the geostrophic wind from wrfout. I used xwrf and wrf-python.getvar to extract geopotential (z), and then used metpy to calculate the geostrophic wind. However, my wind components are ranging from -4000 to 4000 m/s, which is unreasonable. Here are my script and corresponding outputs. If someone have any clue, please let me know.
getvar method, through which I have already extracted the geopotential, and saved into another file
FLLJ = 1
i = 1
instance = '2016-02-22 06:00'
files = glob.glob(f"../FLLJ_{FLLJ}/run_{i}/wrfout_d0*")
wrfin = Dataset(files[0])
z = get_data(i, FLLJ,variable='z', instance=instance)
height = mpcalc.smooth_gaussian(z.height,3)
XLAT = z.XLAT
XLAT = XLAT*units.degrees
projection = z.height.projection
XLAT.attrs['projection'] = projection
XLONG = z.XLONG
XLONG = XLONG*units.degrees
projection = z.height.projection
XLONG.attrs['projection'] = projection
dx = wrfin.getncattr('DX') * units('m')
dy = wrfin.getncattr('DY') * units('m')
# Compute geostrophic wind components u and v
geo_wind_u, geo_wind_v = mpcalc.geostrophic_wind(height,dx,dy,XLAT,x_dim=-1,y_dim=-2)
fig,ax = plt.subplots(1,2,figsize=(15, 5))
geo_wind_u.isel(bottom_top=20).plot(ax=ax[0])
ax[0].set_title('Geostrophic wind U')
geo_wind_v.isel(bottom_top=20).plot(ax=ax[1])
ax[1].set_title('Geostrophic wind V')
plt.tight_layout() # Automatically adjust layout for better spacing
plt.subplots_adjust(wspace=0.6)
xwrf method
# Open the NetCDF file
ds = xr.open_dataset(files[0]).xwrf.postprocess()
z = ds.geopotential_height.sel(Time=instance)
ua = ds.U.sel(Time=instance)
va = ds.V.sel(Time=instance)
# Smooth height data
z = mpcalc.smooth_gaussian(z, 3)
# Compute the geostrophic wind
geo_u, geo_v = mpcalc.geostrophic_wind(z)
fig,ax = plt.subplots(1,2,figsize=(15, 5))
geo_u.isel(z_stag=20).plot(ax=ax[0])
ax[0].set_title('Geostrophic wind U')
geo_v.isel(z_stag=20).plot(ax=ax[1])
ax[1].set_title('Geostrophic wind V')
plt.tight_layout() # Automatically adjust layout for better spacing
plt.subplots_adjust(wspace=0.6)
Can you share the data file somewhere so I can try to reproduce the issue?