mean
- mean(fs, missing=False, dim=None, preserve_dims=None)
Computes the point-wise mean of
fs.- Parameters
fs (
Fieldset) – input fieldsetmissing (bool) – controls what happens when missing values are present in
fs. When it isFalse, 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 isTrueall 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 ifmissingwere set toFalse.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
The result is a
Fieldsetwith a single field in each gridpoint containing the mean of all the values belonging to the same gridpoint throughout the fields infsWith N fields in
fsby 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
dimandpreserve_dimsparameters, and only when this function is used as a method on aFieldsetobject rather than as a function. Thedimparameter should contain the name of an ecCodes key over which the computation should be performed. For example, aFieldsetthat 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
Fieldsetby 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 asdim). They are["shortName", "level", "step", "number", "date", "time"], but can be modifed by supplying a new list of keys via thepreserve_dimsparameter. 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 apreserve_dimsparameter 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.