improver.cli.threshold module

Script to apply thresholding to a parameter dataset.

process(cube, land_sea_mask=None, *, threshold_values=None, threshold_config=None, threshold_units=None, comparison_operator='>', fuzzy_factor=None, collapse_coord=None, vicinity=None)[source]

Module to apply thresholding to a parameter dataset.

Calculate the threshold truth values of input data relative to the provided threshold value. A fuzzy factor or fuzzy bounds may be provided to smooth probabilities where values are close to the threshold.

Parameters
  • cube (iris.cube.Cube) – A cube to be processed.

  • threshold_values (list of float) – Threshold value or values about which to calculate the truth values; e.g. 270,300. Must be omitted if ‘threshold_config’ is used.

  • threshold_config (dict) – Threshold configuration containing threshold values and (optionally) fuzzy bounds. Best used in combination with ‘threshold_units’ It should contain a dictionary of strings that can be interpreted as floats with the structure: “THRESHOLD_VALUE”: [LOWER_BOUND, UPPER_BOUND] e.g: {“280.0”: [278.0, 282.0], “290.0”: [288.0, 292.0]}, or with structure “THRESHOLD_VALUE”: “None” (no fuzzy bounds). Repeated thresholds with different bounds are ignored; only the last duplicate will be used.

  • threshold_units (str) – Units of the threshold values. If not provided the units are assumed to be the same as those of the input cube. Specifying the units here will allow a suitable conversion to match the input units if possible.

  • comparison_operator (str) – Indicates the comparison_operator to use with the threshold. e.g. ‘ge’ or ‘>=’ to evaluate data >= threshold or ‘<’ to evaluate data < threshold. When using fuzzy thresholds, there is no difference between < and <= or > and >=. Options: > >= < <= gt ge lt le.

  • fuzzy_factor (float of None) – A decimal fraction defining the factor about the threshold value(s) which should be treated as fuzzy. Data which fail a test against the hard threshold value may return a fractional truth value if they fall within this fuzzy factor region. Fuzzy factor must be in the range 0-1, with higher values indicating a narrower fuzzy factor region / sharper threshold. A fuzzy factor cannot be used with a zero threshold or a threshold_config file.

  • collapse_coord (str) – An optional ability to set which coordinate we want to collapse over.

  • vicinity (list of float / int) – List of distances in metres used to define the vicinities within which to search for an occurrence. Each vicinity provided will lead to a different gridded field.

  • land_sea_mask (Cube) – Binary land-sea mask data. True for land-points, False for sea. Restricts in-vicinity processing to only include points of a like mask value.

Returns

Cube of probabilities relative to the given thresholds

Return type

iris.cube.Cube

Raises
  • ValueError – If threshold_config and threshold_values are both set

  • ValueError – If threshold_config is used for fuzzy thresholding