diff --git a/docs/src/further_topics/metadata.rst b/docs/src/further_topics/metadata.rst index 4c55047d4c..a564b2ba68 100644 --- a/docs/src/further_topics/metadata.rst +++ b/docs/src/further_topics/metadata.rst @@ -120,7 +120,7 @@ For example, given the following :class:`~iris.cube.Cube`, forecast_reference_time 1859-09-01 06:00:00 height 1.5 m Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' Model scenario 'A1B' diff --git a/docs/src/further_topics/ugrid/operations.rst b/docs/src/further_topics/ugrid/operations.rst index a4e0e593d7..73dadda181 100644 --- a/docs/src/further_topics/ugrid/operations.rst +++ b/docs/src/further_topics/ugrid/operations.rst @@ -566,8 +566,8 @@ Here's another example using a global cubed-sphere data set: Auxiliary coordinates: time x - Cell methods: - mean time (300 s) - mean time_counter + 0 time: mean (interval: 300 s) + 1 time_counter: mean Attributes: Conventions UGRID description Created by xios @@ -687,7 +687,7 @@ mesh, we then reconstruct a :class:`~iris.experimental.ugrid.Mesh` from the Auxiliary coordinates: time x - Cell methods: - point time + 0 time: point Attributes: Conventions UGRID description Created by xios @@ -744,7 +744,7 @@ mesh, we then reconstruct a :class:`~iris.experimental.ugrid.Mesh` from the Auxiliary coordinates: time x - Cell methods: - point time + 0 time: point Attributes: Conventions UGRID description Created by xios @@ -815,8 +815,8 @@ with the Auxiliary coordinates: time x - Cell methods: - mean time (300 s) - mean time_counter + 0 time: mean (interval: 300 s) + 1 time_counter: mean Attributes: Conventions UGRID description Created by xios @@ -851,8 +851,8 @@ with the Auxiliary coordinates: time x - - Cell methods: - mean time (300 s) - mean time_counter + 0 time: mean (interval: 300 s) + 1 time_counter: mean Attributes: Conventions UGRID description Created by xios @@ -894,8 +894,8 @@ previously initialised regridder: Auxiliary coordinates: time x - Cell methods: - mean time (300 s) - mean time_counter + 0 time: mean (interval: 300 s) + 1 time_counter: mean Attributes: Conventions UGRID description Created by xios @@ -917,8 +917,8 @@ previously initialised regridder: Auxiliary coordinates: time x - - Cell methods: - mean time (300 s) - mean time_counter + 0 time: mean (interval: 300 s) + 1 time_counter: mean Attributes: Conventions UGRID description Created by xios diff --git a/docs/src/further_topics/ugrid/other_meshes.rst b/docs/src/further_topics/ugrid/other_meshes.rst index 38abeeca03..82eaaacc6a 100644 --- a/docs/src/further_topics/ugrid/other_meshes.rst +++ b/docs/src/further_topics/ugrid/other_meshes.rst @@ -44,8 +44,8 @@ as the **nodes** when creating the Iris latitude - x longitude - x Cell methods: - mean where sea area - mean time + 0 area: mean where sea + 1 time: mean Attributes: grid 'FESOM 1.4 (unstructured grid in the horizontal with 126859 wet nodes;... ... @@ -77,8 +77,8 @@ as the **nodes** when creating the Iris latitude - x longitude - x Cell methods: - mean where sea area - mean time + 0 area: mean where sea + 1 time: mean Attributes: grid 'FESOM 1.4 (unstructured grid in the horizontal with 126859 wet nodes;... ... @@ -275,7 +275,7 @@ dimensions into a single mesh dimension. Since Iris cubes don't support a "resh depth 4.999938 m, bound=(0.0, 10.0) m time 0001-01-01 12:00:00 Cell methods: - mean time + 0 time: mean Attributes: Conventions 'CF-1.5' @@ -350,7 +350,7 @@ dimensions into a single mesh dimension. Since Iris cubes don't support a "resh name unknown location face Cell methods: - mean time + 0 time: mean Attributes: Conventions 'CF-1.5' diff --git a/docs/src/userguide/cube_statistics.rst b/docs/src/userguide/cube_statistics.rst index 9dc21f91b5..fb389a5229 100644 --- a/docs/src/userguide/cube_statistics.rst +++ b/docs/src/userguide/cube_statistics.rst @@ -86,7 +86,7 @@ we can pass the coordinate name and the aggregation definition to the model_level_number 10, bound=(1, 19) sigma 0.92292976, bound=(0.8458596, 1.0) Cell methods: - mean model_level_number + 0 model_level_number: mean Attributes: STASH m01s00i004 source 'Data from Met Office Unified Model' @@ -145,7 +145,7 @@ These areas can now be passed to the ``collapsed`` method as weights: grid_longitude 358.74948 degrees, bound=(357.48724, 360.01172) degrees surface_altitude 399.625 m, bound=(-14.0, 813.25) m Cell methods: - mean grid_longitude, grid_latitude + 0 grid_longitude: grid_latitude: mean Attributes: STASH m01s00i004 source 'Data from Met Office Unified Model' @@ -193,7 +193,7 @@ the units of the resulting cube are multiplied by an area unit: grid_longitude 358.74948 degrees, bound=(357.48724, 360.01172) degrees surface_altitude 399.625 m, bound=(-14.0, 813.25) m Cell methods: - sum grid_longitude, grid_latitude + 0 grid_longitude: grid_latitude: sum Attributes: STASH m01s00i004 source 'Data from Met Office Unified Model' @@ -276,7 +276,7 @@ Printing this cube now shows that two extra coordinates exist on the cube: Scalar coordinates: forecast_period 0 hours Cell methods: - mean month, year + 0 month: year: mean Attributes: Conventions 'CF-1.5' STASH m01s00i024 @@ -418,8 +418,8 @@ The following example shows a weighted sum (notice the change of the units): Scalar coordinates: forecast_period 0 hours Cell methods: - mean month, year - sum clim_season + 0 month: year: mean + 1 clim_season: sum Attributes: Conventions 'CF-1.5' STASH m01s00i024 diff --git a/docs/src/userguide/interpolation_and_regridding.rst b/docs/src/userguide/interpolation_and_regridding.rst index deae4427ed..cba7d778d5 100644 --- a/docs/src/userguide/interpolation_and_regridding.rst +++ b/docs/src/userguide/interpolation_and_regridding.rst @@ -75,8 +75,8 @@ Let's take the air temperature cube we've seen previously: pressure 1000.0 hPa time 1998-12-01 00:00:00, bound=(1994-12-01 00:00:00, 1998-12-01 00:00:00) Cell methods: - mean within years time - mean over years time + 0 time: mean within years + 1 time: mean over years Attributes: STASH m01s16i203 source 'Data from Met Office Unified Model' @@ -94,8 +94,8 @@ We can interpolate specific values from the coordinates of the cube: pressure 1000.0 hPa time 1998-12-01 00:00:00, bound=(1994-12-01 00:00:00, 1998-12-01 00:00:00) Cell methods: - mean within years time - mean over years time + 0 time: mean within years + 1 time: mean over years Attributes: STASH m01s16i203 source 'Data from Met Office Unified Model' diff --git a/docs/src/userguide/loading_iris_cubes.rst b/docs/src/userguide/loading_iris_cubes.rst index 33ad932d70..b71f033c30 100644 --- a/docs/src/userguide/loading_iris_cubes.rst +++ b/docs/src/userguide/loading_iris_cubes.rst @@ -234,7 +234,7 @@ A single cube is loaded in the following example:: longitude - x ... Cell methods: - mean time + 0 time: mean However, when attempting to load data which would result in anything other than one cube, an exception is raised:: diff --git a/lib/iris/_representation/cube_summary.py b/lib/iris/_representation/cube_summary.py index 6b0d4cf0f3..4e0fcfb1ea 100644 --- a/lib/iris/_representation/cube_summary.py +++ b/lib/iris/_representation/cube_summary.py @@ -264,13 +264,11 @@ def __init__(self, title, cell_methods): self.names = [] self.values = [] self.contents = [] - for method in cell_methods: - name = method.method - # Remove "method: " from the front of the string, leaving the value. - value = str(method)[len(name + ": ") :] - self.names.append(name) + for index, method in enumerate(cell_methods): + value = str(method) + self.names.append(str(index)) self.values.append(value) - content = "{}: {}".format(name, value) + content = "{}: {}".format(index, value) self.contents.append(content) diff --git a/lib/iris/common/resolve.py b/lib/iris/common/resolve.py index a0c97dfc00..19e4e44fc6 100644 --- a/lib/iris/common/resolve.py +++ b/lib/iris/common/resolve.py @@ -144,7 +144,7 @@ class Resolve: forecast_reference_time 1859-09-01 06:00:00 height 1.5 m Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' Model scenario 'A1B' @@ -162,7 +162,7 @@ class Resolve: height 1.5 m time 1860-06-01 00:00:00, bound=(1859-12-01 00:00:00, 1860-12-01 00:00:00) Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' Model scenario 'E1' @@ -185,7 +185,7 @@ class Resolve: forecast_reference_time 1859-09-01 06:00:00 height 1.5 m Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' STASH m01s03i236 @@ -2542,7 +2542,7 @@ def mapped(self): forecast_reference_time 1859-09-01 06:00:00 height 1.5 m Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' Model scenario 'A1B' @@ -2559,7 +2559,7 @@ def mapped(self): height 1.5 m time 1860-06-01 00:00:00, bound=(1859-12-01 00:00:00, 1860-12-01 00:00:00) Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' Model scenario 'E1' @@ -2610,7 +2610,7 @@ def shape(self): forecast_reference_time 1859-09-01 06:00:00 height 1.5 m Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' Model scenario 'A1B' @@ -2627,7 +2627,7 @@ def shape(self): height 1.5 m time 1860-06-01 00:00:00, bound=(1859-12-01 00:00:00, 1860-12-01 00:00:00) Cell methods: - mean time (6 hour) + 0 time: mean (interval: 6 hour) Attributes: Conventions 'CF-1.5' Model scenario 'E1' diff --git a/lib/iris/coords.py b/lib/iris/coords.py index 91bb786ae8..4245fe55ef 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -13,7 +13,7 @@ from collections.abc import Container, Iterator import copy from functools import lru_cache -from itertools import chain, zip_longest +from itertools import zip_longest import operator import warnings import zlib @@ -3078,23 +3078,23 @@ def __init__(self, method, coords=None, intervals=None, comments=None): def __str__(self): """Return a custom string representation of CellMethod""" # Group related coord names intervals and comments together - cell_components = zip_longest( - self.coord_names, self.intervals, self.comments, fillvalue="" + coord_string = " ".join([f"{coord}:" for coord in self.coord_names]) + method_string = str(self.method) + interval_string = " ".join( + [f"interval: {interval}" for interval in self.intervals] ) + comment_string = " ".join([comment for comment in self.comments]) - collection_summaries = [] - cm_summary = "%s: " % self.method - - for coord_name, interval, comment in cell_components: - other_info = ", ".join(filter(None, chain((interval, comment)))) - if other_info: - coord_summary = "%s (%s)" % (coord_name, other_info) - else: - coord_summary = "%s" % coord_name + if interval_string and comment_string: + comment_string = "".join( + [f" comment: {comment}" for comment in self.comments] + ) + cm_summary = f"{coord_string} {method_string}" - collection_summaries.append(coord_summary) + if interval_string or comment_string: + cm_summary += f" ({interval_string}{comment_string})" - return cm_summary + ", ".join(collection_summaries) + return cm_summary def __add__(self, other): # Disable the default tuple behaviour of tuple concatenation diff --git a/lib/iris/cube.py b/lib/iris/cube.py index fcd7b5b828..b09f61aefb 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -788,8 +788,8 @@ class Cube(CFVariableMixin): time \ 1998-12-01 00:00:00, bound=(1994-12-01 00:00:00, 1998-12-01 00:00:00) Cell methods: - mean within years time - mean over years time + 0 time: mean within years + 1 time: mean over years Attributes: STASH m01s16i203 source 'Data from Met Office Unified Model' @@ -3775,8 +3775,8 @@ def collapsed(self, coords, aggregator, **kwargs): longitude \ 180.0 degrees, bound=(0.0, 360.0) degrees Cell methods: - mean month, year - mean longitude + 0 month: year: mean + 1 longitude: mean Attributes: Conventions 'CF-1.5' STASH m01s00i024 @@ -4040,8 +4040,8 @@ def aggregated_by( Scalar coordinates: forecast_period 0 hours Cell methods: - mean month, year - mean year + 0 month: year: mean + 1 year: mean Attributes: Conventions 'CF-1.5' STASH m01s00i024 @@ -4349,7 +4349,7 @@ def rolling_window(self, coord, aggregator, window, **kwargs): forecast_reference_time 2011-07-23 00:00:00 realization 10 Cell methods: - mean time (1 hour) + 0 time: mean (interval: 1 hour) Attributes: STASH m01s00i024 source \ @@ -4374,8 +4374,8 @@ def rolling_window(self, coord, aggregator, window, **kwargs): forecast_reference_time 2011-07-23 00:00:00 realization 10 Cell methods: - mean time (1 hour) - mean time + 0 time: mean (interval: 1 hour) + 1 time: mean Attributes: STASH m01s00i024 source \ diff --git a/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt b/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt index ffb6a62daf..fa1cd1c04c 100644 --- a/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt +++ b/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt @@ -8,10 +8,10 @@ air_temperature / (K) (latitude: 73; longitude: 96) pressure 1000.0 hPa time 1998-12-01 00:00:00 Cell methods: - mean longitude (6 minutes, This is a test comment), latitude (12 minutes) - average longitude (6 minutes, This is another test comment), latitude (15 minutes, This is another comment) - average longitude, latitude - percentile longitude (6 minutes, This is another test comment) + 0 longitude: latitude: mean (interval: 6 minutes interval: 12 minutes comment: This is a test comment) + 1 longitude: latitude: average (interval: 6 minutes interval: 15 minutes comment: This is another test comment comment: This is another comment) + 2 longitude: latitude: average + 3 longitude: percentile (interval: 6 minutes comment: This is another test comment) Attributes: STASH m01s16i203 source 'Data from Met Office Unified Model' \ No newline at end of file diff --git a/lib/iris/tests/unit/coords/test_CellMethod.py b/lib/iris/tests/unit/coords/test_CellMethod.py index b10fd41834..21b309a32b 100644 --- a/lib/iris/tests/unit/coords/test_CellMethod.py +++ b/lib/iris/tests/unit/coords/test_CellMethod.py @@ -22,7 +22,7 @@ def setUp(self): def _check(self, token, coord, default=False): result = CellMethod(self.method, coords=coord) token = token if not default else BaseMetadata.DEFAULT_NAME - expected = "{}: {}".format(self.method, token) + expected = "{}: {}".format(token, self.method) self.assertEqual(str(result), expected) def test_coord_standard_name(self): @@ -64,27 +64,27 @@ def test_coord_stash_default(self): def test_string(self): token = "air_temperature" result = CellMethod(self.method, coords=token) - expected = "{}: {}".format(self.method, token) + expected = "{}: {}".format(token, self.method) self.assertEqual(str(result), expected) def test_string_default(self): token = "air temperature" # includes space result = CellMethod(self.method, coords=token) - expected = "{}: unknown".format(self.method) + expected = "unknown: {}".format(self.method) self.assertEqual(str(result), expected) def test_mixture(self): token = "air_temperature" coord = AuxCoord(1, standard_name=token) result = CellMethod(self.method, coords=[coord, token]) - expected = "{}: {}, {}".format(self.method, token, token) + expected = "{}: {}: {}".format(token, token, self.method) self.assertEqual(str(result), expected) def test_mixture_default(self): token = "air temperature" # includes space coord = AuxCoord(1, long_name=token) result = CellMethod(self.method, coords=[coord, token]) - expected = "{}: unknown, unknown".format(self.method) + expected = "unknown: unknown: {}".format(self.method) self.assertEqual(str(result), expected) diff --git a/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py b/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py index 21fc8efa73..65fb115243 100644 --- a/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py +++ b/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py @@ -537,10 +537,11 @@ def test_section_cell_methods(self): expected = [ "name / (1) (-- : 1)", " Cell methods:", - " stdev area", - " mean y (10m, vertical), time (3min, =duration)", + " 0 area: stdev", + " 1 y: time: mean (interval: 10m" + " interval: 3min comment: vertical comment: =duration)", ] - self.assertEqual(rep, expected) + self.assertEqual(expected, rep) def test_unstructured_cube(self): # Check a sample mesh-cube against the expected result. diff --git a/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py b/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py index bcf31a016f..d81f680df5 100644 --- a/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py +++ b/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py @@ -206,7 +206,7 @@ def test_cell_methods(self): rep = CubeSummary(cube) cell_method_section = rep.scalar_sections["Cell methods:"] - expected_contents = ["mean: x, y", "mean: x"] + expected_contents = ["0: x: y: mean", "1: x: mean"] self.assertEqual(cell_method_section.contents, expected_contents) def test_scalar_cube(self):