From a523d7aa0646c2ef83ea83bfba2b0b7b2f4d8110 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Tue, 19 May 2020 14:31:51 +0100 Subject: [PATCH 01/17] change all default units to "unknown" --- lib/iris/coords.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/iris/coords.py b/lib/iris/coords.py index b5392579c8..3ad5e018f9 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -59,7 +59,7 @@ def __init__( standard_name=None, long_name=None, var_name=None, - units="no-unit", + units=None, attributes=None, ): """ @@ -688,7 +688,7 @@ def __init__( standard_name=None, long_name=None, var_name=None, - units="no-unit", + units=None, attributes=None, ): """ @@ -788,7 +788,7 @@ def __init__( standard_name=None, long_name=None, var_name=None, - units="1", + units=None, attributes=None, measure=None, ): @@ -1440,7 +1440,7 @@ def __init__( standard_name=None, long_name=None, var_name=None, - units="1", + units=None, bounds=None, attributes=None, coord_system=None, @@ -2411,7 +2411,7 @@ def from_regular( standard_name=None, long_name=None, var_name=None, - units="1", + units=None, attributes=None, coord_system=None, circular=False, @@ -2474,7 +2474,7 @@ def __init__( standard_name=None, long_name=None, var_name=None, - units="1", + units=None, bounds=None, attributes=None, coord_system=None, From ed269c64d09b8f236043f66ccfd991ccab29bafb Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Wed, 20 May 2020 11:42:35 +0100 Subject: [PATCH 02/17] modify pp loading to revert units to "1" for sigma and model level number --- lib/iris/fileformats/pp_load_rules.py | 13 +++++++++++-- lib/iris/tests/integration/test_netcdf.py | 2 +- lib/iris/tests/integration/test_pp.py | 14 ++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/iris/fileformats/pp_load_rules.py b/lib/iris/fileformats/pp_load_rules.py index c0a4081970..45b95c41ea 100644 --- a/lib/iris/fileformats/pp_load_rules.py +++ b/lib/iris/fileformats/pp_load_rules.py @@ -147,6 +147,7 @@ def _convert_vertical_coords( model_level_number, standard_name="model_level_number", attributes={"positive": "down"}, + units="1", ) coords_and_dims.append((coord, dim)) @@ -235,6 +236,7 @@ def _convert_vertical_coords( model_level_number, standard_name="model_level_number", attributes={"positive": "up"}, + units="1", ) level_pressure = _dim_or_aux( bhlev, @@ -243,7 +245,10 @@ def _convert_vertical_coords( bounds=np.vstack((bhrlev, brsvd2)).T, ) sigma = AuxCoord( - blev, long_name="sigma", bounds=np.vstack((brlev, brsvd1)).T + blev, + long_name="sigma", + bounds=np.vstack((brlev, brsvd1)).T, + units="1" ) coords_and_dims.extend( [(model_level_number, dim), (level_pressure, dim), (sigma, dim)] @@ -265,6 +270,7 @@ def _convert_vertical_coords( model_level_number, standard_name="model_level_number", attributes={"positive": "up"}, + units="1", ) level_height = _dim_or_aux( blev, @@ -274,7 +280,10 @@ def _convert_vertical_coords( attributes={"positive": "up"}, ) sigma = AuxCoord( - bhlev, long_name="sigma", bounds=np.vstack((bhrlev, brsvd2)).T + bhlev, + long_name="sigma", + bounds=np.vstack((bhrlev, brsvd2)).T, + units="1", ) coords_and_dims.extend( [(model_level_number, dim), (level_height, dim), (sigma, dim)] diff --git a/lib/iris/tests/integration/test_netcdf.py b/lib/iris/tests/integration/test_netcdf.py index 8c6e0f6659..a8363e6d5e 100644 --- a/lib/iris/tests/integration/test_netcdf.py +++ b/lib/iris/tests/integration/test_netcdf.py @@ -81,7 +81,7 @@ def test_hybrid_height_and_pressure(self): 1200.0, long_name="level_pressure", units="hPa" ) ) - cube.add_aux_coord(iris.coords.DimCoord(0.5, long_name="other sigma")) + cube.add_aux_coord(iris.coords.DimCoord(0.5, long_name="other sigma", units='1')) cube.add_aux_coord( iris.coords.DimCoord( 1000.0, long_name="surface_air_pressure", units="hPa" diff --git a/lib/iris/tests/integration/test_pp.py b/lib/iris/tests/integration/test_pp.py index 6fbf180ac5..b9b096d782 100644 --- a/lib/iris/tests/integration/test_pp.py +++ b/lib/iris/tests/integration/test_pp.py @@ -299,7 +299,7 @@ def test_hybrid_height_with_non_standard_coords(self): delta_lower, delta, delta_upper = 150, 200, 250 cube = Cube(np.zeros((ny, nx)), "air_temperature") - level_coord = AuxCoord(0, "model_level_number") + level_coord = AuxCoord(0, "model_level_number", units="1") cube.add_aux_coord(level_coord) delta_coord = AuxCoord( delta, @@ -308,7 +308,10 @@ def test_hybrid_height_with_non_standard_coords(self): units="m", ) sigma_coord = AuxCoord( - sigma, bounds=[[sigma_lower, sigma_upper]], long_name="mavis" + sigma, + bounds=[[sigma_lower, sigma_upper]], + long_name="mavis", + units="1", ) surface_altitude_coord = AuxCoord( np.zeros((ny, nx)), "surface_altitude", units="m" @@ -343,7 +346,7 @@ def test_hybrid_pressure_with_non_standard_coords(self): delta_lower, delta, delta_upper = 0.15, 0.2, 0.25 cube = Cube(np.zeros((ny, nx)), "air_temperature") - level_coord = AuxCoord(0, "model_level_number") + level_coord = AuxCoord(0, "model_level_number", units="1") cube.add_aux_coord(level_coord) delta_coord = AuxCoord( delta, @@ -352,7 +355,10 @@ def test_hybrid_pressure_with_non_standard_coords(self): units="Pa", ) sigma_coord = AuxCoord( - sigma, bounds=[[sigma_lower, sigma_upper]], long_name="mavis" + sigma, + bounds=[[sigma_lower, sigma_upper]], + long_name="mavis", + units="1", ) surface_air_pressure_coord = AuxCoord( np.zeros((ny, nx)), "surface_air_pressure", units="Pa" From 5f3c5a0dd6c7423e3b011d54e28c6dc8a9049a26 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Wed, 20 May 2020 12:09:01 +0100 Subject: [PATCH 03/17] fix tests to avoid errors --- lib/iris/tests/test_plot.py | 1 + lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/iris/tests/test_plot.py b/lib/iris/tests/test_plot.py index 04418d8d40..742bfb55da 100644 --- a/lib/iris/tests/test_plot.py +++ b/lib/iris/tests/test_plot.py @@ -875,6 +875,7 @@ def test_non_cube_coordinate(self): pts, standard_name="model_level_number", attributes={"positive": "up"}, + units="1" ) self.draw("contourf", cube, coords=["grid_latitude", x]) diff --git a/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py b/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py index 789b1d61d5..51a4e41a23 100644 --- a/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py +++ b/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py @@ -144,7 +144,7 @@ def setUp(self): self.delta = iris.coords.DimCoord( [0.0, 1.0, 2.0], long_name="level_pressure", units="Pa" ) - self.sigma = iris.coords.DimCoord([1.0, 0.9, 0.8], long_name="sigma") + self.sigma = iris.coords.DimCoord([1.0, 0.9, 0.8], long_name="sigma", units="1") self.surface_air_pressure = iris.coords.AuxCoord( np.arange(4).reshape(2, 2), "surface_air_pressure", units="Pa" ) From f782c2d5b4b8d65222e54d1201798a7848fd7703 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Wed, 20 May 2020 14:47:52 +0100 Subject: [PATCH 04/17] fix more tests --- lib/iris/fileformats/pp_load_rules.py | 5 +++-- lib/iris/tests/unit/coord_categorisation/test_add_hour.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/iris/fileformats/pp_load_rules.py b/lib/iris/fileformats/pp_load_rules.py index 45b95c41ea..39e693da01 100644 --- a/lib/iris/fileformats/pp_load_rules.py +++ b/lib/iris/fileformats/pp_load_rules.py @@ -198,6 +198,7 @@ def _convert_vertical_coords( model_level_number, long_name="soil_model_level_number", attributes={"positive": "down"}, + units="1", ) coords_and_dims.append((coord, dim)) elif np.any(brsvd1 != brlev): @@ -855,7 +856,7 @@ def _convert_scalar_realization_coords(lbrsvd4): coords_and_dims = [] if lbrsvd4 != 0: coords_and_dims.append( - (DimCoord(lbrsvd4, standard_name="realization"), None) + (DimCoord(lbrsvd4, standard_name="realization", units="1"), None) ) return coords_and_dims @@ -1087,7 +1088,7 @@ def _all_other_rules(f): and f.lbmon == f.lbmond ): aux_coords_and_dims.append( - (AuxCoord(f.lbmon, long_name="month_number"), None) + (AuxCoord(f.lbmon, long_name="month_number", units="1"), None) ) aux_coords_and_dims.append( ( diff --git a/lib/iris/tests/unit/coord_categorisation/test_add_hour.py b/lib/iris/tests/unit/coord_categorisation/test_add_hour.py index 6965ea7a2f..9b101362a5 100644 --- a/lib/iris/tests/unit/coord_categorisation/test_add_hour.py +++ b/lib/iris/tests/unit/coord_categorisation/test_add_hour.py @@ -70,7 +70,7 @@ def test_basic(self): cube = self.cube time_coord = self.time_coord expected_coord = iris.coords.AuxCoord( - self.hour_numbers % 24, long_name=coord_name + self.hour_numbers % 24, long_name=coord_name, units="1" ) ccat.add_hour(cube, time_coord, coord_name) From b96983853f8ee9ce2f4484749dc71ff19b53e71d Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Wed, 20 May 2020 16:38:52 +0100 Subject: [PATCH 05/17] fix more tests --- docs/iris/src/userguide/navigating_a_cube.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/iris/src/userguide/navigating_a_cube.rst b/docs/iris/src/userguide/navigating_a_cube.rst index 055617e047..581d1a67cf 100644 --- a/docs/iris/src/userguide/navigating_a_cube.rst +++ b/docs/iris/src/userguide/navigating_a_cube.rst @@ -229,7 +229,7 @@ by field basis *before* they are automatically merged together: # Add our own realization coordinate if it doesn't already exist. if not cube.coords('realization'): realization = np.int32(filename[-6:-3]) - ensemble_coord = icoords.AuxCoord(realization, standard_name='realization') + ensemble_coord = icoords.AuxCoord(realization, standard_name='realization', units="1") cube.add_aux_coord(ensemble_coord) filename = iris.sample_data_path('GloSea4', '*.pp') From b93527f3f8e6464c9199ef7a86c9ddaac7a7e4c3 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Wed, 20 May 2020 16:55:55 +0100 Subject: [PATCH 06/17] fix more tests --- docs/iris/example_code/Meteorology/lagged_ensemble.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/iris/example_code/Meteorology/lagged_ensemble.py b/docs/iris/example_code/Meteorology/lagged_ensemble.py index 298d178a1e..512d6459ac 100644 --- a/docs/iris/example_code/Meteorology/lagged_ensemble.py +++ b/docs/iris/example_code/Meteorology/lagged_ensemble.py @@ -40,7 +40,7 @@ def realization_metadata(cube, field, fname): import iris.coords realization_coord = iris.coords.AuxCoord( - np.int32(realization_number), "realization" + np.int32(realization_number), "realization", units="1" ) cube.add_aux_coord(realization_coord) From a54301c40a0f34d69f87336cfc41d6e6372b4c49 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 21 May 2020 10:42:16 +0100 Subject: [PATCH 07/17] blacken --- lib/iris/fileformats/pp_load_rules.py | 2 +- lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/iris/fileformats/pp_load_rules.py b/lib/iris/fileformats/pp_load_rules.py index 39e693da01..bee33927f6 100644 --- a/lib/iris/fileformats/pp_load_rules.py +++ b/lib/iris/fileformats/pp_load_rules.py @@ -249,7 +249,7 @@ def _convert_vertical_coords( blev, long_name="sigma", bounds=np.vstack((brlev, brsvd1)).T, - units="1" + units="1", ) coords_and_dims.extend( [(model_level_number, dim), (level_pressure, dim), (sigma, dim)] diff --git a/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py b/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py index 51a4e41a23..14944891f2 100644 --- a/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py +++ b/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py @@ -144,7 +144,9 @@ def setUp(self): self.delta = iris.coords.DimCoord( [0.0, 1.0, 2.0], long_name="level_pressure", units="Pa" ) - self.sigma = iris.coords.DimCoord([1.0, 0.9, 0.8], long_name="sigma", units="1") + self.sigma = iris.coords.DimCoord( + [1.0, 0.9, 0.8], long_name="sigma", units="1" + ) self.surface_air_pressure = iris.coords.AuxCoord( np.arange(4).reshape(2, 2), "surface_air_pressure", units="Pa" ) From b616651a195b2c03cd482bcca2e5d91691aeb1d9 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 21 May 2020 14:38:59 +0100 Subject: [PATCH 08/17] fix more tests --- lib/iris/tests/stock/__init__.py | 4 ++-- .../interpolation/test_RectilinearInterpolator.py | 6 +++--- .../analysis/regrid/test_RectilinearRegridder.py | 2 +- lib/iris/tests/unit/cube/test_Cube.py | 2 +- lib/iris/tests/unit/cube/test_CubeList.py | 14 ++++++++------ .../tests/unit/fileformats/netcdf/test_Saver.py | 2 +- .../pp_load_rules/test__all_other_rules.py | 2 +- .../test__convert_scalar_pseudo_level_coords.py | 3 ++- .../test__convert_scalar_realization_coords.py | 2 +- .../pp_load_rules/test__convert_vertical_coords.py | 2 ++ 10 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/iris/tests/stock/__init__.py b/lib/iris/tests/stock/__init__.py index 9bb1c4626f..1588f464e6 100644 --- a/lib/iris/tests/stock/__init__.py +++ b/lib/iris/tests/stock/__init__.py @@ -834,8 +834,8 @@ def jan_offset(day, year): units="days since 1970-01-01 00:00:00-00", climatological=True, ) - lon_dim = DimCoord(lon, standard_name="longitude") - lat_dim = DimCoord(lat, standard_name="latitude") + lon_dim = DimCoord(lon, standard_name="longitude", units="1") + lat_dim = DimCoord(lat, standard_name="latitude", units="1") data_shape = (len(time_points), len(lat), len(lon)) values = np.zeros(shape=data_shape, dtype=np.int8) diff --git a/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py b/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py index d1eaf71030..0f66b427bd 100644 --- a/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py +++ b/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py @@ -34,9 +34,9 @@ class ThreeDimCube(tests.IrisTest): def setUp(self): cube = stock.simple_3d_w_multidim_coords() - cube.add_aux_coord(iris.coords.DimCoord(np.arange(2), "height"), 0) - cube.add_dim_coord(iris.coords.DimCoord(np.arange(3), "latitude"), 1) - cube.add_dim_coord(iris.coords.DimCoord(np.arange(4), "longitude"), 2) + cube.add_aux_coord(iris.coords.DimCoord(np.arange(2), "height", units="1"), 0) + cube.add_dim_coord(iris.coords.DimCoord(np.arange(3), "latitude", units="1"), 1) + cube.add_dim_coord(iris.coords.DimCoord(np.arange(4), "longitude", units="1"), 2) self.data = np.arange(24).reshape(2, 3, 4).astype(np.float32) cube.data = self.data self.cube = cube diff --git a/lib/iris/tests/unit/analysis/regrid/test_RectilinearRegridder.py b/lib/iris/tests/unit/analysis/regrid/test_RectilinearRegridder.py index 55fb2f4829..492283f843 100644 --- a/lib/iris/tests/unit/analysis/regrid/test_RectilinearRegridder.py +++ b/lib/iris/tests/unit/analysis/regrid/test_RectilinearRegridder.py @@ -1253,7 +1253,7 @@ def setUp(self): units="m", attributes={"positive": "up"}, ) - sigma = AuxCoord(1, long_name="sigma") + sigma = AuxCoord(1, long_name="sigma", units="1") surface_altitude = AuxCoord( (src.data - src.data.min()) * 50, "surface_altitude", units="m" ) diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index 9c03f0f4d4..b1f67f32e3 100644 --- a/lib/iris/tests/unit/cube/test_Cube.py +++ b/lib/iris/tests/unit/cube/test_Cube.py @@ -1077,7 +1077,7 @@ def create_cube(lon_min, lon_max, bounds=False): 0, ) cube.add_aux_coord( - iris.coords.AuxCoord([1.0, 0.9, 0.8, 0.6], long_name="sigma"), 0 + iris.coords.AuxCoord([1.0, 0.9, 0.8, 0.6], long_name="sigma", units="1"), 0 ) cube.add_dim_coord( iris.coords.DimCoord([-45, 0, 45], "latitude", units="degrees"), 1 diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index 6870e2367f..e59775d1c9 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -150,16 +150,18 @@ class Test_merge__time_triple(tests.IrisTest): @staticmethod def _make_cube(fp, rt, t, realization=None): cube = Cube(np.arange(20).reshape(4, 5)) - cube.add_dim_coord(DimCoord(np.arange(5), long_name="x"), 1) - cube.add_dim_coord(DimCoord(np.arange(4), long_name="y"), 0) - cube.add_aux_coord(DimCoord(fp, standard_name="forecast_period")) + cube.add_dim_coord(DimCoord(np.arange(5), long_name="x", units="1"), 1) + cube.add_dim_coord(DimCoord(np.arange(4), long_name="y", units="1"), 0) cube.add_aux_coord( - DimCoord(rt, standard_name="forecast_reference_time") + DimCoord(fp, standard_name="forecast_period", units="1") ) - cube.add_aux_coord(DimCoord(t, standard_name="time")) + cube.add_aux_coord( + DimCoord(rt, standard_name="forecast_reference_time", units="1") + ) + cube.add_aux_coord(DimCoord(t, standard_name="time", units="1")) if realization is not None: cube.add_aux_coord( - DimCoord(realization, standard_name="realization") + DimCoord(realization, standard_name="realization", units="1") ) return cube diff --git a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py index 08595ed3f3..acea552fdf 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py +++ b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py @@ -161,7 +161,7 @@ def _simple_cube(self, dtype): points = np.arange(3, dtype=dtype) bounds = np.arange(6, dtype=dtype).reshape(3, 2) cube = Cube(data, "air_pressure_anomaly") - coord = DimCoord(points, bounds=bounds) + coord = DimCoord(points, bounds=bounds, units="1") cube.add_dim_coord(coord, 0) return cube diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py index d10c1218ab..d44b5a1d54 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py @@ -269,7 +269,7 @@ def test_month_coord(self): res = _all_other_rules(field)[AUX_COORDS_INDEX] expected = [ - (AuxCoord(3, long_name="month_number"), None), + (AuxCoord(3, long_name="month_number", units="1"), None), (AuxCoord("Mar", long_name="month", units=Unit("no unit")), None), ( DimCoord( diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py index 70807408d0..b7074f3c00 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_pseudo_level_coords.py @@ -23,7 +23,8 @@ class Test(TestField): def test_valid(self): coords_and_dims = _convert_scalar_pseudo_level_coords(lbuser5=21) self.assertEqual( - coords_and_dims, [(DimCoord([21], long_name="pseudo_level"), None)] + coords_and_dims, + [(DimCoord([21], long_name="pseudo_level", units="1"), None)], ) def test_missing_indicator(self): diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py index 4a4649c978..929f65c921 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_scalar_realization_coords.py @@ -24,7 +24,7 @@ def test_valid(self): coords_and_dims = _convert_scalar_realization_coords(lbrsvd4=21) self.assertEqual( coords_and_dims, - [(DimCoord([21], standard_name="realization"), None)], + [(DimCoord([21], standard_name="realization", units="1"), None)], ) def test_missing_indicator(self): diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py index b3a6e537ac..676335a3e8 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py @@ -210,6 +210,7 @@ def _check_depth( lblev, standard_name="model_level_number", attributes={"positive": "down"}, + units="1", ), dim, ) @@ -604,6 +605,7 @@ def _check( lblev, standard_name="model_level_number", attributes={"positive": "up"}, + units="1", ), dim, ) From 2925b85e74d38fd6e024600a23978cfa040ab9e6 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 21 May 2020 15:59:42 +0100 Subject: [PATCH 09/17] fix more tests, revert collapsed behaviour to give coordinates with units of "1" --- lib/iris/analysis/__init__.py | 2 +- lib/iris/tests/test_aggregate_by.py | 4 +++- lib/iris/tests/unit/cube/test_Cube.py | 7 +++++-- .../pp_load_rules/test__convert_vertical_coords.py | 3 +++ .../fileformats/um/fast_load/test__convert_collation.py | 2 ++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/iris/analysis/__init__.py b/lib/iris/analysis/__init__.py index 5b7dff813d..5355899255 100644 --- a/lib/iris/analysis/__init__.py +++ b/lib/iris/analysis/__init__.py @@ -802,7 +802,7 @@ def post_process(self, collapsed_cube, data_result, coords, **kwargs): # order cube. for point in points: cube = collapsed_cube.copy() - coord = iris.coords.AuxCoord(point, long_name=coord_name) + coord = iris.coords.AuxCoord(point, long_name=coord_name, units="1") cube.add_aux_coord(coord) cubes.append(cube) diff --git a/lib/iris/tests/test_aggregate_by.py b/lib/iris/tests/test_aggregate_by.py index b4e1bad640..c9e7c34bb7 100644 --- a/lib/iris/tests/test_aggregate_by.py +++ b/lib/iris/tests/test_aggregate_by.py @@ -124,7 +124,9 @@ def setUp(self): ) model_level = iris.coords.DimCoord( - np.arange(z1_points.size), standard_name="model_level_number" + np.arange(z1_points.size), + standard_name="model_level_number", + units="1", ) self.cube_multi.add_aux_coord(self.coord_z1_multi, 0) diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index b1f67f32e3..3b98be6454 100644 --- a/lib/iris/tests/unit/cube/test_Cube.py +++ b/lib/iris/tests/unit/cube/test_Cube.py @@ -276,7 +276,7 @@ def test_byteorder_true(self): def test_cell_measures(self): cube = stock.simple_3d_w_multidim_coords() cm_a = iris.coords.CellMeasure( - np.zeros(cube.shape[-2:]), measure="area" + np.zeros(cube.shape[-2:]), measure="area", units="1" ) cube.add_cell_measure(cm_a, (1, 2)) cm_v = iris.coords.CellMeasure( @@ -1077,7 +1077,10 @@ def create_cube(lon_min, lon_max, bounds=False): 0, ) cube.add_aux_coord( - iris.coords.AuxCoord([1.0, 0.9, 0.8, 0.6], long_name="sigma", units="1"), 0 + iris.coords.AuxCoord( + [1.0, 0.9, 0.8, 0.6], long_name="sigma", units="1" + ), + 0, ) cube.add_dim_coord( iris.coords.DimCoord([-45, 0, 45], "latitude", units="degrees"), 1 diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py index 676335a3e8..2c63caa9e9 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py @@ -355,6 +355,7 @@ def _check_soil_level( lblev, long_name="soil_model_level_number", attributes={"positive": "down"}, + units="1", ) expect_result = [(coord, dim)] self.assertCoordsAndDimsListsMatch(coords_and_dims, expect_result) @@ -632,6 +633,7 @@ def _check( blev, long_name="sigma", bounds=np.vstack((brlev, brsvd1)).T, + units="1", ), dim, ) @@ -708,6 +710,7 @@ def _check( lblev, standard_name="model_level_number", attributes={"positive": "up"}, + units="1", ), dim, ) diff --git a/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py b/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py index 3dc6f96d48..e4086df030 100644 --- a/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py +++ b/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py @@ -335,6 +335,7 @@ def test_soil_level(self): points, long_name="soil_model_level_number", attributes={"positive": "down"}, + units="1", ) coords_and_dims = [(LONGITUDE, 2), (LATITUDE, 1), (level, (0,))] self.assertEqual(metadata.dim_coords_and_dims, coords_and_dims) @@ -416,6 +417,7 @@ def test_vertical_hybrid_height(self): [1, 2, 3], "model_level_number", attributes={"positive": "up"}, + units="1", ), (0,), ), From 23935cadea95948fc87983ffed102af0f88be1f3 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 21 May 2020 17:10:43 +0100 Subject: [PATCH 10/17] fix more tests --- lib/iris/analysis/__init__.py | 4 +++- lib/iris/tests/test_aggregate_by.py | 4 +++- lib/iris/tests/unit/analysis/test_PercentileAggregator.py | 8 ++++---- .../unit/analysis/test_WeightedPercentileAggregator.py | 8 ++++---- .../pp_load_rules/test__convert_vertical_coords.py | 1 + .../fileformats/um/fast_load/test__convert_collation.py | 1 + 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/iris/analysis/__init__.py b/lib/iris/analysis/__init__.py index 5355899255..0f4952b5a8 100644 --- a/lib/iris/analysis/__init__.py +++ b/lib/iris/analysis/__init__.py @@ -802,7 +802,9 @@ def post_process(self, collapsed_cube, data_result, coords, **kwargs): # order cube. for point in points: cube = collapsed_cube.copy() - coord = iris.coords.AuxCoord(point, long_name=coord_name, units="1") + coord = iris.coords.AuxCoord( + point, long_name=coord_name, units="1" + ) cube.add_aux_coord(coord) cubes.append(cube) diff --git a/lib/iris/tests/test_aggregate_by.py b/lib/iris/tests/test_aggregate_by.py index c9e7c34bb7..bc759f251d 100644 --- a/lib/iris/tests/test_aggregate_by.py +++ b/lib/iris/tests/test_aggregate_by.py @@ -89,7 +89,9 @@ def setUp(self): ) model_level = iris.coords.DimCoord( - np.arange(z_points.size), standard_name="model_level_number" + np.arange(z_points.size), + standard_name="model_level_number", + units="1", ) self.cube_single.add_aux_coord(self.coord_z_single, 0) diff --git a/lib/iris/tests/unit/analysis/test_PercentileAggregator.py b/lib/iris/tests/unit/analysis/test_PercentileAggregator.py index 2b2524795c..ef108cd105 100644 --- a/lib/iris/tests/unit/analysis/test_PercentileAggregator.py +++ b/lib/iris/tests/unit/analysis/test_PercentileAggregator.py @@ -71,7 +71,7 @@ def test_simple_single_point(self): self.assertIs(actual.data, data) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) def test_simple_multiple_points(self): @@ -89,7 +89,7 @@ def test_simple_multiple_points(self): self.assertArrayEqual(actual.data, expected) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) def test_multi_single_point(self): @@ -105,7 +105,7 @@ def test_multi_single_point(self): self.assertIs(actual.data, data) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) def test_multi_multiple_points(self): @@ -123,7 +123,7 @@ def test_multi_multiple_points(self): self.assertArrayEqual(actual.data, expected) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) diff --git a/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py b/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py index 1c59ded1fc..41345e581b 100644 --- a/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py +++ b/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py @@ -82,7 +82,7 @@ def test_simple_single_point(self): self.assertIs(actual.data, data) name = "weighted_percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) def test_simple_multiple_points(self): @@ -107,7 +107,7 @@ def test_simple_multiple_points(self): self.assertIs(actual[1], total_weights) name = "weighted_percentile_over_time" coord = actual[0].coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) def test_multi_single_point(self): @@ -123,7 +123,7 @@ def test_multi_single_point(self): self.assertIs(actual.data, data) name = "weighted_percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) def test_multi_multiple_points(self): @@ -141,7 +141,7 @@ def test_multi_multiple_points(self): self.assertArrayEqual(actual.data, expected) name = "weighted_percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name) + expected = AuxCoord(percent, long_name=name, units="1") self.assertEqual(coord, expected) diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py index 2c63caa9e9..a925c4abe5 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py @@ -737,6 +737,7 @@ def _check( bhlev, long_name="sigma", bounds=np.vstack((bhrlev, brsvd2)).T, + units="1" ), dim, ) diff --git a/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py b/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py index e4086df030..7ce0573d25 100644 --- a/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py +++ b/lib/iris/tests/unit/fileformats/um/fast_load/test__convert_collation.py @@ -439,6 +439,7 @@ def test_vertical_hybrid_height(self): [0.9994, 0.9979, 0.9957], long_name="sigma", bounds=[[1, 0.9989], [0.9989, 0.9970], [0.9970, 0.9944]], + units="1", ), (0,), ), From 892263ceb115f8f231700c5bfb75f044a350dcff Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 21 May 2020 17:21:56 +0100 Subject: [PATCH 11/17] fix more tests --- lib/iris/tests/test_concatenate.py | 54 ++++++++++++++++++------------ 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/iris/tests/test_concatenate.py b/lib/iris/tests/test_concatenate.py index bbe5f5eba2..d45a884a2f 100644 --- a/lib/iris/tests/test_concatenate.py +++ b/lib/iris/tests/test_concatenate.py @@ -66,52 +66,58 @@ def _make_cube( cube_data = np.empty((y_size, x_size), dtype=np.float32) cube_data[:] = data cube = iris.cube.Cube(cube_data) - coord = DimCoord(y_range, long_name="y") + coord = DimCoord(y_range, long_name="y", units="1") coord.guess_bounds() cube.add_dim_coord(coord, 0) - coord = DimCoord(x_range, long_name="x") + coord = DimCoord(x_range, long_name="x", units="1") coord.guess_bounds() cube.add_dim_coord(coord, 1) if aux is not None: aux = aux.split(",") if "y" in aux: - coord = AuxCoord(y_range * 10, long_name="y-aux") + coord = AuxCoord(y_range * 10, long_name="y-aux", units="1") cube.add_aux_coord(coord, (0,)) if "x" in aux: - coord = AuxCoord(x_range * 10, long_name="x-aux") + coord = AuxCoord(x_range * 10, long_name="x-aux", units="1") cube.add_aux_coord(coord, (1,)) if "xy" in aux: payload = np.arange(y_size * x_size, dtype=np.float32).reshape( y_size, x_size ) - coord = AuxCoord(payload * 100 + offset, long_name="xy-aux") + coord = AuxCoord( + payload * 100 + offset, long_name="xy-aux", units="1" + ) cube.add_aux_coord(coord, (0, 1)) if cell_measure is not None: cell_measure = cell_measure.split(",") if "y" in cell_measure: - cm = CellMeasure(y_range * 10, long_name="y-aux") + cm = CellMeasure(y_range * 10, long_name="y-aux", units="1") cube.add_cell_measure(cm, (0,)) if "x" in cell_measure: - cm = CellMeasure(x_range * 10, long_name="x-aux") + cm = CellMeasure(x_range * 10, long_name="x-aux", units="1") cube.add_cell_measure(cm, (1,)) if "xy" in cell_measure: payload = x_range + y_range[:, np.newaxis] - cm = CellMeasure(payload * 100 + offset, long_name="xy-aux") + cm = CellMeasure( + payload * 100 + offset, long_name="xy-aux", units="1" + ) cube.add_cell_measure(cm, (0, 1)) if ancil is not None: ancil = ancil.split(",") if "y" in ancil: - av = AncillaryVariable(y_range * 10, long_name="y-aux") + av = AncillaryVariable(y_range * 10, long_name="y-aux", units="1") cube.add_ancillary_variable(av, (0,)) if "x" in ancil: - av = AncillaryVariable(x_range * 10, long_name="x-aux") + av = AncillaryVariable(x_range * 10, long_name="x-aux", units="1") cube.add_ancillary_variable(av, (1,)) if "xy" in ancil: payload = x_range + y_range[:, np.newaxis] - av = AncillaryVariable(payload * 100 + offset, long_name="xy-aux") + av = AncillaryVariable( + payload * 100 + offset, long_name="xy-aux", units="1" + ) cube.add_ancillary_variable(av, (0, 1)) if scalar is not None: @@ -169,50 +175,56 @@ def _make_cube_3d(x, y, z, data, aux=None, offset=0): cube_data = np.empty((x_size, y_size, z_size), dtype=np.float32) cube_data[:] = data cube = iris.cube.Cube(cube_data) - coord = DimCoord(z_range, long_name="z") + coord = DimCoord(z_range, long_name="z", units="1") coord.guess_bounds() cube.add_dim_coord(coord, 0) - coord = DimCoord(y_range, long_name="y") + coord = DimCoord(y_range, long_name="y", units="1") coord.guess_bounds() cube.add_dim_coord(coord, 1) - coord = DimCoord(x_range, long_name="x") + coord = DimCoord(x_range, long_name="x", units="1") coord.guess_bounds() cube.add_dim_coord(coord, 2) if aux is not None: aux = aux.split(",") if "z" in aux: - coord = AuxCoord(z_range * 10, long_name="z-aux") + coord = AuxCoord(z_range * 10, long_name="z-aux", units="1") cube.add_aux_coord(coord, (0,)) if "y" in aux: - coord = AuxCoord(y_range * 10, long_name="y-aux") + coord = AuxCoord(y_range * 10, long_name="y-aux", units="1") cube.add_aux_coord(coord, (1,)) if "x" in aux: - coord = AuxCoord(x_range * 10, long_name="x-aux") + coord = AuxCoord(x_range * 10, long_name="x-aux", units="1") cube.add_aux_coord(coord, (2,)) if "xy" in aux: payload = np.arange(x_size * y_size, dtype=np.float32).reshape( y_size, x_size ) - coord = AuxCoord(payload + offset, long_name="xy-aux") + coord = AuxCoord(payload + offset, long_name="xy-aux", units="1") cube.add_aux_coord(coord, (1, 2)) if "xz" in aux: payload = np.arange(x_size * z_size, dtype=np.float32).reshape( z_size, x_size ) - coord = AuxCoord(payload * 10 + offset, long_name="xz-aux") + coord = AuxCoord( + payload * 10 + offset, long_name="xz-aux", units="1" + ) cube.add_aux_coord(coord, (0, 2)) if "yz" in aux: payload = np.arange(y_size * z_size, dtype=np.float32).reshape( z_size, y_size ) - coord = AuxCoord(payload * 100 + offset, long_name="yz-aux") + coord = AuxCoord( + payload * 100 + offset, long_name="yz-aux", units="1" + ) cube.add_aux_coord(coord, (0, 1)) if "xyz" in aux: payload = np.arange( x_size * y_size * z_size, dtype=np.float32 ).reshape(z_size, y_size, x_size) - coord = AuxCoord(payload * 1000 + offset, long_name="xyz-aux") + coord = AuxCoord( + payload * 1000 + offset, long_name="xyz-aux", units="1" + ) cube.add_aux_coord(coord, (0, 1, 2)) return cube From e3905ad3edf6c6a5ece976517cd074e11562fc2f Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Thu, 21 May 2020 17:44:14 +0100 Subject: [PATCH 12/17] fix more tests --- lib/iris/tests/results/coord_api/minimal.xml | 2 +- .../results/netcdf/netcdf_save_no_name.cdl | 1 - lib/iris/tests/test_coord_api.py | 4 ++-- lib/iris/tests/test_iterate.py | 13 ++++++++--- lib/iris/tests/test_netcdf.py | 22 +++++++++++-------- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/iris/tests/results/coord_api/minimal.xml b/lib/iris/tests/results/coord_api/minimal.xml index a35c93dc68..8f93fb6376 100644 --- a/lib/iris/tests/results/coord_api/minimal.xml +++ b/lib/iris/tests/results/coord_api/minimal.xml @@ -1,2 +1,2 @@ - + diff --git a/lib/iris/tests/results/netcdf/netcdf_save_no_name.cdl b/lib/iris/tests/results/netcdf/netcdf_save_no_name.cdl index e67316b2f7..be13f83fc8 100644 --- a/lib/iris/tests/results/netcdf/netcdf_save_no_name.cdl +++ b/lib/iris/tests/results/netcdf/netcdf_save_no_name.cdl @@ -6,7 +6,6 @@ variables: double unknown(dim0, dim1) ; unknown:coordinates = "unknown_scalar" ; double dim0(dim0) ; - dim0:units = "1" ; double dim1(dim1) ; dim1:units = "m" ; char unknown_scalar(string6) ; diff --git a/lib/iris/tests/test_coord_api.py b/lib/iris/tests/test_coord_api.py index 053b6b509b..d98d771210 100644 --- a/lib/iris/tests/test_coord_api.py +++ b/lib/iris/tests/test_coord_api.py @@ -247,7 +247,7 @@ def test_basic(self): "AuxCoord(" "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])," " standard_name=None," - " units=Unit('1')," + " units=Unit('unknown')," " attributes={'monty': 'python'})" ) self.assertEqual(result, str(b)) @@ -337,7 +337,7 @@ def test_basic(self): "DimCoord(" "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])," " standard_name=None," - " units=Unit('1')," + " units=Unit('unknown')," " attributes={'monty': 'python'})" ) self.assertEqual(result, str(b)) diff --git a/lib/iris/tests/test_iterate.py b/lib/iris/tests/test_iterate.py index 85f5943b8e..e53eede6f4 100644 --- a/lib/iris/tests/test_iterate.py +++ b/lib/iris/tests/test_iterate.py @@ -475,17 +475,24 @@ def test_izip_nd_non_ortho(self): def test_izip_nd_ortho(self): cube1 = iris.cube.Cube(np.zeros((5, 5, 5, 5, 5), dtype="f8")) cube1.add_dim_coord( - iris.coords.DimCoord(np.arange(5, dtype="i8"), long_name="z"), [0] + iris.coords.DimCoord( + np.arange(5, dtype="i8"), long_name="z", units="1" + ), + [0], ) cube1.add_aux_coord( iris.coords.AuxCoord( - np.arange(25, dtype="i8").reshape(5, 5), long_name="y" + np.arange(25, dtype="i8").reshape(5, 5), + long_name="y", + units="1", ), [1, 2], ) cube1.add_aux_coord( iris.coords.AuxCoord( - np.arange(25, dtype="i8").reshape(5, 5), long_name="x" + np.arange(25, dtype="i8").reshape(5, 5), + long_name="x", + units="1", ), [3, 4], ) diff --git a/lib/iris/tests/test_netcdf.py b/lib/iris/tests/test_netcdf.py index a550e1ed4b..e3d23727a6 100644 --- a/lib/iris/tests/test_netcdf.py +++ b/lib/iris/tests/test_netcdf.py @@ -608,10 +608,10 @@ def test_netcdf_multi_with_coords(self): def test_netcdf_multi_wtih_samedimcoord(self): time1 = iris.coords.DimCoord( - np.arange(10), standard_name="time", var_name="time" + np.arange(10), standard_name="time", var_name="time", units="1" ) time2 = iris.coords.DimCoord( - np.arange(20), standard_name="time", var_name="time" + np.arange(20), standard_name="time", var_name="time", units="1" ) self.cube4.add_dim_coord(time1, 0) @@ -630,11 +630,13 @@ def test_netcdf_multi_wtih_samedimcoord(self): def test_netcdf_multi_conflict_name_dup_coord(self): # Duplicate coordinates with modified variable names lookup. latitude1 = iris.coords.DimCoord( - np.arange(10), standard_name="latitude" + np.arange(10), standard_name="latitude", units="1" + ) + time2 = iris.coords.DimCoord( + np.arange(2), standard_name="time", units="1" ) - time2 = iris.coords.DimCoord(np.arange(2), standard_name="time") latitude2 = iris.coords.DimCoord( - np.arange(2), standard_name="latitude" + np.arange(2), standard_name="latitude", units="1" ) self.cube6.add_dim_coord(latitude1, 0) @@ -711,10 +713,10 @@ def test_netcdf_save_conflicting_aux(self): # Test saving CF-netCDF with multi-dimensional auxiliary coordinates, # with conflicts. self.cube4.add_aux_coord( - iris.coords.AuxCoord(np.arange(10), "time"), 0 + iris.coords.AuxCoord(np.arange(10), "time", units="1"), 0 ) self.cube6.add_aux_coord( - iris.coords.AuxCoord(np.arange(10, 20), "time"), 0 + iris.coords.AuxCoord(np.arange(10, 20), "time", units="1"), 0 ) cubes = iris.cube.CubeList([self.cube4, self.cube6]) @@ -811,9 +813,11 @@ def test_netcdf_save_conflicting_names(self): # Test saving CF-netCDF with a dimension name corresponding to # an existing variable name (conflict). self.cube4.add_dim_coord( - iris.coords.DimCoord(np.arange(10), "time"), 0 + iris.coords.DimCoord(np.arange(10), "time", units="1"), 0 + ) + self.cube6.add_aux_coord( + iris.coords.AuxCoord(1, "time", units="1"), None ) - self.cube6.add_aux_coord(iris.coords.AuxCoord(1, "time"), None) cubes = iris.cube.CubeList([self.cube4, self.cube6]) with self.temp_filename(suffix=".nc") as file_out: From 0316a00e73869c866fd616b69bc0a60ec19a3519 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Fri, 22 May 2020 09:35:23 +0100 Subject: [PATCH 13/17] blacken --- lib/iris/tests/integration/test_netcdf.py | 4 +++- lib/iris/tests/test_plot.py | 2 +- .../interpolation/test_RectilinearInterpolator.py | 12 +++++++++--- .../pp_load_rules/test__convert_vertical_coords.py | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/iris/tests/integration/test_netcdf.py b/lib/iris/tests/integration/test_netcdf.py index a8363e6d5e..267e5beb50 100644 --- a/lib/iris/tests/integration/test_netcdf.py +++ b/lib/iris/tests/integration/test_netcdf.py @@ -81,7 +81,9 @@ def test_hybrid_height_and_pressure(self): 1200.0, long_name="level_pressure", units="hPa" ) ) - cube.add_aux_coord(iris.coords.DimCoord(0.5, long_name="other sigma", units='1')) + cube.add_aux_coord( + iris.coords.DimCoord(0.5, long_name="other sigma", units="1") + ) cube.add_aux_coord( iris.coords.DimCoord( 1000.0, long_name="surface_air_pressure", units="hPa" diff --git a/lib/iris/tests/test_plot.py b/lib/iris/tests/test_plot.py index 742bfb55da..600801312f 100644 --- a/lib/iris/tests/test_plot.py +++ b/lib/iris/tests/test_plot.py @@ -875,7 +875,7 @@ def test_non_cube_coordinate(self): pts, standard_name="model_level_number", attributes={"positive": "up"}, - units="1" + units="1", ) self.draw("contourf", cube, coords=["grid_latitude", x]) diff --git a/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py b/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py index 0f66b427bd..fa4ca8b608 100644 --- a/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py +++ b/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py @@ -34,9 +34,15 @@ class ThreeDimCube(tests.IrisTest): def setUp(self): cube = stock.simple_3d_w_multidim_coords() - cube.add_aux_coord(iris.coords.DimCoord(np.arange(2), "height", units="1"), 0) - cube.add_dim_coord(iris.coords.DimCoord(np.arange(3), "latitude", units="1"), 1) - cube.add_dim_coord(iris.coords.DimCoord(np.arange(4), "longitude", units="1"), 2) + cube.add_aux_coord( + iris.coords.DimCoord(np.arange(2), "height", units="1"), 0 + ) + cube.add_dim_coord( + iris.coords.DimCoord(np.arange(3), "latitude", units="1"), 1 + ) + cube.add_dim_coord( + iris.coords.DimCoord(np.arange(4), "longitude", units="1"), 2 + ) self.data = np.arange(24).reshape(2, 3, 4).astype(np.float32) cube.data = self.data self.cube = cube diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py index a925c4abe5..b9a652c397 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__convert_vertical_coords.py @@ -737,7 +737,7 @@ def _check( bhlev, long_name="sigma", bounds=np.vstack((bhrlev, brsvd2)).T, - units="1" + units="1", ), dim, ) From 4028780e0f93ecc3460e213b5972eb835298f3be Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Fri, 22 May 2020 11:14:21 +0100 Subject: [PATCH 14/17] change units in percentile aggregation to "percent" --- lib/iris/analysis/__init__.py | 2 +- lib/iris/tests/unit/analysis/test_PercentileAggregator.py | 8 ++++---- .../unit/analysis/test_WeightedPercentileAggregator.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/iris/analysis/__init__.py b/lib/iris/analysis/__init__.py index 0f4952b5a8..4740d4e342 100644 --- a/lib/iris/analysis/__init__.py +++ b/lib/iris/analysis/__init__.py @@ -803,7 +803,7 @@ def post_process(self, collapsed_cube, data_result, coords, **kwargs): for point in points: cube = collapsed_cube.copy() coord = iris.coords.AuxCoord( - point, long_name=coord_name, units="1" + point, long_name=coord_name, units="percent" ) cube.add_aux_coord(coord) cubes.append(cube) diff --git a/lib/iris/tests/unit/analysis/test_PercentileAggregator.py b/lib/iris/tests/unit/analysis/test_PercentileAggregator.py index ef108cd105..cffac86291 100644 --- a/lib/iris/tests/unit/analysis/test_PercentileAggregator.py +++ b/lib/iris/tests/unit/analysis/test_PercentileAggregator.py @@ -71,7 +71,7 @@ def test_simple_single_point(self): self.assertIs(actual.data, data) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) def test_simple_multiple_points(self): @@ -89,7 +89,7 @@ def test_simple_multiple_points(self): self.assertArrayEqual(actual.data, expected) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) def test_multi_single_point(self): @@ -105,7 +105,7 @@ def test_multi_single_point(self): self.assertIs(actual.data, data) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) def test_multi_multiple_points(self): @@ -123,7 +123,7 @@ def test_multi_multiple_points(self): self.assertArrayEqual(actual.data, expected) name = "percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) diff --git a/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py b/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py index 41345e581b..878708e48a 100644 --- a/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py +++ b/lib/iris/tests/unit/analysis/test_WeightedPercentileAggregator.py @@ -82,7 +82,7 @@ def test_simple_single_point(self): self.assertIs(actual.data, data) name = "weighted_percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) def test_simple_multiple_points(self): @@ -107,7 +107,7 @@ def test_simple_multiple_points(self): self.assertIs(actual[1], total_weights) name = "weighted_percentile_over_time" coord = actual[0].coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) def test_multi_single_point(self): @@ -123,7 +123,7 @@ def test_multi_single_point(self): self.assertIs(actual.data, data) name = "weighted_percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) def test_multi_multiple_points(self): @@ -141,7 +141,7 @@ def test_multi_multiple_points(self): self.assertArrayEqual(actual.data, expected) name = "weighted_percentile_over_time" coord = actual.coord(name) - expected = AuxCoord(percent, long_name=name, units="1") + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) From 767c7d2ef17b33645de1944c60f557810be193f8 Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Fri, 22 May 2020 11:37:59 +0100 Subject: [PATCH 15/17] fix tests --- lib/iris/tests/results/analysis/first_quartile_foo_1d.cml | 2 +- .../results/analysis/first_quartile_foo_1d_fast_percentile.cml | 2 +- lib/iris/tests/results/analysis/first_quartile_foo_2d.cml | 2 +- .../results/analysis/first_quartile_foo_2d_fast_percentile.cml | 2 +- lib/iris/tests/results/analysis/first_quartile_foo_bar_2d.cml | 2 +- .../analysis/first_quartile_foo_bar_2d_fast_percentile.cml | 2 +- lib/iris/tests/results/analysis/last_quartile_foo_3d_masked.cml | 2 +- .../tests/results/analysis/last_quartile_foo_3d_notmasked.cml | 2 +- .../analysis/last_quartile_foo_3d_notmasked_fast_percentile.cml | 2 +- lib/iris/tests/results/analysis/third_quartile_foo_1d.cml | 2 +- .../results/analysis/third_quartile_foo_1d_fast_percentile.cml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/iris/tests/results/analysis/first_quartile_foo_1d.cml b/lib/iris/tests/results/analysis/first_quartile_foo_1d.cml index a9e69c291e..f027f2d9f8 100644 --- a/lib/iris/tests/results/analysis/first_quartile_foo_1d.cml +++ b/lib/iris/tests/results/analysis/first_quartile_foo_1d.cml @@ -6,7 +6,7 @@ - + diff --git a/lib/iris/tests/results/analysis/first_quartile_foo_1d_fast_percentile.cml b/lib/iris/tests/results/analysis/first_quartile_foo_1d_fast_percentile.cml index a9e69c291e..f027f2d9f8 100644 --- a/lib/iris/tests/results/analysis/first_quartile_foo_1d_fast_percentile.cml +++ b/lib/iris/tests/results/analysis/first_quartile_foo_1d_fast_percentile.cml @@ -6,7 +6,7 @@ - + diff --git a/lib/iris/tests/results/analysis/first_quartile_foo_2d.cml b/lib/iris/tests/results/analysis/first_quartile_foo_2d.cml index 34c9e746f6..1bc809ce63 100644 --- a/lib/iris/tests/results/analysis/first_quartile_foo_2d.cml +++ b/lib/iris/tests/results/analysis/first_quartile_foo_2d.cml @@ -11,7 +11,7 @@ - + diff --git a/lib/iris/tests/results/analysis/first_quartile_foo_2d_fast_percentile.cml b/lib/iris/tests/results/analysis/first_quartile_foo_2d_fast_percentile.cml index 34c9e746f6..1bc809ce63 100644 --- a/lib/iris/tests/results/analysis/first_quartile_foo_2d_fast_percentile.cml +++ b/lib/iris/tests/results/analysis/first_quartile_foo_2d_fast_percentile.cml @@ -11,7 +11,7 @@ - + diff --git a/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d.cml b/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d.cml index b3f135cede..cadd1e8b65 100644 --- a/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d.cml +++ b/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d.cml @@ -9,7 +9,7 @@ - + diff --git a/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d_fast_percentile.cml b/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d_fast_percentile.cml index b3f135cede..cadd1e8b65 100644 --- a/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d_fast_percentile.cml +++ b/lib/iris/tests/results/analysis/first_quartile_foo_bar_2d_fast_percentile.cml @@ -9,7 +9,7 @@ - + diff --git a/lib/iris/tests/results/analysis/last_quartile_foo_3d_masked.cml b/lib/iris/tests/results/analysis/last_quartile_foo_3d_masked.cml index 80fab0e150..059541e208 100644 --- a/lib/iris/tests/results/analysis/last_quartile_foo_3d_masked.cml +++ b/lib/iris/tests/results/analysis/last_quartile_foo_3d_masked.cml @@ -9,7 +9,7 @@ - + diff --git a/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked.cml b/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked.cml index 80fab0e150..059541e208 100644 --- a/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked.cml +++ b/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked.cml @@ -9,7 +9,7 @@ - + diff --git a/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked_fast_percentile.cml b/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked_fast_percentile.cml index 80fab0e150..059541e208 100644 --- a/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked_fast_percentile.cml +++ b/lib/iris/tests/results/analysis/last_quartile_foo_3d_notmasked_fast_percentile.cml @@ -9,7 +9,7 @@ - + diff --git a/lib/iris/tests/results/analysis/third_quartile_foo_1d.cml b/lib/iris/tests/results/analysis/third_quartile_foo_1d.cml index b14c51cfb3..038e7c8668 100644 --- a/lib/iris/tests/results/analysis/third_quartile_foo_1d.cml +++ b/lib/iris/tests/results/analysis/third_quartile_foo_1d.cml @@ -6,7 +6,7 @@ - + diff --git a/lib/iris/tests/results/analysis/third_quartile_foo_1d_fast_percentile.cml b/lib/iris/tests/results/analysis/third_quartile_foo_1d_fast_percentile.cml index b14c51cfb3..038e7c8668 100644 --- a/lib/iris/tests/results/analysis/third_quartile_foo_1d_fast_percentile.cml +++ b/lib/iris/tests/results/analysis/third_quartile_foo_1d_fast_percentile.cml @@ -6,7 +6,7 @@ - + From 4ead626ed879ea380af5046ed3442165637dac5f Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Mon, 1 Jun 2020 11:09:46 +0100 Subject: [PATCH 16/17] address review comments --- lib/iris/tests/stock/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/iris/tests/stock/__init__.py b/lib/iris/tests/stock/__init__.py index 1588f464e6..41979fad94 100644 --- a/lib/iris/tests/stock/__init__.py +++ b/lib/iris/tests/stock/__init__.py @@ -834,8 +834,8 @@ def jan_offset(day, year): units="days since 1970-01-01 00:00:00-00", climatological=True, ) - lon_dim = DimCoord(lon, standard_name="longitude", units="1") - lat_dim = DimCoord(lat, standard_name="latitude", units="1") + lon_dim = DimCoord(lon, standard_name="longitude", units="degrees") + lat_dim = DimCoord(lat, standard_name="latitude", units="degrees") data_shape = (len(time_points), len(lat), len(lon)) values = np.zeros(shape=data_shape, dtype=np.int8) From e0dca256eece0759a8b3d8e50d6ac9ba0a96392f Mon Sep 17 00:00:00 2001 From: "stephen.worsley" Date: Mon, 1 Jun 2020 11:51:14 +0100 Subject: [PATCH 17/17] fix tests --- .../climatology/TestClimatology/reference_simpledata.cdl | 4 ++-- .../unit/fileformats/netcdf/Saver/write/with_climatology.cdl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/iris/tests/results/integration/climatology/TestClimatology/reference_simpledata.cdl b/lib/iris/tests/results/integration/climatology/TestClimatology/reference_simpledata.cdl index 1740926645..1f6bc36832 100644 --- a/lib/iris/tests/results/integration/climatology/TestClimatology/reference_simpledata.cdl +++ b/lib/iris/tests/results/integration/climatology/TestClimatology/reference_simpledata.cdl @@ -17,11 +17,11 @@ variables: double time_climatology(time, bnds) ; double latitude(latitude) ; latitude:axis = "Y" ; - latitude:units = "1" ; + latitude:units = "degrees_north" ; latitude:standard_name = "latitude" ; double longitude(longitude) ; longitude:axis = "X" ; - longitude:units = "1" ; + longitude:units = "degrees_east" ; longitude:standard_name = "longitude" ; // global attributes: diff --git a/lib/iris/tests/results/unit/fileformats/netcdf/Saver/write/with_climatology.cdl b/lib/iris/tests/results/unit/fileformats/netcdf/Saver/write/with_climatology.cdl index 3646627746..3c1033c17e 100644 --- a/lib/iris/tests/results/unit/fileformats/netcdf/Saver/write/with_climatology.cdl +++ b/lib/iris/tests/results/unit/fileformats/netcdf/Saver/write/with_climatology.cdl @@ -17,10 +17,10 @@ variables: double time_climatology(time, bnds) ; double latitude(latitude) ; latitude:axis = "Y" ; - latitude:units = "1" ; + latitude:units = "degrees_north" ; latitude:standard_name = "latitude" ; double longitude(longitude) ; longitude:axis = "X" ; - longitude:units = "1" ; + longitude:units = "degrees_east" ; longitude:standard_name = "longitude" ; }