Skip to content

Commit e8531e3

Browse files
committed
rebase with prt components, remove mock data and use real models for tests
1 parent e19eec2 commit e8531e3

File tree

7 files changed

+656
-307
lines changed

7 files changed

+656
-307
lines changed

autotest/test_mp6.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ def test_loadtxt(function_tmpdir, mp6_test_path):
310310
pthld = PathlineFile(pthfile)
311311
ra = loadtxt(pthfile, delimiter=" ", skiprows=3, dtype=pthld._dtype)
312312
ra2 = loadtxt(
313-
pthfile, delimiter=" ", skiprows=3, dtype=pthld._dtype, use_pandas=False
313+
pthfile,
314+
delimiter=" ",
315+
skiprows=3,
316+
dtype=pthld._dtype,
317+
use_pandas=False,
314318
)
315319
assert np.array_equal(ra, ra2)
316320

autotest/test_plotutil.py

Lines changed: 99 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from flopy.utils.modpathfile import PathlineFile as MpPathlineFile
1515
from flopy.utils.prtfile import PathlineFile as PrtPathlineFile
1616

17-
1817
nlay = 1
1918
nrow = 10
2019
ncol = 10
@@ -73,9 +72,7 @@ def gwf_sim(function_tmpdir):
7372
pname="tdis",
7473
time_units="DAYS",
7574
nper=nper,
76-
perioddata=[
77-
(perlen, nstp, tsmult)
78-
],
75+
perioddata=[(perlen, nstp, tsmult)],
7976
)
8077

8178
# create gwf model
@@ -131,9 +128,10 @@ def gwf_sim(function_tmpdir):
131128

132129

133130
@pytest.fixture
134-
def mp7_sim(gwf_sim, function_tmpdir):
131+
def mp7_sim(gwf_sim):
135132
gwf = gwf_sim.get_model()
136-
mp7_ws = function_tmpdir / "mp7"
133+
ws = gwf_sim.sim_path.parent
134+
mp7_ws = ws / "mp7"
137135
releasepts_mp7 = [
138136
# node number, localx, localy, localz
139137
(0, float(f"0.{i + 1}"), float(f"0.{i + 1}"), 0.5)
@@ -172,9 +170,10 @@ def mp7_sim(gwf_sim, function_tmpdir):
172170

173171

174172
@pytest.fixture
175-
def prt_sim(function_tmpdir):
176-
gwf_ws = function_tmpdir / "gwf"
177-
prt_ws = function_tmpdir / "prt"
173+
def prt_sim(gwf_sim):
174+
ws = gwf_sim.sim_path.parent
175+
gwf_ws = ws / "gwf"
176+
prt_ws = ws / "prt"
178177
prt_name = "plotutil_prt"
179178
gwf_name = "plotutil_gwf"
180179
releasepts_prt = [
@@ -219,9 +218,7 @@ def prt_sim(function_tmpdir):
219218
)
220219

221220
# create mip package
222-
flopy.mf6.ModflowPrtmip(
223-
prt, pname="mip", porosity=porosity
224-
)
221+
flopy.mf6.ModflowPrtmip(prt, pname="mip", porosity=porosity)
225222

226223
# create prp package
227224
prp_track_file = f"{prt_name}.prp.trk"
@@ -276,8 +273,16 @@ def prt_sim(function_tmpdir):
276273

277274

278275
@pytest.mark.parametrize("dataframe", [True, False])
279-
def test_to_mp7_pathlines(prt_sim, dataframe):
276+
def test_to_mp7_pathlines(gwf_sim, prt_sim, dataframe):
277+
gwf_sim.write_simulation()
278+
gwf_sim.run_simulation()
279+
280+
prt_sim.write_simulation()
281+
prt_sim.run_simulation()
282+
280283
prt_pls = pd.read_csv(prt_sim.sim_path / f"{prt_sim.name}.trk.csv")
284+
if not dataframe:
285+
prt_pls = prt_pls.to_records(index=False)
281286
mp7_pls = to_mp7_pathlines(prt_pls)
282287

283288
assert (
@@ -291,13 +296,18 @@ def test_to_mp7_pathlines(prt_sim, dataframe):
291296

292297

293298
@pytest.mark.parametrize("dataframe", [True, False])
294-
def test_to_mp7_pathlines_empty(dataframe):
299+
def test_to_mp7_pathlines_empty(gwf_sim, prt_sim, dataframe):
300+
gwf_sim.write_simulation()
301+
gwf_sim.run_simulation()
302+
303+
prt_sim.write_simulation()
304+
prt_sim.run_simulation()
305+
306+
prt_pls = pd.read_csv(prt_sim.sim_path / f"{prt_sim.name}.trk.csv")
295307
prt_pls = (
296-
pd.DataFrame.from_records(
297-
[], columns=PrtPathlineFile.dtype.names
298-
)
308+
pd.DataFrame.from_records([], columns=prt_pls.dtypes)
299309
if dataframe
300-
else np.recarray((0,), dtype=PrtPathlineFile.dtype)
310+
else np.recarray((0,), dtype=prt_pls.to_records(index=False).dtype)
301311
)
302312
mp7_pls = to_mp7_pathlines(prt_pls)
303313

@@ -308,46 +318,69 @@ def test_to_mp7_pathlines_empty(dataframe):
308318

309319

310320
@pytest.mark.parametrize("dataframe", [True, False])
311-
def test_to_mp7_pathlines_noop(mp7_sim, dataframe):
312-
plf = flopy.utils.PathlineFile(Path(mp7_sim.model_ws) / f"{mp7_sim.name}.mppth")
313-
og_pls = pd.DataFrame(
314-
plf.get_destination_pathline_data(range(mp7_sim.modelgrid.nnodes), to_recarray=True)
321+
def test_to_mp7_pathlines_noop(gwf_sim, mp7_sim, dataframe):
322+
gwf_sim.write_simulation()
323+
gwf_sim.run_simulation()
324+
325+
mp7_sim.write_input()
326+
mp7_sim.run_model()
327+
328+
plf = flopy.utils.PathlineFile(
329+
Path(mp7_sim.model_ws) / f"{mp7_sim.name}.mppth"
330+
)
331+
og_pls = plf.get_destination_pathline_data(
332+
range(gwf_sim.get_model().modelgrid.nnodes), to_recarray=True
315333
)
334+
if dataframe:
335+
og_pls = pd.DataFrame(og_pls)
316336
mp7_pls = to_mp7_pathlines(og_pls)
317337

318338
assert (
319339
type(mp7_pls)
320-
== type(mp7_pls)
340+
== type(og_pls)
321341
== (pd.DataFrame if dataframe else np.recarray)
322342
)
323343
assert set(
324344
dict(mp7_pls.dtypes).keys() if dataframe else mp7_pls.dtype.names
325345
) == set(MpPathlineFile.dtypes[7].names)
326346
assert np.array_equal(
327-
mp7_pls if dataframe else pd.DataFrame(mp7_pls), og_pls
347+
pd.DataFrame(mp7_pls) if dataframe else mp7_pls, og_pls
328348
)
329349

330350

331351
@pytest.mark.parametrize("dataframe", [True, False])
332-
def test_to_mp7_endpoints(prt_sim, dataframe):
352+
def test_to_mp7_endpoints(gwf_sim, prt_sim, dataframe):
353+
gwf_sim.write_simulation()
354+
gwf_sim.run_simulation()
355+
356+
prt_sim.write_simulation()
357+
prt_sim.run_simulation()
358+
333359
prt_pls = pd.read_csv(prt_sim.sim_path / f"{prt_sim.name}.trk.csv")
334360
prt_eps = prt_pls[prt_pls.ireason == 3]
335-
mp7_eps = to_mp7_endpoints(mp7_eps)
336-
361+
if not dataframe:
362+
prt_eps = prt_eps.to_records(index=False)
363+
mp7_eps = to_mp7_endpoints(prt_eps)
364+
337365
assert np.isclose(mp7_eps.time[0], prt_eps.t.max())
338366
assert set(
339367
dict(mp7_eps.dtypes).keys() if dataframe else mp7_eps.dtype.names
340368
) == set(MpEndpointFile.dtypes[7].names)
341369

342370

343371
@pytest.mark.parametrize("dataframe", [True, False])
344-
def test_to_mp7_endpoints_empty(dataframe):
372+
def test_to_mp7_endpoints_empty(gwf_sim, prt_sim, dataframe):
373+
gwf_sim.write_simulation()
374+
gwf_sim.run_simulation()
375+
376+
prt_sim.write_simulation()
377+
prt_sim.run_simulation()
378+
379+
prt_pls = pd.read_csv(prt_sim.sim_path / f"{prt_sim.name}.trk.csv")
345380
mp7_eps = to_mp7_endpoints(
346-
pd.DataFrame.from_records(
347-
[], columns=PrtPathlineFile.dtype.names
348-
)
381+
pd.DataFrame.from_records([], columns=prt_pls.dtypes)
349382
if dataframe
350-
else np.recarray((0,), dtype=PrtPathlineFile.dtype)
383+
else np.recarray((0,), dtype=prt_pls.to_records(index=False).dtype)
351384
)
352385

353386
assert mp7_eps.empty if dataframe else mp7_eps.size == 0
@@ -357,26 +390,41 @@ def test_to_mp7_endpoints_empty(dataframe):
357390

358391

359392
@pytest.mark.parametrize("dataframe", [True, False])
360-
def test_to_mp7_endpoints_noop(mp7_sim, dataframe):
393+
def test_to_mp7_endpoints_noop(gwf_sim, mp7_sim, dataframe):
361394
"""Test a recarray or dataframe which already contains MP7 endpoint data"""
362-
epf = flopy.utils.EndpointFile(Path(mp7_sim.model_ws) / f"{mp7_sim.name}.mpend")
363-
og_eps = pd.DataFrame(
364-
epf.get_destination_endpoint_data(range(mp7_sim.modelgrid.nnodes), to_recarray=True)
395+
396+
gwf_sim.write_simulation()
397+
gwf_sim.run_simulation()
398+
399+
mp7_sim.write_input()
400+
mp7_sim.run_model()
401+
402+
epf = flopy.utils.EndpointFile(
403+
Path(mp7_sim.model_ws) / f"{mp7_sim.name}.mpend"
365404
)
405+
og_eps = epf.get_destination_endpoint_data(
406+
range(gwf_sim.get_model().modelgrid.nnodes)
407+
)
408+
if dataframe:
409+
og_eps = pd.DataFrame(og_eps)
366410
mp7_eps = to_mp7_endpoints(og_eps)
367411

368412
assert np.array_equal(
369-
mp7_eps if dataframe else pd.DataFrame(mp7_eps), og_eps
413+
pd.DataFrame(mp7_eps) if dataframe else mp7_eps, og_eps
370414
)
371415

372416

373417
@pytest.mark.parametrize("dataframe", [True, False])
374-
def test_to_prt_pathlines_roundtrip(prt_sim, dataframe):
418+
def test_to_prt_pathlines_roundtrip(gwf_sim, prt_sim, dataframe):
419+
gwf_sim.write_simulation()
420+
gwf_sim.run_simulation()
421+
422+
prt_sim.write_simulation()
423+
prt_sim.run_simulation()
424+
375425
og_pls = pd.read_csv(prt_sim.sim_path / f"{prt_sim.name}.trk.csv")
376426
mp7_pls = to_mp7_pathlines(
377-
og_pls
378-
if dataframe
379-
else og_pls.to_records(index=False)
427+
og_pls if dataframe else og_pls.to_records(index=False)
380428
)
381429
prt_pls = to_prt_pathlines(mp7_pls)
382430

@@ -395,13 +443,18 @@ def test_to_prt_pathlines_roundtrip(prt_sim, dataframe):
395443

396444

397445
@pytest.mark.parametrize("dataframe", [True, False])
398-
def test_to_prt_pathlines_roundtrip_empty(dataframe):
446+
def test_to_prt_pathlines_roundtrip_empty(gwf_sim, prt_sim, dataframe):
447+
gwf_sim.write_simulation()
448+
gwf_sim.run_simulation()
449+
450+
prt_sim.write_simulation()
451+
prt_sim.run_simulation()
452+
453+
og_pls = pd.read_csv(prt_sim.sim_path / f"{prt_sim.name}.trk.csv")
399454
og_pls = to_mp7_pathlines(
400-
pd.DataFrame.from_records(
401-
[], columns=PrtPathlineFile.dtype.names
402-
)
455+
pd.DataFrame.from_records([], columns=og_pls.dtypes)
403456
if dataframe
404-
else np.recarray((0,), dtype=PrtPathlineFile.dtype)
457+
else np.recarray((0,), dtype=og_pls.to_records(index=False).dtype)
405458
)
406459
prt_pls = to_prt_pathlines(og_pls)
407460

0 commit comments

Comments
 (0)