reduce

earthkit.transforms.temporal.reduce(dataarray: Dataset | DataArray, *_args, time_dim: str | None = None, **kwargs) Dataset | DataArray[source]

Reduce an xarray.dataarray/dataset along the time/date dimension using a specified how method.

With the option to apply weights either directly or using a specified weights method.

Parameters:
  • dataarray (xarray.DataArray or xarray.Dataset) – Data object to reduce

  • time_dim (str) – Name of the time dimension, or coordinate, in the xarray object, default behaviour is to deduce time dimension from attributes of coordinates, then fall back to “time”. If you do not want to aggregate along the time dimension use earthkit.transforms.aggregate.reduce

  • how (str or callable) – Method used to reduce data. Default=’mean’, which will implement the xarray in-built mean. If string, it must be an in-built xarray reduce method, a earthkit how method or any numpy method. In the case of duplicate names, method selection is first in the order: xarray, earthkit, numpy. Otherwise it can be any function which can be called in the form f(x, axis=axis, **kwargs) to return the result of reducing an array over an integer valued axis

  • weights (str) – Choose a recognised method to apply weighting. Currently available methods are; ‘latitude’

  • how_label (str) – Label to append to the name of the variable in the reduced object, default is _{how}

  • how_dropna (str) – Choose how to drop nan values. Default is None and na values are preserved. Options are ‘any’ and ‘all’.

  • **kwargs – kwargs recognised by the how :func: earthkit.transforms.aggregate.reduce

Returns:

A dataarray reduced in the time dimension using the specified method

Return type:

xarray.Dataset | xarray.DataArray