Skip to content

Commit

Permalink
Fix hindcast notebook (#463)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Fixes an API issue in `Comparing_hindcasts_and_ESP_forecasts.ipynb`

### Does this PR introduce a breaking change?

No.
  • Loading branch information
Zeitsperre authored Feb 25, 2025
2 parents 2f58b6a + 0adc922 commit 6dbfb8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
15 changes: 11 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ Changelog
v0.18.0 (unreleased)
--------------------

* `ravenpy` now supports Python3.13. (PR #459)
* Updated `raven-hydro` to v0.4.0 (`RavenHydroFramework` v4.0.1). (PR #459)
* Updated `xclim` to v0.54.0, `pint` to v0.24.4, and `numpy` to v1.24.0 (no longer pinned below v2.0). (PR #459)

Bug fixes
^^^^^^^^^
* Fix bug in _MonthlyRecord class definition crashing the pydantic-autodoc serialization. (PR #458)
* Fixed a small API bug in the `Comparing_hindcasts_and_ESP_forecasts.ipynb` notebook. (PR #463)

Internal changes
^^^^^^^^^^^^^^^^
* Updated the cookiecutter template to the latest commit: (PR #454)
* GitHub Actions and Python dependencies have been updated.
* New `pre-commit` hooks for `vulture` (find dead code) and `codespell` (spelling errors).
* Removed several `type: ignore` statements.
* Spelling errors in documentation have been addressed.
* Fix bug in _MonthlyRecord class definition crashing the pydantic-autodoc serialization. (PR #458)
* `ravenpy` now supports Python3.13. (PR #459)
* Update `raven-hydro` to v0.4.0 (`RavenHydroFramework` v4.0.1). (PR #459)
* Update `xclim` to v0.54.0, `pint` to v0.24.4, and `numpy` to v1.24.0 (no longer pinned below v2.0). (PR #459)
* GitHub Workflows now test `ravenpy` using macOS as well as Python3.13. (PR #459)

v0.17.0 (2025-01-27)
Expand Down
24 changes: 12 additions & 12 deletions docs/notebooks/Comparing_hindcasts_and_ESP_forecasts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"\n",
"import matplotlib.pyplot as plt\n",
"import xarray as xr\n",
"from clisops.core import average, subset\n",
"from clisops.core import subset\n",
"\n",
"from ravenpy import Emulator\n",
"from ravenpy.config import commands as rc\n",
Expand Down Expand Up @@ -143,7 +143,7 @@
"\n",
"# Build a new model config:\n",
"# Model configuration\n",
"model_config_ESP = emulators.GR4JCN(\n",
"model_config_ESP = GR4JCN(\n",
" params=[0.529, -3.396, 407.29, 1.072, 16.9, 0.947],\n",
" Gauge=[\n",
" rc.Gauge.from_nc(\n",
Expand Down Expand Up @@ -216,9 +216,8 @@
" dim=(\"rlat\", \"rlon\")\n",
" )\n",
"\n",
"ts_subset = ts_subset.resample(time=\"6H\").nearest(\n",
" tolerance=\"1H\"\n",
") # To make the timesteps identical across the entire duration\n",
"# To make the time steps identical across the entire duration\n",
"ts_subset = ts_subset.resample(time=\"6h\").nearest(tolerance=\"1h\")\n",
"\n",
"# We need to write the hindcast data as a file for Raven to be able to access it.\n",
"fname = \"/tmp/hindcast.nc\"\n",
Expand All @@ -236,28 +235,29 @@
"\n",
"# We will need to reuse this for GR4J. Update according to your needs. For example, here we will also pass\n",
"# the catchment latitude and longitude as our CaSPAr data has been averaged at the catchment scale.\n",
"# We also need to tell the model to deaccumulate the precipitation and shift it in time by 6 hours for our\n",
"# We also need to tell the model to de-accumulate the precipitation and shift it in time by 6 hours for our\n",
"# catchment (UTC timezones):\n",
"data_kwds = {\n",
" \"ALL\": {\n",
" \"elevation\": hru[\"elevation\"],\n",
" \"Latitude\": hru[\"latitude\"],\n",
" \"Longitude\": hru[\"longitude\"],\n",
" },\n",
" # Since we are de-accumulating, we need to manually specify scale.\n",
" \"PRECIP\": {\n",
" \"Deaccumulate\": True,\n",
" \"TimeShift\": -0.25,\n",
" \"LinearTransform\": {\n",
" \"scale\": 1000.0\n",
" }, # Since we are deaccumulating, we need to manually specify scale.\n",
" }, # Converting meters to mm (multiply by 1000).\n",
" \"scale\": 1000.0 # Converting meters to mm (multiply by 1000).\n",
" },\n",
" },\n",
" \"TEMP_AVE\": {\n",
" \"TimeShift\": -0.25,\n",
" },\n",
"}\n",
"\n",
"# Model configuration for forecasting, including correct start date and forecast duration\n",
"model_config_fcst = emulators.GR4JCN(\n",
"model_config_forecast = GR4JCN(\n",
" params=[0.529, -3.396, 407.29, 1.072, 16.9, 0.947],\n",
" Gauge=[\n",
" rc.Gauge.from_nc(\n",
Expand All @@ -271,12 +271,12 @@
")\n",
"\n",
"# Update the initial states\n",
"model_config_fcst = model_config_fcst.set_solution(hotstart)\n",
"model_config_forecast = model_config_forecast.set_solution(hotstart)\n",
"\n",
"# Generate the hindcast by providing all necessary information to generate virtual stations representing\n",
"# the forecast members\n",
"hindcast_sims = forecasting.hindcast_from_meteo_forecast(\n",
" model_config_fcst,\n",
" model_config_forecast,\n",
" forecast=fname,\n",
" overwrite=True,\n",
" # We also need to provide the necessary information to create gauges inside the forecasting model:\n",
Expand Down

0 comments on commit 6dbfb8b

Please sign in to comment.