From 13abf441b7e06220fc8397fe4d1ed475b6d11779 Mon Sep 17 00:00:00 2001 From: David Hassell Date: Mon, 26 Feb 2024 13:57:56 +0000 Subject: [PATCH 1/4] Fix bad git mess --- cf/aggregate.py | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/cf/aggregate.py b/cf/aggregate.py index 878007bf85..6fe53c2c9f 100644 --- a/cf/aggregate.py +++ b/cf/aggregate.py @@ -210,7 +210,6 @@ class _Meta: ( "Type", "Identity", - "featureType", "Units", "Cell_methods", "Data", @@ -390,8 +389,6 @@ def __init__( if field_identity: self.identity = f.get_property(field_identity, None) - self.featureType = f.get_property('featureType', None) - construct_axes = f.constructs.data_axes() # ------------------------------------------------------------ @@ -505,7 +502,6 @@ def __init__( "identity": dim_identity, "key": dim_coord_key, "units": units, - "cf_role": None, "hasdata": dim_coord.has_data(), "hasbounds": hasbounds, "coordrefs": self.find_coordrefs(axis), @@ -543,14 +539,11 @@ def __init__( aux_coord, aux_identity, relaxed_units=relaxed_units ) - cf_role = self.featureType and aux_coord.get_property("cf_role", None) - info_aux.append( { "identity": aux_identity, "key": key, "units": units, - "cf_role": cf_role, "hasdata": aux_coord.has_data(), "hasbounds": aux_coord.has_bounds(), "coordrefs": self.find_coordrefs(key), @@ -599,7 +592,6 @@ def __init__( "ids": "identity", "keys": "key", "units": "units", - "cf_role": "cf_role", "hasdata": "hasdata", "hasbounds": "hasbounds", "coordrefs": "coordrefs", @@ -1568,9 +1560,6 @@ def coord_has_identity_and_data(self, coord, axes=None): default=None, ) - if self.featureType and coord.get_property('cf_role', None): - print(11111, repr(coord)) - if identity is not None: all_coord_identities = self.all_coord_identities.setdefault( axes, set() @@ -1784,9 +1773,6 @@ def structural_signature(self): Cell_methods = self.cell_methods Data = self.has_field_data - # FeatureType - featureType = self.featureType - # Properties Properties = self.properties @@ -1826,7 +1812,6 @@ def structural_signature(self): ] ), ), - ("cf_role", axis[identity]["cf_role"]), ("hasdata", axis[identity]["hasdata"]), ("hasbounds", axis[identity]["hasbounds"]), ("coordrefs", axis[identity]["coordrefs"]), @@ -1933,7 +1918,6 @@ def structural_signature(self): self.signature = self._structural_signature( Type=Type, Identity=Identity, - featureType=featureType, Units=Units, Cell_methods=Cell_methods, Data=Data, @@ -4148,9 +4132,6 @@ def _hash_values(m): hash0 = hash1 - if m0.featureType and not count: - print(9999999999999) - if count == 1: # -------------------------------------------------------- # Exactly one axis has different 1-d coordinate values @@ -4252,24 +4233,10 @@ def _hash_values(m): # aggregate anything in this entire group. # -------------------------------------------------------- if info: - coord_ids = [] - for k, v in m0.axis.items(): - coord_ids.extend([repr(i) for i in v['ids']]) - - if len(coord_ids) > 1: - coord_ids = ( - f"{', '.join(coord_ids[:-1])} and {coord_ids[-1]}" - ) - elif coord_ids: - coord_ids = coord_ids[0] - else: - coord_ids = "" - meta[ 0 ].message = ( - f"Some fields have identical sets of 1-d {coord_ids} " - "coordinates." + "Some fields have identical sets of 1-d coordinates." ) return () From c48eca0226253b2cdeec0a484095934c3d3cf930 Mon Sep 17 00:00:00 2001 From: David Hassell Date: Thu, 29 Feb 2024 23:29:36 +0000 Subject: [PATCH 2/4] For DSGs, don't aggregate non-feature axes --- cf/aggregate.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cf/aggregate.py b/cf/aggregate.py index dffdca9f58..6154c14012 100644 --- a/cf/aggregate.py +++ b/cf/aggregate.py @@ -2977,9 +2977,18 @@ def aggregate( # ------------------------------------------------------------ if axes is None: # Aggregation will be over as many axes as possible - aggregating_axes = meta[0].axis_ids + m0 = meta[0] + aggregating_axes = m0.axis_ids[:] + + # For DSG feature types, only consider aggregating the + # feature dimension(s). + if m0.featureType: + for axis in aggregating_axes[:]: + if not dsg_feature_type_axis(m0, axis): + aggregating_axes.remove(axis) + _create_hash_and_first_values( - meta, None, False, hfl_cache, rtol, atol + meta, aggregating_axes, False, hfl_cache, rtol, atol ) else: From 602f74ae3a10311cd411dfcd19e2b74195113cd3 Mon Sep 17 00:00:00 2001 From: David Hassell Date: Fri, 1 Mar 2024 08:26:34 +0000 Subject: [PATCH 3/4] For DSGs, don't aggregate non-feature axes --- cf/aggregate.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cf/aggregate.py b/cf/aggregate.py index 6154c14012..ffbab2f15b 100644 --- a/cf/aggregate.py +++ b/cf/aggregate.py @@ -2990,7 +2990,6 @@ def aggregate( _create_hash_and_first_values( meta, aggregating_axes, False, hfl_cache, rtol, atol ) - else: # Specific aggregation axes have been selected aggregating_axes = [] @@ -3501,7 +3500,8 @@ def _create_hash_and_first_values( meta: `list` of `_Meta` - axes: `None` or `list` + axes: `list` + The identities of the possible aggregating axes. donotchecknonaggregatingaxes: `bool` @@ -3514,10 +3514,15 @@ def _create_hash_and_first_values( # identity. canonical_direction = {} + aggregating_axes = list(axes) + for m in meta: field = m.field constructs = field.constructs.todict() + # Store the aggregating axis identities + m.aggregating_axes = aggregating_axes + m_sort_keys = m.sort_keys m_sort_indices = m.sort_indices @@ -4140,7 +4145,7 @@ def _group_fields(meta, axis, info=False): group is represented by a `list` of `_Meta` objects. """ - axes = meta[0].axis_ids + axes = meta[0].aggregating_axes if axes: if axis in axes: From 4f023d6063fedecfb824258a663df7cfac05a588 Mon Sep 17 00:00:00 2001 From: David Hassell Date: Fri, 1 Mar 2024 16:22:21 +0000 Subject: [PATCH 4/4] aggregating_axes --- cf/aggregate.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/cf/aggregate.py b/cf/aggregate.py index ffbab2f15b..496189f3d0 100644 --- a/cf/aggregate.py +++ b/cf/aggregate.py @@ -3492,7 +3492,7 @@ def climatology_cells( def _create_hash_and_first_values( - meta, axes, donotchecknonaggregatingaxes, hfl_cache, rtol, atol + meta, aggregating_axes, donotchecknonaggregatingaxes, hfl_cache, rtol, atol ): """Updates each field's _Meta object. @@ -3500,7 +3500,7 @@ def _create_hash_and_first_values( meta: `list` of `_Meta` - axes: `list` + axes: sequence The identities of the possible aggregating axes. donotchecknonaggregatingaxes: `bool` @@ -3514,8 +3514,6 @@ def _create_hash_and_first_values( # identity. canonical_direction = {} - aggregating_axes = list(axes) - for m in meta: field = m.field constructs = field.constructs.todict() @@ -3541,9 +3539,9 @@ def _create_hash_and_first_values( # -------------------------------------------------------- for identity in m.axis_ids: if ( - axes is not None + aggregating_axes is not None and donotchecknonaggregatingaxes - and identity not in axes + and identity not in aggregating_axes ): x = [None] * len(m.axis[identity]["keys"]) m_hash_values[identity] = x @@ -3685,12 +3683,12 @@ def _create_hash_and_first_values( coord = constructs[key] - axes = aux["axes"] + c_axes = aux["axes"] canonical_axes = aux["canonical_axes"] - if axes != canonical_axes: + if c_axes != canonical_axes: # Transpose the N-d auxiliary coordinate so that # it has the canonical axis order - iaxes = [axes.index(axis) for axis in canonical_axes] + iaxes = [c_axes.index(axis) for axis in canonical_axes] coord = coord.transpose(iaxes) sort_indices, needs_sorting = _sort_indices(m, canonical_axes) @@ -3736,14 +3734,14 @@ def _create_hash_and_first_values( else: for canonical_units, msr in m.msr.items(): hash_values = [] - for key, axes, canonical_axes in zip( + for key, c_axes, canonical_axes in zip( msr["keys"], msr["axes"], msr["canonical_axes"] ): cell_measure = constructs[key] - if axes != canonical_axes: + if c_axes != canonical_axes: # Transpose the cell measure so that it has # the canonical axis order - iaxes = [axes.index(axis) for axis in canonical_axes] + iaxes = [c_axes.index(axis) for axis in canonical_axes] cell_measure = cell_measure.transpose(iaxes) sort_indices, needs_sorting = _sort_indices( @@ -3850,12 +3848,12 @@ def _create_hash_and_first_values( field_anc = constructs[key] - axes = anc["axes"] + c_axes = anc["axes"] canonical_axes = anc["canonical_axes"] - if axes != canonical_axes: + if c_axes != canonical_axes: # Transpose the field ancillary so that it has the # canonical axis order - iaxes = [axes.index(axis) for axis in canonical_axes] + iaxes = [c_axes.index(axis) for axis in canonical_axes] field_anc = field_anc.transpose(iaxes) sort_indices, needs_sorting = _sort_indices(m, canonical_axes) @@ -3888,12 +3886,12 @@ def _create_hash_and_first_values( domain_anc = constructs[key] - axes = anc["axes"] + c_axes = anc["axes"] canonical_axes = anc["canonical_axes"] - if axes != canonical_axes: + if c_axes != canonical_axes: # Transpose the domain ancillary so that it has # the canonical axis order - iaxes = [axes.index(axis) for axis in canonical_axes] + iaxes = [c_axes.index(axis) for axis in canonical_axes] domain_anc = domain_anc.transpose(iaxes) sort_indices, needs_sorting = _sort_indices(m, canonical_axes)