improver.categorical.utilities module
This module defines the utilities required for decision tree plugin
- _check_diagnostic_lists_consistency(query)[source]
Checks if specific input lists have same nested list structure. e.g. [‘item’] != [[‘item’]]
- _check_nested_list_consistency(query)[source]
Return True if all input lists have same nested list structure. e.g. [‘item’] != [[‘item’]]
- categorical_attributes(decision_tree, name)[source]
Extracts leaf items from decision_tree and creates cube attributes from them.
- check_tree(decision_tree, target_period=None)[source]
Perform some checks to ensure the provided decision tree is valid.
- Parameters:
decision_tree (
Dict
[str
,Dict
[str
,Any
]]) – Decision tree definition, provided as a dictionary.target_period (
Optional
[int
]) – The period in seconds that the categorical data being produced should represent. This should correspond with any period diagnostics, e.g. precipitation accumulation, being used as input. This is used to scale any threshold values that are defined with an associated period in the decision tree.
- Return type:
- Returns:
A list of problems found in the decision tree, or if none are found, the required input diagnostics.
- Raises:
ValueError – If decision_tree is not a dictionary.
- day_night_map(decision_tree)[source]
Returns a dict showing which night values are linked to which day values
- get_parameter_names(diagnostic_fields)[source]
For diagnostic fields that can contain operators and values, strips out just the parameter names.
- interrogate_decision_tree(decision_tree)[source]
Obtain a list of necessary inputs from the decision tree as it is currently defined. Return a formatted string that contains the diagnostic names, the thresholds needed, and whether they are thresholded above or below these values. If the required diagnostic is deterministic then just the diagnostic names are outputted. This output is used with the –check-tree option in the CLI, informing the user of the necessary inputs for a provided decision tree.
- is_decision_node(key, query)[source]
Determine whether a given node is a decision node. The meta node has a key of “meta”, leaf nodes have a query key of “leaf”, everything else is a decision node.
- is_variable(thing)[source]
Identify whether given string is likely to be a variable name by identifying the exceptions.
- update_tree_thresholds(tree, target_period=None)[source]
Replaces value / unit pairs from tree definition with an Iris AuxCoord that encodes the same information. Also scales any threshold values that have an associated period (e.g. accumulation in 3600 seconds) by a factor to reflect the target period (e.g. a 3-hour, 10800 second, weather symbol).
- Parameters:
target_period (
Optional
[int
]) – The period in seconds that the categories being produced should represent. This should correspond with any period diagnostics, e.g. precipitation accumulation, being used as input. This is used to scale any threshold values that are defined with an associated period in the decision tree.
- Return type:
- Returns:
The tree now containing AuxCoords instead of value / unit pairs, with period diagnostic threshold values scaled appropriately.
- Raises:
ValueError – If thresholds are defined with an associated period and no target_period is provided.