From 571251c6a51b3bd866f39824902b851da7f6b6ca Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Mon, 29 Apr 2024 12:48:42 -0400 Subject: [PATCH 1/3] Remove change_significance --- docs/api.rst | 3 -- xclim/ensembles/__init__.py | 1 - xclim/ensembles/_robustness.py | 69 ++-------------------------------- 3 files changed, 3 insertions(+), 70 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 8c4f5d60e..04e07fb96 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -59,9 +59,6 @@ Ensembles Module .. autofunction:: xclim.ensembles.robustness_categories :noindex: -.. autofunction:: xclim.ensembles.change_significance - :noindex: - .. autofunction:: xclim.ensembles.robustness_coefficient :noindex: diff --git a/xclim/ensembles/__init__.py b/xclim/ensembles/__init__.py index a6a0c1f82..8f6451495 100644 --- a/xclim/ensembles/__init__.py +++ b/xclim/ensembles/__init__.py @@ -19,7 +19,6 @@ plot_rsqprofile, ) from ._robustness import ( - change_significance, robustness_categories, robustness_coefficient, robustness_fractions, diff --git a/xclim/ensembles/_robustness.py b/xclim/ensembles/_robustness.py index 9c1603336..322d85e53 100644 --- a/xclim/ensembles/_robustness.py +++ b/xclim/ensembles/_robustness.py @@ -9,7 +9,6 @@ from __future__ import annotations -import warnings from inspect import Parameter, signature import numpy as np @@ -20,7 +19,6 @@ from xclim.indices.generic import compare, detrend __all__ = [ - "change_significance", "robustness_categories", "robustness_coefficient", "robustness_fractions", @@ -33,7 +31,7 @@ New tests must be decorated with :py:func:`significance_test` and fulfill the following requirements: - Function name should begin by "_", registered test name is the function name without its first character and with _ replaced by -. -- Function must accept 2 positional arguments : fut and ref (see :py:func:`change_significance` for definitions) +- Function must accept 2 positional arguments : fut and ref (see :py:func:`robustness_fractions` for definitions) - Function may accept other keyword-only arguments. - Function must return 2 values : + `changed` : 1D boolean array along `realization`. True for realization with significant change. @@ -42,7 +40,7 @@ def significance_test(func): - """Register a significance test for use in :py:func:`change_significance`. + """Register a significance test for use in :py:func:`robustness_fractions`. See :py:data:`SIGNIFICANCE_TESTS`. """ @@ -294,67 +292,6 @@ def robustness_fractions( # noqa: C901 return out -def change_significance( # noqa: C901 - fut: xr.DataArray | xr.Dataset, - ref: xr.DataArray | xr.Dataset, - test: str | None = "ttest", - weights: xr.DataArray | None = None, - p_vals: bool = False, - **kwargs, -) -> ( - tuple[xr.DataArray | xr.Dataset, xr.DataArray | xr.Dataset] - | tuple[ - xr.DataArray | xr.Dataset, - xr.DataArray | xr.Dataset, - xr.DataArray | xr.Dataset | None, - ] -): - """Backwards-compatible implementation of :py:func:`robustness_fractions`.""" - warnings.warn( - ( - "Function change_significance is deprecated as of xclim 0.47 and will be removed in 0.49. " - "Please use robustness_fractions instead." - ), - FutureWarning, - ) - - if isinstance(fut, xr.Dataset): - outs = { - v: robustness_fractions( - fut[v], - ref[v] if isinstance(ref, xr.Dataset) else ref, - test=test, - weights=weights[v] if isinstance(weights, xr.Dataset) else weights, - **kwargs, - ) - for v in fut.data_vars.keys() - } - change_frac = xr.merge([fracs.changed.rename(v) for v, fracs in outs.items()]) - pos_frac = xr.merge( - [ - (fracs.changed_positive / fracs.changed).rename(v) - for v, fracs in outs.items() - ] - ) - if p_vals: - if "pvals" in list(outs.values())[0]: - pvals = xr.merge([fracs.pvals.rename(v) for v, fracs in outs.items()]) - else: - pvals = None - return change_frac, pos_frac, pvals - return change_frac, pos_frac - - fracs = robustness_fractions(fut, ref, test=test, weights=weights, **kwargs) - # different def. - # Old "pos_frac" is fraction of change_frac that is positive - # New change_pos_frac is fraction of all that is both positive and significant - pos_frac = fracs.changed_positive / fracs.changed - - if p_vals: - return fracs.changed, pos_frac, fracs.pvals if "pvals" in fracs else None - return fracs.changed, pos_frac - - def robustness_categories( changed_or_fractions: xr.Dataset | xr.DataArray, agree: xr.DataArray | None = None, @@ -667,7 +604,7 @@ def _ipcc_ar6_c(fut, ref, *, ref_pi=None): return changed, None -# Add doc of each significance test to the `change_significance` output. +# Add doc of each significance test to `robustness_fractions` output's doc. def _gen_test_entry(namefunc): name, func = namefunc doc = func.__doc__.replace("\n ", "\n\t\t").rstrip() From 1007a72af63b4ebef68eed726b821f9d16371a18 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Mon, 29 Apr 2024 14:19:21 -0400 Subject: [PATCH 2/3] upd changeS --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index bf9636021..6ae403454 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,8 +18,10 @@ New indicators Breaking changes ^^^^^^^^^^^^^^^^ * The previously deprecated functions ``xclim.sdba.processing.construct_moving_yearly_window`` and ``xclim.sdba.processing.unpack_moving_yearly_window`` have been removed. These functions have been replaced by ``xclim.core.calendar.stack_periods`` and ``xclim.core.calendar.unstack_periods``. (:pull:`1717`). +* The previously deprecated function ``xclim.ensembles.change_significance`` has been removed. (:pull:`1737`). * Indicators ``snw_season_length`` and ``snd_season_length`` have been modified, see above. + Bug fixes ^^^^^^^^^ * Fixed an bug in sdba's ``map_groups`` that prevented passing DataArrays with cftime coordinates if the ``sdba_encode_cf`` option was True. (:issue:`1673`, :pull:`1674`). From fd0591284cee44d50980497c232f55c9d66ffd98 Mon Sep 17 00:00:00 2001 From: Pascal Bourgault Date: Mon, 29 Apr 2024 14:47:37 -0400 Subject: [PATCH 3/3] Update CHANGES.rst Co-authored-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index b355ccf45..49bc50e2d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -22,7 +22,7 @@ New indicators Breaking changes ^^^^^^^^^^^^^^^^ * The previously deprecated functions ``xclim.sdba.processing.construct_moving_yearly_window`` and ``xclim.sdba.processing.unpack_moving_yearly_window`` have been removed. These functions have been replaced by ``xclim.core.calendar.stack_periods`` and ``xclim.core.calendar.unstack_periods``. (:pull:`1717`). -* The previously deprecated function ``xclim.ensembles.change_significance`` has been removed. (:pull:`1737`). +* The previously deprecated function ``xclim.ensembles.change_significance`` has been removed. (:pull:`1737`). * Indicators ``snw_season_length`` and ``snd_season_length`` have been modified, see above. * The `hargeaves85`/`hg85` method for the ``potential_evapotranspiration`` indicator and indice has been modified for precision and consistency with recent academic literature. (:issue:`1710`, :pull:`1723`).