icclim._core.generic.threshold.basic
#
BasicThreshold module.
Module Contents#
- class icclim._core.generic.threshold.basic.BasicThreshold(operator: icclim._core.model.operator.Operator | str, value: icclim._core.model.threshold.ThresholdValueType, unit: str | None = None, initial_query: str | None = None, threshold_min_value: pint.Quantity | None = None, threshold_var_name: str | None = None, offset: pint.Quantity | None = None, **kwargs)[source]#
Pint ready simple threshold (e.g. “> 300 K”).
- Parameters:
operator (Operator or str) – The operator used for the threshold comparison.
value (ThresholdValueType) – The threshold value(s) to compare against.
unit (str, optional) – The unit of the threshold value(s).
initial_query (str, optional) – The initial query used to build the threshold.
threshold_min_value (pint.Quantity, optional) – The minimum value for the threshold.
threshold_var_name (str, optional) – The name of the threshold variable.
offset (pint.Quantity, optional) – The offset to be applied to the threshold value(s).
Notes
When built, value is always turned into a xarray.DataArray. The unit property has a setter that will attempt a unit conversion using units found in xclim’s pint registry.
The actual unit can be overridden by modifying value.attrs[“units”] directly.
- format_metadata(jinja_scope: dict[str, Any], jinja_env: jinja2.Environment, **kwargs) icclim._core.generic.threshold.threshold_templates.ThresholdMetadata [source]#
Generate the metadata for the threshold.
These metadata are used to fill the generic template.
- Parameters:
jinja_scope (dict) – The jinja scope, it contains the variables to be used in the jinja template.
jinja_env (jinja2.Environment) – The jinja environment, it contains the jinja rendering engine.
**kwargs – Additional keyword arguments, ignored for compatibility with other format_metadata methods.
- Returns:
The metadata for the threshold.
- Return type:
- compute(comparison_data: xarray.DataArray, override_op: Callable[[xarray.DataArray, xarray.DataArray], xarray.DataArray] | None = None, **kwargs) xarray.DataArray [source]#
Compute the threshold exceedance value.
- Parameters:
comparison_data (xr.DataArray) – The data array to compare with the threshold value.
override_op (Callable[[DataArray, DataArray], DataArray] | None, optional) – A custom override function to compute the threshold value. If provided, this function will be used instead of the default operator.
**kwargs – Additional keyword arguments.
- Returns:
The computed threshold value.
- Return type:
DataArray
Notes
If override_op is not None, the override_op function will be used to compute the threshold exceedance using the comparison_data and self.value as inputs. If override_op is None, the default operator defined in self.operator will be used to compute the threshold exceedance.