-
Notifications
You must be signed in to change notification settings - Fork 422
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
Improved xarray compatibility on function input and output #1490
Improved xarray compatibility on function input and output #1490
Conversation
762ee5b
to
4d50ffa
Compare
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.
Quick review of a couple of items. For the most part, everything seems to be working well from my end when using my GEMPAK comparison notebook that I used to test an earlier implementation. I've noted a couple of things in various parts, mainly around advection
, which has a minus sign error and the adding of dx
and dy
is not working as I think it is intended. Additionally, the broadcasting of f
and latitude
also doesn't appear to be working.
I also need to investigate the inertial-advective wind a bit more, there are some vectors that are not as closely aligned with what comes out of GEMPAK...but that will have to wait and really unrelated to this PR.
Working on this now, particularly updating MetPy/tests/calc/test_kinematics.py Lines 205 to 207 in 2c2d442
Turns out the git blame for using an |
4d50ffa
to
f299672
Compare
DeepCode's analysis on #98600d found:
Top issues
👉 View analysis in DeepCode’s Dashboard | Configure the bot |
Hey, it made sense as a simple way to make sure the function worked as expected...but yes, not a very generalizable test. Oops. I'm actually amazed tests from my grad school days survived. |
3f38ead
to
1666875
Compare
This should now be ready for a full review! All tests and docs pass for me locally, so we'll see what CI shows. (@kgoebber I found that the latitude issue was that my grid argument decorator was returning latitude as a Quantity and not a DataArray, so it wasn't being broadcast via the xarray decorator. That should be fixed now.) |
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.
Using the GEMPAK comparison notebooks that I have, all of those calculations checkout and it is much cleaner being able to use DataArrays as input and have various other parameters computed and input in the background.
Broadcasting of latitude also works for all instances checked and advection now has the correct sign.
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.
This looks really good and is just about there.
@jthielen If you don't have the time to make any needed changes, it would be helpful to have your responses and I can make changes. |
1666875
to
5d94b4e
Compare
I've made the direct changes based on feedback. I should be able to fix the remaining items once you get the chance to reply to my responses @dopplershift. Thanks for the reviews! |
…ults and weird Pint __eq__ mutation issue
…ics dim kwarg order
5d94b4e
to
98600d6
Compare
We can ignore CodeClimate here. The coverage aren't too great, and stem from a bunch of warnings/exceptions that aren't hit. |
Would you want me to go back and add tests for those (could probably do that this evening)? Or just merge and not hold this up any longer? |
Yeah, this. |
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.
Apologies for the wait, but I feel like I've got a pretty good grapple on everything going in and no big hold-ups from this point on my end! Super appreciative of this and excited to see it go in. Onward to #1385!
Overview Of Changes
At long last, the updated version of #1353. This PR (and hopefully not yet another replacement) is the big "xarray compatibility" PR for v1.0. Feature highlights:
dx
,dy
,f
,latitude
)x_dim
andy_dim
kwargs or automatic identification from DataArrays)advection
function (simplified implementation and greater consistency with the rest of kinematics; xref Inconsistent arguments for gradient and advection #896)axis
argument tovertical_dim
for consistency when referring uniquely to vertical dimension (for consistency with kinematics)Remaining To-Do List/Discussion Items
I wanted to get this PR up as soon as I had it in a sufficient state for first review and not wait too long, since it has already taken far to long to get to this point! Below are remaining to-dos and unresolved discussion items from before:
To-Dos:
parcel_profile_with_lcl_as_dataset
(new)isentropic_interpolation_as_dataset
(new)advection
(mind as well be new)Discussion Items:
advection
seem reasonable? A: Yes*_as_dataset
additions, or should those become the primary APIs, and the originals renamed/made private? A: Good with them as islatitude
andf
. Should we standardize around one or the other, or at least document why each function has each (such as not standardizing aroundlatitude
to allowf
to be specified for f or beta plane approximated calculations)? @kgoebber A: use latitudelifted_index
? (API doesn't make as much sense in context of xarray, but likely still useful) A: Use as-isangle_to_direction
? (the one function where output in DataArray may be desired, but can't use Quantities as intermediary because the output is strings, rather than numeric) A: Use as-isChecklist