diagnostic.wrappers.required_variables#
- 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