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
Allow PW calculation when NaNs present #1188
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Makes sense as trapz
is not NaN-aware. Is the data in the test just copied from the values in #1184?
Yes the test case is the one provided in #1184 |
Also should we be doing this for CAPE since it uses the same logic? @akrherz you have a profile you mentioned for this? |
Maybe we should refactor the integration with NaN handling and unit support into a separate (private) helper? I'd like to avoid playing whack-a- |
Was wondering the same thing...can play around and see if we can get something more universal. |
When I run my example in #1184 without filtering into CAPE, it does not traceback, but I get a ton of warnings
|
Took a swing at this helper...tried to make it as general as possible while not being overly complicated. Added it to PW and all CAPEs for now. |
src/metpy/calc/tools.py
Outdated
Takes a variable number of arguments | ||
Returns a dictionary with arrays in the same order as provided | ||
""" | ||
no_nan_variable = nan_variable[~np.isnan(nan_variable) & ~np.isnan(pressure)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the docstring is out of date or not, but I do think it would be good to work with multiple variables at once. In fact, that might actually be necessary if you get data where dewpoint and temperature have nans in different spots. What about:
def remove_nans(*variables):
# Determine mask joint across all variables
mask = None
for v in variables:
if mask is None:
mask = np.isnan(v)
else:
mask |= np.isnan(v)
# Mask everyone with that joint mask
ret = []
for v in variables:
ret.append(v[~mask])
return ret
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this...this was what I was intending but didn't know how to do. Haven't used |=
before - very handy here!
src/metpy/calc/thermo.py
Outdated
@@ -407,6 +407,8 @@ def lfc(pressure, temperature, dewpt, parcel_temperature_profile=None, dewpt_sta | |||
parcel_profile | |||
|
|||
""" | |||
_, temperature = _remove_nans(pressure, temperature) | |||
pressure, dewpt = _remove_nans(pressure, dewpt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you be able to do this now:
pressure, temperature, dewpt = _remove_nans(pressure, temperature, dewpt)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll apply that to this function and the rest of the thermo calc that I applied this to.
that can't handle them
This pull request introduces 2 alerts when merging f8e06b4 into a928abf - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what LGTM is really complaining about. This looks good.
Description Of Changes
Remove NaNs if present in dewpoint or pressure and calculate PW.
Checklist