diff --git a/imod/tests/test_wq/test_wq_ani.py b/imod/tests/test_wq/test_wq_ani.py new file mode 100644 index 000000000..8e781efdc --- /dev/null +++ b/imod/tests/test_wq/test_wq_ani.py @@ -0,0 +1,30 @@ +import textwrap +from pathlib import Path + +from imod.wq import HorizontalAnisotropy, HorizontalAnisotropyFile + + +def test_render_ani(): + ani = HorizontalAnisotropy(factor=1.0, angle=0.0) + + compare = textwrap.dedent( + """\ + [ani] + anifile = ani/test.ani + """ + ) + + assert ani._render(modelname="test", directory=Path("./ani"), nlayer=1) == compare + + +def test_render_anifile(): + ani = HorizontalAnisotropyFile(anifile="test.test") + + compare = textwrap.dedent( + """\ + [ani] + anifile = ani/test.ani + """ + ) + + assert ani._render(modelname="test", directory=Path("./ani"), nlayer=1) == compare diff --git a/imod/tests/test_wq/test_wq_hfb.py b/imod/tests/test_wq/test_wq_hfb.py new file mode 100644 index 000000000..92dc6a4e5 --- /dev/null +++ b/imod/tests/test_wq/test_wq_hfb.py @@ -0,0 +1,17 @@ +import textwrap +from pathlib import Path + +from imod.wq import HorizontalFlowBarrier + + +def test_render(): + hfb = HorizontalFlowBarrier(hfbfile=None) + + compare = textwrap.dedent( + """\ + [hfb6] + hfbfile = hfb/test.hfb + """ + ) + + assert hfb._render(modelname="test", directory=Path("./hfb")) == compare diff --git a/imod/wq/__init__.py b/imod/wq/__init__.py index 6cbaf02ef..08e2d5b4f 100644 --- a/imod/wq/__init__.py +++ b/imod/wq/__init__.py @@ -14,6 +14,7 @@ AdvectionModifiedMOC, AdvectionTVD, ) +from imod.wq.ani import HorizontalAnisotropy, HorizontalAnisotropyFile from imod.wq.bas import BasicFlow from imod.wq.btn import BasicTransport from imod.wq.chd import ConstantHead @@ -26,6 +27,7 @@ EvapotranspirationTopLayer, ) from imod.wq.ghb import GeneralHeadBoundary +from imod.wq.hfb import HorizontalFlowBarrier from imod.wq.lpf import LayerPropertyFlow from imod.wq.mal import MassLoading from imod.wq.model import SeawatModel diff --git a/imod/wq/ani.py b/imod/wq/ani.py new file mode 100644 index 000000000..29381ee44 --- /dev/null +++ b/imod/wq/ani.py @@ -0,0 +1,182 @@ +import pathlib +import re +import shutil + +import numpy as np + +import imod +from imod.wq.pkgbase import Package + + +class HorizontalAnisotropyFile(Package): + """ + Horizontal Anisotropy package. + + Parameters + ---------- + anifile: str + is the file location of the imod-wq ani-file. This file contains the + anisotropy factor and angle of each layer, either as a constant or a + reference to the file location of an '.arr' file. No checks are + implemented for this file, user is responsible for consistency with + model. + """ + + _pkg_id = "ani" + + _template = "[ani]\n" " anifile = {anifile}\n" + + def __init__( + self, + anifile, + ): + super().__init__() + self["anifile"] = anifile + + def _render(self, modelname, directory, nlayer): + # write ani file + # in render function, as here we know where the model is run from + # and how many layers: store this info for later use in save + self.anifile = f"{modelname}.ani" + self.rendir = directory + self.nlayer = nlayer + + d = {"anifile": f"{directory.as_posix()}/{modelname}.ani"} + + return self._template.format(**d) + + def save(self, directory): + """Overload save function. + Saves anifile to location, along with referenced .arr files + assumes _render() to have run previously""" + directory.mkdir(exist_ok=True) # otherwise handled by idf.save + + path_ani = pathlib.Path(str(self["anifile"].values)) + + # regex adapted from stackoverflow: https://stackoverflow.com/questions/54990405/a-general-regex-to-extract-file-paths-not-urls + rgx = r"((?:[a-zA-Z]:|(?