improver.nowcasting.accumulation module

This module defines the Accumulation class for calculating precipitation accumulations from advected radar fields. It is also possible to create longer accumulations from shorter intervals.

class Accumulation(accumulation_units='m', accumulation_period=None, forecast_periods=None)[source]

Bases: BasePlugin

Class to calculate precipitation accumulations from radar rates fields provided at discrete time intervals. The plugin will calculate accumulations between each pair of rates fields provided. These will be used to construct the accumulation period requested when possible, and cubes of this desired period are then returned.

__init__(accumulation_units='m', accumulation_period=None, forecast_periods=None)[source]

Initialise the plugin.

Parameters:
  • accumulation_units (str) – The physical units in which the accumulation should be returned. The default is metres.

  • accumulation_period (Optional[int]) – The desired accumulation period in seconds. This period must be evenly divisible by the time intervals of the input cubes. The default is None, in which case an accumulation is calculated across the span of time covered by the input rates cubes.

  • forecast_periods (Optional[List[float]]) – The forecast periods in seconds that define the end of an accumulation period.

_abc_impl = <_abc_data object>
static _calculate_accumulation(cube_subset, time_interval)[source]

Calculate the accumulation for the requested accumulation period by finding the mean rate between each adjacent pair of cubes within the cube_subset and multiplying this mean rate by the time_interval, in order to compute an accumulation. The accumulation between each pair of cubes is summed, in order to generate a total accumulation using all of the cubes within the cube_subset.

Parameters:
  • cube_subset (CubeList) – Cubelist containing all the rates cubes that will be used to calculate the accumulation.

  • time_interval (float) – Interval between the timesteps from the input cubelist.

Return type:

Optional[ndarray]

Returns:

If either the forecast period given by the input cube is not a requested forecast_period at which to calculate the accumulations, or the number of input cubelist is only sufficient to partially cover the desired accumulation, then None is returned. If an accumulation can be successfully computed, then a numpy array is returned.

_check_inputs(cubes)[source]

Check the inputs prior to calculating the accumulations.

Parameters:

cubes (CubeList) – Cube list of precipitation rates that will be checked for their appropriateness in calculating the requested accumulations. The timesteps between the cubes in this cubelist are expected to be regular.

Return type:

Tuple[CubeList, float]

Returns:

  • Modified version of the input cube list of precipitation rates that have had the units of the coordinates and cube data enforced. The cube list has also been sorted by time.

  • Interval between the timesteps from the input cubelist.

Raises:
  • ValueError – The input rates cubes must be at regularly spaced time intervals.

  • ValueError – The accumulation period is less than the time interval between the rates cubes.

  • ValueError – The specified accumulation period is not cleanly divisible by the time interval.

_get_cube_subsets(cubes, forecast_period)[source]

Finding the subset of cubes from the input cubelist that are within the accumulation period, based on the required forecast period that defines the upper bound of the accumulation period and the length of the accumulation period.

Parameters:
  • cubes (CubeList) – Cubelist containing all the rates cubes that are available to be used to calculate accumulations.

  • forecast_period (Union[int, ndarray]) – Forecast period in seconds matching the upper bound of the accumulation period.

Return type:

CubeList

Returns:

Cubelist that defines the cubes used to calculate the accumulations.

static _set_metadata(cube_subset)[source]

Set the metadata on the accumulation cube. This includes expanding the bounds to cover the accumulation period with the point within the time and forecast_period coordinates recorded as the upper bound of the accumulation period.

Parameters:

cube_subset (CubeList) – Cubelist containing the subset of cubes used to calculate the accumulations. The bounds from these cubes will be used to set the metadata on the output accumulation cube.

Return type:

Cube

Returns:

Accumulation cube with the desired metadata.

process(cubes)[source]

Calculate period precipitation accumulations based upon precipitation rate fields. All calculations are performed in SI units, so precipitation rates are converted to “m/s” and times into seconds before calculations are performed. The output units of accumulation are set by the plugin keyword argument accumulation_units.

Parameters:

cubes (CubeList) – A cubelist containing input precipitation rate cubes.

Return type:

CubeList

Returns:

A cubelist containing precipitation accumulation cubes where the accumulation periods are determined by plugin argument accumulation_period.

static sort_cubes_by_time(cubes)[source]

Sort cubes in time ascending order (from earliest time to latest time).

Parameters:

cubes (CubeList) – A cubelist containing input precipitation rate cubes.

Return type:

Tuple[CubeList, List[int]]

Returns:

  • The cubelist in ascending time order.

  • A list of the validity times of the precipitation rate cubes in integer seconds since 1970-01-01 00:00:00.