From 3fdccacdfd84bcbdd24dd50baa902d9911c596e8 Mon Sep 17 00:00:00 2001 From: stephenworsley <49274989+stephenworsley@users.noreply.github.com> Date: Mon, 1 Jun 2020 12:27:23 +0100 Subject: [PATCH] Change default units to "unknown" for all DimensionalMetadata (#3713) --- .../Meteorology/lagged_ensemble.py | 2 +- docs/iris/src/userguide/navigating_a_cube.rst | 2 +- lib/iris/analysis/__init__.py | 4 +- lib/iris/coords.py | 12 ++--- lib/iris/fileformats/pp_load_rules.py | 18 +++++-- lib/iris/tests/integration/test_netcdf.py | 4 +- lib/iris/tests/integration/test_pp.py | 14 +++-- .../analysis/first_quartile_foo_1d.cml | 2 +- .../first_quartile_foo_1d_fast_percentile.cml | 2 +- .../analysis/first_quartile_foo_2d.cml | 2 +- .../first_quartile_foo_2d_fast_percentile.cml | 2 +- .../analysis/first_quartile_foo_bar_2d.cml | 2 +- ...st_quartile_foo_bar_2d_fast_percentile.cml | 2 +- .../analysis/last_quartile_foo_3d_masked.cml | 2 +- .../last_quartile_foo_3d_notmasked.cml | 2 +- ...rtile_foo_3d_notmasked_fast_percentile.cml | 2 +- .../analysis/third_quartile_foo_1d.cml | 2 +- .../third_quartile_foo_1d_fast_percentile.cml | 2 +- lib/iris/tests/results/coord_api/minimal.xml | 2 +- .../TestClimatology/reference_simpledata.cdl | 4 +- .../results/netcdf/netcdf_save_no_name.cdl | 1 - .../netcdf/Saver/write/with_climatology.cdl | 4 +- lib/iris/tests/stock/__init__.py | 4 +- lib/iris/tests/test_aggregate_by.py | 8 ++- lib/iris/tests/test_concatenate.py | 54 +++++++++++-------- lib/iris/tests/test_coord_api.py | 4 +- lib/iris/tests/test_iterate.py | 13 +++-- lib/iris/tests/test_netcdf.py | 22 ++++---- lib/iris/tests/test_plot.py | 1 + .../test_RectilinearInterpolator.py | 12 +++-- .../regrid/test_RectilinearRegridder.py | 2 +- .../analysis/test_PercentileAggregator.py | 8 +-- .../test_WeightedPercentileAggregator.py | 8 +-- .../aux_factory/test_HybridPressureFactory.py | 4 +- .../coord_categorisation/test_add_hour.py | 2 +- lib/iris/tests/unit/cube/test_Cube.py | 7 ++- lib/iris/tests/unit/cube/test_CubeList.py | 14 ++--- .../unit/fileformats/netcdf/test_Saver.py | 2 +- .../pp_load_rules/test__all_other_rules.py | 2 +- ...est__convert_scalar_pseudo_level_coords.py | 3 +- ...test__convert_scalar_realization_coords.py | 2 +- .../test__convert_vertical_coords.py | 6 +++ .../um/fast_load/test__convert_collation.py | 3 ++ 43 files changed, 170 insertions(+), 100 deletions(-) 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) 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') diff --git a/lib/iris/analysis/__init__.py b/lib/iris/analysis/__init__.py index 5b7dff813d..4740d4e342 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) + coord = iris.coords.AuxCoord( + point, long_name=coord_name, units="percent" + ) cube.add_aux_coord(coord) cubes.append(cube) 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, diff --git a/lib/iris/fileformats/pp_load_rules.py b/lib/iris/fileformats/pp_load_rules.py index c0a4081970..bee33927f6 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)) @@ -197,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): @@ -235,6 +237,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 +246,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 +271,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 +281,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)] @@ -846,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 @@ -1078,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/integration/test_netcdf.py b/lib/iris/tests/integration/test_netcdf.py index 8c6e0f6659..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")) + 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" 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 @@ - + 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/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/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/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" ; } diff --git a/lib/iris/tests/stock/__init__.py b/lib/iris/tests/stock/__init__.py index 9bb1c4626f..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") - lat_dim = DimCoord(lat, standard_name="latitude") + 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) diff --git a/lib/iris/tests/test_aggregate_by.py b/lib/iris/tests/test_aggregate_by.py index b4e1bad640..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) @@ -124,7 +126,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/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 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: diff --git a/lib/iris/tests/test_plot.py b/lib/iris/tests/test_plot.py index 04418d8d40..600801312f 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/analysis/interpolation/test_RectilinearInterpolator.py b/lib/iris/tests/unit/analysis/interpolation/test_RectilinearInterpolator.py index d1eaf71030..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"), 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/analysis/test_PercentileAggregator.py b/lib/iris/tests/unit/analysis/test_PercentileAggregator.py index 2b2524795c..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) + 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) + 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) + 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) + 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 1c59ded1fc..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) + 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) + 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) + 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) + expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected) diff --git a/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py b/lib/iris/tests/unit/aux_factory/test_HybridPressureFactory.py index 789b1d61d5..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") + 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" ) 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) diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index 9c03f0f4d4..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"), 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..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 @@ -210,6 +210,7 @@ def _check_depth( lblev, standard_name="model_level_number", attributes={"positive": "down"}, + units="1", ), dim, ) @@ -354,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) @@ -604,6 +606,7 @@ def _check( lblev, standard_name="model_level_number", attributes={"positive": "up"}, + units="1", ), dim, ) @@ -630,6 +633,7 @@ def _check( blev, long_name="sigma", bounds=np.vstack((brlev, brsvd1)).T, + units="1", ), dim, ) @@ -706,6 +710,7 @@ def _check( lblev, standard_name="model_level_number", attributes={"positive": "up"}, + units="1", ), dim, ) @@ -732,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 3dc6f96d48..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 @@ -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,), ), @@ -437,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,), ),