Math between metpy return dataarrays and xarray dataarrays #2987
-
Doing some math between some data returned from Metpy and other # get pressure in Pa
pa = grb.data_to_da(pkey)
pa.values = pa.values * 1e-2 # change to hPa
pa.attrs['units'] = 'hPa'
# get mixing ratio
mr = grb.data_to_da(mrkey)
mr.values = mr.values * 1e3 #Changed units to g/kg according to metpy example
mr.attrs['units'] = 'g/kg'
print('calculate the water vapor pressure...')
pw = vapor_pressure(pa, mr)
print('Extracting the temperature...')
t = grb.data_to_da(tkey)
print('Calculate the refractivity...')
ref = ( b1 * ((pa.data-pw.data)/t.data) ) + \
( b2 * ((pw.data) /t) ) + \
( b3 * (pw.data/(t.data*t.data)) ) Error:
How do I remove the effects of pint so that I can do the calculations in the form: This solution works but is the effects of Pint supposed follow the returned dataarray? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
There's nothing in Pint keeping you from doing appropriate math with units. Your issue here is that your The xarray with MetPy Tutorial in the docs has a units section for working with Pint-in-xarray. You can |
Beta Was this translation helpful? Give feedback.
So I just wanted to follow up and show how I would do this so that you're not fighting the unit framework, but using it to make sure you've got everything right and in proper unit agreement:
By using the built-i…