-
Notifications
You must be signed in to change notification settings - Fork 300
Moveplottests #2139
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
Moveplottests #2139
Changes from 5 commits
cc44b54
fc88776
5e543e7
eae2a17
b3b9b0a
2300ff7
3b658cf
c494b69
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # (C) British Crown Copyright 2013 - 2015, Met Office | ||
| # (C) British Crown Copyright 2013 - 2016, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
|
|
@@ -32,20 +32,15 @@ | |
| from iris.cube import Cube | ||
| from iris.tests.stock import global_pp | ||
|
|
||
| # Run tests in no graphics mode if matplotlib is not available. | ||
| if tests.MPL_AVAILABLE: | ||
| import iris.quickplot as qplt | ||
|
|
||
|
|
||
| @tests.skip_data | ||
| @tests.skip_plot | ||
| class TestOSGBToLatLon(tests.GraphicsTest): | ||
| class TestOSGBToLatLon(tests.IrisTest): | ||
| def setUp(self): | ||
| path = tests.get_data_path( | ||
| ('NIMROD', 'uk2km', 'WO0000000003452', | ||
| '201007020900_u1096_ng_ey00_visibility0180_screen_2km')) | ||
| self.src = iris.load_cube(path)[0] | ||
| self.src.data = self.src.data.astype(np.float32) | ||
| self.src.data = self.src.data.astype(np.float64) | ||
|
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. |
||
| self.grid = Cube(np.empty((73, 96))) | ||
| cs = GeogCS(6370000) | ||
| lat = DimCoord(np.linspace(46, 65, 73), 'latitude', units='degrees', | ||
|
|
@@ -58,23 +53,27 @@ def setUp(self): | |
| def _regrid(self, method): | ||
| regridder = Regridder(self.src, self.grid, method, 'mask') | ||
| result = regridder(self.src) | ||
| qplt.pcolor(result, antialiased=False) | ||
| qplt.plt.gca().coastlines() | ||
| return result | ||
|
|
||
| def test_linear(self): | ||
| self._regrid('linear') | ||
| self.check_graphic() | ||
| result = self._regrid('linear') | ||
| self.assertEqual(result.shape, (73, 96)) | ||
| self.assertArrayAlmostEqual(result.data.mean(), -16100.351951) | ||
| self.assertArrayAlmostEqual(result.data.std(), 5603.850769) | ||
|
|
||
| def test_nearest(self): | ||
| self._regrid('nearest') | ||
| self.check_graphic() | ||
| result = self._regrid('nearest') | ||
| self.assertEqual(result.shape, (73, 96)) | ||
| self.assertArrayAlmostEqual(result.data.mean(), -16095.965585) | ||
| self.assertArrayAlmostEqual(result.data.std(), 5612.657155) | ||
|
|
||
|
|
||
| @tests.skip_data | ||
| @tests.skip_plot | ||
| class TestGlobalSubsample(tests.GraphicsTest): | ||
| class TestGlobalSubsample(tests.IrisTest): | ||
| def setUp(self): | ||
| self.src = global_pp() | ||
| _ = self.src.data | ||
|
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.
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. it will, but it can make for messy output during debugging |
||
| self.src.data = self.src.data.astype(np.float64) | ||
| # Subsample and shift the target grid so that we can see a visual | ||
| # difference between regridding scheme methods. | ||
| grid = self.src[1::2, 1::3] | ||
|
|
@@ -85,16 +84,19 @@ def setUp(self): | |
| def _regrid(self, method): | ||
| regridder = Regridder(self.src, self.grid, method, 'mask') | ||
| result = regridder(self.src) | ||
| qplt.pcolormesh(result) | ||
| qplt.plt.gca().coastlines() | ||
| return result | ||
|
|
||
| def test_linear(self): | ||
| self._regrid('linear') | ||
| self.check_graphic() | ||
| result = self._regrid('linear') | ||
| self.assertEqual(result.shape, (36, 32)) | ||
| self.assertArrayAlmostEqual(result.data.mean(), 280.35907) | ||
| self.assertArrayAlmostEqual(result.data.std(), 15.997223) | ||
|
|
||
| def test_nearest(self): | ||
| self._regrid('nearest') | ||
| self.check_graphic() | ||
| result = self._regrid('nearest') | ||
| self.assertEqual(result.shape, (36, 32)) | ||
| self.assertArrayAlmostEqual(result.data.mean(), 280.33726) | ||
| self.assertArrayAlmostEqual(result.data.std(), 16.064001) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
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.
Here and elsewhere you're using
assertArrayAlmostEqualfor scalars.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.
Out of interest, why have you used 'AlmostEqual', rather than 'Equal'?
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.
because every time someone compares two floats for equality in a test, a fairy dies ;)
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.
So it's a precision issue? In that case, maybe a hash of data would be better to test. NumPy arrays can't be hashed, but the underyling buffer (
ndarray.data) can be, if thewriteableflag of thendarrayis set toFalse.I'm wondering if testing the mean/standard deviation means we wouldn't catch bugs which only changed the data slightly. It's probably nothing to worry about, but just a thought.