improver.utilities.probability_manipulation module
Module for utilities that manipulate probabilities.
- comparison_operator_dict()[source]
Generate dictionary linking string comparison operators to functions. Each key contains a dict of: - ‘function’: The operator function for this comparison_operator, - ‘spp_string’: Comparison_Operator string for use in CF-convention metadata - ‘inverse’: The inverse operator, i.e. ge has an inverse of lt.
- invert_probabilities(cube)[source]
Given a cube with a probability threshold, invert the probabilities relative to the existing thresholding inequality. Update the coordinate metadata to indicate the new threshold inequality.
- Parameters:
cube (
Cube
) – A probability cube with a threshold coordinate.- Return type:
- Returns:
Cube with the probabilities inverted relative to the input thresholding inequality.
- Raises:
ValueError – If no threshold coordinate is found.
- to_threshold_inequality(cube, above=True)[source]
Takes a cube and a target relative to threshold inequality; above or not above. The function returns probabilities in relation to the threshold values with the target inequality.
The threshold inequality is limited to being above (above=True) or below (above=False) a threshold, rather than more specific targets such as “greater_than_or_equal_to”. It is not possible to flip probabilities from e.g. “less_than_or_equal_to” to “greater_than_or_equal_to”, only to “greater_than”. As such the operation will use the valid inversion that achieves the broader target inequality.
- Parameters:
- Return type:
- Returns:
A cube with the probabilities relative to the threshold values with the target inequality.
- Raised:
ValueError: If the input cube has no threshold coordinate.