Skip to content

Commit f67d09a

Browse files
authored
Fix notebooks for new RavenPy (#524)
### What kind of change does this PR introduce? * Updates the notebooks and re-runs all of them to ensure they are working with latest libraries * Adds a few missing testing data files to the pooch registry * Unpin `scipy` version (related dependency issues addressed) * Adjusts a few triggers and allowed connections for CI workflows ### Does this PR introduce a breaking change? Yes. Testing data was added to the `registry.txt` so a new version of `RavenPy` is needed on PAVICS. ### Other information: We don't currently run the notebooks here in CI, as a few of them take far too long to compute. Perhaps we need to add a build for this regardless. Changes here required for: Ouranosinc/PAVICS-e2e-workflow-tests#150
2 parents b4c77c2 + 6990cc3 commit f67d09a

16 files changed

+80
-43
lines changed

.github/workflows/bump-version.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ on:
1919
- .zenodo.json
2020
- AUTHORS.rst
2121
- CHANGELOG.rst
22-
- CI/**/*.in
23-
- CI/**/*.py
24-
- CI/**/*.txt
22+
- CI/**.in
23+
- CI/**.txt
2524
- CODE_OF_CONDUCT.md
2625
- CONTRIBUTING.rst
2726
- Makefile
2827
- .readthedocs.yml
2928
- docs/*.py
30-
- docs/*.rst
29+
- docs/**.rst
30+
- docs/notebooks/**.ipynb
3131
- environment-docs.yml
3232
- environment-dev.yml
3333
- pyproject.toml

.github/workflows/cache-cleaner.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ jobs:
1919
uses: step-security/harden-runner@6c439dc8bdf85cadbbce9ed30d1c7b959517bc49 # v2.12.2
2020
with:
2121
disable-sudo: true
22-
egress-policy: audit
22+
egress-policy: block
23+
allowed-endpoints: >
24+
api.github.com:443
25+
github.com:443
26+
objects.githubusercontent.com:443
27+
release-assets.githubusercontent.com:443
2328
2429
- name: Checkout Repository
2530
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

CHANGELOG.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
Changelog
33
=========
44

5+
v0.19.1 (unreleased)
6+
--------------------
7+
8+
Breaking changes
9+
^^^^^^^^^^^^^^^^
10+
* `scipy` is no longer pinned below v1.16.0, as newer `statsmodels` is now compatible with modern `scipy` versions. (PR #524)
11+
12+
Internal changes
13+
^^^^^^^^^^^^^^^^
14+
* Updates the notebooks and re-runs all of them to ensure they are working with latest libraries. (PR #524)
15+
* Adds a few missing testing data files to the `pooch` ``registry.txt`` file that are necessary for running the notebooks. (PR #524)
16+
* Slightly adjusted CI workflows for security and behaviour improvements. (PR #524)
17+
518
v0.19.0 (2025-07-16)
619
--------------------
720

docs/notebooks/05_Advanced_RavenPy_configuration.ipynb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"metadata": {},
2727
"outputs": [],
2828
"source": [
29+
"from pathlib import Path\n",
30+
"\n",
2931
"# Utility that simplifies fetching and caching data hosted on GitHub\n",
3032
"from ravenpy.testing.utils import get_file"
3133
]
@@ -80,9 +82,9 @@
8082
"from ravenpy import OutputReader, ravenpy\n",
8183
"\n",
8284
"run_name = \"raven-gr4j-salmon\" # As can be seen in the config above, this is the name of the .rvX files.\n",
83-
"configdir = config[\n",
84-
" 0\n",
85-
"].parent # We can get the path to the folder containing the .rvX files this way\n",
85+
"configdir = Path(\n",
86+
" config[0]\n",
87+
").parent # We can get the path to the folder containing the .rvX files this way\n",
8688
"\n",
8789
"# Run the model and get the path to outputs\n",
8890
"outputs_path = ravenpy.run(modelname=run_name, configdir=configdir, overwrite=True)\n",
@@ -216,7 +218,7 @@
216218
"\n",
217219
"# Observed weather data for the Salmon river. We extracted this using Tutorial Notebook 03 and the\n",
218220
"# salmon_river.geojson file as the contour.\n",
219-
"ts = yangtze.fetch(\"notebook_inputs/ERA5_weather_data_Salmon.nc\")\n",
221+
"ts = get_file(\"notebook_inputs/ERA5_weather_data_Salmon.nc\")\n",
220222
"\n",
221223
"# Set alternate variable names in the timeseries data file\n",
222224
"alt_names = {\n",
@@ -573,7 +575,7 @@
573575
"name": "python",
574576
"nbconvert_exporter": "python",
575577
"pygments_lexer": "ipython3",
576-
"version": "3.10.9"
578+
"version": "3.12.9"
577579
}
578580
},
579581
"nbformat": 4,

docs/notebooks/09_Hydrological_impacts_of_climate_change.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
"name": "python",
207207
"nbconvert_exporter": "python",
208208
"pygments_lexer": "ipython3",
209-
"version": "3.10.9"
209+
"version": "3.12.9"
210210
}
211211
},
212212
"nbformat": 4,

docs/notebooks/12_Performing_hindcasting_experiments.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
"# This entire section is cookiecutter template to import required packages and prepare the temporary writing space.\n",
2424
"import datetime as dt\n",
2525
"import tempfile\n",
26+
"import warnings\n",
2627
"from pathlib import Path\n",
2728
"\n",
2829
"import xarray as xr\n",
2930
"from clisops.core import subset\n",
3031
"\n",
32+
"# ignore warnings from xsdba\n",
33+
"warnings.simplefilter(\"ignore\", category=UserWarning)\n",
34+
"\n",
3135
"from ravenpy import Emulator\n",
3236
"from ravenpy.config import commands as rc\n",
3337
"from ravenpy.config.emulators import GR4JCN\n",
@@ -69,9 +73,8 @@
6973
" ts_subset = subset.subset_shape(ts_hindcast, basin_contour).mean(\n",
7074
" dim=(\"rlat\", \"rlon\")\n",
7175
" )\n",
72-
"ts_subset = ts_subset.resample(time=\"6H\").nearest(\n",
73-
" tolerance=\"1H\"\n",
74-
") # To make the timesteps identical across the entire duration"
76+
"# To make the timesteps identical across the entire duration\n",
77+
"ts_subset = ts_subset.resample(time=\"6h\").nearest(tolerance=\"1h\")"
7578
]
7679
},
7780
{
@@ -312,7 +315,7 @@
312315
"name": "python",
313316
"nbconvert_exporter": "python",
314317
"pygments_lexer": "ipython3",
315-
"version": "3.10.9"
318+
"version": "3.12.9"
316319
}
317320
},
318321
"nbformat": 4,

docs/notebooks/Assess_probabilistic_flood_risk.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
" params=[0.529, -3.396, 407.29, 1.072, 16.9, 0.947],\n",
149149
" Gauge=[\n",
150150
" rc.Gauge.from_nc(\n",
151-
" yangtze.fetch(file),\n",
151+
" get_file(file),\n",
152152
" data_type=data_type,\n",
153153
" alt_names=alt_names,\n",
154154
" data_kwds=data_kwds,\n",
@@ -257,7 +257,7 @@
257257
"name": "python",
258258
"nbconvert_exporter": "python",
259259
"pygments_lexer": "ipython3",
260-
"version": "3.9.16"
260+
"version": "3.12.9"
261261
}
262262
},
263263
"nbformat": 4,

docs/notebooks/Comparing_hindcasts_and_ESP_forecasts.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
"%matplotlib inline\n",
2323
"\n",
2424
"import datetime as dt\n",
25+
"import warnings\n",
2526
"\n",
2627
"import matplotlib.pyplot as plt\n",
2728
"import xarray as xr\n",
2829
"from clisops.core import subset\n",
2930
"\n",
31+
"# ignore warnings from xsdba\n",
32+
"warnings.simplefilter(\"ignore\", category=UserWarning)\n",
33+
"\n",
3034
"from ravenpy import Emulator\n",
3135
"from ravenpy.config import commands as rc\n",
3236
"from ravenpy.config.emulators import GR4JCN\n",
@@ -337,9 +341,9 @@
337341
"name": "python",
338342
"nbconvert_exporter": "python",
339343
"pygments_lexer": "ipython3",
340-
"version": "3.10.9"
344+
"version": "3.12.9"
341345
}
342346
},
343347
"nbformat": 4,
344-
"nbformat_minor": 1
348+
"nbformat_minor": 4
345349
}

docs/notebooks/Hydrological_realtime_forecasting.ipynb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@
1717
"source": [
1818
"%matplotlib inline\n",
1919
"\n",
20-
"# Import the required packages\n",
21-
"\n",
2220
"import datetime as dt\n",
2321
"\n",
22+
"# Import the required packages\n",
23+
"import warnings\n",
24+
"\n",
2425
"import fiona\n",
2526
"import matplotlib.pyplot as plt\n",
2627
"import xarray as xr\n",
2728
"\n",
29+
"# ignore warnings from xsdba\n",
30+
"warnings.simplefilter(\"ignore\", category=UserWarning)\n",
31+
"\n",
2832
"from ravenpy import Emulator\n",
2933
"from ravenpy.config import commands as rc\n",
3034
"from ravenpy.config import emulators\n",
@@ -160,8 +164,11 @@
160164
" },\n",
161165
"}\n",
162166
"\n",
167+
"# Handle CFTime encoding\n",
168+
"time_coder = xr.coders.CFDatetimeCoder(use_cftime=True)\n",
169+
"\n",
163170
"# ECCC forecast time format is a bit complex to work with, so we will use cftime to make it more manageable.\n",
164-
"fcst_tmp = xr.open_dataset(fname, use_cftime=True)\n",
171+
"fcst_tmp = xr.open_dataset(fname, decode_times=time_coder)\n",
165172
"\n",
166173
"# Get the first timestep that will be used for the model simulation\n",
167174
"start_date = fcst_tmp.time.data[0] + dt.timedelta(days=1)\n",
@@ -243,9 +250,9 @@
243250
"name": "python",
244251
"nbconvert_exporter": "python",
245252
"pygments_lexer": "ipython3",
246-
"version": "3.10.9"
253+
"version": "3.12.9"
247254
}
248255
},
249256
"nbformat": 4,
250-
"nbformat_minor": 1
257+
"nbformat_minor": 4
251258
}

docs/notebooks/Running_HMETS_with_CANOPEX_dataset.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@
358358
"name": "python",
359359
"nbconvert_exporter": "python",
360360
"pygments_lexer": "ipython3",
361-
"version": "3.9.16"
361+
"version": "3.12.9"
362362
}
363363
},
364364
"nbformat": 4,

0 commit comments

Comments
 (0)