Contributing reference#

Reference document for contributors. Here we document part of the private API of the library as well as the suite of developer commands and scripts configured and included in the repository.

tox commands#

xarray-einstats uses tox to automatically handle testing (locally and on GitHub actions), building documentation locally, formatting and linting.

Here are the tox commands available which should be executed as tox -e <command>

reformat#

Modifies the files using black and isort so they comply with formatting requirements.

check#

Runs black, isort, pylint and pydocstyle to check both code style, presence of documentation everywhere that follows numpydoc convention and catching some code errors and bad practices.

docs#

Uses sphinx-build to generate the documentation.

cleandocs#

Deletes all doc cache and intermediate files to rebuild the docs from scratch the next time you use the docs command.

viewdocs#

Uses gnome-open to open the documentation build by tox. Opens the homepage

py3x#

Runs test suite with pytest

Private API#

Stats#

_wrap_method(method)

_add_documented_method(cls, wrapped_cls, methods)

Register methods to XrRV classes and document them from a template.

XrRV(dist, *args, **kwargs)

Base random variable wrapper class.

_apply_nonreduce_func(func, da, dims, kwargs)

Help wrap functions with a single input that return an output with the same size.

_apply_reduce_func(func, da, dims, kwargs[, ...])

Help wrap functions with a single input that return an output after reducing some dimensions.

Linear Algebra#

PairHandler(all_dims, keep_dims)

_translate_pattern_string(subscripts)

Translate a pattern given as string of dimension names to list of dimension names.

_einsum_parent(dims, *operands[, keep_dims])

Preprocess inputs to call numpy.einsum or numpy.einsum_path.

_einsum_path(dims, *operands[, keep_dims, ...])

Wrap numpy.einsum_path directly.

_einsum(dims, *operands[, keep_dims, ...])

Wrap numpy.einsum directly.

Einops#

DimHandler()

Handle converting actual dimension names to placeholders for einops.

process_pattern_list(redims, handler[, ...])

Process a pattern list and convert it to an einops expression using placeholders.

translate_pattern(pattern)

Translate a string pattern to a list pattern.

_reduce(da, reduction, out_dims[, in_dims, ...])

Wrap einops.reduce.

_rearrange(da, out_dims[, in_dims, dim_lengths])

Wrap einops.rearrange.

Tutorial#

Tutorial module with data for docs and quick testing.

generate_mcmc_like_dataset([seed])

Generate a Dataset with multiple variables, some with dimensions from mcmc sampling.

generate_matrices_dataarray([seed])

Generate a 4d DataArray representing a batch of matrices.