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
6 changes: 6 additions & 0 deletions docs/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ The format is based on `Keep a Changelog`_, and this project adheres to
[Unreleased]
------------

Added
~~~~~

- :func:`imod.data.tutorial_03` to load data for the iMOD Documentation
tutorial.

Fixed
~~~~~

Expand Down
1 change: 1 addition & 0 deletions imod/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
hondsrug_simulation,
imod5_projectfile_data,
lakes_shp,
tutorial_03,
twri_output,
)
1 change: 1 addition & 0 deletions imod/data/registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ lakes_shp.zip 564c20d722639f1ca19bb78e32bfe575e1e0779f3c922a1aa1a386c2a43db10d
circle-nodes.txt 1ff03b8721c6e7bb6289251373d66d5b8ee2388c03493dfc75c1bf1fe7e586d2
circle-triangles.txt 546d5e6ba6f9d16bb5330313edf36d4a9fc4821c9a89eedfa76ac2266dd2a5fa
iMOD5_model.zip e5808579bd4f0663f0b04f8333b3e2edde785a92c83156837d29bbaed595940f
iMOD-Documentation-tutorial_03.zip e4184f08c53d263939e1ead3bb66a9701e0a326ffaeda9b34a54999912a118cb
20 changes: 19 additions & 1 deletion imod/data/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def load_pooch_registry(registry: pooch.core.Pooch) -> pooch.core.Pooch:


def twri_output(path: Union[str, Path]) -> None:
# Unzips TWRI output to ``path``. Has a race condition when executed
# multiple times with the same path.
lock = FileLock(REGISTRY.path / "ex01-twri-output.zip.lock")
with lock:
_ = REGISTRY.fetch("ex01-twri-output.zip", processor=Unzip(extract_dir=path))
Expand All @@ -63,8 +65,9 @@ def hondsrug_layermodel() -> xr.Dataset:
lock = FileLock(REGISTRY.path / "hondsrug-layermodel.nc.lock")
with lock:
fname = REGISTRY.fetch("hondsrug-layermodel.nc")
hondsrug_layermodel = xr.open_dataset(fname)

return xr.open_dataset(fname)
return hondsrug_layermodel


def hondsrug_meteorology() -> xr.Dataset:
Expand Down Expand Up @@ -275,3 +278,18 @@ def colleagues_river_data(path: Union[str, Path]):
x_preserve | y_preserve, riv_bot_da + 0.15
)
return riv_ds


def tutorial_03(path: Path | str) -> None:
"""
Starting dataset for tutorial 3 in the iMOD Documentation.
"""
# Unzips tutorial content to ``path``. Has a race condition when executed
# multiple times with the same path.
path = Path(path)
filename = "iMOD-Documentation-tutorial_03.zip"
lock = FileLock(REGISTRY.path / f"{filename}.lock")
with lock:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the path provided to this method unique? Otherwise there can still be a race condition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

_ = REGISTRY.fetch(filename, processor=Unzip(extract_dir=path))

return path / "tutorial_03" / "GWF_model_Hondsrug.prj"
44 changes: 44 additions & 0 deletions imod/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import xarray as xr

Expand Down Expand Up @@ -26,3 +27,46 @@ def test_hondsrug_data():
imod.data.hondsrug_drainage,
]:
assert isinstance(f(), xr.Dataset)


def test_tutorial_03_data__unzipped(tmp_path):
"""
Test if tutorial 03 material can be unzipped.
"""
# Act
prj_path = imod.data.tutorial_03(tmp_path)

# Assert
assert isinstance(prj_path, Path)
assert prj_path.suffix == ".prj"
n_files = sum(1 for x in prj_path.parent.rglob("*") if x.is_file())
assert n_files == 107


def test_tutorial_03_data__open_data(tmp_path):
"""
Test if tutorial 03 material can be opened.
"""
# Act
prj_path = imod.data.tutorial_03(tmp_path)
imod5_data, _ = imod.formats.prj.open_projectfile_data(prj_path)

# Assert
expected_keys = {
"bnd",
"top",
"bot",
"khv",
"kva",
"sto",
"shd",
"rch",
"riv",
"drn-1",
"drn-2",
"drn-3",
"drn-4",
"pcg",
}
missing_keys = expected_keys - set(imod5_data.keys())
assert len(missing_keys) == 0