Open sgdecker opened 5 years ago
@sgdecker Yes, the NAM data is grid relative, which is not easy information to find! I recently added an example of 500 hPa model output to the Python Gallery (http://unidata.github.io/python-gallery/examples/500hPa_Absolute_Vorticity_winds.html#sphx-glr-examples-500hpa-absolute-vorticity-winds-py) that addresses this and has an example function for converting to Earth-relative u and v winds. I haven't created a MetPy PR for this yet, but may, so any feedback would be great.
def earth_relative_wind_components(da, ugrd, vgrd):
"""Calculate the north-relative components of the wind from the grid-relative
components using Cartopy transform_vectors.
Parameters
----------
ds : Xarray DataArray
Either of u- or v-component of the wind
ugrd : (M, N) Quantity
grid relative u-component of the wind
vgrd : (M, N) Quantity
grid relative v-component of the wind
Returns
-------
unr, vnr : tuple of array-like Quantity
The north-relative wind components in the X (East-West) and Y (North-South)
directions, respectively.
"""
if 'crs' not in list(da.coords):
raise ValueError('No CRS in coordinate, be sure to use the MetPy accessor parse_cf()')
data_crs = da.metpy.cartopy_crs
x = da.x.values
y = da.y.values
xx, yy = np.meshgrid(x, y)
ut, vt = ccrs.PlateCarree().transform_vectors(data_crs, xx, yy, ugrd.m, vgrd.m)
uer = ut * ugrd.units
ver = vt * vgrd.units
return uer, ver
What's the purpose of the da
argument in the function above? Otherwise, it seems like a nice example of what we want future API calls to look like, at least as input. The only other question would be: Should we go ahead and to the work to return a DataArray
?
Upon closer inspection, I guess it doesn't need the DataArray
since all of the requisite information needed would all be contained within either the ugrd
or vgrd
object - since they are DataArray
's themselves. It would likely work well to return as a DataArray as it would be easy to fit back into a Dataset
if needed.
That was my thinking as well.
Feature Request: I am trying to replicate GEMPAK's gdprof to a reasonable extent.
My GEMPAK settings:
The plot:
My MetPy attempt:
The plot:
For this issue, I am focusing on the wind profile, but as side issues, is my code as clean as currently possible, and is there a way not to have to figure out manually the lat and lon for Goose Bay?
Looking at the wind barbs, you'll see they differ. GEMPAK automagically plots them in north-relative coordinates. The MetPy sounding is in grid-relative coordinates, which is misleading in a sounding (or cross section for that matter). I tried to find functionality to do the conversion, but couldn't find any, and I do see VECR and VECN are blank in the GEMPAK Conversion Guide. I think ideally this would make use of the crs as well as a table of station IDs to be automatic.
(Edited so my GPOINT shows up)