earthkit.transforms.temporal

The transforms.temporal module includes methods for aggregating data in time. This includes reducing the data in time dimension to a single value, daily values or monthly values.

To reduce the data in time dimension to a single value you can use the temporal.reduce, temporal.mean, temporal.sum, temporal.min, temporal.max functions. These functions take an xarray data object and return the aggregated value of the data. The time dimension is automatically detected based on the metadata of the data object, to override this you can use the time_dim parameter.

To calculate calculate daily/monthly values you can use the temporal.daily_reduce or temporal.monthly_reduce functions. These functions reduce the data in time dimension to daily or monthly values respectively. The how parameter can be used to specify the aggregation method. The default is mean.

earthkit.transforms.temporal.daily_reduce(dataarray, how='mean', time_dim=None, **kwargs)

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

Parameters:
  • dataarray (xr.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, default behaviour is to deduce time dimension from attributes of coordinates, then fall back to “time”.

  • time_shift ((optional) None, timedelta or dict) – 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. 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 _daily_{how}

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

Returns:

A dataarray reduced to daily values using the specified method

Return type:

xr.DataArray | xr.Dataset

earthkit.transforms.temporal.monthly_reduce(dataarray, how='mean', time_dim=None, **kwargs)

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

Parameters:
  • dataarray (xr.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 ((optional) None, timedelta or dict) – 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. 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}

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

Returns:

A dataarray reduced to monthly values using the specified method

Return type:

xr.DataArray | xr.Dataset

In addition to the XXX_reduce functions, the temporal module also includes several methods which calculate the desired reduction, without the “how” parameter. These methods are wrappers of the daily_reduce and monthly_reduce methods and are documented in the API reference guide: transforms.temporal:

  • temporal.daily_mean

  • temporal.daily_median

  • temporal.daily_min

  • temporal.daily_max

  • temporal.daily_sum

  • temporal.daily_std

  • temporal.monthly_mean

  • temporal.monthly_median

  • temporal.monthly_min

  • temporal.monthly_max

  • temporal.monthly_sum

  • temporal.monthly_std