Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "xsdba" in docs and option #72

Merged
merged 10 commits into from
Feb 18, 2025
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixes
^^^^^
* Gave credits to the package to all previous contributors of ``xclim.sdba`` (:issue:`58`, :pull:`59`).
* Pin `sphinx-codeautolink` to fix ReadTheDocs and correct some docs errors (:pull:`40`).
* Changes to reflect the change of library name `xsdba` (:pull:`72`)

.. _changes_0.2.0:

Expand Down
18 changes: 9 additions & 9 deletions src/xsdba/adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,19 +1308,19 @@ class OTC(Adjust):
If `True`, a random location is picked uniformly inside their bin. Default is `True`.
adapt_freq_thresh : dict or str, optional
Threshold for frequency adaptation per variable.
See :py:class:`xclim.sdba.processing.adapt_freq` for details.
See :py:class:`xsdba.processing.adapt_freq` for details.
Frequency adaptation is not applied to missing variables if is dict.
Applied to all variables if is string.
normalization : {None, 'standardize', 'max_distance', 'max_value'}
Per-variable transformation applied before the distances are calculated.
Default is "max_distance".
See notes for details.
group : Union[str, Grouper]
The grouping information. See :py:class:`xclim.sdba.base.Grouper` for details.
The grouping information. See :py:class:`xsdba.base.Grouper` for details.
Default is "time", meaning a single adjustment group along dimension "time".
pts_dim : str
The name of the "multivariate" dimension. Defaults to "multivar", which is the
normal case when using :py:func:`xclim.sdba.base.stack_variables`.
normal case when using :py:func:`xsdba.base.stack_variables`.

Notes
-----
Expand Down Expand Up @@ -1445,7 +1445,7 @@ def _adjust(
class dOTC(Adjust):
r"""Dynamical Optimal Transport Correction.

This method is the dynamical version of :py:class:`~xclim.sdba.adjustment.OTC`, as presented by :cite:t:`robin_2019`.
This method is the dynamical version of :py:class:`~xsdba.adjustment.OTC`, as presented by :cite:t:`robin_2019`.
The temporal evolution of the model is found for every point by mapping the historical to the future dataset with
optimal transport. A mapping between historical and reference data is found in the same way, and the temporal evolution
of model data is applied to their assigned reference.
Expand Down Expand Up @@ -1479,26 +1479,26 @@ class dOTC(Adjust):
Applied to all variables if is string.
adapt_freq_thresh : dict or str, optional
Threshold for frequency adaptation per variable.
See :py:class:`xclim.sdba.processing.adapt_freq` for details.
See :py:class:`xsdba.processing.adapt_freq` for details.
Frequency adaptation is not applied to missing variables if is dict.
Applied to all variables if is string.
normalization : {None, 'standardize', 'max_distance', 'max_value'}
Per-variable transformation applied before the distances are calculated
in the optimal transport. Default is "max_distance".
See :py:class:`~xclim.sdba.adjustment.OTC` for details.
See :py:class:`~xsdba.adjustment.OTC` for details.
group : Union[str, Grouper]
The grouping information. See :py:class:`xclim.sdba.base.Grouper` for details.
The grouping information. See :py:class:`xsdba.base.Grouper` for details.
Default is "time", meaning a single adjustment group along dimension "time".
pts_dim : str
The name of the "multivariate" dimension. Defaults to "multivar", which is the
normal case when using :py:func:`xclim.sdba.base.stack_variables`.
normal case when using :py:func:`xsdba.base.stack_variables`.

Notes
-----
The simulated historical, simulated future and observed data sets :math:`X0`, :math:`X1` and :math:`Y0` are
discretized and standardized using histograms whose bin length along dimension `k` is given by `bin_width[k]`.
Mappings between :math:`Y0` and :math:`X0` on the one hand and between :math:`X0` and :math:`X1` on the other
are found by optimal transport (see :py:class:`~xclim.sdba.adjustment.OTC`). The latter mapping is used to
are found by optimal transport (see :py:class:`~xsdba.adjustment.OTC`). The latter mapping is used to
compute the temporal evolution of model data. This evolution is computed additively or multiplicatively for
each variable depending on its `kind`, and is applied to observed data with

Expand Down
4 changes: 2 additions & 2 deletions src/xsdba/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from boltons.funcutils import wraps
from xarray.core import dtypes

from xsdba.options import OPTIONS, SDBA_ENCODE_CF
from xsdba.options import OPTIONS, XSDBA_ENCODE_CF

# TODO : Redistributes some functions in existing/new scripts

Expand Down Expand Up @@ -675,7 +675,7 @@ def _map_blocks(ds, **kwargs): # noqa: C901
# duck empty calls dask if chunks is not None
tmpl[var] = duck_empty(dims, sizes, dtype=dtype, chunks=chunks)

if OPTIONS[SDBA_ENCODE_CF]:
if OPTIONS[XSDBA_ENCODE_CF]:
ds = ds.copy()
# Optimization to circumvent the slow pickle.dumps(cftime_array)
# List of the keys to avoid changing the coords dict while iterating over it.
Expand Down
2 changes: 1 addition & 1 deletion src/xsdba/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StatisticalMeasure(Indicator):
"""Base indicator class for statistical measures used when validating bias-adjusted outputs.

Statistical measures use input data where the time dimension was reduced, usually by the computation
of a :py:class:`xclim.sdba.properties.StatisticalProperty` instance. They usually take two arrays
of a :py:class:`xsdba.properties.StatisticalProperty` instance. They usually take two arrays
as input: "sim" and "ref", "sim" being measured against "ref". The two arrays must have identical
coordinates on their common dimensions.

Expand Down
8 changes: 4 additions & 4 deletions src/xsdba/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
from collections.abc import Callable

XSDBA_EXTRA_OUTPUT = "xsdba_extra_output"
SDBA_ENCODE_CF = "sdba_encode_cf"
XSDBA_ENCODE_CF = "xsdba_encode_cf"
AS_DATASET = "as_dataset"

MISSING_METHODS: dict[str, Callable] = {}

OPTIONS = {
XSDBA_EXTRA_OUTPUT: False,
SDBA_ENCODE_CF: False,
XSDBA_ENCODE_CF: False,
AS_DATASET: False,
}

_VALIDATORS = {
XSDBA_EXTRA_OUTPUT: lambda opt: isinstance(opt, bool),
SDBA_ENCODE_CF: lambda opt: isinstance(opt, bool),
XSDBA_ENCODE_CF: lambda opt: isinstance(opt, bool),
AS_DATASET: lambda opt: isinstance(opt, bool),
}

Expand All @@ -36,7 +36,7 @@ class set_options:
docstring. When activated, `adjust` will return a Dataset with `scen` and those extra diagnostics
For `processing` functions, see the doc, the output type might change, or not depending on the
algorithm. Default: ``False``.
sdba_encode_cf : bool
xsdba_encode_cf : bool
Whether to encode cf coordinates in the ``map_blocks`` optimization that most adjustment methods are based on.
This should have no impact on the results, but should run much faster in the graph creation phase.
If True, indicators output datasets. If False, they output DataArrays. Default :``False``.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def test_mon_u(
@pytest.mark.parametrize("use_dask", [True, False])
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
def test_add_dims(self, use_dask, gosset):
with set_options(sdba_encode_cf=use_dask):
with set_options(xsdba_encode_cf=use_dask):
if use_dask:
chunks = {"location": -1}
else:
Expand Down Expand Up @@ -680,7 +680,7 @@ class TestMBCn:
@pytest.mark.parametrize("period_dim", [None, "period"])
def test_simple(self, use_dask, group, window, period_dim, gosset):
group, window, period_dim, use_dask = "time", 1, None, False
with set_options(sdba_encode_cf=use_dask):
with set_options(xsdba_encode_cf=use_dask):
if use_dask:
chunks = {"location": -1}
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,5 @@ def func(ds, *, group):
d = ds.mean("location")
return d.rename("data").to_dataset()

with set_options(sdba_encode_cf=True):
with set_options(xsdba_encode_cf=True):
func(ds.convert_calendar("noleap").tasmax, group=Grouper("time"))
Loading