[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #CCF-756181]: metpy - metpy.calc.geopotential_to_height(...)



Greetings,

Apologies for the delayed response.

Where are you finding resources referring to using MetPy's geostrophic_wind() 
like that? As of MetPy 1.0 (now over 3 years old), geostrophic wind takes 
height, and optionally dx, dy, and latitude parameters, so there's no way to 
pass in f.

Since you're an xarray user, you should be able to only pass in a 
height/geopotential dataarray, and MetPy will grab/calculate all of the 
coordinate information. So I would expect you to only need to do:

    geostrophic_wind(h)

You indicate this won't work with your ERA5 data (which surprises me), but if 
that's the case, you would just need to pass latitude:

    geostrophic_wind(h, latitude=lat)

No flipping of u,v should be necessary, especially when using xarray.

Hope this helps,

Ryan

> To whom it may concern,
> 
> I wonder if you may unravel something for me regarding the above function as 
> I have spent many days looking at this.
> 
> ALL the documentation and examples online have the following text:
> 
> "
> # Set up some constants based on our projection, including the Coriolis 
> parameter and
> # grid spacing, converting lon/lat spacing to Cartesian
> f = mpcalc.coriolis_parameter(np.deg2rad(lat_2d)).to('1/s')
> dx, dy = mpcalc.lat_lon_grid_deltas(lon_2d, lat_2d)
> 
> # In MetPy 0.5, geostrophic_wind() assumes the order of the dimensions is (X, 
> Y),
> # so we need to transpose from the input data, which are ordered lat (y), lon 
> (x).
> # Once we get the components,transpose again so they match our original data.
> geo_wind_u, geo_wind_v = mpcalc.geostrophic_wind(height * units.m, f, dx, dy)
> geo_wind_u = geo_wind_u
> geo_wind_v = geo_wind_v
> 
> # Calculate ageostrophic wind components
> ageo_wind_u = u_wind - geo_wind_u
> ageo_wind_v = v_wind - geo_wind_v
> "
> 
> 
> 
> 
> I have managed to ascertain that later versions of metpy require the function:
> 
> mpcalc.geostrophic_wind(height * units.m, f, dx, dy)
> as
> mpcalc.geostrophic_wind(height * units.m, dx, dy, f)
> 
> However, within the comments, the text states:
> "# In MetPy 0.5, geostrophic_wind() assumes the order of the dimensions is 
> (X, Y),
> # so we need to transpose from the input data, which are ordered lat (y), lon 
> (x).
> # Once we get the components,transpose again so they match our original data."
> 
> And then follows with the lines:
> geo_wind_u = geo_wind_u
> geo_wind_v = geo_wind_v
> 
> which obviously does nothing.  What I am trying to ascertain is whether the 
> comments are only specifically related to MetPy 0.5 (and maybe earlier 
> versions), and that the lines above have just been left in (but with u and v 
> now unchanged), or whether this relates to all versions from MetPy0.5 onwards 
> and the lines should be:
> geo_wind_u = geo_wind_v
> geo_wind_v = geo_wind_u
> 
> 
> Apologies for the ask - the complication for me is compounded by the fact 
> that I have to convert the pint.quantity returned 'f' array from the 
> mpcalc.coriolis_parameter into an xarray.values to pass to the 
> mpcalc.geostrophic.winds function (can't use pint.quantities - have to use 
> xarray for a variety of reasons).
> 
> All the examples I have found specify that I must first find 'f' with the 
> Coriolis parameter function, then pass this value to the geostrophic winds 
> function.  I am aware that it is possible to simply pass height to the 
> geostrophic winds function but the function cannot interpret the netcdf files 
> I have (ERA5) to calculate all the other parameters, hence me having to do it 
> 'long-handed'.  I am getting some weird results and really want to make sure 
> that I know whether I should be flipping u and v or not!
> 
> Thank you for your time - it is much appreciated.
> 


Ticket Details
===================
Ticket ID: CCF-756181
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with NSF Unidata User Support are recorded in the 
Unidata inquiry tracking system and then made publicly available through the 
web.  If you do not want to have your interactions made available in this way, 
you must let us know in each email you send to us.