diff --git a/CHANGES.rst b/CHANGES.rst index bf01c1f80..154df7cde 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,7 @@ Contributors to this version: Trevor James Smith (:user:`Zeitsperre`), Éric Dup New features and enhancements ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * New properties: Bivariate Spell Length (``xclim.sdba.properties.bivariate_spell_length``), generalized spell lengths with an argument for `window`, and specific spell lengths with `window` fixed to 1 (``xclim.sdba.propertiies.threshold_count``, ``xclim.sdba.propertiies.bivariate_threshold_count``). (:pull:`1758`). +* New option `normalize` in ``sdba.measures.taylordiagram`` to obtain normalized Taylor diagrams (divide standard deviations by standard deviation of the reference). (:pull:`1764`). Breaking changes ^^^^^^^^^^^^^^^^ diff --git a/tests/test_sdba/test_measures.py b/tests/test_sdba/test_measures.py index 2410c63e3..2235251d6 100644 --- a/tests/test_sdba/test_measures.py +++ b/tests/test_sdba/test_measures.py @@ -92,3 +92,11 @@ def test_taylordiagram(open_dataset): ) test = sdba.measures.taylordiagram(sim, ref).values np.testing.assert_array_almost_equal(test, [13.12244701, 6.76166582, 0.73230199], 4) + + # test normalization option + test_normalize = sdba.measures.taylordiagram(sim, ref, normalize=True).values + np.testing.assert_array_almost_equal( + test_normalize, + [13.12244701 / 13.12244701, 6.76166582 / 13.12244701, 0.73230199], + 4, + ) diff --git a/xclim/sdba/measures.py b/xclim/sdba/measures.py index e6957f434..43432d5ee 100644 --- a/xclim/sdba/measures.py +++ b/xclim/sdba/measures.py @@ -451,6 +451,7 @@ def _taylordiagram( ref: xr.DataArray, dim: str = "time", group: str | Grouper = "time", + normalize: bool = False, ) -> xr.DataArray: """Taylor diagram. @@ -468,6 +469,9 @@ def _taylordiagram( group : str Compute the property and measure for each temporal groups individually. Currently not implemented. + normalize : bool + If `True`, divide the standard deviations by the standard deviation of the reference. + Default is `False`. Returns @@ -496,6 +500,19 @@ def _taylordiagram( } ) + # Normalize the standard deviations byt the standard deviation of the reference. + if normalize: + if (out[{"taylor_param": 0}] == 0).any(): + raise ValueError( + "`ref_std =0` (homogeneous field) obtained, normalization is not possible." + ) + with xr.set_options(keep_attrs=True): + out[{"taylor_param": [0, 1]}] = ( + out[{"taylor_param": [0, 1]}] / out[{"taylor_param": 0}] + ) + out.attrs["normalized"] = True + out.attrs["units"] = "" + return out