monthly_reduce

earthkit.transforms.temporal.monthly_reduce(dataarray: Dataset | DataArray, how: str | Callable = 'mean', time_dim: str | None = None, **kwargs)[source]

Group data by month and reduce using the given how method.

Parameters:
  • dataarray (xarray.DataArray) – DataArray containing a time dimension.

  • 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

  • time_dim (str) – Name of the time dimension, or coordinate, in the xarray object to use for the calculation, default behaviour is to deduce time dimension from attributes of coordinates, then fall back to “time”.

  • time_shift (None, timedelta, dict, str or xarray.DataArray, optional) – A time shift to apply to the data prior to calculation, e.g. to change the local time zone. It can be provided as any object that can be understood by pandas.Timedelta, a dictionary is passed as kwargs to pandas.Timedelta. A string that cannot be parsed as a timedelta is interpreted as a reference to a coordinate of the input dataarray, allowing, e.g., for spatially-varying per-gridpoint time zone offsets. An xarray.DataArray can also be provided directly. Default is None.

  • remove_partial_periods (bool) – If True and a time_shift has been applied, the first and last time steps are removed to ensure equality in sampling periods. Default is False.

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

  • extra_reduce_dims (str or list of str) – Additional dimensions to reduce over (in addition to the grouping dimension), for example to calculate a monthly global mean you would set this to “longitude” and “latitude”. Default is None.

  • **kwargs – Keyword arguments to be passed to reduce().

Returns:

A dataarray reduced to monthly values using the specified method

Return type:

xarray.DataArray | xarray.Dataset