Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
- name: Set GDAL_VERSION (macOS)
if: matrix.os == 'macos-latest'
run: |
echo "GDAL_VERSION=$(gdalinfo --version | awk '{print $2}' | sed s'/.$//')" >> $GITHUB_ENV
echo "GDAL_VERSION=$(gdalinfo --version | sed -E 's/^GDAL //; s/[^0-9.].*$//')" >> $GITHUB_ENV

- name: Install CI libraries
run: |
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ Changelog

v0.18.3 (unreleased)
--------------------
* Fix bug affecting GriddedForcing, where `station_idx` in the call to `nc_specs` was set to ``1`` instead of ``None``. (#PR #501)

Bug fixes
^^^^^^^^^
* Fixed bug affecting `GriddedForcing`, where `station_idx` in the call to ``nc_specs`` was set to ``1`` instead of ``None``. (PR #501)

Internal changes
^^^^^^^^^^^^^^^^
* `ravenpy` now requires `xclim>=0.57.0` and `xsdba` (v0.4.0+). (PR #511)

v0.18.2 (2025-05-05)
--------------------
Expand Down
14 changes: 7 additions & 7 deletions docs/notebooks/08_Getting_and_bias_correcting_CMIP6_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"import numpy as np\n",
"import xarray as xr\n",
"import xclim\n",
"import xclim.sdba as sdba\n",
"import xsdba\n",
"from clisops.core import average, subset\n",
"\n",
"from ravenpy.utilities.testdata import get_file\n",
Expand Down Expand Up @@ -495,7 +495,7 @@
"source": [
"The model is now going to be trained to find correction factors between the reference dataset (observations) and historical dataset (climate model outputs for the same time period). The correction factors obtained are then applied to both reference and future climate outputs to correct them. This step is called the bias correction. In this test-case, we apply a method named `detrended quantile mapping`.\n",
"\n",
"Here we use the `xclim` utilities to bias-correct CMIP6 GCM data using ERA5 reanalysis data as the reference. See `xclim` documentation for more options! (https://xclim.readthedocs.io/en/stable/notebooks/sdba.html)\n",
"Here we use the `xsdba` utilities to bias-correct CMIP6 GCM data using ERA5 reanalysis data as the reference. See `xsdba` documentation for more options! (https://xsdba.readthedocs.io/en/latest/index.html)\n",
"\n",
"> **Warning**\n",
"> This following block of code will take a while to run, and some warning messages will appear during the process (related to longitude wrapping and other information on calendar types). Unless an error message appears, the code should run just fine!"
Expand All @@ -509,11 +509,11 @@
},
"outputs": [],
"source": [
"# Use xclim utilities (SDBA) to give information on the type of window used for the bias correction.\n",
"group_month_window = sdba.utils.Grouper(\"time.dayofyear\", window=15)\n",
"# Use xsdba utilities to give information on the type of window used for the bias correction.\n",
"group_month_window = xsdba.utils.Grouper(\"time.dayofyear\", window=15)\n",
"\n",
"# This is an adjusting function. It builds the tool that will perform the corrections.\n",
"Adjustment = sdba.DetrendedQuantileMapping.train(\n",
"Adjustment = xsdba.DetrendedQuantileMapping.train(\n",
" ref=ERA5_pr, hist=historical_pr, nquantiles=50, kind=\"+\", group=group_month_window\n",
")\n",
"\n",
Expand All @@ -528,7 +528,7 @@
"corrected_fut_precip = corrected_fut_precip.where(corrected_fut_precip > 0, 0)\n",
"\n",
"# Train the model to find the correction factors for the maximum temperature (tasmax) data.\n",
"Adjustment = sdba.DetrendedQuantileMapping.train(\n",
"Adjustment = xsdba.DetrendedQuantileMapping.train(\n",
" ref=ERA5_tmax,\n",
" hist=historical_tasmax,\n",
" nquantiles=50,\n",
Expand All @@ -543,7 +543,7 @@
"corrected_fut_tasmax = Adjustment.adjust(future_tasmax, interp=\"linear\")\n",
"\n",
"# Train the model to find the correction factors for the minimum temperature (tasmin) data.\n",
"Adjustment = sdba.DetrendedQuantileMapping.train(\n",
"Adjustment = xsdba.DetrendedQuantileMapping.train(\n",
" ref=ERA5_tmin,\n",
" hist=historical_tasmin,\n",
" nquantiles=50,\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"\n",
"# Packages required for data processing:\n",
"import xclim\n",
"import xclim.sdba as sdba\n",
"import xsdba\n",
"from birdy import WPSClient\n",
"from clisops.core import average, subset\n",
"from dask.diagnostics import ProgressBar\n",
Expand Down Expand Up @@ -369,7 +369,7 @@
"ds = ds.assign_coords(time=ds.time.dt.floor(\"D\"))\n",
"\n",
"\"\"\"\n",
"Get the ERA5 data. \n",
"Get the ERA5 data.\n",
"We will rechunk it to a single chunk to make it compatible with other codes on the platform especially bias-correction.\n",
"We are also taking the daily min and max temperatures as well as the daily total precipitation.\n",
"\"\"\"\n",
Expand Down Expand Up @@ -544,18 +544,17 @@
},
"outputs": [],
"source": [
"# Use xclim utilities (SDBA) to give information on the type of window used for the bias correction.\n",
"# Use xsdba utilities to give information on the type of window used for the bias correction.\n",
"\n",
"# FIXME: Monkeypatch xclim.sdba to allow different training periods\n",
"xclim.sdba.DetrendedQuantileMapping._allow_diff_training_times = True\n",
"# xclim.sdba.DetrendedQuantileMapping._allow_diff_calendars = True\n",
"xsdba.DetrendedQuantileMapping._allow_diff_training_times = True\n",
"# xsdba.DetrendedQuantileMapping._allow_diff_calendars = True\n",
"\n",
"group_month_window = sdba.utils.Grouper(\"time.dayofyear\", window=15)\n",
"group_month_window = xsdba.utils.Grouper(\"time.dayofyear\", window=15)\n",
"\n",
"# This is an adjusting function.\n",
"# It builds the tool that will perform the corrections.\n",
"\n",
"Adjustment = sdba.DetrendedQuantileMapping.train(\n",
"Adjustment = xsdba.DetrendedQuantileMapping.train(\n",
" ref=ERA5_weather.pr,\n",
" hist=historical_pr,\n",
" nquantiles=50,\n",
Expand All @@ -574,7 +573,7 @@
"corrected_fut_precip = corrected_fut_precip.where(corrected_fut_precip > 0, 0)\n",
"\n",
"# Train the model to find the correction factors for the maximum temperature (tasmax) data.\n",
"Adjustment = sdba.DetrendedQuantileMapping.train(\n",
"Adjustment = xsdba.DetrendedQuantileMapping.train(\n",
" ref=ERA5_weather.tmax,\n",
" hist=historical_tasmax,\n",
" nquantiles=50,\n",
Expand All @@ -589,7 +588,7 @@
"corrected_fut_tasmax = Adjustment.adjust(future_tasmax, interp=\"linear\")\n",
"\n",
"# Train the model to find the correction factors for the minimum temperature (tasmin) data.\n",
"Adjustment = sdba.DetrendedQuantileMapping.train(\n",
"Adjustment = xsdba.DetrendedQuantileMapping.train(\n",
" ref=ERA5_weather.tmin,\n",
" hist=historical_tasmin,\n",
" nquantiles=50,\n",
Expand Down
5 changes: 3 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
- haversine >=2.8.0
- matplotlib-base >=3.6.0
- netcdf4 >=1.7.2
- numpy >=1.24.0
- numpy >=1.25.0
- owslib >=0.29.1
- pandas >=2.2.0
- pint >=0.24.4
Expand All @@ -36,8 +36,9 @@ dependencies:
- statsmodels >=0.14.2
- typing_extensions
- xarray >=2023.11.0,!=2024.10.0
- xclim >=0.55.1
- xclim >=0.57.0
- xesmf
- xsdba >=0.4.0
- xskillscore
- zarr >=2.13,<3.0 # FIXME: zarr v3 does not support FSMap like before: https://github.com/zarr-developers/zarr-python/issues/2706
# Dev tools and testing
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies = [
"h5netcdf >=1.3.0",
"haversine >=2.8.0",
"matplotlib >=3.6.0",
"numpy >=1.24.0",
"numpy >=1.25.0",
"owslib >=0.29.1",
"pandas >=2.2.0",
"pint >=0.24.4",
Expand All @@ -57,7 +57,8 @@ dependencies = [
"statsmodels >=0.14.2",
"typing-extensions",
"xarray >=2023.11.0,!=2024.10.0",
"xclim >=0.55.1",
"xclim >=0.57.0",
"xsdba >=0.4.0",
"xskillscore"
]

Expand Down
10 changes: 5 additions & 5 deletions tests/test_bias_correction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import xarray as xr
import xclim.sdba as sdba
import xsdba
from xarray.coding.calendar_ops import convert_calendar


Expand All @@ -24,9 +24,9 @@ def test_bias_correction(self, get_local_testdata):
get_local_testdata("nrcan/NRCAN_1971-1972_subset.nc")
)
ds_his_sub = convert_calendar(ds_his_sub, "noleap")
group = sdba.Grouper("time.month")
group = xsdba.Grouper("time.month")
# Train the model to find the correction factors
Adj = sdba.DetrendedQuantileMapping.train(
Adj = xsdba.DetrendedQuantileMapping.train(
ref=ds_ref_sub["pr"],
hist=ds_his_sub["pr"],
nquantiles=50,
Expand All @@ -38,7 +38,7 @@ def test_bias_correction(self, get_local_testdata):
Adj.adjust(ds_fut_sub["pr"], interp="linear")

# Repeat for temperature max
Adj = sdba.DetrendedQuantileMapping.train(
Adj = xsdba.DetrendedQuantileMapping.train(
ref=ds_ref_sub["tasmax"],
hist=ds_his_sub["tasmax"],
nquantiles=50,
Expand All @@ -50,7 +50,7 @@ def test_bias_correction(self, get_local_testdata):
Adj.adjust(ds_fut_sub["tasmax"], interp="linear")

# Repeat for tasmin
Adj = sdba.DetrendedQuantileMapping.train(
Adj = xsdba.DetrendedQuantileMapping.train(
ref=ds_ref_sub["tasmin"],
hist=ds_his_sub["tasmin"],
nquantiles=50,
Expand Down
6 changes: 6 additions & 0 deletions tests/test_geo_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def test_gdal_aspect_not_projected(self, tmp_path, get_local_testdata):
assert Path(aspect_tempfile).stat().st_size > 0

# Slope values are high due to data values using Geographic CRS
@pytest.mark.xfail(
reason="Console commands have been modified in GDAL 3.11+", strict=False
)
def test_gdal_slope_not_projected(self, tmp_path, get_local_testdata):
slope_grid = self.analysis.gdal_slope_analysis(get_local_testdata(raster_file))
np.testing.assert_almost_equal(slope_grid.min(), 0.0)
Expand All @@ -161,6 +164,9 @@ def test_gdal_slope_not_projected(self, tmp_path, get_local_testdata):
assert Path(slope_tempfile).stat().st_size > 0

# Slope values are high due to data values using Geographic CRS
@pytest.mark.xfail(
reason="Console commands have been modified in GDAL 3.11+", strict=False
)
def test_dem_properties(self, get_local_testdata):
dem_properties = self.analysis.dem_prop(get_local_testdata(raster_file))
np.testing.assert_almost_equal(dem_properties["aspect"], 10.91190, decimal=5)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def test_ts_fit_graph(self, get_local_testdata, tmp_path):
np.testing.assert_array_equal(p.isnull(), False)

fig = graphs.ts_fit_graph(ts, p)
return fig
assert fig
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ install_command =
deps =
coverage: coveralls>=4.0.1
; numpy must be present in python env before GDAL is installed
numpy >=1.24.0
numpy >=1.25.0
gdal == {env:GDAL_VERSION}
commands_pre =
python -m pip list
Expand Down