Skip to content

Commit

Permalink
Adds a download agent to pooch/Deveraux calls (#231)
Browse files Browse the repository at this point in the history
<!-- Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [x] This PR addresses an already opened issue (for bug fixes /
features)
  - This PR fixes #xyz
- [x] (If applicable) Documentation has been added / updated (for bug
fixes / features).
- [x] (If applicable) Tests have been added.
- [x] CHANGELOG.rst has been updated (with summary of main changes).
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added.

### What kind of change does this PR introduce?

* Fixes an issue related to `pooch` in recent ReadTheDocs builds.

### Other information:

- See readthedocs/readthedocs.org#11763
  • Loading branch information
RondeauG authored Nov 20, 2024
2 parents 5914012 + bd91a2b commit f603ea7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 118 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Contributors to this version: Thomas-Charles Fortier Filion (:user:`TC-FF`).

Internal changes
^^^^^^^^^^^^^^^^
land_use_classification default collection has been changed to io-lulc-annual-v02 as previous one will be deprecated december 2024. (:pull:`227`).
Also added some collection, year, resolution and history attributes to xarray output of land_use_classification. (:pull:`227`).
* land_use_classification default collection has been changed to io-lulc-annual-v02 as previous one will be deprecated december 2024. (:pull:`227`).
* Also added some collection, year, resolution and history attributes to xarray output of land_use_classification. (:pull:`227`).
* Added a downloader agent to fix an issue related to ``pooch`` in recent ReadTheDocs builds. (:pull:`231`).

v0.4.1 (2024-11-07)
-------------------
Expand Down
11 changes: 7 additions & 4 deletions docs/notebooks/climate_change.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@
"from xhydro.testing.helpers import deveraux\n",
"\n",
"D = deveraux()\n",
"downloader = pooch.HTTPDownloader(headers={\"User-Agent\": f\"xHydro-{xh.__version__}\"})\n",
"\n",
"# Future streamflow file (1 file - Hydrotel driven by BCC-CSM-1.1(m))\n",
"streamflow_file = D.fetch(\n",
" \"cc_indicators/streamflow_BCC-CSM1.1-m_rcp45.nc\",\n",
" \"cc_indicators/streamflow_BCC-CSM1.1-m_rcp45.nc\", downloader=downloader\n",
")\n",
"\n",
"# Reference mean annual streamflow (QMOYAN) for 6 calibrations of Hydrotel\n",
"reference_files = D.fetch(\"cc_indicators/reference.zip\", pooch.Unzip())\n",
"reference_files = D.fetch(\n",
" \"cc_indicators/reference.zip\", pooch.Unzip(), downloader=downloader\n",
")\n",
"\n",
"# Future deltas of QMOYAN (63 simulations x 6 calibrations of Hydrotel)\n",
"deltas_files = D.fetch(\"cc_indicators/deltas.zip\", pooch.Unzip())"
"deltas_files = D.fetch(\"cc_indicators/deltas.zip\", pooch.Unzip(), downloader=downloader)"
]
},
{
Expand Down Expand Up @@ -651,7 +654,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions docs/notebooks/hydrological_modelling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,18 @@
"metadata": {},
"outputs": [],
"source": [
"import pooch\n",
"import xarray as xr\n",
"\n",
"from xhydro.testing.helpers import deveraux\n",
"\n",
"D = deveraux()\n",
"downloader = pooch.HTTPDownloader(headers={\"User-Agent\": f\"xHydro-{xh.__version__}\"})\n",
"\n",
"# This notebook will use ERA5 data for a small watershed in Eastern Quebec, along with faked elevation data.\n",
"\n",
"# Streamflow file (1 file - Hydrotel driven by BCC-CSM-1.1(m))\n",
"meteo_file = D.fetch(\"hydro_modelling/ERA5_testdata.nc\")\n",
"meteo_file = D.fetch(\"hydro_modelling/ERA5_testdata.nc\", downloader=downloader)\n",
"ds = xr.open_dataset(meteo_file)\n",
"ds"
]
Expand Down Expand Up @@ -509,7 +511,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
22 changes: 11 additions & 11 deletions docs/notebooks/optimal_interpolation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"import xarray as xr\n",
"from scipy.stats import norm\n",
"\n",
"import xhydro as xh\n",
"import xhydro.optimal_interpolation.optimal_interpolation_fun as opt\n",
"from xhydro.optimal_interpolation.ECF_climate_correction import general_ecf"
"from xhydro.optimal_interpolation.ECF_climate_correction import general_ecf\n",
"from xhydro.testing.helpers import deveraux"
]
},
{
Expand Down Expand Up @@ -324,16 +326,14 @@
"metadata": {},
"outputs": [],
"source": [
"# Get data with pooch\n",
"test_data_path = pooch.retrieve(\n",
" url=\"https://github.com/hydrologie/xhydro-testdata/raw/main/data/optimal_interpolation/OI_data_corrected.zip\",\n",
" known_hash=\"md5:acdf90b78b53595eb97ff0e84fc07aa8\",\n",
"# Get data\n",
"downloader = pooch.HTTPDownloader(headers={\"User-Agent\": f\"xHydro-{xh.__version__}\"})\n",
"test_data_path = deveraux().fetch(\n",
" \"optimal_interpolation/OI_data_corrected.zip\",\n",
" pooch.Unzip(),\n",
" downloader=downloader,\n",
")\n",
"\n",
"# Extract to a cache path.\n",
"directory_to_extract_to = Path(test_data_path).parent\n",
"with ZipFile(test_data_path, \"r\") as zip_ref:\n",
" zip_ref.extractall(directory_to_extract_to)\n",
"directory_to_extract_to = Path(test_data_path[0]).parent\n",
"\n",
"# Read-in all the files and set to paths that we can access later.\n",
"flow_obs_info_file = directory_to_extract_to / \"A20_HYDOBS_TEST_corrected.nc\"\n",
Expand Down Expand Up @@ -678,7 +678,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.7"
},
"vscode": {
"interpreter": {
Expand Down
131 changes: 32 additions & 99 deletions docs/notebooks/pmp.ipynb

Large diffs are not rendered by default.

0 comments on commit f603ea7

Please sign in to comment.