transforms.temporal
Temporal transformations for earthkit data objects.
Typically this is done with an xarray representation of data. Some pandas methods are used for indexing and selecting data.
Functions
|
Calculate the daily maximum. |
|
Return the daily mean of the datacube. |
|
Return the daily median of the datacube. |
|
Calculate the daily minimum. |
|
Group data by day and reduce using the given how method. |
|
Calculate the daily standard deviation. |
|
Calculate the daily sum (accumulation). |
|
Calculate the max of an xarray.dataarray or xarray.dataset along the time/date dimension. |
|
Calculate the mean of an xarray.dataarray or xarray.dataset along the time/date dimension. |
|
Calculate the median of an xarray.dataarray or xarray.dataset along the time/date dimension. |
|
Calculate the mn of an xarray.dataarray or xarray.dataset along the time/date dimension. |
|
Calculate the monthly max. |
|
Calculate the monthly mean. |
|
Calculate the monthly median. |
|
Calculate the monthly min. |
|
Group data by day and reduce using the given how method. |
|
Calculate the monthly standard deviation. |
|
Calculate the monthly sum/accumulation along the time dimension. |
|
Reduce an xarray.dataarray/dataset along the time/date dimension using a specified how method. |
|
Return reduced data using a moving window over the time dimension. |
|
Convert time coordinates to a standard format using the Gregorian calendar. |
|
Calculate the standard deviation of an xarray.dataarray/dataset along the time/date dimension. |
|
Calculate the standard deviation of an xarray.dataarray/dataset along the time/date dimension. |
|
Convert a variable accumulated from the beginning of the forecast to a rate. |
|
Alias for accumulation_to_rate function with rate_units set to 'step_length'. |
Package Contents
- transforms.temporal.daily_max(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
reduce().
- Returns:
A dataarray reduced to daily max values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.daily_mean(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
reduce().
- Returns:
A dataarray reduced to daily mean values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.daily_median(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
reduce().
- Returns:
A dataarray reduced to daily median values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.daily_min(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
reduce().
- Returns:
A dataarray reduced to daily min values
- Return type:
xr.DataArray | xr.Dataset
- 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 (
strorcallable) – 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 axistime_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,timedeltaordict) – 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}extra_reduce_dims (
strorlistofstr) – Additional dimensions to reduce over (in addition to the grouping dimension), for example to calculate a daily 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 daily values using the specified method
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.daily_std(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
reduce().
- Returns:
A dataarray reduced to daily standard deviation values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.daily_sum(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
reduce().
- Returns:
A dataarray reduced to daily sum values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.max(*_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.DataArrayorxr.Dataset) – Data object to reducetime_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.reduceweights (
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 _meanhow_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 of the maximum value in the time dimensions
- Return type:
xr.Dataset | xr.DataArray
- transforms.temporal.mean(*_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.DataArrayorxr.Dataset) – Data object to reducetime_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.reduceweights (
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 _meanhow_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 of the mean value in the time dimensions
- Return type:
xr.Dataset | xr.DataArray
- transforms.temporal.median(*_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.DataArrayorxr.Dataset) – Data object to reducetime_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.reduceweights (
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 _meanhow_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 of the median value in the time dimensions
- Return type:
xr.Dataset | xr.DataArray
- transforms.temporal.min(*_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.DataArrayorxr.Dataset) – Data object to reducetime_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.reduceweights (
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 _meanhow_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 of the minimum value in the time dimensions
- Return type:
xr.Dataset | xr.DataArray
- transforms.temporal.monthly_max(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
resample().
- Returns:
A dataarray reduced to monthly maximum values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.monthly_mean(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
resample().
- Returns:
A dataarray reduced to monthly mean values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.monthly_median(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
resample().
- Returns:
A dataarray reduced to monthly median values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.monthly_min(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
resample().
- Returns:
A dataarray reduced to monthly minimum values
- Return type:
xr.DataArray | xr.Dataset
- 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 (
strorcallable) – 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 axistime_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,timedeltaordict) – 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}extra_reduce_dims (
strorlistofstr) – 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:
xr.DataArray | xr.Dataset
- transforms.temporal.monthly_std(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
resample().
- Returns:
A dataarray reduced to monthly standard deviation values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.monthly_sum(*_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) None,timedeltaordict) – 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.**kwargs – Keyword arguments to be passed to
resample().
- Returns:
A dataarray reduced to monthly sum values
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.reduce(dataarray, *_args, time_dim=None, **kwargs)
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 (
xr.DataArrayorxr.Dataset) – Data object to reducetime_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.reducehow (
strorcallable) – 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 axisweights (
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:
xr.Dataset | xr.DataArray
- transforms.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.DataArrayorxr.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.rollingcenter (
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.
- Returns:
A dataarray reduced values with a rolling window applied along the time dimension.
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.standardise_time(dataarray, target_format='%Y-%m-%d %H:%M:%S', time_dim=None)
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.Datasetorxr.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.time_dim (
str, optional) – 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”. If you do not want to aggregate along the time dimension use earthkit.transforms.aggregate.reduce
- Returns:
Data object with the time coordinate standardised to the specified format
- Return type:
xr.Dataset | xr.DataArray
- transforms.temporal.std(*_args, **kwargs)
Calculate the standard deviation of an xarray.dataarray/dataset along the time/date dimension.
With the option to apply weights either directly or using a specified weights method.
- Parameters:
dataarray (
xr.DataArrayorxr.Dataset) – Data object to reducetime_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.reduceweights (
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 _meanhow_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 of the standard deviation in the time dimensions
- Return type:
xr.Dataset | xr.DataArray
- transforms.temporal.sum(*_args, **kwargs)
Calculate the standard deviation of an xarray.dataarray/dataset along the time/date dimension.
With the option to apply weights either directly or using a specified weights method.
- Parameters:
dataarray (
xr.DataArrayorxr.Dataset) – Data object to reducetime_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.reduceweights (
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 _meanhow_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 summed in the time dimensions
- Return type:
xr.Dataset | xr.DataArray
- transforms.temporal.accumulation_to_rate(dataarray, *_args, **_kwargs)
Convert a variable accumulated from the beginning of the forecast to a rate.
The rate is computed by considering first-order discrete differences in data along the inferred, or specified, time dimension. The difference are converted to a rate by dividing by the time step duration, unless specified otherwise.
- Parameters:
dataarray (
xr.DataArray | xr.Dataset) – Data accumulated along time to be converted into rate (per second).step (timedelta | str , optional) – Interval between consecutive time steps. If a string, it should be a valid pandas time frequency string (e.g., ‘15min’, ‘3h’, ‘1 day’). If not provided, the will be inferred from the data.
rate_units (
timedelta | str, optional) – Units for the output rate. If a string, it must be a valid pandas time frequency string (e.g., ‘15min’, ‘3h’, ‘1 day’) or simple units like ‘seconds’, ‘minutes’, ‘hours’, ‘days’. If set to ‘step_length’, the rate will be accumulation per time step (“deaccumulated”) and the returned object will preserve the units and long_name attributes of the input dataarray. The default is ‘seconds’.rate_label (
str | None = None, optional) – Suffix to append to the name of the output dataarray. If None, defaults to ‘rate’ or ‘per_step’ depending on the rate_units.xp (
T.Any) – The array namespace to use for the reduction. If None, it will be inferred from the dataarray.time_dim (
str, optional) – 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”.accumulation_type (
str, optional) –Type of accumulation used in the input data. Default is “start_of_step”. Options are: - “start_of_step”: accumulation restarts at the beginning of each time step. - “start_of_forecast”: accumulation starts at the beginning of the forecast and continues
throughout the forecast period.
”start_of_day”: accumulation restarts at the beginning of each day (00:00 UTC).
Default is “start_of_step”.
from_first_step (
bool, optional) – Only used if accumulation_type is “start_of_forecast”. If True, the first time step’s rate is calculated by dividing the first accumulation value by the step duration. Default is False.provenance (
bool, optional) – If True, appends a history entry to the output dataarray’s attributes indicating that the transformation was applied. Default is True.
- Returns:
Data object with rate calculated based on the accumulation data.
- Return type:
xr.DataArray | xr.Dataset
- transforms.temporal.deaccumulate(dataarray, *_args, **_kwargs)
Alias for accumulation_to_rate function with rate_units set to ‘step_length’.
The returned object will preserve the units and long_name attributes of the input dataarray.
- Parameters:
dataarray (
xr.DataArray | xr.Dataset) – Data accumulated along time to be converted into rate (per time step).step (timedelta | str , optional) – Interval between consecutive time steps. If a string, it should be a valid pandas time frequency string (e.g., ‘15min’, ‘3h’, ‘1 day’). If not provided, the will be inferred from the data.
rate_label (str =
"", optional) – Suffix to append to the name and long_name of the output dataarray.xp (
T.Any) – The array namespace to use for the reduction. If None, it will be inferred from the dataarray.time_dim (
str, optional) – 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”.accumulation_type (
str, optional) –Type of accumulation used in the input data. Default is “start_of_forecast”. Options are: - “start_of_step”: accumulation restarts at the beginning of each time step. - “start_of_forecast”: accumulation starts at the beginning of the forecast and continues
throughout the forecast period.
”start_of_day”: accumulation restarts at the beginning of each day (00:00 UTC).
Default is “start_of_step”.
from_first_step (
bool, optional) – Only used if accumulation_type is “start_of_forecast”. If True, the first time step’s rate is calculated by dividing the first accumulation value by the step duration. Default is False.provenance (
bool, optional) – If True, appends a history entry to the output dataarray’s attributes indicating that the transformation was applied. Default is True.
- Returns:
Data object with deaccumulation data.
- Return type:
xr.DataArray | xr.Dataset