Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1025 shorten unittests #1029

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion imod/tests/fixtures/flow_transport_simulation_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def flow_transport_simulation():
duration = pd.to_timedelta("2000d")
start = pd.to_datetime("2000-01-01")
simulation.create_time_discretization(additional_times=[start, start + duration])
simulation["time_discretization"]["n_timesteps"] = 100
simulation["time_discretization"]["n_timesteps"] = 50

return simulation
# %%
8 changes: 4 additions & 4 deletions imod/tests/fixtures/mf6_circle_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def make_circle_model():
reordering_method=None,
relaxation_factor=0.97,
)
simtimes = pd.date_range(start="2000-01-01", end="2001-01-01", freq="W")
simtimes = pd.date_range(start="2000-01-01", end="2000-01-03")
simulation.create_time_discretization(additional_times=simtimes)
return simulation

Expand Down Expand Up @@ -157,7 +157,7 @@ def make_circle_model_flow_with_transport_data(species: list[str]):
reordering_method=None,
relaxation_factor=0.97,
)
simtimes = pd.date_range(start="2000-01-01", end="2001-01-01", freq="W")
simtimes = pd.date_range(start="2000-01-01", end="2000-01-03")
simulation.create_time_discretization(simtimes)
return simulation

Expand Down Expand Up @@ -336,7 +336,7 @@ def circle_model_transport():
reordering_method=None,
relaxation_factor=0.97,
)
simtimes = pd.date_range(start="2000-01-01", end="2001-01-01", freq="W")
simtimes = pd.date_range(start="2000-01-01", end="2000-01-03")
simulation.create_time_discretization(additional_times=simtimes)
return simulation

Expand Down Expand Up @@ -413,6 +413,6 @@ def circle_model_transport_multispecies_variable_density():
reordering_method=None,
relaxation_factor=0.97,
)
simtimes = pd.date_range(start="2000-01-01", end="2001-01-01", freq="W")
simtimes = pd.date_range(start="2000-01-01", end="2000-01-03")
simulation.create_time_discretization(additional_times=simtimes)
return simulation
4 changes: 2 additions & 2 deletions imod/tests/fixtures/mf6_twri_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def transient_twri_model():
save_flows=True,
)
simulation.create_time_discretization(
additional_times=pd.date_range("2000-01-01", " 2000-01-31")
additional_times=pd.date_range("2000-01-01", " 2000-01-03")
)
return simulation

Expand Down Expand Up @@ -255,7 +255,7 @@ def transient_unconfined_twri_model():
# Write specific discharges
gwf_model["npf"]["save_specific_discharge"] = True
simulation.create_time_discretization(
additional_times=pd.date_range("2000-01-01", " 2000-01-31")
additional_times=pd.date_range("2000-01-01", " 2000-01-03")
)
return simulation

Expand Down
12 changes: 6 additions & 6 deletions imod/tests/test_mf6/test_mf6_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_open_cbc__dis_transient(transient_twri_result):
"wel",
]
for array in cbc.values():
assert array.shape == (30, 3, 15, 15)
assert array.shape == (2, 3, 15, 15)
assert isinstance(array, xr.DataArray)
assert isinstance(array.data, dask.array.Array)

Expand Down Expand Up @@ -266,7 +266,7 @@ def test_open_cbc__dis_transient_unconfined(transient_unconfined_twri_result):
"wel",
]
for array in cbc.values():
assert array.shape == (30, 3, 15, 15)
assert array.shape == (2, 3, 15, 15)
assert isinstance(array, xr.DataArray)
assert isinstance(array.data, dask.array.Array)

Expand All @@ -289,10 +289,10 @@ def test_open_cbc__disv(circle_result):
]
for key, array in cbc.items():
if key in ("chd", "flow-lower-face"):
assert array.shape == (52, 2, 216)
assert array.shape == (2, 2, 216)
assert array.dims[-1] == array.ugrid.grid.face_dimension
else:
assert array.shape == (52, 2, 342)
assert array.shape == (2, 2, 342)
assert array.dims[-1] == array.ugrid.grid.edge_dimension
assert isinstance(array, xu.UgridDataArray)
assert isinstance(array.data, dask.array.Array)
Expand Down Expand Up @@ -333,10 +333,10 @@ def test_open_cbc__disv_sto(circle_result_sto):
]
for key, array in cbc.items():
if key in ("chd", "flow-lower-face", "sto-ss"):
assert array.shape == (52, 2, 216)
assert array.shape == (2, 2, 216)
assert array.dims[-1] == array.ugrid.grid.face_dimension
else:
assert array.shape == (52, 2, 342)
assert array.shape == (2, 2, 342)
assert array.dims[-1] == array.ugrid.grid.edge_dimension
assert isinstance(array, xu.UgridDataArray)
assert isinstance(array.data, dask.array.Array)
Expand Down
8 changes: 4 additions & 4 deletions imod/tests/test_mf6/test_mf6_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ def test_simulation_open_head(circle_model, tmp_path):

assert isinstance(head_notime, xu.UgridDataArray)
assert head_notime.dims == ("time", "layer", "mesh2d_nFaces")
assert head_notime.shape == (52, 2, 216)
assert head_notime.shape == (2, 2, 216)

# open heads with time conversion.
head = simulation.open_head(
simulation_start_time=datetime(2013, 3, 11, 22, 0, 0), time_unit="w"
)
assert head.dims == ("time", "layer", "mesh2d_nFaces")
assert head.shape == (52, 2, 216)
assert str(head.coords["time"].values[()][0]) == "2013-04-29T22:00:00.000000000"
assert head.shape == (2, 2, 216)
assert str(head.coords["time"].values[()][0]) == "2013-03-18T22:00:00.000000000"


@pytest.mark.usefixtures("circle_model")
Expand All @@ -100,7 +100,7 @@ def test_simulation_open_head_relative_path(circle_model, tmp_path):

assert isinstance(head, xu.UgridDataArray)
assert head.dims == ("time", "layer", "mesh2d_nFaces")
assert head.shape == (52, 2, 216)
assert head.shape == (2, 2, 216)


@pytest.mark.usefixtures("circle_model")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,7 @@ def test_import_heads_structured(
assert np.allclose(merged_heads.coords["layer"].values, [1, 2, 3])
assert np.allclose(
merged_heads.coords["time"].values,
[
1.0,
2.0,
3.0,
4.0,
5.0,
6.0,
7.0,
8.0,
9.0,
10.0,
11.0,
12.0,
13.0,
14.0,
15.0,
16.0,
17.0,
18.0,
19.0,
20.0,
21.0,
22.0,
23.0,
24.0,
25.0,
26.0,
27.0,
28.0,
29.0,
30.0,
],
[1.0, 2.0],
)


Expand All @@ -109,9 +78,7 @@ def test_import_heads_unstructured(tmp_path, circle_partitioned):

# Assert
assert np.allclose(merged_heads.coords["layer"].values, [1, 2])
assert np.allclose(
merged_heads.coords["time"].values, list(np.arange(7.0, 365.0, 7.0))
)
assert np.allclose(merged_heads.coords["time"].values, [1.0, 2.0])
assert np.allclose(merged_heads.coords["mesh2d_nFaces"].values, list(range(216)))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,14 @@ def run_simulation(tmp_path, simulation, species=None):
simulation.run()
head = simulation.open_head()
flow_budget = simulation.open_flow_budget()
flow_budget = flow_budget.sel(time=364)
flow_budget = flow_budget.sel(time=2)
concentration = None
transport_budget = None
transport_budget = None
if has_transport:
concentration = simulation.open_concentration()
transport_budget = simulation.open_transport_budget(species)
transport_budget = transport_budget.sel(time=364)
transport_budget = transport_budget.sel(time=2)
return head, concentration, flow_budget, transport_budget


Expand Down