improver.utilities.threshold_interpolation module#

Script to linearly interpolate thresholds

class ThresholdInterpolation(thresholds)[source]#

Bases: PostProcessingPlugin

__init__(thresholds)[source]#
Parameters:

thresholds (List[float]) – List of the desired output thresholds.

Raises:

ValueError – If the thresholds list is empty.

_abc_impl = <_abc._abc_data object>#
_interpolate_thresholds(forecast_at_thresholds)[source]#

Interpolate forecast data to a new set of thresholds.

This method performs linear interpolation of forecast data from an initial set of thresholds to a new set of thresholds. The interpolation is done by converting the data to a 2D array, performing the interpolation, and then restoring the original dimensions.

Parameters:

forecast_at_thresholds (Cube) – Cube containing forecast data with a threshold coordinate.

Returns:

Interpolated forecast data with the new set of thresholds.

Return type:

ndarray

create_cube_with_thresholds(forecast_at_thresholds, cube_data)[source]#

Create a cube with a threshold coordinate based on a template cube extracted by slicing over the threshold coordinate.

The resulting cube will have an extra threshold coordinate compared with the template cube. The shape of the cube_data should be the shape of the desired output cube.

Parameters:
  • forecast_at_thresholds (Cube) – Cube containing forecast data with a threshold coordinate.

  • cube_data (ndarray) – Array containing the interpolated forecast data with the new thresholds.

Return type:

Cube

Returns:

Cube containing the new threshold coordinate and the interpolated data.

mask_checking(forecast_at_thresholds)[source]#

Check if the mask is consistent across different slices of the threshold coordinate.

Parameters:

forecast_at_thresholds (Cube) – The input cube containing forecast data with a threshold coordinate.

Returns:

The original mask if the data is masked and the mask is consistent across different slices of the threshold coordinate, otherwise None.

Return type:

original_mask

Raises:

ValueError – If the mask varies across different slices of the threshold coordinate.

process(forecast_at_thresholds)[source]#

Process the input cube to interpolate forecast data to a new set of thresholds.

This method performs the following steps: 1. Identifies the threshold coordinate in the input cube. 2. Checks if the mask is consistent across different slices of the threshold coordinate. 3. Collapses the realizations if present. 4. Interpolates the forecast data to the new set of thresholds. 5. Creates a new cube with the interpolated threshold data. 6. Applies the original mask to the new cube if it exists.

Parameters:

forecast_at_thresholds (Cube) – Cube expected to contain a threshold coordinate.

Returns:

Cube with forecast values at the desired set of thresholds. The threshold coordinate is always the zeroth dimension.

Return type:

Cube