-
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
Fix precision issue with interpolation in profile helper #1192
Conversation
Another question: so the problem is that the LCL is at the surface, but it’s returning a pressure slightly above the first? |
Yeah, the LCL pressure is being returned as slightly greater than the surface pressure (in this case surface pressure is 900 hPa and LCL pressure is like 900.000000004 hPa. So another fix could just be making the LCL pressure equal to the surface pressure if |
Yeah, the right fix might be to figure out why there’s any numerical precision in the LCL in that situation. At least, that seems like the fundamental problem to me here. |
One option might be to do something like: If is_close(lcl_pressure, pressure[0]):
return pressure[0] |
Yup, that could work. I went digging for where the precision issue traced back to and it looks like it's the |
We also determine where convergence is by considering two points “close”. Are we picking the wrong point of those two to return? |
# Conditional needed due to precision error with np.log in dewpoint. | ||
# Causes issues with parcel_profile_with_lcl if removed. Issue #1187 | ||
if np.isclose(lcl_p, pressure): | ||
lcl_p = 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.
As I look at this change now, I don't understand it. Doesn't this return the entire pressure profile?
thanks, confused in Iowa.
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.
lcl
only takes scalar input variables (not arrays), so this will only return the pressure provided. The function will error out earlier than this line if an array is provided.
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.
Oh thank you! I was confused as stated since lcl() in 0.11.0 takes arrays. Whew.
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.
it appears to me that np.isclose
is now where this errors out when passed an array. FWIW
File "/home/akrherz/projects/MetPy/src/metpy/calc/thermo.py", line 365, in lcl
if np.isclose(lcl_p, pressure):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
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.
Well you've just won yourself a bug for the day. I'll open an issue, since if this conditional were not present, it would indeed return an array. We should be catching if arrays are fed in and either take the initial value or return an error. Where did you see it saying that lcl
takes arrays in 0.11, because I don't see that in the release notes?
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 didn't see it, I was just naively/ignorantly doing it. Just taking the same profile object and sequentially passing it to various sounding functions without thinking about it.
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.
Ok thanks. I opened up #1199 to discuss this. If you have an opinion about how to handle this case, feel free to comment there.
Description Of Changes
Ah, precision issues. This bug was due to the LCL pressure having rounding issues and being greater than the surface profile pressure in the helper function for
parcel_profile_with_lcl
. A simple rounding to take care of the precision issue solves this.Checklist