transforms.aggregate.temporal

Attributes

logger

Functions

standardise_time(dataarray[, target_format])

Convert time coordinates to a standard format using the Gregorian calendar.

reduce(dataarray, *args[, time_dim])

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

mean(dataarray, *args, **kwargs)

Calculate the mean of an xarray.dataarray or xarray.dataset along the time/date dimension.

median(dataarray, *args, **kwargs)

Calculate the median of an xarray.dataarray or xarray.dataset along the time/date dimension.

min(dataarray, *args, **kwargs)

Calculate the mn of an xarray.dataarray or xarray.dataset along the time/date dimension.

max(dataarray, *args, **kwargs)

Calculate the max of an xarray.dataarray or xarray.dataset along the time/date dimension.

std(dataarray, *args, **kwargs)

Calculate the standard deviation of an xarray.dataarray or xarray.dataset along the time/date dimension.

sum(dataarray, *args, **kwargs)

Calculate the standard deviation of an xarray.dataarray or xarray.dataset along the time/date dimension.

daily_reduce(dataarray[, how, time_dim])

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

daily_mean(dataarray, *args, **kwargs)

Return the daily mean of the datacube.

daily_median(dataarray, *args, **kwargs)

Return the daily median of the datacube.

daily_max(dataarray, *args, **kwargs)

Calculate the daily maximum.

daily_min(dataarray, *args, **kwargs)

Calculate the daily minimum.

daily_std(dataarray, *args, **kwargs)

Calculate the daily standard deviation.

daily_sum(dataarray, *args, **kwargs)

Calculate the daily sum (accumulation).

monthly_reduce(dataarray[, how, time_dim])

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

monthly_mean(dataarray, *args, **kwargs)

Calculate the monthly mean.

monthly_median(dataarray, *args, **kwargs)

Calculate the monthly median.

monthly_min(dataarray, *args, **kwargs)

Calculate the monthly min.

monthly_max(dataarray, *args, **kwargs)

Calculate the monthly max.

monthly_std(dataarray, *args, **kwargs)

Calculate the monthly standard deviation.

monthly_sum(dataarray, *args, **kwargs)

Calculate the monthly sum/accumulation along the time dimension.

rolling_reduce(dataarray[, window_length, time_dim])

Return reduced data using a moving window over the time dimension.

Module Contents

transforms.aggregate.temporal.logger
transforms.aggregate.temporal.standardise_time(dataarray, target_format='%Y-%m-%d %H:%M:%S')

Convert time coordinates to a standard format using the Gregorian calendar.

This function is helpful when combining data from different sources with different time standards or calendars - for example, when combining data which uses a 360-day calendar with data which uses a Gregorian calendar. All data passed into this function will be converted to a standard Gregorian calendar format.

Parameters:
  • dataarray (xr.Dataset or xr.DataArray) – Data object with a time coordinate to be standardised.

  • target_format (str, optional) – Datetime format to use when creating the standardised datetime object. This can be used to change the resolution of the datetime object - for example, “%Y-%m-%d” will reduce to daily resolution - or to fix elements of the datetime object - for example, “%Y-%m-15” would reduce to monthly resolution and fix the date to the 15th of each month.

Returns:

Data object with the time coordinate standardised to the specified format.

Return type:

xr.Dataset or xr.DataArray

transforms.aggregate.temporal.reduce(dataarray, *args, time_dim=None, **kwargs)

Reduce an xarray.dataarray or xarray.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 (xr.DataArray or xr.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 np.ndarray over an integer valued axis

  • weights (str) – Choose a recognised method to apply weighting. Currently availble 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

Return type:

A data array with reduce dimensions removed.

transforms.aggregate.temporal.mean(dataarray, *args, **kwargs)

Calculate the mean of an xarray.dataarray or xarray.dataset along the time/date dimension.

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

Parameters:
  • dataarray (xr.DataArray or xr.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

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

  • how_label (str) – Label to append to the name of the variable in the reduced object, default is _mean

  • 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

Return type:

A data array with reduce dimensions removed.

transforms.aggregate.temporal.median(dataarray, *args, **kwargs)

Calculate the median of an xarray.dataarray or xarray.dataset along the time/date dimension.

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

Parameters:
  • dataarray (xr.DataArray or xr.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

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

  • how_label (str) – Label to append to the name of the variable in the reduced object, default is _mean

  • 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

Return type:

A data array with reduce dimensions removed.

transforms.aggregate.temporal.min(dataarray, *args, **kwargs)

Calculate the mn of an xarray.dataarray or xarray.dataset along the time/date dimension.

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

Parameters:
  • dataarray (xr.DataArray or xr.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

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

  • how_label (str) – Label to append to the name of the variable in the reduced object, default is _mean

  • 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

Return type:

A data array with reduce dimensions removed.

transforms.aggregate.temporal.max(dataarray, *args, **kwargs)

Calculate the max of an xarray.dataarray or xarray.dataset along the time/date dimension.

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

Parameters:
  • dataarray (xr.DataArray or xr.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

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

  • how_label (str) – Label to append to the name of the variable in the reduced object, default is _mean

  • 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

Return type:

A data array with reduce dimensions removed.

transforms.aggregate.temporal.std(dataarray, *args, **kwargs)

Calculate the standard deviation of an xarray.dataarray or xarray.dataset along the time/date dimension.

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

Parameters:
  • dataarray (xr.DataArray or xr.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

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

  • how_label (str) – Label to append to the name of the variable in the reduced object, default is _mean

  • 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

Return type:

A data array with reduce dimensions removed.

transforms.aggregate.temporal.sum(dataarray, *args, **kwargs)

Calculate the standard deviation of an xarray.dataarray or xarray.dataset along the time/date dimension.

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

Parameters:
  • dataarray (xr.DataArray or xr.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

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

  • how_label (str) – Label to append to the name of the variable in the reduced object, default is _mean

  • 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

Return type:

A data array with reduce dimensions removed.

transforms.aggregate.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 np.ndarray 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) 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 dictonary is passed as kwargs to pandas.Timedelta

  • 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().

Return type:

xr.DataArray

transforms.aggregate.temporal.daily_mean(dataarray, *args, **kwargs)

Return the daily mean of the datacube.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.daily_median(dataarray, *args, **kwargs)

Return the daily median of the datacube.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.daily_max(dataarray, *args, **kwargs)

Calculate the daily maximum.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.daily_min(dataarray, *args, **kwargs)

Calculate the daily minimum.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.daily_std(dataarray, *args, **kwargs)

Calculate the daily standard deviation.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.daily_sum(dataarray, *args, **kwargs)

Calculate the daily sum (accumulation).

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.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 np.ndarray 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) 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 dictonary is passed as kwargs to pandas.Timedelta

  • 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().

Return type:

xr.DataArray

transforms.aggregate.temporal.monthly_mean(dataarray, *args, **kwargs)

Calculate the monthly mean.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.monthly_median(dataarray, *args, **kwargs)

Calculate the monthly median.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.monthly_min(dataarray, *args, **kwargs)

Calculate the monthly min.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.monthly_max(dataarray, *args, **kwargs)

Calculate the monthly max.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.monthly_std(dataarray, *args, **kwargs)

Calculate the monthly standard deviation.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.monthly_sum(dataarray, *args, **kwargs)

Calculate the monthly sum/accumulation along the time dimension.

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

  • 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) 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 dictonary is passed as kwargs to pandas.Timedelta

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

Return type:

xr.DataArray

transforms.aggregate.temporal.rolling_reduce(dataarray, window_length=None, time_dim=None, **kwargs)

Return reduced data using a moving window over the time dimension.

Parameters:
  • dataarray (xr.DataArray or xr.Dataset) – Data over which the moving window is applied according to the reduction method.

  • window_length – Length of window for the rolling groups along the time dimension. see documentation for xarray.dataarray.rolling.

  • 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”.

  • min_periods (integer) – The minimum number of observations in the window required to have a value (otherwise result is NaN). Default is to set min_periods equal to the size of the window. see documentation for xarray.dataarray.rolling

  • center (bool) – Set the labels at the centre of the window, see documentation for xarray.dataarray.rolling.

  • how_reduce (str,) – Function to be applied for reduction. Default is ‘mean’.

  • how_dropna (str) – Determine if dimension is removed from the output when we have at least one NaN or all NaN. how_dropna can be ‘None’, ‘any’ or ‘all’. Default is ‘any’.

  • windows (dict[str, int]) – Any other windows to apply to other dimensions in the dataset/dataarray

  • **kwargs – Any kwargs that are compatible with the select how_reduce method.

Return type:

xr.DataArray or xr.Dataset (as provided)