improver.wxcode.utilities module
This module defines the utilities required for wxcode 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’]]
- check_tree(wxtree, target_period=None)[source]
Perform some checks to ensure the provided decision tree is valid.
- Parameters
wxtree (
Dict[str,Dict[str,Any]]) – Weather symbols decision tree definition, provided as a dictionary.target_period (
Optional[int]) – The period in seconds that the weather symbol 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 wxtree is not a dictionary.
- get_parameter_names(diagnostic_fields)[source]
For diagnostic fields that can contain operators and values, strips out just the parameter names.
- interrogate_decision_tree(wxtree)[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. 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_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
tree (
Dict[str,Dict[str,Any]]) – Weather symbols decision tree.target_period (
Optional[int]) – The period in seconds that the weather symbol 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.