@@ -4919,6 +4919,7 @@ def collapse(
49194919 scale=None,
49204920 radius="earth",
49214921 great_circle=False,
4922+ cell_measures=True,
49224923 verbose=None,
49234924 remove_vertical_crs=True,
49244925 _create_zero_size_cell_bounds=False,
@@ -5472,52 +5473,61 @@ def collapse(
54725473
54735474 weights: optional
54745475 Specify the weights for the collapse axes. The weights
5475- are, in general, those that would be returned by this
5476- call of the field construct's `weights` method:
5477- ``f.weights(weights, axes=axes, measure=measure,
5478- scale=scale, radius=radius, great_circle=great_circle,
5479- components=True)``. See the *axes*, *measure*,
5480- *scale*, *radius* and *great_circle* parameters and
5481- `cf.Field.weights` for details, and note that the
5476+ are created internaly as the output of this call of
5477+ the field construct's `weights` method:
5478+ ``f.weights(weights, components=True, axes=axes,
5479+ measure=measure, scale=scale, radius=radius,
5480+ great_circle=great_circle,
5481+ cell_measures=cell_measures)``.
5482+
5483+ See the *axes*, *measure*, *scale*, *radius*,
5484+ *great_circle*, and *cell_measures* parameters, and
5485+ `cf.Field.weights` for details; and note that the
54825486 value of *scale* may be modified depending on the
54835487 value of *measure*.
54845488
5485- .. note:: By default *weights* is `None`, resulting in
5486- **unweighted calculations**.
5489+ .. warning:: By default *weights* is `None`, resulting
5490+ in **unweighted calculations**.
5491+
5492+ .. note:: Setting *weights* to `True` is generally a
5493+ good way to ensure that all collapses are
5494+ appropriately weighted according to the
5495+ field construct's metadata. In this case, if
5496+ it is not possible to create weights for any
5497+ axis then an exception will be raised.
54875498
54885499 .. note:: Unless the *method* is ``'integral'``, the
54895500 units of the weights are not combined with
54905501 the field's units in the collapsed field.
54915502
5492- If the alternative form of providing the collapse method
5493- and axes combined as a CF cell methods-like string via the
5494- *method* parameter has been used, then the *axes*
5495- parameter is ignored and the axes are derived from the
5496- *method* parameter. For example, if *method* is ``'T:
5497- area: minimum'`` then this defines axes of ``['T',
5498- 'area']``. If *method* specifies multiple collapses,
5499- e.g. ``'T: minimum area: mean'`` then this implies axes of
5500- ``'T'`` for the first collapse, and axes of ``'area'`` for
5501- the second collapse.
5502-
5503- .. note:: Setting *weights* to `True` is generally a good
5504- way to ensure that all collapses are
5505- appropriately weighted according to the field
5506- construct's metadata. In this case, if it is not
5507- possible to create weights for any axis then an
5508- exception will be raised.
5503+ .. note:: A pre-calculated weights array may also be
5504+ provided as the *weights* parameter. See
5505+ `cf.Field.weights` for details
55095506
5510- However, care needs to be taken if *weights* is
5511- `True` when cell volume weights are desired. The
5512- volume weights will be taken from a "volume"
5513- cell measure construct if one exists, otherwise
5514- the cell volumes will be calculated as being
5515- proportional to the sizes of one-dimensional
5516- vertical coordinate cells. In the latter case
5517- **if the vertical dimension coordinates do not
5518- define the actual height or depth thickness of
5519- every cell in the domain then the weights will
5520- be incorrect**.
5507+ If the collapse method and axes have been provided as
5508+ a CF cell methods-like string via the *method*
5509+ parameter, then the *axes* parameter is ignored and
5510+ the axes for weights instead inferred from that
5511+ string. For instance, if *method* is ``'T: xarea:
5512+ minimum'`` then this defines axes of ``['T',
5513+ 'area']``. If *method* specifies multiple collapses,
5514+ e.g. ``'T: minimum area: mean'`` then this implies
5515+ axes of ``'T'`` for the first collapse, and axes of
5516+ ``'area'`` for the second collapse.
5517+
5518+ .. warning:: Care needs to be taken if *weights* is
5519+ set to `True` when cell volume weights
5520+ are desired. The volume weights will be
5521+ taken from a "volume" cell measure
5522+ construct if one exists, otherwise the
5523+ cell volumes will be calculated as being
5524+ proportional to the sizes of
5525+ one-dimensional vertical coordinate
5526+ cells. In the latter case **if the
5527+ vertical dimension coordinates do not
5528+ define the actual height or depth
5529+ thickness of every cell in the domain
5530+ then the weights will be incorrect**.
55215531
55225532 *Parameter example:*
55235533 To specify weights based on the field construct's
@@ -5609,6 +5619,15 @@ def collapse(
56095619
56105620 .. versionadded:: 3.2.0
56115621
5622+ cell_measures: `bool`, optional
5623+ If True, the default, then area and volume cell
5624+ measure constructs are considered for weights creation
5625+ when *weights* is `True`, ``'area'``, or
5626+ ``'volume'``. If False then cell measure constructs
5627+ are ignored for these *weights*.
5628+
5629+ .. versionadded:: NEXTVERSION
5630+
56125631 squeeze: `bool`, optional
56135632 If True then size 1 collapsed axes are removed from the
56145633 output data array. By default the axes which are collapsed
@@ -6714,6 +6733,7 @@ def collapse(
67146733 measure=measure,
67156734 radius=radius,
67166735 great_circle=great_circle,
6736+ cell_measures=cell_measures,
67176737 )
67186738 if g_weights:
67196739 # For grouped collapses, bring the weights
@@ -6748,6 +6768,7 @@ def collapse(
67486768 group_by=group_by,
67496769 axis_in=axes_in[0],
67506770 verbose=verbose,
6771+ cell_measures=cell_measures,
67516772 )
67526773
67536774 if regroup:
@@ -6818,6 +6839,7 @@ def collapse(
68186839 measure=measure,
68196840 radius=radius,
68206841 great_circle=great_circle,
6842+ cell_measures=cell_measures,
68216843 )
68226844 if d_weights:
68236845 d_kwargs["weights"] = d_weights
@@ -7091,6 +7113,7 @@ def _collapse_grouped(
70917113 coordinate=None,
70927114 measure=False,
70937115 weights=None,
7116+ cell_measures=True,
70947117 squeeze=None,
70957118 group_by=None,
70967119 axis_in=None,
0 commit comments