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’]]

Parameters

query (Dict[str, Any]) – of weather-symbols decision-making information

Return type

bool

_check_nested_list_consistency(query)[source]

Return True if all input lists have same nested list structure. e.g. [‘item’] != [[‘item’]]

Parameters

query (List[List[Any]]) – Nested lists to check for consistency.

Return type

bool

Returns

True if diagnostic query lists have same nested list structure, else returns False.

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

str

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.

expand_nested_lists(query, key)[source]

Produce flat lists from list and nested lists.

Parameters
  • query (Dict[str, Any]) – A single query from the decision tree.

  • key (str) – A string denoting the field to be taken from the dict.

Return type

List[Any]

Returns

A 1D list containing all the values for a given key.

get_parameter_names(diagnostic_fields)[source]

For diagnostic fields that can contain operators and values, strips out just the parameter names.

Parameters

diagnostic_fields (List[List[str]]) –

Return type

List[List[str]]

Returns

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.

Parameters

wxtree (Dict[str, Dict[str, Any]]) – The weather symbol tree that is to be interrogated.

Return type

List[str]

Returns

Returns a formatted string descring the diagnostics required, including threshold details.

is_variable(thing)[source]

Identify whether given string is likely to be a variable name by identifying the exceptions.

Parameters

thing (str) – The string to operate on

Return type

bool

Returns

False if thing is one of [“+”, “-”, “*”, “/”] or if float( thing) does not raise a ValueError, else True.

update_daynight(cubewx)[source]

Update weather cube depending on whether it is day or night

Parameters

cubewx (Cube) – Cube containing only daytime weather symbols.

Return type

Cube

Returns

Cube containing day and night weather symbols

Raises

CoordinateNotFoundError – cube must have time coordinate.

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

Dict[str, Dict[str, Any]]

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.

weather_code_attributes()[source]
Return type

Dict[str, Any]

Returns

Attributes defining weather code meanings.