improver.utilities.deterministic_realization_selector module#

Module containing a deterministic realization selector.

class DeterministicRealizationSelector(target_realization_number=0, attribute='primary_input_realizations_to_clusters')[source]#

Bases: PostProcessingPlugin

Plugin to extract a deterministic realization from a set of realizations that have been clustered using the improver.clustering.realization_clustering plugin.

__init__(target_realization_number=0, attribute='primary_input_realizations_to_clusters')[source]#

Initialise the plugin.

Parameters:
  • target_realization_number (int) – The number of the realization of interest. Default value = 0.

  • attribute (str) – The attribute of the cluster cube, used to identify target realization, and it’s associated cluster. Default value = “primary_input_realizations_to_clusters”.

_abc_impl = <_abc._abc_data object>#
static extract_cluster_from_cube(target_key, forecast_cube)[source]#

Extract the cluster containing the target realization. This cube becomes our deterministic realization.

Parameters:
  • target_key (int) – The key corresponding to the cluster, that contains the target realization.

  • forecast_cube (Cube) – The cube with the clusters containing the target realization to be extracted.

Return type:

Cube

Returns:

  • Cube containing only the cluster with the target realization.

find_target_key(cluster_cube)[source]#

Find the key (cluster) of the cluster cube, that contains the target realization. This cluster will become the deterministic realization.

Parameters:

cluster_cube (Cube) – Clustered cube with the attribute : “primary_input_realizations_to_clusters”, as a dictionary, to be searched through for the target realization.

Return type:

int | None

Returns:

  • Key (cluster) that contains the target realization.

process(cubes)[source]#

Extracts the target deterministic realization from the forecast cubes. Identifies the cluster cube, (containing the attribute: “primary_input_realizations_to_clusters”) and the forecast cube from the input cubelist. Determines the target realization, and its cluster, extracts this from the forecast cube and returns the deterministic_realization_cube.

Parameters:

cubes (CubeList) – A list of two cubes containing a forecast and a cluster cube. The cluster cube will contain the attribute: “primary_input_realizations_to_clusters”. This will be used to split the forecasts and cluster cube and determine which realizations to extract from the forecast cube.

Return type:

Cube

Returns:

  • Forecast cube containing only the cluster with the target realization.

This cluster becomes our deterministic realization.

Raises:

AttributeError

  • If the target realization, does not exist or cannot be extracted.

split_input_cubelist(input_cubelist)[source]#

Splits the input cubelist into two cubes, depending on whether they contain the attribute:”primary_input_realizations_to_clusters”.

Parameters:

input_cubelist (CubeList) – A list of cubes containing two cubes with only one which contains the attribute: “primary_input_realizations_to_clusters”.

Returns:

“primary_input_realizations_to_clusters”. - Cube, to be the forecast_cube, which doesn’t contain the attribute: “primary_input_realizations_to_clusters”.

Return type:

  • Cube, to be the cluster_cube, which contains the attribute

Raises:

AttributeError

  • If the input cubelist contains more than two cubes. - If the forecast_cube or cluster_cube cannot be found in the input.