xclim.testing package

Helpers for testing xclim.

Submodules

xclim.testing.utils module

Testing and tutorial utilities’ module.

xclim.testing.utils.get_all_CMIP6_variables(get_cell_methods=True)[source]
xclim.testing.utils.list_datasets(github_repo='Ouranosinc/xclim-testdata', branch='main')[source]

Return a DataFrame listing all xclim test datasets available on the GitHub repo for the given branch.

The result includes the filepath, as passed to open_dataset, the file size (in KB) and the html url to the file. This uses an unauthenticated call to GitHub’s REST API, so it is limited to 60 requests per hour (per IP). A single call of this function triggers one request per subdirectory, so use with parsimony.

xclim.testing.utils.list_input_variables(submodules: Optional[Sequence[str]] = None, realms: Optional[Sequence[str]] = None) dict[source]

List all possible variables names used in xclim’s indicators.

Made for development purposes. Parses all indicator parameters with the xclim.core.utils.InputKind.VARIABLE or OPTIONAL_VARIABLE kinds.

Parameters
  • realms (Sequence of str, optional) – Restrict the output to indicators of a list of realms only. Default None, which parses all indicators.

  • submodules (str, optional) – Restrict the output to indicators of a list of submodules only. Default None, which parses all indicators.

Returns

dict – A mapping from variable name to indicator class.

xclim.testing.utils.open_dataset(name: str, suffix: str | None = None, dap_url: str | None = None, github_url: str = 'https://github.com/Ouranosinc/xclim-testdata', branch: str = 'main', cache: bool = True, cache_dir: Path = PosixPath('/home/docs/.xclim_testing_data'), **kwargs) Dataset[source]

Open a dataset from the online GitHub-like repository.

If a local copy is found then always use that to avoid network traffic.

Parameters
  • name (str) – Name of the file containing the dataset.

  • suffix (str, optional) – If no suffix is given, assumed to be netCDF (‘.nc’ is appended). For no suffix, set “”.

  • dap_url (str, optional) – URL to OPeNDAP folder where the data is stored. If supplied, supersedes github_url.

  • github_url (str) – URL to GitHub repository where the data is stored.

  • branch (str, optional) – For GitHub-hosted files, the branch to download from.

  • cache_dir (Path) – The directory in which to search for and write cached data.

  • cache (bool) – If True, then cache data locally for use on subsequent calls.

  • kwargs – For NetCDF files, keywords passed to xarray.open_dataset().

Returns

Union[Dataset, Path]

See also

xarray.open_dataset

xclim.testing.utils.publish_release_notes(style: str = 'md', file: os.PathLike | StringIO | TextIO | None = None) str | None[source]

Format release history in Markdown or ReStructuredText.

Parameters
  • style ({“rst”, “md”}) – Use ReStructuredText formatting or Markdown. Default: Markdown.

  • file ({os.PathLike, StringIO, TextIO}, optional) – If provided, prints to the given file-like object. Otherwise, returns a string.

Returns

str, optional

Notes

This function is solely for development purposes.

xclim.testing.utils.show_versions(file: os.PathLike | StringIO | TextIO | None = None) str | None[source]

Print the versions of xclim and its dependencies.

Parameters

file ({os.PathLike, StringIO, TextIO}, optional) – If provided, prints to the given file-like object. Otherwise, returns a string.

Returns

str or None

xclim.testing.utils.update_variable_yaml(filename=None, xclim_needs_only=True)[source]

Update a variable from a yaml file.