-
Notifications
You must be signed in to change notification settings - Fork 314
Partial Collapse of Multidimensional Auxcoords with Bounds #3302
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| * :meth:`iris.cube.Cube.collapsed` now handles partial collapsing of | ||
| multidimensional coordinates that have bounds. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # (C) British Crown Copyright 2013 - 2018, Met Office | ||
| # (C) British Crown Copyright 2013 - 2019, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
|
|
@@ -303,6 +303,30 @@ def test_numeric_nd(self): | |
| [4, 10], | ||
| [5, 11]])) | ||
|
|
||
| def test_numeric_nd_bounds(self): | ||
| self.setupTestArrays((3, 4)) | ||
| coord = AuxCoord(self.pts_real, bounds=self.bds_real) | ||
|
|
||
| collapsed_coord = coord.collapsed() | ||
| self.assertArrayEqual(collapsed_coord.points, np.array([55])) | ||
| self.assertArrayEqual(collapsed_coord.bounds, np.array([[-2, 112]])) | ||
|
|
||
| # Test partially collapsing one dimension... | ||
| collapsed_coord = coord.collapsed(1) | ||
| self.assertArrayEqual(collapsed_coord.points, np.array([15, 55, 95])) | ||
| self.assertArrayEqual(collapsed_coord.bounds, np.array([[-2, 32], | ||
| [38, 72], | ||
| [78, 112]])) | ||
|
|
||
| # ... and the other | ||
| collapsed_coord = coord.collapsed(0) | ||
| self.assertArrayEqual( | ||
| collapsed_coord.points, np.array([40, 50, 60, 70])) | ||
| self.assertArrayEqual(collapsed_coord.bounds, np.array([[-2, 82], | ||
| [8, 92], | ||
| [18, 102], | ||
| [28, 112]])) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you split this into 3 tests? i.e. one test for each collapse operation. My concern with having them all in the one test is that if the first one fails we won't know the result of the other two collapses until we get the first one working.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And perhaps add a test where the dimensions given are negative to test that handling is correct:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do, and thanks for explaining why - it makes sense. Should I do the same with the lazy equivalent below?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes please!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Also moved the dask import to the top of the module. This is consistent with other test modules that use dask. Since I now have |
||
|
|
||
| def test_lazy_nd_bounds(self): | ||
| import dask.array as da | ||
|
|
||
|
|
@@ -319,6 +343,22 @@ def test_lazy_nd_bounds(self): | |
| self.assertArrayEqual(collapsed_coord.points, np.array([55])) | ||
| self.assertArrayEqual(collapsed_coord.bounds, da.array([[-2, 112]])) | ||
|
|
||
| # Test partially collapsing one dimension... | ||
| collapsed_coord = coord.collapsed(1) | ||
| self.assertArrayEqual(collapsed_coord.points, np.array([15, 55, 95])) | ||
| self.assertArrayEqual(collapsed_coord.bounds, np.array([[-2, 32], | ||
| [38, 72], | ||
| [78, 112]])) | ||
|
|
||
| # ... and the other | ||
| collapsed_coord = coord.collapsed(0) | ||
| self.assertArrayEqual( | ||
| collapsed_coord.points, np.array([40, 50, 60, 70])) | ||
| self.assertArrayEqual(collapsed_coord.bounds, np.array([[-2, 82], | ||
| [8, 92], | ||
| [18, 102], | ||
| [28, 112]])) | ||
|
|
||
| def test_lazy_nd_points_and_bounds(self): | ||
| import dask.array as da | ||
|
|
||
|
|
||
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.
Nice!