-
Notifications
You must be signed in to change notification settings - Fork 300
Remove coord checks when adding/subtracting cubes #1911
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
Conversation
|
I seem to be getting PEP8 failures for files I haven't touched 😕 . |
|
I can't see any PEP 8 failures, but there were time-outs on the main tests so I've restarted those and they've cleared up. Also, the "Calculating the difference between two cubes" example in the user guide is showing a genuine mismatch. The result now has |
|
Thanks @rhattersley, I can think of examples where it would make sense to keep the scalar coord from Allowing the mismatch on the scalar cube is consistent with the fact that we'd now be allowing mismatches between the dimension coords on I'm not sure what the ideal answer is: perhaps creating a new coord by a function of the coords on One major issue with my branch as it stands is that it could break existing user code: if you assumed the (scalar) Thoughts? |
I'm not sure which would be better, but what does seem clear is:
If it were me I'd get all of Either way, I'm happy to help with code changes, review comments, throwing rocks from my ivory tower, etc. 😉 |
|
Just to add further to the murkiness, it occured to be that we have 2 type of "ignorable" coords:
I think in the second case it makes more sense to keep the coord, as there may be a good reason why the coord doesn't exist on other. For example, other may contain some threshold values that don't vary with time (I've recently been trying to do a difference between soil moisture and the wilting point parameter, which only varies geographically). |
I'm inclined to agree with you there @rcomer. |
|
Sorry, wrong button! |
We've all been there. 😁 |
|
OK, so how about we have Is there a beginners' guide to working with |
|
In the meantime I have added the coord removal to |
|
Here is a better example from my recent work, where I definitely wouldn't want the division to remove metadata: if cube.name() == 'geopotential':
# Convert ERA-I geopotential to geopotential_height.
gravity = iris.cube.Cube(9.80665, units='m s-2')
cube = cube / gravityI don't understand the latest Travis failure... |
they're not linked to your PR, just a transient test run artefact; all working now |
|
Is there anything I need to do to take this forward? I've just seen the announcement that Iris 2.0 should be released this summer, which seems soon enough to me. So I guess extra work for backwards-compatibility in Iris 1.x would be more trouble than it's worth. Or have I misunderstood? Thanks. |
|
The removal of the deprecated |
|
Does anyone have any suggestions for a good name for the FUTURE flag? I'm currently using |
|
|
|
For some reason I'd previously focussed on just the behaviour with respect to scalar coordinates and missed the differences in the behaviour of vector coordinates with add/subtract vs. multiply/divide. Some of these differences are hard to understand, let alone argue the case for changing so I've tried to capture what's going on. If I've missed an aspect or got it wrong please shout! The current (i.e. prior to this PR) behaviour of add/subtract is:
The handling of mismatched scalar coordinates might not be ideal, but the overall behaviour is pretty simple to get my head around. 👍 The new behaviour of add/subtract (which is mostly just the existing behaviour of multiply/divide, so not changed by this PR) is ... um... obscure?! 😕 But it includes:
Based on the discussion in this PR, the handling of output scalar coordinates seems like an improvement. But the handling of the non-scalar coordinates is all over the place. 😱 I'm all for consistency, but I'm wondering if this is the wrong approach to solving the
|
|
Can open; worms everywhere.... 😉 Having different Another is when you have vector coords which don't exist at all on I also think it's reasonable for a user to want to do something like |
|
This might be a daft idea but... Could the non-matching coords from |
That seems like a simple to understand extension of the scalar coordinate handling. 👍
I can see how that would make some sense for a regular time series. Interestingly, that's not the way that something like pandas or xarray would work. (They would "line up" the cubes using the coordinate values of the two series and apply the subtraction where they overlap.) For that particular operation pandas supplies: If we're going to be more flexible, I still think we need to make the behaviour more predictable/easier to understand. For example, the var_name issue is only fixed by multiply/divide behaviour if the two cubes have exactly the same shape. If the two cubes have a different dimension order (e.g. one is a transpose of the other) then the var_name issue rears its head again.
Do we really need to do that? It doesn't seem very appealing. |
Agreed - I hadn't actually realised it was possible to broadcast cubes with different dimension orders!
No. Like I said, daft idea 😁. |
fadc8ec to
9ccd0c4
Compare
|
I've modified It also now adds a length 1 anonymous dimension if the coord isn't found on |
|
I just realised that in my |
5134529 to
b8a1cee
Compare
So the coordinate comparison still doesn't pay attention to values (something which I don't have a particularly strong opinion on either way), and now doesn't pay attention to units, attributes, or the coordinate system. If we're going to ignore values then I guess I'm OK with that.
Very nice 👍 Before we get into the nit-picky business of finalising tests, and providing (and documenting) backwards compatibility... are we all happy with the proposed behaviour? |
In the case where the shapes match, the coord names are still not checked (as far as I can see). Do we want to change that? (I added the Can I get a restart on my Travis |
Done. |
|
I just noticed that the user guide is still encouraging use of the |
|
I've noticed recent PRs to make |
|
@corinnebosley Does any of this relate to the POC you were doing today with xarray? |
|
@rcomer Remember this PR? I wouln't blame you if you didn't. I just made the So I'm keen to get that work done, and we can see how it impacts / relates to this PR. Does that sound reasonable? |
|
@rcomer Oh my gosh... Righty, I'm going to put this PR to bed on the promise that we're finally going to address all these issues for Maybe we should have some kinda party to celebrate if and when we finally get it all right?! Cheers! I'll be in touch. I'd appreciate you test driving the forthcoming cube arithmetic feature branch. |
As discussed at #1887, this PR removes checks which are applied to coordinates before adding and subtracting cubes. It makes these operations consistent with multiplication and division in terms of whether two cubes are compatible.
Having bypassed
_add_subtract_common, scalar coords which exist oncubebut not onother("ignorable" coords) are no longer removed as part of the operation. I think this is consistent with allowing the vector coords to differ (if I've understood correctly,_binary_op_commonignores all of the coords onother). There are no unit tests to check whether the "ignorable" coords are removed, but I am getting a failure in the doctests foruserguide/cube_maths.rstbecause a print out of a cube shows more metadata than previously.I have also removed the depreciated (since 0.8.0) keyword
ignore. It's not 100% clear what it did, but I guess it triggered the above mentioned removal of "ignorable" coords.