-
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
WIP: Enhanced xarray function compatibility on input/output #1304
Conversation
@dopplershift I'm just now getting the chance to get back to this, and after running into some ...interesting... issues combining xarray, pint, and MetPy in current versions, I wanted to ask about what the target "xarray data structure" should be in v1.0 to guide the effort here. Should it be
|
@jthielen 😭 The pain of being at the cutting edge. First question: Is it possible that both are supported? I'd like to get to the second, but that seems like a pretty big reach today (feel free to correct me if I'm wrong). I'm ok with updating to the latest versions; I have concerns about how much back-porting might be required. |
Now that you say that, yes, it should be technically possible to support both, they would just become separate options in the However, I think it would be rather confusing for end users to have two different kinds of DataArray output from MetPy functions that they would have to interact with differently. For instance, to apply an offset to, say, potential temperature, the first option would look something like theta = potential_temperature(pressure, temperature)
theta.metpy.unit_array = theta_0.metpy.unit_array + 5 * units.K (in general, lots of reliance on MetPy's accessor and explicitly handling magnitudes/units, and easy to mess up if you try multiplying a DataArray by something with a unit) and the second like theta = potential_temperature(pressure, temperature) + 5 * units.K (more natural, can be easily conceptualized as a "Quantity with coordinates on top") Things could also go quite wrong if these two are mixed outside of the relative safety of MetPy's calculation wrappers (e.g., units being dropped from the units-on-attribute DataArray, but not the Quantity-DataArray).
I'm glad to hear the versions aren't an issue! Although, I'm not quite sure of what you exactly mean by "pretty big reach." Is it effort in implementation? Reliance on yet-to-be-finalized upstream functionality? Impacts on documentation/downstream code/training materials? Something else? Implementation-wise, I really don't think it's that big of a deal. Since (in the philosophy of this PR at least) most of the calculation internals remain operating on Quantities, preferring the second option over the first is a simple switch in how the wrapper reconstructs the DataArray (and may even make using DataArrays internally in the calculations easier down the road). The " While I've not run into any issues recently with having Quantities-in-DataArrays in my own tests (with the exclusion of coordinates/indexes of course), I'm a bit nervous about relying on the technically-WIP compatibility in production code. However, the alternative (how it is now) definitely feels like an ugly API to commit to. Switching to just using the second would no doubt require adjustments elsewhere. However, I think they would mostly be clean-ups to the unit-compatibility hacks that are required now? Though, any place where I guess a lot of this is rambling to say that:
|
@jthielen I see what you're saying. I think it's clear that the second is the most desirable option, and I agree having two similar, but different, paths is not a good user experience. As I understand this, the main challenges we're looking at relying on some WIP support upstream is that things could:
All we really need right now is to commit to an interface for our users. It sounds to me like we have that, it just might be a slightly rough road. Worst case, people need to drop back to numpy arrays if they run into bugs, right? |
Sounds good, and I agree. I'll move forward with the Quantity-inside-DataArray option. |
Closing in favor of #1353. |
Description Of Changes
This PR utilizes the wrapper of #1223 across the library where it naturally fit, as well allowing broadcasting of xarray elements in the xarray preprocessing decorator. It also has an attempt at filling in kinematics grid parameters (however, there are still some errors in the code).
Checklist