-
Notifications
You must be signed in to change notification settings - Fork 416
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
Issue with mpcalc.equivalent_potential_temperature #1364
Comments
Thank you for the report! The second case (array of scalar quantities) is indeed unintended behavior. To aid in debugging, would you be able to let us know what the type of your inputs pmsl, T_Sfc, Td_sfc are (e.g., xarray.DataArray, pint.Quantity, numpy.ndarray)? Also, because much of the unit compatibility features have been in flux recently, could you also let us know what versions of MetPy, NumPy, Pint, and xarray you are using? |
MetPy - 0.12.0 Input was from the UCAR Thredds server... ncss = NCSS('http://thredds.ucar.edu' Query for required variablesdata = ncss.query().time(modtime) data.variables('MSLP_Eta_model_reduction_msl', Set the lat/lon box for the data to pull in.data.lonlat_box(wlon, elon, slat, nlat) ############################ Actually getting the datadata = ncss.get_data(data) Assign variable names to collected datadtime = data.variables['Temperature_height_above_ground'].dimensions[0] T_Sfc = (units(data.variables['Temperature_height_above_ground'].units) * Td_sfc = (units(data.variables['Dewpoint_temperature_height_above_ground'].units) * uwnd_10m = units('m/s') * data.variables['u-component_of_wind_height_above_ground'][0, 0, :] pmsl = (units(data.variables['MSLP_Eta_model_reduction_msl'].units) * |
@SPiltz01 Thank you for that additional information. Based on this, it looks like a masked array issue within https://github.com/Unidata/MetPy/blob/v0.12.1/src/metpy/calc/thermo.py#L992-L1002 As your own code correctly accounts for, multiplying masked arrays by units on the right does not work for masked arrays as of recent versions of Pint. If you wanted a workaround for this bug for now, you can either wrap your NetCDF4 variables with That being said, this is still a bug in MetPy (that was missed in #983 ... it will be nice when #1214 is in place). I believe changing the concluding line to instead be return units.Quantity(th_e, 'kelvin') will resolve this. |
Thanks Jon. I appreciate the help. - Steve |
I noticed that mpcalc.potential_temperature(pmsl, T_Sfc) and mpcalc.equivalent_potential_temperature(pmsl, T_Sfc, Td_sfc) return two different array types. It looks like
mpcalc.potential_temperature
is returning a 2D array with units attached, whilempcalc.equivalent_potential_temperature
is returning a 2D array of individual unit-ed quantities.#Sfc theta
sfc_Theta = mpcalc.potential_temperature(pmsl, T_Sfc)
print('Theta:')
print(sfc_Theta)
Theta:
[[294.52630615234375 294.7657165527344 297.162841796875 ... 295.77618408203125 294.7249450683594 294.43292236328125] [294.4823303222656 294.2461853027344 298.4425048828125 ... 295.5538635253906 294.7125549316406 294.36090087890625] [298.4830017089844 299.8385009765625 299.524169921875 ... 295.846923828125 295.6717834472656 294.9158020019531] ... [297.68463134765625 297.5202331542969 297.4456787109375 ... 296.65972900390625 296.6708984375 296.67218017578125] [297.57684326171875 297.4230651855469 297.5305480957031 ... 296.80523681640625 296.8392333984375 296.8185729980469] [297.8320007324219 297.47601318359375 297.5194396972656 ... 297.0497741699219 297.0862121582031 297.0396423339844]] kelvin
#Sfc thetae
sfc_Thetae = mpcalc.equivalent_potential_temperature(pmsl, T_Sfc, Td_sfc)
print('Theta-E:')
print(sfc_Thetae)
Theta-E:
[[<Quantity(303.69500732421875, 'kelvin')>
<Quantity(303.3419494628906, 'kelvin')>
<Quantity(305.7081604003906, 'kelvin')> ...
<Quantity(329.5704040527344, 'kelvin')>
<Quantity(329.3699645996094, 'kelvin')>
<Quantity(329.0014953613281, 'kelvin')>]
[<Quantity(303.3021545410156, 'kelvin')>
<Quantity(302.5059814453125, 'kelvin')>
<Quantity(306.9647521972656, 'kelvin')> ...
<Quantity(331.018798828125, 'kelvin')>
<Quantity(329.92242431640625, 'kelvin')>
<Quantity(329.8907470703125, 'kelvin')>]
[<Quantity(307.45062255859375, 'kelvin')>
<Quantity(308.7452697753906, 'kelvin')>
<Quantity(308.14593505859375, 'kelvin')> ...
<Quantity(330.7307434082031, 'kelvin')>
<Quantity(331.5306701660156, 'kelvin')>
<Quantity(331.3540954589844, 'kelvin')>]
...
[<Quantity(332.9311218261719, 'kelvin')>
<Quantity(333.3431701660156, 'kelvin')>
<Quantity(333.7388000488281, 'kelvin')> ...
<Quantity(345.5285949707031, 'kelvin')>
<Quantity(345.1958923339844, 'kelvin')>
<Quantity(344.6487731933594, 'kelvin')>]
[<Quantity(333.20770263671875, 'kelvin')>
<Quantity(333.5695495605469, 'kelvin')>
<Quantity(334.2283935546875, 'kelvin')> ...
<Quantity(346.56817626953125, 'kelvin')>
<Quantity(346.26495361328125, 'kelvin')>
<Quantity(345.5577087402344, 'kelvin')>]
[<Quantity(332.3034973144531, 'kelvin')>
<Quantity(333.88092041015625, 'kelvin')>
<Quantity(334.7017517089844, 'kelvin')> ...
<Quantity(347.37225341796875, 'kelvin')>
<Quantity(347.0073547363281, 'kelvin')>
<Quantity(346.72216796875, 'kelvin')>]]
Thanks!
The text was updated successfully, but these errors were encountered: