-
Notifications
You must be signed in to change notification settings - Fork 39
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
Preserve metadata during anomalies computation when using iris cubes difference #652
Conversation
Note on implementation: |
Wow, that was fast, thanks! I'll try to it today or tomorrow. |
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 can confirm that this fix solves my problem. Thanks a lot for the quick reply!
assert result.var_name == cube.var_name | ||
assert result.units == cube.units |
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.
Perhaps we can use
assert result.var_name == cube.var_name | |
assert result.units == cube.units | |
assert result.xml() == cube.xml() |
to verify that all metadata matches. That seems to pass for my use case, and it's more complete. For example, one of the subsequent problems I got with this bugs is that the time bounds were removed. These are included in the xml.
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.
that'll not work, there are differences in the xml's that got nothing to do with the actual metadata; I have enhanced the test to look for identical bounds and identical coord objects
Co-authored-by: Bouwe Andela <b.andela@esciencecenter.nl>
for coord_cube, coord_res in zip(cube.coords(), result.coords()): | ||
if coord_cube.has_bounds() and coord_res.has_bounds(): | ||
assert_array_equal(coord_cube.bounds, coord_res.bounds) | ||
assert coord_cube == coord_res |
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'm not sure if this is needed, because you're testing that the metadata was preserved, right?
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.
the metadata object does not contain information on the coords, I was quite surprised by that too
cube.units = "m" | ||
result = anomalies(cube, period, reference, standardize=standardize) | ||
assert result.metadata == cube.metadata | ||
for coord_cube, coord_res in zip(cube.coords(), result.coords()): |
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.
Note that if one array is longer than the other, zip will only iterate over the number of elements in the shortest iterable, so this does not test that the cubes have the same coordinates
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.
good point actually! but the cubes should have the same number of coords otherwise the iris cube difference would fail beforehand
Co-authored-by: Bouwe Andela <b.andela@esciencecenter.nl>
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.
@mattiarighi Could you please test?
Before you start, please read CONTRIBUTING.md.
Tasks
yamllint
to check that your YAML files do not contain mistakesIf you need help with any of the tasks above, please do not hesitate to ask by commenting in the issue or pull request.
Closes #651