14
14
from flopy .utils .modpathfile import PathlineFile as MpPathlineFile
15
15
from flopy .utils .prtfile import PathlineFile as PrtPathlineFile
16
16
17
-
18
17
nlay = 1
19
18
nrow = 10
20
19
ncol = 10
@@ -73,9 +72,7 @@ def gwf_sim(function_tmpdir):
73
72
pname = "tdis" ,
74
73
time_units = "DAYS" ,
75
74
nper = nper ,
76
- perioddata = [
77
- (perlen , nstp , tsmult )
78
- ],
75
+ perioddata = [(perlen , nstp , tsmult )],
79
76
)
80
77
81
78
# create gwf model
@@ -131,9 +128,10 @@ def gwf_sim(function_tmpdir):
131
128
132
129
133
130
@pytest .fixture
134
- def mp7_sim (gwf_sim , function_tmpdir ):
131
+ def mp7_sim (gwf_sim ):
135
132
gwf = gwf_sim .get_model ()
136
- mp7_ws = function_tmpdir / "mp7"
133
+ ws = gwf_sim .sim_path .parent
134
+ mp7_ws = ws / "mp7"
137
135
releasepts_mp7 = [
138
136
# node number, localx, localy, localz
139
137
(0 , float (f"0.{ i + 1 } " ), float (f"0.{ i + 1 } " ), 0.5 )
@@ -172,9 +170,10 @@ def mp7_sim(gwf_sim, function_tmpdir):
172
170
173
171
174
172
@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"
178
177
prt_name = "plotutil_prt"
179
178
gwf_name = "plotutil_gwf"
180
179
releasepts_prt = [
@@ -219,9 +218,7 @@ def prt_sim(function_tmpdir):
219
218
)
220
219
221
220
# create mip package
222
- flopy .mf6 .ModflowPrtmip (
223
- prt , pname = "mip" , porosity = porosity
224
- )
221
+ flopy .mf6 .ModflowPrtmip (prt , pname = "mip" , porosity = porosity )
225
222
226
223
# create prp package
227
224
prp_track_file = f"{ prt_name } .prp.trk"
@@ -276,8 +273,16 @@ def prt_sim(function_tmpdir):
276
273
277
274
278
275
@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
+
280
283
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 )
281
286
mp7_pls = to_mp7_pathlines (prt_pls )
282
287
283
288
assert (
@@ -291,13 +296,18 @@ def test_to_mp7_pathlines(prt_sim, dataframe):
291
296
292
297
293
298
@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" )
295
307
prt_pls = (
296
- pd .DataFrame .from_records (
297
- [], columns = PrtPathlineFile .dtype .names
298
- )
308
+ pd .DataFrame .from_records ([], columns = prt_pls .dtypes )
299
309
if dataframe
300
- else np .recarray ((0 ,), dtype = PrtPathlineFile .dtype )
310
+ else np .recarray ((0 ,), dtype = prt_pls . to_records ( index = False ) .dtype )
301
311
)
302
312
mp7_pls = to_mp7_pathlines (prt_pls )
303
313
@@ -308,46 +318,69 @@ def test_to_mp7_pathlines_empty(dataframe):
308
318
309
319
310
320
@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
315
333
)
334
+ if dataframe :
335
+ og_pls = pd .DataFrame (og_pls )
316
336
mp7_pls = to_mp7_pathlines (og_pls )
317
337
318
338
assert (
319
339
type (mp7_pls )
320
- == type (mp7_pls )
340
+ == type (og_pls )
321
341
== (pd .DataFrame if dataframe else np .recarray )
322
342
)
323
343
assert set (
324
344
dict (mp7_pls .dtypes ).keys () if dataframe else mp7_pls .dtype .names
325
345
) == set (MpPathlineFile .dtypes [7 ].names )
326
346
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
328
348
)
329
349
330
350
331
351
@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
+
333
359
prt_pls = pd .read_csv (prt_sim .sim_path / f"{ prt_sim .name } .trk.csv" )
334
360
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
+
337
365
assert np .isclose (mp7_eps .time [0 ], prt_eps .t .max ())
338
366
assert set (
339
367
dict (mp7_eps .dtypes ).keys () if dataframe else mp7_eps .dtype .names
340
368
) == set (MpEndpointFile .dtypes [7 ].names )
341
369
342
370
343
371
@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" )
345
380
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 )
349
382
if dataframe
350
- else np .recarray ((0 ,), dtype = PrtPathlineFile .dtype )
383
+ else np .recarray ((0 ,), dtype = prt_pls . to_records ( index = False ) .dtype )
351
384
)
352
385
353
386
assert mp7_eps .empty if dataframe else mp7_eps .size == 0
@@ -357,26 +390,41 @@ def test_to_mp7_endpoints_empty(dataframe):
357
390
358
391
359
392
@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 ):
361
394
"""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"
365
404
)
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 )
366
410
mp7_eps = to_mp7_endpoints (og_eps )
367
411
368
412
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
370
414
)
371
415
372
416
373
417
@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
+
375
425
og_pls = pd .read_csv (prt_sim .sim_path / f"{ prt_sim .name } .trk.csv" )
376
426
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 )
380
428
)
381
429
prt_pls = to_prt_pathlines (mp7_pls )
382
430
@@ -395,13 +443,18 @@ def test_to_prt_pathlines_roundtrip(prt_sim, dataframe):
395
443
396
444
397
445
@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" )
399
454
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 )
403
456
if dataframe
404
- else np .recarray ((0 ,), dtype = PrtPathlineFile .dtype )
457
+ else np .recarray ((0 ,), dtype = og_pls . to_records ( index = False ) .dtype )
405
458
)
406
459
prt_pls = to_prt_pathlines (og_pls )
407
460
0 commit comments