From 6221785cf5f0210734463876be3b4af128f05ef8 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Thu, 24 Oct 2024 10:53:13 -0400 Subject: [PATCH 01/13] remove support for deprecated function --- src/xscen/ensembles.py | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/xscen/ensembles.py b/src/xscen/ensembles.py index 5d9181a4..cc55fb99 100644 --- a/src/xscen/ensembles.py +++ b/src/xscen/ensembles.py @@ -108,7 +108,7 @@ def ensemble_stats( # noqa: C901 # if input files are .zarr, change the engine automatically if isinstance(datasets, list) and isinstance(datasets[0], str | os.PathLike): path = Path(datasets[0]) - if path.suffix == ".zarr": + if path.suffix in [".zarr", ".zip"]: create_kwargs.setdefault("engine", "zarr") if not isinstance(datasets, xr.Dataset): @@ -137,6 +137,7 @@ def ensemble_stats( # noqa: C901 # Workaround for robustness_categories real_stat = None + categories_kwargs = {} if stat == "robustness_categories": real_stat = "robustness_categories" stat = "robustness_fractions" @@ -155,20 +156,10 @@ def ensemble_stats( # noqa: C901 f"Weighting is not supported for '{stat}'. The results may be incorrect." ) - # FIXME: change_significance is deprecated and will be removed in xclim 0.49. if stat in [ - "change_significance", "robustness_fractions", "robustness_categories", ]: - # FIXME: This can be removed once change_significance is removed. - # It's here because the 'ref' default was removed for change_significance in xclim 0.47. - stats_kwargs.setdefault("ref", None) - if (stats_kwargs.get("ref") is not None) and len(statistics_to_compute) > 1: - raise ValueError( - f"The input requirements for '{stat}' when 'ref' is specified are not compatible with other statistics." - ) - # These statistics only work on DataArrays for v in ens.data_vars: with xr.set_options(keep_attrs=True): @@ -188,22 +179,6 @@ def ensemble_stats( # noqa: C901 # Call the function tmp = getattr(ensembles, stat)(ens_v, **stats_kwargs) - # Manage the multiple outputs of change_significance - # FIXME: change_significance is deprecated and will be removed in xclim 0.49. - if ( - stat == "change_significance" - and stats_kwargs.get("p_vals", False) is False - ): - ens_stats[f"{v}_change_frac"], ens_stats[f"{v}_pos_frac"] = tmp - elif stat == "change_significance" and stats_kwargs.get( - "p_vals", False - ): - ( - ens_stats[f"{v}_change_frac"], - ens_stats[f"{v}_pos_frac"], - ens_stats[f"{v}_p_vals"], - ) = tmp - # Robustness categories if real_stat == "robustness_categories": categories = ensembles.robustness_categories( From 00e79ff117b178d107c07786d182648f9f5873f1 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Thu, 24 Oct 2024 12:14:00 -0400 Subject: [PATCH 02/13] change units without affecting original ds --- environment-dev.yml | 2 +- environment.yml | 2 +- pyproject.toml | 2 +- src/xscen/utils.py | 14 ++++++++++---- tests/test_ensembles.py | 16 ---------------- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/environment-dev.yml b/environment-dev.yml index 9d4434da..73a6dde3 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -30,7 +30,7 @@ dependencies: - sparse - toolz - xarray >=2023.11.0, !=2024.6.0 - - xclim >=0.52.2, <0.53 + - xclim >=0.53.1, <0.54 - xesmf >=0.7 - zarr >=2.13 # Opt diff --git a/environment.yml b/environment.yml index e5336ab8..5976e9e8 100644 --- a/environment.yml +++ b/environment.yml @@ -30,7 +30,7 @@ dependencies: - sparse - toolz - xarray >=2023.11.0, !=2024.6.0 - - xclim >=0.52.2, <0.53 + - xclim >=0.53.1, <0.54 - xesmf >=0.7 - zarr >=2.13 # To install from source diff --git a/pyproject.toml b/pyproject.toml index d8771658..f2e810aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ dependencies = [ "sparse", "toolz", "xarray >=2023.11.0, !=2024.6.0", - "xclim >=0.52.2, <0.53", + "xclim >=0.53.1, <0.54", "zarr >=2.13" ] diff --git a/src/xscen/utils.py b/src/xscen/utils.py index 0dcc8871..ea1d043b 100644 --- a/src/xscen/utils.py +++ b/src/xscen/utils.py @@ -812,20 +812,26 @@ def change_units(ds: xr.Dataset, variables_and_units: dict) -> xr.Dataset: ).dimensionality.get("[time]") if time_in_ds == time_in_out: - ds[v] = units.convert_units_to(ds[v], variables_and_units[v]) + ds[v] = ds.assign( + {v: units.convert_units_to(ds[v], variables_and_units[v])} + ) elif time_in_ds - time_in_out == 1: # ds is an amount - ds[v] = units.amount2rate(ds[v], out_units=variables_and_units[v]) + ds[v] = ds.assign( + {v: units.amount2rate(ds[v], out_units=variables_and_units[v])} + ) elif time_in_ds - time_in_out == -1: # ds is a rate - ds[v] = units.rate2amount(ds[v], out_units=variables_and_units[v]) + ds[v] = ds.assign( + {v: units.rate2amount(ds[v], out_units=variables_and_units[v])} + ) else: raise ValueError( f"No known transformation between {ds[v].units} and {variables_and_units[v]} (temporal dimensionality mismatch)." ) elif (v in ds) and (ds[v].units != variables_and_units[v]): # update unit name if physical units are equal but not their name (ex. degC vs °C) - ds[v] = ds[v].assign_attrs(units=variables_and_units[v]) + ds[v] = ds.assign({v: ds[v].assign_attrs(units=variables_and_units[v])}) return ds diff --git a/tests/test_ensembles.py b/tests/test_ensembles.py index 6aa596e2..e21a409a 100644 --- a/tests/test_ensembles.py +++ b/tests/test_ensembles.py @@ -258,22 +258,6 @@ def test_errors(self): }, ) - # Error if you try to use a robustness_fractions with a reference dataset, but also specify other statistics - with pytest.raises( - ValueError, match="The input requirements for 'robustness_fractions'" - ): - xs.ensemble_stats( - ens, - statistics={ - "robustness_fractions": { - "test": "threshold", - "abs_thresh": 2.5, - "ref": ref, - }, - "ensemble_mean_std_max_min": None, - }, - ) - class TestGenerateWeights: @staticmethod From 204ce8ac147c974ef8c7c463f1bf5ae8de753b62 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Thu, 24 Oct 2024 12:18:15 -0400 Subject: [PATCH 03/13] upd changelog --- CHANGELOG.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 78a5e5bc..dd59adee 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,10 +15,16 @@ New features and enhancements Breaking changes ^^^^^^^^^^^^^^^^ * ``xs.get_warming_level`` has been renamed to ``xs.get_period_from_warming_level``. Its argument `return_horizon` was reversed and renamed `return_central_year` (:pull:`474`). +* Removed support for the deprecated `xclim` function `change_significance` in `ensemble_stats`. (:pull:`482`). Bug fixes ^^^^^^^^^ * ``xs.io.save_to_table`` now correctly handles the case where the input is a `DataArray` or a `Dataset` with a single variable. (:pull:`473`). +* Fixed a bug in ``xs.utils.change_units`` where the original dataset was modified. (:pull:`482`). + +Internal changes +^^^^^^^^^^^^^^^^ +* Bumped the version of `xclim` to 0.53.1. (:pull:`482`). v0.10.0 (2024-09-30) -------------------- From 7ab9b1e2bd1114ceb62d7951d128fde5192ec36e Mon Sep 17 00:00:00 2001 From: RondeauG <38501935+RondeauG@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:19:01 -0400 Subject: [PATCH 04/13] Update src/xscen/utils.py Co-authored-by: Pascal Bourgault --- src/xscen/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xscen/utils.py b/src/xscen/utils.py index ea1d043b..7bd9ffe1 100644 --- a/src/xscen/utils.py +++ b/src/xscen/utils.py @@ -812,7 +812,7 @@ def change_units(ds: xr.Dataset, variables_and_units: dict) -> xr.Dataset: ).dimensionality.get("[time]") if time_in_ds == time_in_out: - ds[v] = ds.assign( + ds = ds.assign( {v: units.convert_units_to(ds[v], variables_and_units[v])} ) elif time_in_ds - time_in_out == 1: From bcd63e268a996e771a5938a675ce49187da37f9f Mon Sep 17 00:00:00 2001 From: RondeauG <38501935+RondeauG@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:19:06 -0400 Subject: [PATCH 05/13] Update src/xscen/utils.py Co-authored-by: Pascal Bourgault --- src/xscen/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xscen/utils.py b/src/xscen/utils.py index 7bd9ffe1..5526efa7 100644 --- a/src/xscen/utils.py +++ b/src/xscen/utils.py @@ -817,7 +817,7 @@ def change_units(ds: xr.Dataset, variables_and_units: dict) -> xr.Dataset: ) elif time_in_ds - time_in_out == 1: # ds is an amount - ds[v] = ds.assign( + ds = ds.assign( {v: units.amount2rate(ds[v], out_units=variables_and_units[v])} ) elif time_in_ds - time_in_out == -1: From 0b1c2126c3b24c464f6826d302224065bdc8ec51 Mon Sep 17 00:00:00 2001 From: RondeauG <38501935+RondeauG@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:19:13 -0400 Subject: [PATCH 06/13] Update src/xscen/utils.py Co-authored-by: Pascal Bourgault --- src/xscen/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xscen/utils.py b/src/xscen/utils.py index 5526efa7..c95c9383 100644 --- a/src/xscen/utils.py +++ b/src/xscen/utils.py @@ -822,7 +822,7 @@ def change_units(ds: xr.Dataset, variables_and_units: dict) -> xr.Dataset: ) elif time_in_ds - time_in_out == -1: # ds is a rate - ds[v] = ds.assign( + ds = ds.assign( {v: units.rate2amount(ds[v], out_units=variables_and_units[v])} ) else: From 444cdd03a6e9c87aa14b877cbfd0b372597e6148 Mon Sep 17 00:00:00 2001 From: RondeauG <38501935+RondeauG@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:19:19 -0400 Subject: [PATCH 07/13] Update src/xscen/utils.py Co-authored-by: Pascal Bourgault --- src/xscen/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xscen/utils.py b/src/xscen/utils.py index c95c9383..d68bebec 100644 --- a/src/xscen/utils.py +++ b/src/xscen/utils.py @@ -831,7 +831,7 @@ def change_units(ds: xr.Dataset, variables_and_units: dict) -> xr.Dataset: ) elif (v in ds) and (ds[v].units != variables_and_units[v]): # update unit name if physical units are equal but not their name (ex. degC vs °C) - ds[v] = ds.assign({v: ds[v].assign_attrs(units=variables_and_units[v])}) + ds = ds.assign({v: ds[v].assign_attrs(units=variables_and_units[v])}) return ds From f82354017d670918db4cd8f7dc51fd6969dc5b58 Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:33:45 -0400 Subject: [PATCH 08/13] raise pins --- environment-dev.yml | 8 ++++---- environment.yml | 4 ++-- pyproject.toml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/environment-dev.yml b/environment-dev.yml index 73a6dde3..5b06e841 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -30,7 +30,7 @@ dependencies: - sparse - toolz - xarray >=2023.11.0, !=2024.6.0 - - xclim >=0.53.1, <0.54 + - xclim >=0.53.2, <0.54 - xesmf >=0.7 - zarr >=2.13 # Opt @@ -40,13 +40,13 @@ dependencies: - babel - black ==24.8.0 - blackdoc ==0.3.9 - - bump-my-version >=0.25.1 + - bump-my-version >=0.26.8 - coverage>=7.5.0 - coveralls>=4.0.1 - - flake8 >=6.1.0 + - flake8 >=7.1.0 - flake8-rst-docstrings>=0.3.0 - ipykernel - - ipython + - ipython >=8.5.0 - isort ==5.13.2 - jupyter_client - nbsphinx diff --git a/environment.yml b/environment.yml index 5976e9e8..3e4232f3 100644 --- a/environment.yml +++ b/environment.yml @@ -30,7 +30,7 @@ dependencies: - sparse - toolz - xarray >=2023.11.0, !=2024.6.0 - - xclim >=0.53.1, <0.54 + - xclim >=0.53.2, <0.54 - xesmf >=0.7 - zarr >=2.13 # To install from source @@ -39,4 +39,4 @@ dependencies: # Opt - nc-time-axis >=1.3.1 - pyarrow >=10.0.1 - - pip + - pip >=24.2.0 diff --git a/pyproject.toml b/pyproject.toml index f2e810aa..27750623 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,7 @@ dependencies = [ "sparse", "toolz", "xarray >=2023.11.0, !=2024.6.0", - "xclim >=0.53.1, <0.54", + "xclim >=0.53.2, <0.54", "zarr >=2.13" ] @@ -84,7 +84,7 @@ dev = [ "isort ==5.13.2", "mypy", "numpydoc >=1.8.0", - "pooch", + "pooch >=1.8.0", "pre-commit >=3.3.2", "pytest-cov >=5.0.0", "pytest >=8.3.2", @@ -97,7 +97,7 @@ dev = [ docs = [ # Documentation and examples "ipykernel", - "ipython", + "ipython >=8.5.0", "jupyter_client", "nbsphinx", "nbval", From d3f34b9289798decfcc5db0e2cdd4e2deda82f45 Mon Sep 17 00:00:00 2001 From: RondeauG <38501935+RondeauG@users.noreply.github.com> Date: Fri, 1 Nov 2024 14:47:34 -0400 Subject: [PATCH 09/13] Update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index dd59adee..4bb841a9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -24,7 +24,7 @@ Bug fixes Internal changes ^^^^^^^^^^^^^^^^ -* Bumped the version of `xclim` to 0.53.1. (:pull:`482`). +* Bumped the version of `xclim` to 0.53.2. (:pull:`482`). v0.10.0 (2024-09-30) -------------------- From e7c4ed429e5aa55457f41396fa16138c00c14c33 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Fri, 1 Nov 2024 15:11:00 -0400 Subject: [PATCH 10/13] fix docs --- docs/notebooks/4_ensembles.ipynb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/notebooks/4_ensembles.ipynb b/docs/notebooks/4_ensembles.ipynb index cf6a2576..4bc0a6e9 100644 --- a/docs/notebooks/4_ensembles.ipynb +++ b/docs/notebooks/4_ensembles.ipynb @@ -53,9 +53,9 @@ "}\n", "\n", "for d in datasets:\n", - " ds = open_dataset(datasets[d], branch=\"v2023.12.14\").isel(\n", - " lon=slice(0, 4), lat=slice(0, 4)\n", - " )\n", + " ds = open_dataset(\n", + " datasets[d], # branch=\"v2023.12.14\"\n", + " ).isel(lon=slice(0, 4), lat=slice(0, 4))\n", " ds = xs.climatological_op(\n", " ds,\n", " op=\"mean\",\n", @@ -66,6 +66,15 @@ " datasets[d] = xs.compute_deltas(ds, reference_horizon=\"1981-2010\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "datasets" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -263,7 +272,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.7" } }, "nbformat": 4, From e7b409fbc7543e463d52f3d49494526026e0726a Mon Sep 17 00:00:00 2001 From: RondeauG Date: Fri, 1 Nov 2024 15:12:45 -0400 Subject: [PATCH 11/13] fix docs --- docs/notebooks/4_ensembles.ipynb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/notebooks/4_ensembles.ipynb b/docs/notebooks/4_ensembles.ipynb index 4bc0a6e9..dad0407f 100644 --- a/docs/notebooks/4_ensembles.ipynb +++ b/docs/notebooks/4_ensembles.ipynb @@ -53,9 +53,7 @@ "}\n", "\n", "for d in datasets:\n", - " ds = open_dataset(\n", - " datasets[d], # branch=\"v2023.12.14\"\n", - " ).isel(lon=slice(0, 4), lat=slice(0, 4))\n", + " ds = open_dataset(datasets[d]).isel(lon=slice(0, 4), lat=slice(0, 4))\n", " ds = xs.climatological_op(\n", " ds,\n", " op=\"mean\",\n", From e14ea86c24ec0b074932e8a1e8aac08c4a1422a5 Mon Sep 17 00:00:00 2001 From: RondeauG <38501935+RondeauG@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:05:27 -0500 Subject: [PATCH 12/13] Update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4bb841a9..8f5e7817 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,7 +20,7 @@ Breaking changes Bug fixes ^^^^^^^^^ * ``xs.io.save_to_table`` now correctly handles the case where the input is a `DataArray` or a `Dataset` with a single variable. (:pull:`473`). -* Fixed a bug in ``xs.utils.change_units`` where the original dataset was modified. (:pull:`482`). +* Fixed a bug in ``xs.utils.change_units`` where the original dataset was also getting modified. (:pull:`482`). Internal changes ^^^^^^^^^^^^^^^^ From 211816f81689a312a37be12b8cae9836db65ad67 Mon Sep 17 00:00:00 2001 From: Ouranos Helper Bot Date: Mon, 4 Nov 2024 15:17:54 +0000 Subject: [PATCH 13/13] =?UTF-8?q?Bump=20version:=200.10.1-dev.4=20?= =?UTF-8?q?=E2=86=92=200.10.1-dev.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cruft.json | 2 +- pyproject.toml | 2 +- src/xscen/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.cruft.json b/.cruft.json index 1bba414c..cfbef221 100644 --- a/.cruft.json +++ b/.cruft.json @@ -11,7 +11,7 @@ "project_slug": "xscen", "project_short_description": "A climate change scenario-building analysis framework, built with xclim/xarray.", "pypi_username": "RondeauG", - "version": "0.10.1-dev.4", + "version": "0.10.1-dev.5", "use_pytest": "y", "use_black": "y", "use_conda": "y", diff --git a/pyproject.toml b/pyproject.toml index 27750623..21e1d4b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,7 +133,7 @@ target-version = [ ] [tool.bumpversion] -current_version = "0.10.1-dev.4" +current_version = "0.10.1-dev.5" commit = true commit_args = "--no-verify" tag = false diff --git a/src/xscen/__init__.py b/src/xscen/__init__.py index 3b2f7704..d9cea8d2 100644 --- a/src/xscen/__init__.py +++ b/src/xscen/__init__.py @@ -71,7 +71,7 @@ __author__ = """Gabriel Rondeau-Genesse""" __email__ = "rondeau-genesse.gabriel@ouranos.ca" -__version__ = "0.10.1-dev.4" +__version__ = "0.10.1-dev.5" def warning_on_one_line(