@@ -2977,11 +2977,19 @@ def aggregate(
29772977 # ------------------------------------------------------------
29782978 if axes is None :
29792979 # Aggregation will be over as many axes as possible
2980- aggregating_axes = meta [0 ].axis_ids
2980+ m0 = meta [0 ]
2981+ aggregating_axes = m0 .axis_ids [:]
2982+
2983+ # For DSG feature types, only consider aggregating the
2984+ # feature dimension(s).
2985+ if m0 .featureType :
2986+ for axis in aggregating_axes [:]:
2987+ if not dsg_feature_type_axis (m0 , axis ):
2988+ aggregating_axes .remove (axis )
2989+
29812990 _create_hash_and_first_values (
2982- meta , None , False , hfl_cache , rtol , atol
2991+ meta , aggregating_axes , False , hfl_cache , rtol , atol
29832992 )
2984-
29852993 else :
29862994 # Specific aggregation axes have been selected
29872995 aggregating_axes = []
@@ -3484,15 +3492,16 @@ def climatology_cells(
34843492
34853493
34863494def _create_hash_and_first_values (
3487- meta , axes , donotchecknonaggregatingaxes , hfl_cache , rtol , atol
3495+ meta , aggregating_axes , donotchecknonaggregatingaxes , hfl_cache , rtol , atol
34883496):
34893497 """Updates each field's _Meta object.
34903498
34913499 :Parameters:
34923500
34933501 meta: `list` of `_Meta`
34943502
3495- axes: `None` or `list`
3503+ axes: sequence
3504+ The identities of the possible aggregating axes.
34963505
34973506 donotchecknonaggregatingaxes: `bool`
34983507
@@ -3509,6 +3518,9 @@ def _create_hash_and_first_values(
35093518 field = m .field
35103519 constructs = field .constructs .todict ()
35113520
3521+ # Store the aggregating axis identities
3522+ m .aggregating_axes = aggregating_axes
3523+
35123524 m_sort_keys = m .sort_keys
35133525 m_sort_indices = m .sort_indices
35143526
@@ -3527,9 +3539,9 @@ def _create_hash_and_first_values(
35273539 # --------------------------------------------------------
35283540 for identity in m .axis_ids :
35293541 if (
3530- axes is not None
3542+ aggregating_axes is not None
35313543 and donotchecknonaggregatingaxes
3532- and identity not in axes
3544+ and identity not in aggregating_axes
35333545 ):
35343546 x = [None ] * len (m .axis [identity ]["keys" ])
35353547 m_hash_values [identity ] = x
@@ -3671,12 +3683,12 @@ def _create_hash_and_first_values(
36713683
36723684 coord = constructs [key ]
36733685
3674- axes = aux ["axes" ]
3686+ c_axes = aux ["axes" ]
36753687 canonical_axes = aux ["canonical_axes" ]
3676- if axes != canonical_axes :
3688+ if c_axes != canonical_axes :
36773689 # Transpose the N-d auxiliary coordinate so that
36783690 # it has the canonical axis order
3679- iaxes = [axes .index (axis ) for axis in canonical_axes ]
3691+ iaxes = [c_axes .index (axis ) for axis in canonical_axes ]
36803692 coord = coord .transpose (iaxes )
36813693
36823694 sort_indices , needs_sorting = _sort_indices (m , canonical_axes )
@@ -3722,14 +3734,14 @@ def _create_hash_and_first_values(
37223734 else :
37233735 for canonical_units , msr in m .msr .items ():
37243736 hash_values = []
3725- for key , axes , canonical_axes in zip (
3737+ for key , c_axes , canonical_axes in zip (
37263738 msr ["keys" ], msr ["axes" ], msr ["canonical_axes" ]
37273739 ):
37283740 cell_measure = constructs [key ]
3729- if axes != canonical_axes :
3741+ if c_axes != canonical_axes :
37303742 # Transpose the cell measure so that it has
37313743 # the canonical axis order
3732- iaxes = [axes .index (axis ) for axis in canonical_axes ]
3744+ iaxes = [c_axes .index (axis ) for axis in canonical_axes ]
37333745 cell_measure = cell_measure .transpose (iaxes )
37343746
37353747 sort_indices , needs_sorting = _sort_indices (
@@ -3836,12 +3848,12 @@ def _create_hash_and_first_values(
38363848
38373849 field_anc = constructs [key ]
38383850
3839- axes = anc ["axes" ]
3851+ c_axes = anc ["axes" ]
38403852 canonical_axes = anc ["canonical_axes" ]
3841- if axes != canonical_axes :
3853+ if c_axes != canonical_axes :
38423854 # Transpose the field ancillary so that it has the
38433855 # canonical axis order
3844- iaxes = [axes .index (axis ) for axis in canonical_axes ]
3856+ iaxes = [c_axes .index (axis ) for axis in canonical_axes ]
38453857 field_anc = field_anc .transpose (iaxes )
38463858
38473859 sort_indices , needs_sorting = _sort_indices (m , canonical_axes )
@@ -3874,12 +3886,12 @@ def _create_hash_and_first_values(
38743886
38753887 domain_anc = constructs [key ]
38763888
3877- axes = anc ["axes" ]
3889+ c_axes = anc ["axes" ]
38783890 canonical_axes = anc ["canonical_axes" ]
3879- if axes != canonical_axes :
3891+ if c_axes != canonical_axes :
38803892 # Transpose the domain ancillary so that it has
38813893 # the canonical axis order
3882- iaxes = [axes .index (axis ) for axis in canonical_axes ]
3894+ iaxes = [c_axes .index (axis ) for axis in canonical_axes ]
38833895 domain_anc = domain_anc .transpose (iaxes )
38843896
38853897 sort_indices , needs_sorting = _sort_indices (m , canonical_axes )
@@ -4131,7 +4143,7 @@ def _group_fields(meta, axis, info=False):
41314143 group is represented by a `list` of `_Meta` objects.
41324144
41334145 """
4134- axes = meta [0 ].axis_ids
4146+ axes = meta [0 ].aggregating_axes
41354147
41364148 if axes :
41374149 if axis in axes :
0 commit comments