diagnostic.wrappers#

Functions

acceptable_variables(variables)

Decorator that checks if the dataset contains at least one of the acceptable variables before applying the diagnostic.

required_variables(variables)

A decorator that checks if the required variables are present in the dataset (and reference dataset if applicable) before applying the diagnostic.

acceptable_variables(variables)[source]#

Decorator that checks if the dataset contains at least one of the acceptable variables before applying the diagnostic. The required variables are specified as a list of strings. If at least one of the acceptable variables is present the diagnostic is applied. If an acceptable variable is present all acceptable variables are passed to the diagnostic function - other variables will be dropped.

Parameters:

variables (str or list of str) – The variable(s) that are acceptable to apply the diagnostic.

Examples

>>> # The diagnostic function accepts the variables 'tas', 'tas_max' and 'tas_min'.
>>> @acceptable_variables(["tas", "tas_max", "tas_min"])
>>> def my_diagnostic(ds: xr.Dataset):
>>>    #Function which is valid for tas, tas_max and tas_min
>>>    return result
required_variables(variables)[source]#

A decorator that checks if the required variables are present in the dataset (and reference dataset if applicable) before applying the diagnostic. The required variables are specified as a list of strings. Only if all the required variables are present, the diagnostic is applied. Note that this is a minimum requirement; the dataset may contain other variables than the required ones.

Parameters:

variables (str or list of str) – The variable(s) required to apply the diagnostic.

Examples

>>> # The diagnostic function requires the variables 'tas' and 'pr' to be present in the dataset.
>>> @required_variables(["tas", "pr"])
>>> def my_diagnostic(ds: xr.Dataset):
>>>    return ds.tas + ds.pr
>>> # This also checks if the variables are present in both the data and the reference.
>>> # An error is raised if the required variables are not present in the data or the reference.
>>> @required_variables(["tas", "pr"])
>>> def my_diagnostic(ds: xr.Dataset, ref: xr.Dataset):
>>>    return ds.tas + ref.pr