-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Units Errors when dealing with larger arrays - Pint #1064
Comments
Thanks for documenting this for us. As you stated, the second error is due to pint 0.9. We'll be including a fix for that in 0.11. The first error I'll need to dig into more - can you provide an example data file you're using here (or just the arrays of temperature and RH)? Thanks! |
Not sure how I can upload the file itself, but it's a netcdf of ERA5 data that I trimmed down into a manageable (though still large) file that just covers the CONUS. Temp and RH arrays -
|
Thanks - that'll do! |
I could be wrong here, but since RH is a masked array, you have to use MetPy's helper to keep the units from getting dropped from metpy.units import masked_array
rh = masked_array(f.variables['rh'][ k , ::-1 , i , j ] / 100., units.dimensionless) |
Yup, that's exactly it. If the array is unmasked and doesn't have units assigned, dewpoint_rh() will work just fine. But with the masked array, you'll have to keep the units explicitly assigned. |
Since the pint 0.9 problem is already documented in #997, I'm going to close this issue. |
I hate masked arrays. 😞 |
Getting two separate but related issues, both of which seem related to the Pint issues documented in previous posts - notably #1032 and #998.
The first issue occurs when representing units through parentheses instead of units.meter etc.
`for k in range(0,6):
for i in range(latli, latui):
for j in range(lonli, lonui):
u = f.variables['u'][ k , : , i , j ] * units.meter / units.second # * units('m/s') will cause an error
v = f.variables['v'][ k , : , i , j ] * units.meter / units.second # * units('m/s')
u = u[::-1]
v = v[::-1]
Different errors will show up for different units, but most of them are fairly similar. Error message below:
File "", line 1, in
runfile('C:/Users/Daniel/Documents/Research/ERA5scripts/dp_test.py', wdir='C:/Users/Daniel/Documents/Research/ERA5scripts')
File "C:\Users\Daniel\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\Users\Daniel\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Daniel/Documents/Research/ERA5scripts/dp_test.py", line 54, in
dp = calc.dewpoint_rh(temp,rh)
File "C:\Users\Daniel\Anaconda3\lib\site-packages\metpy\xarray.py", line 436, in wrapper
return func(*args, **kwargs)
File "C:\Users\Daniel\Anaconda3\lib\site-packages\metpy\units.py", line 305, in wrapper
return func(*args, **kwargs)
File "C:\Users\Daniel\Anaconda3\lib\site-packages\metpy\calc\thermo.py", line 700, in dewpoint_rh
return dewpoint(rh * saturation_vapor_pressure(temperature))
File "C:\Users\Daniel\Anaconda3\lib\site-packages\metpy\xarray.py", line 436, in wrapper
return func(*args, **kwargs)
File "C:\Users\Daniel\Anaconda3\lib\site-packages\metpy\units.py", line 304, in wrapper
raise ValueError(msg)
ValueError:
dewpoint
given arguments with incorrect units:e
requires "[pressure]" but given "none".Any variable
x
can be assigned a unit as follows:from metpy.units import units
x = x * units.meter / units.second
The first error was solved by just reverting to the other format for units, and adding units.dimensionless for RH.
The second error happened when I put the above code back in my main script, causing the below error.
TypeError: tuple indices must be integers or slices, not tuple
Downgrading from Pint 0.9 to 0.8.1 fixed this error, but not the first one.
For the full code that I've been using, see attached text file. And sorry if anything here is unclear, first time making a GitHub post.
dp_test.txt
The text was updated successfully, but these errors were encountered: