Skip to content

Commit

Permalink
Add tests from plot.flopy, gwt and hfb
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencalje committed Nov 17, 2023
1 parent b6df910 commit 3c33531
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nlmod/gwf/horizontal_flow_barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def get_hfb_spd(gwf, linestrings, hydchr=1 / 100, depth=None, elevation=None):

cells = line2hfb(linestrings, gwf)

# drop cells on the edge of the model
cells = [x for x in cells if len(x) > 1]

spd = []

# hydchr = 1 / 100 # resistance of 100 days
Expand Down
4 changes: 4 additions & 0 deletions nlmod/plot/flopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,17 @@ def facet_plot(
if iper is None:
raise ValueError("Pass 'period' to select timestep to plot.")
a = arr[iper]
else:
a = arr
elif plot_dim == "time":
ilay = layer
iper = i
if arr.ndim == 4:
if ilay is None:
raise ValueError("Pass 'layer' to select layer to plot.")
a = arr[iper]
else:
a = arr
else:
raise ValueError("'plot_dim' must be one of ['layer', 'time']")

Expand Down
23 changes: 23 additions & 0 deletions tests/test_012_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,26 @@ def test_plot_data_array_vertex():

def test_plot_get_map():
nlmod.plot.get_map([100000, 101000, 400000, 401000], background=True, figsize=3)


def test_map_array():
ds = util.get_ds_structured()
gwf = util.get_gwf(ds)
nlmod.plot.flopy.map_array(ds["kh"], gwf, ilay=0)


def test_flopy_contour_array():
ds = util.get_ds_structured()
gwf = util.get_gwf(ds)
nlmod.plot.flopy.contour_array(ds["kh"], gwf, ilay=0)


def test_flopy_animate_map():
# no test implemented yet
pass


def test_flopy_facet_plot():
ds = util.get_ds_structured()
gwf = util.get_gwf(ds)
nlmod.plot.flopy.facet_plot(gwf, ds["kh"])
8 changes: 8 additions & 0 deletions tests/test_022_gwt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import nlmod


def test_prepare():
ds = nlmod.get_ds([0, 1000, 0, 2000])
ds = nlmod.gwt.prepare.set_default_transport_parameters(
ds, transport_type="chloride"
)
37 changes: 37 additions & 0 deletions tests/test_023_hfb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from shapely.geometry import LineString, Polygon
import geopandas as gpd
import flopy
import nlmod
import util


def test_get_hfb_spd():
# this test also tests line2hfb
ds = util.get_ds_vertex()
ds = nlmod.time.set_ds_time(ds, "2023", time="2024")
gwf = util.get_gwf(ds)

coords = [(0, 1000), (1000, 0)]
gdf = gpd.GeoDataFrame({"geometry": [LineString(coords)]})

spd = nlmod.gwf.horizontal_flow_barrier.get_hfb_spd(gwf, gdf, depth=5.0)
hfb = flopy.mf6.ModflowGwfhfb(gwf, stress_period_data={0: spd})

# also test the plot method
ax = gdf.plot()
nlmod.gwf.horizontal_flow_barrier.plot_hfb(hfb, gwf, ax=ax)


def test_polygon_to_hfb():
ds = util.get_ds_vertex()
ds = nlmod.time.set_ds_time(ds, "2023", time="2024")
gwf = util.get_gwf(ds)

coords = [(135, 230), (568, 170), (778, 670), (260, 786)]
gdf = gpd.GeoDataFrame({"geometry": [Polygon(coords)]}).reset_index()

hfb = nlmod.gwf.horizontal_flow_barrier.polygon_to_hfb(gdf, ds, gwf=gwf)

# also test the plot method
ax = gdf.plot()
nlmod.gwf.horizontal_flow_barrier.plot_hfb(hfb, gwf, ax=ax)
9 changes: 9 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ def get_ds_vertex(extent=None, line=None, **kwargs):
refinement_features = [([LineString(line)], "line", 1)]
ds = nlmod.grid.refine(ds, model_ws, refinement_features=refinement_features)
return ds


def get_gwf(ds):
sim = nlmod.sim.sim(ds)
if "time" in ds.variables:
nlmod.sim.tdis(ds, sim)
gwf = nlmod.gwf.gwf(ds, sim)
nlmod.gwf.dis(ds, gwf)
return gwf

0 comments on commit 3c33531

Please sign in to comment.