mean

mean(fs, missing=False, dim=None, preserve_dims=None)

Computes the point-wise mean of fs.

Parameters
  • fs (Fieldset) – input fieldset

  • missing (bool) – controls what happens when missing values are present in fs. When it is False, a missing value in any of the fields at a given gridpoint will result in a missing value in the corresponding gridpoint in the output. If it is True all the non-missing values across the fields at a given grid point will be used to compute the mean. This parameter is new in Metview version 5.16.0. In earlier versions the computations are carried out as if missing were set to False.

  • dim (str) – restrict the computations to a single dimension of the data - see main text below. New in metview-python version 1.13.0.

  • preserve_dims (list) – may be used in conjunction with parameter dim - see main text below. New in metview-python version 1.13.0.

Return type

Fieldset

The result is a Fieldset with a single field in each gridpoint containing the mean of all the values belonging to the same gridpoint throughout the fields in fs

With N fields in fs by denoting the i-th value in the k-th field by \(f_{i}^{k}\) the output values can be written as:

\[m_{i} = \frac {1}{N} \sum_{k}^{N}f_{i}^{k}\]

Dimensions

New in metview-python version 1.13.0.

The ability to restrict the computations over a single dimension, such as time or ensemble member, is available via the dim and preserve_dims parameters, and only when this function is used as a method on a Fieldset object rather than as a function. The dim parameter should contain the name of an ecCodes key over which the computation should be performed. For example, a Fieldset that contains multiple parameters, vertical levels, forecast steps and ensemble members can be used to quickly generate an ensemble mean with the following call:

data = mv.read("ens_data.grib")
ens_mean = data.mean(dim="number") # "number" is the ecCodes key for ensemble member

In order to perform this computation, Metview must be able to split the input Fieldset by its other dimensions so that they are preserved - in the above example, each parameter, level and forecast step must be preserved, and only the ensemble members ‘collapsed’. An ensemble mean will be generated for each unique combination of parameter, level and step. Metview uses a built-in list of keys that it ensures are preserved (unless specified as dim). They are ["shortName", "level", "step", "number", "date", "time"], but can be modifed by supplying a new list of keys via the preserve_dims parameter. An example of using this would be if the input data contains multiple experiment versions. In this case, Metview by default would not preserve them as a ‘dimension’, but would include them in the mean computation. The solution would be to supply a preserve_dims parameter that includes "experimentVersionNumber".

Note

See also sum().

mean(gpt)

Computes the mean of all the values in the values column of gpt.

Parameters

gpt (Geopoints) – input geopoints

Return type

number or None

Missing values are bypassed in this calculation. If there are no valid values, then None is returned.

Notebooks using metview.mean