icclim._core.generic.indicator#

Contain the GenericIndicator class.

Module Contents#

class icclim._core.generic.indicator.GenericIndicator(name: str, process: Callable[Ellipsis, xarray.DataArray], definition: str, check_vars: Callable[[list[icclim._core.climate_variable.ClimateVariable], GenericIndicator], None] | None = None, sampling_methods: list[str] | None = None, missing: str = 'from_context', missing_options: dict | None = None, qualifiers: tuple = ())[source]#

GenericIndicator are climate indicators wich are not specific to a particular domain.

They can be computed from any climate variable and are combined with Threshold objects to create personalized indicators.

Parameters:
  • name (str) – The name of the indicator.

  • process (Callable[..., DataArray]) – The function that processes the indicator.

  • definition (str) – The definition of the indicator.

  • check_vars (Callable[[list[ClimateVariable], GenericIndicator], None], optional) – A function that checks if the variables meet the indicator requirements. Defaults to None.

  • sampling_methods (list[str], optional) – A list of sampling methods that can be used with the indicator. Defaults to None.

  • missing (str, optional) – The method for handling missing values. Defaults to “from_context”.

  • missing_options (dict, optional) – Additional options for handling missing values. Defaults to None.

  • qualifiers (tuple, optional) – Additional qualifiers for the indicator. Defaults to ().

missing[source]#

The method for handling missing values.

Type:

str

missing_options[source]#

Additional options for handling missing values.

Type:

dict | None

preprocess(climate_vars: list[icclim._core.climate_variable.ClimateVariable], jinja_scope: dict[str, Any], output_frequency: icclim._core.frequency.Frequency, src_freq: icclim._core.frequency.Frequency, output_unit: str | None, coef: float | None, sampling_method: str) list[icclim._core.climate_variable.ClimateVariable][source]#

Preprocesses the climate variables before computing the indicator.

Parameters:
  • climate_vars (list[ClimateVariable]) – The list of climate variables to be preprocessed.

  • jinja_scope (dict[str, Any]) – The Jinja scope used for formatting the template.

  • output_frequency (Frequency) – The desired frequency of the output.

  • src_freq (Frequency) – The source frequency of the climate variables.

  • output_unit (str | None) – The desired output unit of the indicator. If None, no unit conversion is performed.

  • coef (float | None) – The coefficient to multiply the climate variable data with. If None, no multiplication is performed.

  • sampling_method (str) – The sampling method used for some specific indicators. See difference_of_means for example.

Returns:

The preprocessed climate variables.

Return type:

list[ClimateVariable]

postprocess(result: xarray.DataArray, climate_vars: list[icclim._core.climate_variable.ClimateVariable], output_freq: str, src_freq: str, indexer: dict, out_unit: str | None) xarray.DataArray[source]#

Postprocesses the result of the indicator computation.

Parameters:
  • result (DataArray) – The result of the indicator computation.

  • climate_vars (list[ClimateVariable]) – The list of climate variables used for the computation.

  • output_freq (str) – The desired output frequency of the postprocessed result.

  • src_freq (str) – The source frequency of the input data.

  • indexer (dict) – The indexer used to subset the input data.

  • out_unit (str | None) – The desired output unit of the postprocessed result. If None, no unit conversion is performed.

Returns:

The postprocessed result.

Return type:

DataArray

icclim._core.generic.indicator._check_cf(climate_vars: list[icclim._core.climate_variable.ClimateVariable]) None[source]#

Compare metadata attributes to CF-Convention standards.

Default cfchecks use the specifications in xclim.core.utils.VARIABLES, assuming the indicator’s inputs are using the CMIP6/xclim variable names correctly. Variables absent from these default specs are silently ignored.

When subclassing this method, use functions decorated using xclim.core.options.cfcheck.