From 4f2a7d1c8bdacf54993bc3e9a28b4d7bb688fedc Mon Sep 17 00:00:00 2001 From: Emma Hogan Date: Mon, 23 Dec 2019 12:45:53 +0000 Subject: [PATCH 1/3] Update test to compare cubes rather than data --- .../area_weighted/test_AreaWeightedRegridder.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py b/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py index b4dc426c6d..072bc3d680 100644 --- a/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py +++ b/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py @@ -143,12 +143,13 @@ def test_multiple_src_on_same_grid(self): target.coord(name).units = None # Ensure the bounds of the target cover the same range as the # source. - target.coord(name).bounds = np.column_stack( + target_bounds = np.column_stack( ( src1.coord(name).bounds[[0, 1], [0, 1]], src1.coord(name).bounds[[2, 3], [0, 1]], ) ) + target.coord(name).bounds = target_bounds regridder = AreaWeightedRegridder(src1, target) result1 = regridder(src1) @@ -169,8 +170,18 @@ def test_multiple_src_on_same_grid(self): ] ) - self.assertArrayEqual(result1.data, reference1.data) - self.assertArrayEqual(result2.data, reference2.data) + for name in coord_names: + # Remove coords system and units so it is no longer spherical. + reference1.coord(name).coord_system = None + reference1.coord(name).units = None + reference2.coord(name).coord_system = None + reference2.coord(name).units = None + reference1.coord(name).bounds = target_bounds + reference2.coord(name).bounds = target_bounds + + # Compare the cubes rather than just the data. + self.assertEqual(result1, reference1) + self.assertEqual(result2, reference2) def test_mismatched_data_dims(self): coord_names = ["latitude", "longitude"] From 6f2dcdaf5d0cf05a6fbaf3ab7a3edde18deac112 Mon Sep 17 00:00:00 2001 From: Emma Hogan Date: Mon, 23 Dec 2019 13:02:44 +0000 Subject: [PATCH 2/3] Ensure test fails on correct issue --- .../test_AreaWeightedRegridder.py | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py b/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py index 072bc3d680..1e494de259 100644 --- a/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py +++ b/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py @@ -137,19 +137,26 @@ def test_multiple_src_on_same_grid(self): src2.coord(name).guess_bounds() target = self.cube(np.linspace(20, 32, 2), np.linspace(10, 22, 2)) + # Ensure the bounds of the target cover the same range as the + # source. + target_lat_bounds = np.column_stack( + ( + src1.coord("latitude").bounds[[0, 1], [0, 1]], + src1.coord("latitude").bounds[[2, 3], [0, 1]], + ) + ) + target.coord("latitude").bounds = target_lat_bounds + target_lon_bounds = np.column_stack( + ( + src1.coord("longitude").bounds[[0, 1], [0, 1]], + src1.coord("longitude").bounds[[2, 3], [0, 1]], + ) + ) + target.coord("longitude").bounds = target_lon_bounds for name in coord_names: # Remove coords system and units so it is no longer spherical. target.coord(name).coord_system = None target.coord(name).units = None - # Ensure the bounds of the target cover the same range as the - # source. - target_bounds = np.column_stack( - ( - src1.coord(name).bounds[[0, 1], [0, 1]], - src1.coord(name).bounds[[2, 3], [0, 1]], - ) - ) - target.coord(name).bounds = target_bounds regridder = AreaWeightedRegridder(src1, target) result1 = regridder(src1) @@ -162,6 +169,9 @@ def test_multiple_src_on_same_grid(self): [np.mean(src1.data[2:4, 0:2]), np.mean(src1.data[2:4, 2:4])], ] ) + reference1.coord("latitude").bounds = target_lat_bounds + reference1.coord("longitude").bounds = target_lon_bounds + reference2 = self.cube(np.linspace(20, 32, 2), np.linspace(10, 22, 2)) reference2.data = np.array( [ @@ -169,6 +179,8 @@ def test_multiple_src_on_same_grid(self): [np.mean(src2.data[2:4, 0:2]), np.mean(src2.data[2:4, 2:4])], ] ) + reference2.coord("latitude").bounds = target_lat_bounds + reference2.coord("longitude").bounds = target_lon_bounds for name in coord_names: # Remove coords system and units so it is no longer spherical. @@ -176,8 +188,6 @@ def test_multiple_src_on_same_grid(self): reference1.coord(name).units = None reference2.coord(name).coord_system = None reference2.coord(name).units = None - reference1.coord(name).bounds = target_bounds - reference2.coord(name).bounds = target_bounds # Compare the cubes rather than just the data. self.assertEqual(result1, reference1) From 9e33c80368d67a4ad52681ca1fea7a30ac2339e1 Mon Sep 17 00:00:00 2001 From: Emma Hogan Date: Mon, 23 Dec 2019 13:20:00 +0000 Subject: [PATCH 3/3] Use == rather than is when checking for equality --- lib/iris/analysis/_regrid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/iris/analysis/_regrid.py b/lib/iris/analysis/_regrid.py index 19ed909fdc..0670c073ae 100644 --- a/lib/iris/analysis/_regrid.py +++ b/lib/iris/analysis/_regrid.py @@ -881,9 +881,9 @@ def _create_cube( def copy_coords(src_coords, add_method): for coord in src_coords: dims = src.coord_dims(coord) - if coord is src_x_coord: + if coord == src_x_coord: coord = grid_x_coord - elif coord is src_y_coord: + elif coord == src_y_coord: coord = grid_y_coord elif x_dim in dims or y_dim in dims: continue