-
Notifications
You must be signed in to change notification settings - Fork 300
Changed to auto convert from aux to dim coord #1039
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
Changed to auto convert from aux to dim coord #1039
Conversation
lib/iris/cube.py
Outdated
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 is considered bad practice as it will catch any exception at all, including things like keyboard interrupts, which are outside the desired behaviour. You should have some idea of what is likely to go wrong and catch only those errors.
|
I've made a couple of minor coding comments. However, I'm not confident in deciding if this is generally a good idea or not so I'd like to let others provide feedback too (although the idea seems fairly reasonable to me). |
I know what you mean - I'm just (as usual) pushing from the user side - its something that I find myself doing a lot, and I can't think of a reason why I should...doesn't mean there isn't any! |
|
Changes made |
lib/iris/cube.py
Outdated
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.
What extra information is contained in str(e) (not necessarily a criticism, I'm at a windows machine so I can't check myself)?
If it doesn't add much useful I'd say ditch it and go for a more descriptive static message. On the flip side, if e already contains a descriptive message that is good to use as is then we don't even necessarily have to re-raise 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.
ValueError: Could not convert coord to DimCoord: The points array must be strictly monotonic.
Probably worth keeping, do you think? Could do with being changed from a colon after DimCoord thought
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, then I guess what I want to know is will it ever be anything other than that? If not then you could just write that... If it can be one of any number of things then maybe this is OK.
|
Interesting. I'll try to give this some thought on Monday, and check for performance implications, etc. |
|
Is travis unwell? I managed to restart this but it failed at intsalling pyke |
Probably. I'll restart mine + see if it fails in the same way. |
|
I object to this. Currently if I add a coordinate to a cube, the reference to the object that I have is a reference to the coordinate that is now in the cube. The result of this PR is to break that relationship some, but not all, of the time. Implicit changing of types is in my view undesirable and potentiality confusing behaviour. |
|
Perhaps I haven't understood the full implications of what I've done then. I thought I was creating a completely new and separate dim coord from the aux coord instance. If I understand you correctly, I am creating a new version of the aux_coord which is masquerading as a dim_coord? i.e. if the original aux_coord is changed it will break anything that uses its dim_coord version? Or have I go the wrong end of the stick?
Would you be any happier if we spawned a new instance of the coord? The fundamental problem is the part of the definition of dim_coord as having to be something defining a cube's dimension. In this context its irrelevant weather the coord was used to define a dim, or as a secondary coord as long as its monotonic etc. However we currently still make that distinction with this check. I fully admit that this PR might not be the answer to that conundrum though. |
You are, this is the problem as highlighted by @esc24.
The other way around. Currently the coordinate on the cube and the instance that was added are the same thing, so if you change one you change the other. Your modification breaks this by using an entirely new DimCoord instance. |
|
literally 180 deg the wrong end of the stick - ok, I'm with you now. I still think there might be problem in that the coords are defined by how they are used, not what properties they posses |
I'm not sure I agree. |
|
An aux coord and a dim coord can be identical in all but name. The fact that the from_coord method can exist at all suggests the coords are (or should I say "can be") defined by how they are used i.e. weather they are used as the primary description of a dimension or not. I think it would be better if we had:
infact, conceptually, there are three types of coord in a cube
This comes up when trying to use aux coords from one cube to construct a new cube for instance. Its really not a big deal adding one more line of code, so a involved redesign might not be worth it, but I do think that the current solution is sub-optimal. However, I think that one line is asking the users to navigate round the design of iris. I remember finding the distinction between aux and dim very confusing when I first started using iris |
|
Have we run out of steam on this one? I suspect the consensus might be "you might have a point but it needs a lot more coding to sort a relatively small issue"? Bottom line is that I think DimCoord.from_coord() exists for users to navigate around the iris api, rather to do something that is conceptually a task that a user wants to perform |
I think so. It was a reasonable enough idea, but unfortunately it breaks the existing API in that we could no longer guarantee the relationship between a particular coordinate object and its corresponding coordinate on a cube. This may seem minor but I think it is quite a big deal in terms of the design and how much user code it could end up breaking. If you can agree with that point perhaps you could close the PR @niallrobinson? Your other point is much more philosophical in nature and would warrant discussion in a wider forum if you still want to pursue it. I doubt anyone will drop by the PR to discuss it further anyway. |
yeh - it escalated fast! |
Currently iris raises an error if you try and pass an aux coord to a function that wants a dim coord, even if the aux coord is capable of being converted to a dim coord (i.e. monotonic). This PR attempts to convert aux coords and then raises the current error if that fails.
Note I haven't updated the documentation - not sure what to say: "or an aux_coord that can be converted using DimCoord.from_cube()" or something?