improver.categorical.subperiod_selector module#
- class SubperiodSelector(percentile, new_name='selected_subperiods', model_id_attr=None, record_run_attr=None, **threshold_kwargs)[source]#
Bases:
PostProcessingPluginPlugin to deaggregate a fraction-of-period-that-is-xxx diagnostic into this-subperiod-is-xxx.
For example, if light rain is expected for 6 hours within a 24 hour period (e.g. the 50th percentile of light rain over a 24 hour period is 0.25), this plugin selects the 6 hours most likely to contain that light rain. The result can be used in the weather symbol decision tree to force the selection of a wet symbol.
- __init__(percentile, new_name='selected_subperiods', model_id_attr=None, record_run_attr=None, **threshold_kwargs)[source]#
Initialise the plugin.
- Parameters:
percentile (
float) – The percentile of the main period diagnostic to select.new_name (
str) – Name of output cube.model_id_attr (
str) – Name of attribute recording source models to be copied to the output cube.record_run_attr (
str) – Name of attribute used to record models and cycles to be copied to the output cube.**threshold_kwargs – Keyword arguments specifying the names and values of threshold coords associated with the main period diagnostic to select. One of these will also match the threshold coord on the subperiod diagnostic, which will be used to identify which subperiods to select.
- _abc_impl = <_abc._abc_data object>#
- _apply_constraints(main_period_cube, subperiod_cube)[source]#
Select the required cube slices
The main period cube is expected to have a percentile coordinate and one or more threshold coordinates, and the subperiod cube is expected to have a time coordinate and one or more threshold coordinates that match those on the main period cube. The required slice is selected from the main period cube using the percentile and threshold constraints, and the required slice is selected from the subperiod cube using whichever of the threshold constraints matches a coordinate on the subperiod cube.
- Parameters:
main_period_cube (
Cube) – Cube containing the main period diagnostic to select, with a percentile coordinate and one or more threshold coordinates.subperiod_cube (
Cube) – Cube containing the subperiod diagnostic to select, with a time coordinate and one or more threshold coordinates that match those on the main period cube.
- Returns:
The selected slice from the main period cube. subperiod_slice:
The selected slice from the subperiod cube.
- Return type:
main_period_slice
- Raises:
If no data is found in the main period cube matching the percentile and threshold constraints. - If no matching threshold coordinate is found on the subperiod cube. - If no data is found in the subperiod cube matching the threshold constraints. - If the subperiod cube does not have exactly one more dimension than the main period cube.
- static _pick_subperiods(main_period_data, subperiod_data)[source]#
Identify the subperiods most likely to contain the phenomenon.
At each grid point, the main period data specifies the fraction of subperiods to select, and the subperiod data is the likelihood of the phenomenon occurring in each subperiod. The subperiods with the highest likelihood are selected until the number of selected subperiods matches the value from the main period data.
Where multiple subperiods have equal likelihood, the selection between them is random.
- Parameters:
main_period_data (
ndarray) – 2D array containing the main period diagnostic slice, with values indicating the fraction of subperiods to select.subperiod_data (
ndarray) – 3D array containing the subperiod diagnostic slice, with values indicating the likelihood of the phenomenon occurring in each subperiod.
- Return type:
- Returns:
3D array with the same shape as subperiod_data, where the selected subperiods are indicated by 1 and the non-selected subperiods are indicated by 0.