Skip to content

Commit a446dbb

Browse files
Fix tests
1 parent f0f8a57 commit a446dbb

4 files changed

Lines changed: 98 additions & 66 deletions

File tree

imod/tests/test_mf6/test_circle.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime
44

55
import numpy as np
6+
import pandas as pd
67
import pytest
78
import xugrid as xu
89

@@ -24,17 +25,18 @@ def test_simulation_write_and_run(circle_model, tmp_path):
2425
with pytest.raises(
2526
RuntimeError, match="Simulation circle has not been written yet."
2627
):
27-
circle_model.run()
28+
simulation.run()
2829

2930
modeldir = tmp_path / "circle"
3031

31-
mask = deepcopy(circle_model["GWF_1"].domain)
32+
mask = deepcopy(simulation["GWF_1"].domain)
3233
mask.values[:, 133] = -1
3334
simulation.mask_all_models(mask)
3435

3536
simulation.write(modeldir, binary=False, use_absolute_paths=True)
3637
simulation.run()
37-
38+
# Test opening with different time unit, see if time unit is correctly
39+
# converted to seconds
3840
head = imod.mf6.open_hds(
3941
modeldir / "GWF_1/GWF_1.hds",
4042
modeldir / "GWF_1/disv.disv.grb",
@@ -44,10 +46,10 @@ def test_simulation_write_and_run(circle_model, tmp_path):
4446
assert isinstance(head, xu.UgridDataArray)
4547
assert np.all(
4648
head["time"].values[0]
47-
== np.array(datetime(1999, 1, 1, 0, 0, 7), dtype="datetime64[ns]")
49+
== np.array(datetime(1999, 1, 1, 0, 0, 1), dtype="datetime64[ns]")
4850
)
4951
assert head.dims == ("time", "layer", "mesh2d_nFaces")
50-
assert head.shape == (52, 2, 216)
52+
assert head.shape == (2, 2, 216)
5153

5254

5355
def test_gwfmodel_render(circle_model, tmp_path):
@@ -87,7 +89,7 @@ def test_simulation_write_and_run_evt(circle_model_evt, tmp_path):
8789
with pytest.raises(
8890
RuntimeError, match="Simulation circle has not been written yet."
8991
):
90-
circle_model_evt.run()
92+
simulation.run()
9193

9294
modeldir = tmp_path / "circle_evt"
9395
simulation.write(modeldir, binary=True)
@@ -98,22 +100,22 @@ def test_simulation_write_and_run_evt(circle_model_evt, tmp_path):
98100
)
99101
assert isinstance(head, xu.UgridDataArray)
100102
assert head.dims == ("time", "layer", "mesh2d_nFaces")
101-
assert head.shape == (52, 2, 216)
103+
assert head.shape == (2, 2, 216)
102104

103105

104106
def test_simulation_write_and_run_evt__no_segments(circle_model_evt, tmp_path):
105107
simulation = circle_model_evt
106108

107-
evt = circle_model_evt["GWF_1"].pop("evt")
109+
evt = simulation["GWF_1"].pop("evt")
108110
evt_ds = evt.dataset
109111
evt_ds = evt_ds.drop_vars(["proportion_rate", "proportion_depth"])
110112
evt_dict = {key: evt_ds[key] for key in evt_ds.keys()}
111-
circle_model_evt["GWF_1"]["evt"] = imod.mf6.Evapotranspiration(**evt_dict)
113+
simulation["GWF_1"]["evt"] = imod.mf6.Evapotranspiration(**evt_dict)
112114

113115
with pytest.raises(
114116
RuntimeError, match="Simulation circle has not been written yet."
115117
):
116-
circle_model_evt.run()
118+
simulation.run()
117119

118120
modeldir = tmp_path / "circle_evt"
119121
simulation.write(modeldir, binary=True)
@@ -124,7 +126,7 @@ def test_simulation_write_and_run_evt__no_segments(circle_model_evt, tmp_path):
124126
)
125127
assert isinstance(head, xu.UgridDataArray)
126128
assert head.dims == ("time", "layer", "mesh2d_nFaces")
127-
assert head.shape == (52, 2, 216)
129+
assert head.shape == (2, 2, 216)
128130

129131

130132
def test_gwfmodel_render_evt(circle_model_evt, tmp_path):
@@ -161,11 +163,10 @@ def test_gwfmodel_render_evt(circle_model_evt, tmp_path):
161163

162164
def test_simulation_write_and_run_transport(circle_model_transport, tmp_path):
163165
simulation = circle_model_transport
164-
165166
with pytest.raises(
166167
RuntimeError, match="Simulation circle has not been written yet."
167168
):
168-
circle_model_transport.run()
169+
simulation.run()
169170

170171
modeldir = tmp_path / "circle_transport"
171172
simulation.write(modeldir)
@@ -175,11 +176,11 @@ def test_simulation_write_and_run_transport(circle_model_transport, tmp_path):
175176

176177
assert isinstance(head, xu.UgridDataArray)
177178
assert head.dims == ("time", "layer", "mesh2d_nFaces")
178-
assert head.shape == (52, 2, 216)
179+
assert head.shape == (2, 2, 216)
179180

180181
assert isinstance(concentration, xu.UgridDataArray)
181182
assert concentration.dims == ("time", "layer", "mesh2d_nFaces")
182-
assert concentration.shape == (52, 2, 216)
183+
assert concentration.shape == (2, 2, 216)
183184

184185

185186
def test_simulation_write_and_run_transport_vsc(circle_model_transport_vsc, tmp_path):
@@ -198,11 +199,11 @@ def test_simulation_write_and_run_transport_vsc(circle_model_transport_vsc, tmp_
198199

199200
assert isinstance(head, xu.UgridDataArray)
200201
assert head.dims == ("time", "layer", "mesh2d_nFaces")
201-
assert head.shape == (52, 2, 216)
202+
assert head.shape == (2, 2, 216)
202203

203204
assert isinstance(concentration, xu.UgridDataArray)
204205
assert concentration.dims == ("time", "layer", "mesh2d_nFaces")
205-
assert concentration.shape == (52, 2, 216)
206+
assert concentration.shape == (2, 2, 216)
206207

207208

208209
def run_simulation(simulation, modeldir):
@@ -251,8 +252,8 @@ def test_simulation_clip_and_state_at_boundary(circle_model_transport, tmp_path)
251252

252253
# Test if model runs
253254
head_half, concentration_half = run_simulation(half_simulation, tmp_path / "half")
254-
assert head_half.shape == (52, 2, 108)
255-
assert concentration_half.shape == (52, 2, 108)
255+
assert head_half.shape == (2, 2, 108)
256+
assert concentration_half.shape == (2, 2, 108)
256257

257258

258259
def test_simulation_clip_and_constant_state_at_boundary__transient_chd(
@@ -289,12 +290,12 @@ def test_simulation_clip_and_constant_state_at_boundary__transient_chd(
289290
assert conc_clipped.notnull().sum() == 20
290291
head_clipped = half_simulation["GWF_1"]["chd_clipped"]["head"]
291292
assert head_clipped.sizes["layer"] == 2
292-
assert head_clipped.sizes["time"] == 52
293-
assert head_clipped.notnull().sum() == 20 * 52
293+
assert head_clipped.sizes["time"] == 2
294+
assert head_clipped.notnull().sum() == 20 * 2
294295
# Test if model runs
295296
head_half, concentration_half = run_simulation(half_simulation, tmp_path / "half")
296-
assert head_half.shape == (52, 2, 108)
297-
assert concentration_half.shape == (52, 2, 108)
297+
assert head_half.shape == (2, 2, 108)
298+
assert concentration_half.shape == (2, 2, 108)
298299

299300

300301
def test_simulation_clip_and_transient_state_at_boundary__transient_chd(
@@ -304,9 +305,17 @@ def test_simulation_clip_and_transient_state_at_boundary__transient_chd(
304305
Test with a transient chd boundary condition and transient states for
305306
boundary conditions. The time steps of the chd package are outside of the
306307
time domain of the states_for_boundary.
308+
309+
Extend the time discretization as it was before
310+
https://github.com/Deltares/imod-python/pull/1029, to allow clipping longer
311+
timeseries.
307312
"""
308313
# Arrange
309314
simulation = circle_model_transport
315+
simulation.create_time_discretization(
316+
additional_times=pd.date_range(start="2000-01-01", end="2001-01-01", freq="W")
317+
)
318+
310319
idomain = simulation["GWF_1"]["disv"]["idomain"].compute()
311320
time = simulation["time_discretization"].dataset.coords["time"].values
312321

0 commit comments

Comments
 (0)