From 613153cf1217885f086a5f03bffab8c1c0a60a57 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 10 Nov 2022 10:40:09 +0000 Subject: [PATCH] address review comments --- .../regrid/test__CurvilinearRegridder.py | 60 +++++++++++++------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/iris/tests/unit/analysis/regrid/test__CurvilinearRegridder.py b/lib/iris/tests/unit/analysis/regrid/test__CurvilinearRegridder.py index add729f76f2..9b0160aee4b 100644 --- a/lib/iris/tests/unit/analysis/regrid/test__CurvilinearRegridder.py +++ b/lib/iris/tests/unit/analysis/regrid/test__CurvilinearRegridder.py @@ -169,7 +169,9 @@ def test_caching(self): ], ) - def test_derived_coords(self): + +class Test__derived_coord(tests.IrisTest): + def setUp(self): src = realistic_4d()[0] tgt = realistic_4d() new_lon, new_lat = np.meshgrid( @@ -197,33 +199,57 @@ def test_derived_coords(self): src.add_aux_coord(lon, [1, 2]) src_t.add_aux_coord(lat_t, [2, 1]) src_t.add_aux_coord(lon_t, [2, 1]) - rg = Regridder(src, tgt) - res = rg(src) + self.src = src.copy() + self.src_t = src_t + self.tgt = tgt + self.altitude = src.coord("altitude") + transposed_src = src.copy() + transposed_src.transpose([0, 2, 1]) + self.altitude_transposed = transposed_src.coord("altitude") + + def test_no_transpose(self): + rg = Regridder(self.src, self.tgt) + res = rg(self.src) assert len(res.aux_factories) == 1 and isinstance( res.aux_factories[0], HybridHeightFactory ) - assert np.allclose( - res.coord("altitude").points, src.coord("altitude").points + assert np.allclose(res.coord("altitude").points, self.altitude.points) + + def test_cube_transposed(self): + rg = Regridder(self.src, self.tgt) + transposed_cube = self.src.copy() + transposed_cube.transpose([0, 2, 1]) + res = rg(transposed_cube) + + assert len(res.aux_factories) == 1 and isinstance( + res.aux_factories[0], HybridHeightFactory ) - src.transpose([0, 2, 1]) - res = rg(src) assert np.allclose( - res.coord("altitude").points, src.coord("altitude").points + res.coord("altitude").points, self.altitude_transposed.points ) - rg_t = Regridder(src_t, tgt) - res_t = rg_t(src_t) - assert np.allclose( - res_t.coord("altitude").points, - np.moveaxis(src_t.coord("altitude").points, 1, 2), + def test_coord_transposed(self): + rg = Regridder(self.src_t, self.tgt) + res = rg(self.src_t) + + assert len(res.aux_factories) == 1 and isinstance( + res.aux_factories[0], HybridHeightFactory ) - src_t.transpose([0, 2, 1]) - res_t = rg_t(src_t) assert np.allclose( - res_t.coord("altitude").points, - np.moveaxis(src_t.coord("altitude").points, 1, 2), + res.coord("altitude").points, self.altitude_transposed.points + ) + + def test_both_transposed(self): + rg = Regridder(self.src_t, self.tgt) + transposed_cube = self.src_t.copy() + transposed_cube.transpose([0, 2, 1]) + res = rg(transposed_cube) + + assert len(res.aux_factories) == 1 and isinstance( + res.aux_factories[0], HybridHeightFactory ) + assert np.allclose(res.coord("altitude").points, self.altitude.points) @tests.skip_data