improver.metadata.probabilistic module

Utilities for interrogating IMPROVER probabilistic metadata

_extract_diagnostic_name(cube_name, check_vicinity=False)[source]

Extract the standard or long name X of the diagnostic from a probability cube name of the form ‘probability_of_X_above/below_threshold’, ‘probability_of_X_between_thresholds’, or ‘probability_of_X_in_vicinity_above/below_threshold’.

Parameters:
  • cube_name (str) – The probability cube name

  • check_vicinity (bool) – If False the function will return X as described above, which matches the name of the threshold-type coordinate on the cube. If True, the cube name is checked to see whether it is a vicinity diagnostic, and if so the function returns “X_in.*_vicinity”. This is the name of the equivalent diagnostic in percentile or realization space.

Return type:

str

Returns:

The name of the diagnostic underlying this probability

Raises:

ValueError – If the input name does not match the expected regular expression (ie if cube_name_regex(cube_name) returns None).

find_percentile_coordinate(cube)[source]

Find percentile coord in cube.

Parameters:

cube (Cube) – Cube contain one or more percentiles.

Return type:

Coord

Returns:

Percentile coordinate.

Raises:
  • TypeError – If cube is not of type iris.cube.Cube.

  • CoordinateNotFoundError – If no percentile coordinate is found in cube.

  • ValueError – If there is more than one percentile coords in the cube.

find_threshold_coordinate(cube)[source]

Find threshold coordinate in cube.

Compatible with both the old (cube.coord(“threshold”)) and new (cube.coord.var_name == “threshold”) IMPROVER metadata standards.

Parameters:

cube (Cube) – Cube containing thresholded probability data

Return type:

Coord

Returns:

Threshold coordinate

Raises:
  • TypeError – If cube is not of type iris.cube.Cube.

  • CoordinateNotFoundError – If no threshold coordinate is found.

format_cell_methods_for_diagnostic(cube)[source]

Remove reference to threshold-type coordinate from cell method comments that were previously on a probability cube. Modifies cube in place.

Parameters:

cube (Cube) – Cube to update

Return type:

None

format_cell_methods_for_probability(cube, threshold_name)[source]

Update cell methods on a diagnostic cube to reflect the fact that the data to which they now refer is on a coordinate. Modifies cube in place.

Parameters:
  • cube (Cube) – Cube to update

  • threshold_name (str) – Name of the threshold-type coordinate to which the cell method now refers

Return type:

None

get_diagnostic_cube_name_from_probability_name(cube_name)[source]

Get the name of the original diagnostic cube, including vicinity, from the name of the probability cube.

Return type:

str

get_threshold_coord_name_from_probability_name(cube_name)[source]

Get the name of the threshold coordinate from the name of the probability cube. This can be used to set or modify a threshold coordinate name after renaming or conversion from probabilities to percentiles / realizations.

Return type:

str

in_vicinity_name_format(cube_name)[source]

Generate the correct name format for an ‘in_vicinity’ probability cube, taking into account the ‘above/below_threshold’ or ‘between_thresholds’ suffix required by convention.

Parameters:

cube_name (str) – The non-vicinity probability cube name to be formatted.

Return type:

str

Returns:

Correctly formatted name following the accepted convention e.g. ‘probability_of_X_in_vicinity_above_threshold’.

is_percentile(cube)[source]

Determines whether a cube contains probability data at a range of percentiles.

Parameters:

cube (Cube) – Cube to check for percentile data.

Return type:

bool

Returns:

True if in percentile representation.

is_probability(cube)[source]

Determines whether a cube contains probability data at a range of thresholds.

Parameters:

cube (Cube) – Cube to check for probability threshold data.

Return type:

bool

Returns:

True if in threshold representation.

probability_cube_name_regex(cube_name)[source]

Regular expression matching IMPROVER probability cube name. Returns None if the cube_name does not match the regular expression (ie does not start with ‘probability_of’).

Parameters:

cube_name (str) – Probability cube name

Return type:

Optional[Match]

Returns:

The regex match

probability_is_above_or_below(cube)[source]

Checks the spp__relative_to_threshold attribute and outputs whether it is above or below the threshold given. If there isn’t a spp__relative_to_threshold attribute it returns None.

Parameters:

cube (Cube) – Cube containing thresholded probability data

Return type:

Optional[str]

Returns:

Which indicates whether the cube has data that is above or below the threshold