accumulation_to_rate

earthkit.transforms.temporal.accumulation_to_rate(dataarray: Dataset | DataArray, *_args, **_kwargs) Dataset | DataArray[source]

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 (xarray.DataArray | xarray.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, it 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 or 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).

  • 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:

xarray.DataArray | xarray.Dataset