From d5bb782ee4214a880adc50de3c1a5efc5fea5da9 Mon Sep 17 00:00:00 2001 From: JoerivanEngelen Date: Tue, 13 Jan 2026 16:23:29 +0100 Subject: [PATCH 1/2] Add missing bdgfile, bdgcsvfile, and stagefile options to lakefile template. --- docs/api/changelog.rst | 2 ++ imod/mf6/lak.py | 4 +++ imod/templates/mf6/gwf-lak.j2 | 52 +++++++++++++++-------------- imod/tests/test_mf6/test_mf6_lak.py | 30 +++++++++++++++++ 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/docs/api/changelog.rst b/docs/api/changelog.rst index c9df74458..407a57809 100644 --- a/docs/api/changelog.rst +++ b/docs/api/changelog.rst @@ -39,6 +39,8 @@ Fixed and the model already contained a :class:`imod.mf6.ConstantHead` or :class:`imod.mf6.ConstantConcentration`, both with timesteps, which were unaligned. +- Fixed bug where :class:`imod.mf6.Lake` package did not pass ``budgetfile``, + ``budgetcsvfile``, ``stagefile`` options to the written MODFLOW 6 package. Changed ~~~~~~~ diff --git a/imod/mf6/lak.py b/imod/mf6/lak.py index 5004c4dd1..50d294829 100644 --- a/imod/mf6/lak.py +++ b/imod/mf6/lak.py @@ -9,6 +9,7 @@ import textwrap from collections import defaultdict from typing import Any, Dict +from pathlib import Path import jinja2 import numpy as np @@ -670,6 +671,9 @@ class Lake(BoundaryCondition): DTypeSchema(np.floating), DimsSchema("index", "time") | DimsSchema(), ], + "budgetcsvfile": [DTypeSchema(str) | DTypeSchema(Path)], + "stagefile": [DTypeSchema(str) | DTypeSchema(Path)], + "budgetfile": [DTypeSchema(str) | DTypeSchema(Path)], } _write_schemata = { diff --git a/imod/templates/mf6/gwf-lak.j2 b/imod/templates/mf6/gwf-lak.j2 index b0e08ba13..baefe9285 100644 --- a/imod/templates/mf6/gwf-lak.j2 +++ b/imod/templates/mf6/gwf-lak.j2 @@ -1,31 +1,33 @@ begin options {% if auxiliary is defined %} auxiliary{% for aux in auxiliary %} {{aux}}{% endfor %} {% endif %} -{%- if boundnames is defined -%} boundnames -{% endif -%} -{%- if print_input is defined -%} print_input -{% endif -%} -{%- if print_stage is defined -%} print_stage -{% endif -%} -{%- if print_flows is defined -%} print_flows -{% endif -%} -{%- if save_flows is defined -%} save_flows -{% endif -%} -{%- if stage_filerecord is defined -%}stage fileout {{stagefile}} -{% endif -%} -{%- if budget_filerecord is defined -%} budget fileout {{budgetfile}} -{% endif -%} -{%- if ts_filerecord is defined -%} ts6 filein {{ts6_filename}} -{% endif -%} -{%- if obs_filerecord is defined -%} obs6 filein {{obs6_filename}} -{% endif -%} -{%- if mover is defined -%} mover -{% endif -%} -{%- if surfdep is defined -%} surfdep {{surfdep}} -{% endif -%} -{%- if time_conversion is defined -%} time_conversion {{time_conversion}} -{% endif -%} -{%- if length_conversion is defined -%} length_conversion {{length_conversion}} +{%- if boundnames is defined %} boundnames +{% endif %} +{%- if print_input is defined %} print_input +{% endif %} +{%- if print_stage is defined %} print_stage +{% endif %} +{%- if print_flows is defined %} print_flows +{% endif %} +{%- if save_flows is defined %} save_flows +{% endif %} +{%- if stagefile is defined %} stage fileout {{stagefile}} +{% endif %} +{%- if budgetfile is defined %} budget fileout {{budgetfile}} +{% endif %} +{%- if budgetcsvfile is defined %} budgetcsv fileout {{budgetcsvfile}} +{% endif %} +{%- if ts_filerecord is defined %} ts6 filein {{ts6_filename}} +{% endif %} +{%- if obs_filerecord is defined %} obs6 filein {{obs6_filename}} +{% endif %} +{%- if mover is defined%} mover +{% endif %} +{%- if surfdep is defined %} surfdep {{surfdep}} +{% endif %} +{%- if time_conversion is defined %} time_conversion {{time_conversion}} +{% endif %} +{%- if length_conversion is defined %} length_conversion {{length_conversion}} {% endif -%} end options diff --git a/imod/tests/test_mf6/test_mf6_lak.py b/imod/tests/test_mf6/test_mf6_lak.py index 821d07995..ed20eae7a 100644 --- a/imod/tests/test_mf6/test_mf6_lak.py +++ b/imod/tests/test_mf6/test_mf6_lak.py @@ -1,4 +1,5 @@ import textwrap +from pathlib import Path import numpy as np import pandas as pd @@ -48,6 +49,35 @@ def test_lake_render(lake_package): assert actual == expected +def test_lake_render__options(lake_package): + lake_package.dataset["stagefile"] = Path("path/to/stagefile.bin") + lake_package.dataset["budgetfile"] = "path/to/budgetfile.bin" + lake_package.dataset["budgetcsvfile"] = "path/to/budgetcsvfile.bin" + lake_package._validate_init_schemata(True) # Verify that added options pass validation. + actual = lake_package._render(None, None, None, False) + expected = textwrap.dedent( + """\ + begin options + stage fileout path\\to\\stagefile.bin + budget fileout path/to/budgetfile.bin + budgetcsv fileout path/to/budgetcsvfile.bin + end options + + begin dimensions + nlakes 2 + noutlets 2 + ntables 0 + end dimensions + + begin packagedata + 1 11.0 3 Naardermeer + 2 15.0 3 IJsselmeer + end packagedata + """ + ) + assert actual == expected + + def test_lake_connection_dataframe(lake_package): df = lake_package._connection_dataframe() assert isinstance(df, pd.DataFrame) From 60be13a210895583f42d7f43599cbbc5a58619bf Mon Sep 17 00:00:00 2001 From: JoerivanEngelen Date: Wed, 14 Jan 2026 11:07:16 +0100 Subject: [PATCH 2/2] Format --- imod/mf6/lak.py | 2 +- imod/tests/test_mf6/test_mf6_lak.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/imod/mf6/lak.py b/imod/mf6/lak.py index 50d294829..bdc2b231b 100644 --- a/imod/mf6/lak.py +++ b/imod/mf6/lak.py @@ -8,8 +8,8 @@ import pathlib import textwrap from collections import defaultdict -from typing import Any, Dict from pathlib import Path +from typing import Any, Dict import jinja2 import numpy as np diff --git a/imod/tests/test_mf6/test_mf6_lak.py b/imod/tests/test_mf6/test_mf6_lak.py index ed20eae7a..cad368508 100644 --- a/imod/tests/test_mf6/test_mf6_lak.py +++ b/imod/tests/test_mf6/test_mf6_lak.py @@ -53,7 +53,9 @@ def test_lake_render__options(lake_package): lake_package.dataset["stagefile"] = Path("path/to/stagefile.bin") lake_package.dataset["budgetfile"] = "path/to/budgetfile.bin" lake_package.dataset["budgetcsvfile"] = "path/to/budgetcsvfile.bin" - lake_package._validate_init_schemata(True) # Verify that added options pass validation. + lake_package._validate_init_schemata( + True + ) # Verify that added options pass validation. actual = lake_package._render(None, None, None, False) expected = textwrap.dedent( """\