[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[python #DGY-360774]: Dimensional error with metpy Calc height_to_geopotential
- Subject: [python #DGY-360774]: Dimensional error with metpy Calc height_to_geopotential
- Date: Tue, 13 Apr 2021 13:34:50 -0600
Greetings!
Apologies that it's taken me so long to get back to this. You're running into a
problem with numpy masked arrays (which is what's returned out of
netCDF4-python when you get data) and units. The quick answer is that you
should multiply units on the left instead of the right. So the relevant lines
in your script (57-63) should look like:
alt0 = units.m * n.squeeze(data0.variables['h'][i,43,407:613,18:245])
alt1 = units.m * n.squeeze(data0.variables['h'][i,55,490:530,166:210])
alt2 = units.m * n.squeeze(data0.variables['h'][i,71,502:519,178:196])
press0 = units.hPa *
n.squeeze(data0.variables['pl'][i,43,407:613,18:245])/100 # avg 265 hPa
press1 = units.hPa *
n.squeeze(data0.variables['pl'][i,55,490:530,166:210])/100 # avg 702 hPa
press2 = units.hPa *
n.squeeze(data0.variables['pl'][i,71,502:519,178:196])/100 # avg 975 hPa
See this issue as an example for more information:
https://github.com/Unidata/MetPy/issues/983
This is not a problem when using xarray (http://xarray.pydata.org/en/stable/)
since we can automatically handle reading from the unit metadata there, so you
might want to consider using that as well.
Hope this helps!
Ryan
> Also, here is a snip of what happens.
> [image: image.png]
>
Ticket Details
===================
Ticket ID: DGY-360774
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with 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.