Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cf cell method #5224

Merged
merged 9 commits into from
Apr 4, 2023
2 changes: 1 addition & 1 deletion docs/src/further_topics/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
24 changes: 12 additions & 12 deletions docs/src/further_topics/ugrid/operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions docs/src/further_topics/ugrid/other_meshes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;...
...
Expand Down Expand Up @@ -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;...
...
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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'

Expand Down
12 changes: 6 additions & 6 deletions docs/src/userguide/cube_statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions docs/src/userguide/interpolation_and_regridding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion docs/src/userguide/loading_iris_cubes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
10 changes: 4 additions & 6 deletions lib/iris/_representation/cube_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
14 changes: 7 additions & 7 deletions lib/iris/common/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
28 changes: 14 additions & 14 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])

trexfeathers marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
18 changes: 9 additions & 9 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
Loading