11
11
import flopy
12
12
from flopy .utils import import_optional_dependency
13
13
from flopy .utils .datautil import DatumUtil
14
-
15
-
16
- class TestInfo :
17
- def __init__ (
18
- self ,
19
- original_simulation_folder ,
20
- netcdf_simulation_folder ,
21
- netcdf_output_file ,
22
- ):
23
- self .original_simulation_folder = original_simulation_folder
24
- self .netcdf_simulation_folder = netcdf_simulation_folder
25
- self .netcdf_output_file = netcdf_output_file
14
+ from flopy .utils .gridutil import get_disv_kwargs
26
15
27
16
28
17
@requires_pkg ("xarray" )
@@ -32,23 +21,19 @@ def test_load_netcdf_gwfsto01(function_tmpdir, example_data_path):
32
21
xr = import_optional_dependency ("xarray" )
33
22
data_path_base = example_data_path / "mf6" / "netcdf"
34
23
tests = {
35
- "test_gwf_sto01_mesh" : TestInfo (
36
- "gwf_sto01" ,
37
- "gwf_sto01_write" ,
38
- "gwf_sto01.ugrid.nc" ,
39
- ),
40
- "test_gwf_sto01_structured" : TestInfo (
41
- "gwf_sto01" ,
42
- "gwf_sto01_write" ,
43
- "gwf_sto01.structured.nc" ,
44
- ),
24
+ "test_gwf_sto01_mesh" : {
25
+ "base_sim_dir" : "gwf_sto01" ,
26
+ "netcdf_output_file" : "gwf_sto01.in.nc" ,
27
+ },
28
+ "test_gwf_sto01_structured" : {
29
+ "base_sim_dir" : "gwf_sto01" ,
30
+ "netcdf_output_file" : "gwf_sto01.in.nc" ,
31
+ },
45
32
}
46
33
ws = function_tmpdir / "ws"
47
34
for base_folder , test_info in tests .items ():
48
35
print (f"RUNNING TEST: { base_folder } " )
49
- data_path = os .path .join (
50
- data_path_base , base_folder , test_info .original_simulation_folder
51
- )
36
+ data_path = os .path .join (data_path_base , base_folder , test_info ["base_sim_dir" ])
52
37
# copy example data into working directory
53
38
base_model_folder = os .path .join (ws , f"{ base_folder } _base" )
54
39
test_model_folder = os .path .join (ws , f"{ base_folder } _test" )
@@ -76,7 +61,7 @@ def test_load_netcdf_gwfsto01(function_tmpdir, example_data_path):
76
61
print (f"cmp => { f } " )
77
62
base = os .path .join (base_model_folder , f )
78
63
gen = os .path .join (test_model_folder , f )
79
- if f != test_info . netcdf_output_file :
64
+ if f != test_info [ " netcdf_output_file" ] :
80
65
# "gwf_sto01.dis.ncf": # TODO wkt string missing on write?
81
66
with open (base , "r" ) as file1 , open (gen , "r" ) as file2 :
82
67
# Skip first line
@@ -91,25 +76,23 @@ def test_load_netcdf_gwfsto01(function_tmpdir, example_data_path):
91
76
92
77
93
78
@requires_pkg ("xarray" )
94
- @requires_exe ("mf6" )
95
79
@pytest .mark .regression
96
80
def test_create_netcdf_gwfsto01 (function_tmpdir , example_data_path ):
97
81
xr = import_optional_dependency ("xarray" )
98
82
data_path_base = example_data_path / "mf6" / "netcdf"
99
83
tests = {
100
- "test_gwf_sto01_mesh" : TestInfo (
101
- "gwf_sto01" ,
102
- "gwf_sto01_write " ,
103
- "gwf_sto01.ugrid.nc " ,
104
- ) ,
105
- "test_gwf_sto01_structured" : TestInfo (
106
- "gwf_sto01" ,
107
- "gwf_sto01_write " ,
108
- "gwf_sto01. structured.nc " ,
109
- ) ,
84
+ "test_gwf_sto01_mesh" : {
85
+ "base_sim_dir" : " gwf_sto01" ,
86
+ "netcdf_output_file" : "gwf_sto01.in.nc " ,
87
+ "netcdf_type" : "mesh2d " ,
88
+ } ,
89
+ "test_gwf_sto01_structured" : {
90
+ "base_sim_dir" : " gwf_sto01" ,
91
+ "netcdf_output_file" : "gwf_sto01.in.nc " ,
92
+ "netcdf_type" : " structured" ,
93
+ } ,
110
94
}
111
95
name = "gwf_sto01"
112
- cases = ["mesh2d" , "structured" ]
113
96
114
97
# static model data
115
98
# temporal discretization
@@ -189,10 +172,7 @@ def test_create_netcdf_gwfsto01(function_tmpdir, example_data_path):
189
172
ws = function_tmpdir / "ws"
190
173
for idx , (base_folder , test_info ) in enumerate (tests .items ()):
191
174
print (f"RUNNING TEST: { base_folder } " )
192
- netcdf = cases [idx ]
193
- data_path = os .path .join (
194
- data_path_base , base_folder , test_info .original_simulation_folder
195
- )
175
+ data_path = os .path .join (data_path_base , base_folder , test_info ["base_sim_dir" ])
196
176
# copy example data into working directory
197
177
base_model_folder = os .path .join (ws , f"{ base_folder } _base" )
198
178
test_model_folder = os .path .join (ws , f"{ base_folder } _test" )
@@ -301,7 +281,62 @@ def test_create_netcdf_gwfsto01(function_tmpdir, example_data_path):
301
281
)
302
282
303
283
sim .set_sim_path (test_model_folder )
304
- sim .write_simulation (netcdf = netcdf )
284
+ sim .write_simulation (netcdf = test_info ["netcdf_type" ])
285
+
286
+ # compare generated files
287
+ gen_files = [
288
+ f
289
+ for f in os .listdir (test_model_folder )
290
+ if os .path .isfile (os .path .join (test_model_folder , f ))
291
+ ]
292
+ base_files = [
293
+ f
294
+ for f in os .listdir (base_model_folder )
295
+ if os .path .isfile (os .path .join (base_model_folder , f ))
296
+ ]
297
+ # assert len(gen_files) == len(base_files)
298
+ for f in base_files :
299
+ print (f"cmp => { f } " )
300
+ base = os .path .join (base_model_folder , f )
301
+ gen = os .path .join (test_model_folder , f )
302
+ if f != test_info ["netcdf_output_file" ]:
303
+ with open (base , "r" ) as file1 , open (gen , "r" ) as file2 :
304
+ # Skip first line
305
+ next (file1 )
306
+ next (file2 )
307
+
308
+ for line1 , line2 in zip (file1 , file2 ):
309
+ assert line1 == line2
310
+ else :
311
+ # TODO compare nc files
312
+ assert os .path .exists (gen )
313
+
314
+
315
+ @requires_pkg ("xarray" )
316
+ @pytest .mark .regression
317
+ def test_load_netcdf_disv01b (function_tmpdir , example_data_path ):
318
+ xr = import_optional_dependency ("xarray" )
319
+ data_path_base = example_data_path / "mf6" / "netcdf"
320
+ tests = {
321
+ "test_gwf_disv01b" : {
322
+ "base_sim_dir" : "disv01b" ,
323
+ "netcdf_output_file" : "disv01b.in.nc" ,
324
+ },
325
+ }
326
+ ws = function_tmpdir / "ws"
327
+ for base_folder , test_info in tests .items ():
328
+ print (f"RUNNING TEST: { base_folder } " )
329
+ data_path = os .path .join (data_path_base , base_folder , test_info ["base_sim_dir" ])
330
+ # copy example data into working directory
331
+ base_model_folder = os .path .join (ws , f"{ base_folder } _base" )
332
+ test_model_folder = os .path .join (ws , f"{ base_folder } _test" )
333
+ shutil .copytree (data_path , base_model_folder )
334
+ # load example
335
+ sim = flopy .mf6 .MFSimulation .load (sim_ws = base_model_folder )
336
+ # change simulation path
337
+ sim .set_sim_path (test_model_folder )
338
+ # write example simulation to reset path
339
+ sim .write_simulation ()
305
340
306
341
# compare generated files
307
342
gen_files = [
@@ -319,24 +354,104 @@ def test_create_netcdf_gwfsto01(function_tmpdir, example_data_path):
319
354
print (f"cmp => { f } " )
320
355
base = os .path .join (base_model_folder , f )
321
356
gen = os .path .join (test_model_folder , f )
322
- if f != test_info . netcdf_output_file :
357
+ if f != test_info [ " netcdf_output_file" ] :
323
358
with open (base , "r" ) as file1 , open (gen , "r" ) as file2 :
324
359
# Skip first line
325
360
next (file1 )
326
361
next (file2 )
327
362
328
363
for line1 , line2 in zip (file1 , file2 ):
329
- if "netcdf filein" in line1 .lower ():
330
- if netcdf == "mesh2d" :
331
- suffix = "ugrid"
332
- else :
333
- suffix = netcdf
334
- assert line1 == f" NETCDF FILEIN gwf_sto01.{ suffix } .nc\n "
335
- assert line2 == " NETCDF FILEIN gwf_sto01.in.nc\n "
336
- else :
337
- assert line1 == line2
364
+ assert line1 .lower () == line2 .lower ()
338
365
else :
339
366
# TODO compare nc files
340
- assert os .path .exists (
341
- os .path .join (test_model_folder , "gwf_sto01.in.nc" )
342
- )
367
+ assert os .path .exists (gen )
368
+
369
+
370
+ @requires_pkg ("xarray" )
371
+ @pytest .mark .regression
372
+ def test_create_netcdf_disv01b (function_tmpdir , example_data_path ):
373
+ xr = import_optional_dependency ("xarray" )
374
+ data_path_base = example_data_path / "mf6" / "netcdf"
375
+ tests = {
376
+ "test_gwf_disv01b" : {
377
+ "base_sim_dir" : "disv01b" ,
378
+ "netcdf_output_file" : "disv01b.in.nc" ,
379
+ "netcdf_type" : "mesh2d" ,
380
+ },
381
+ }
382
+
383
+ name = "disv01b"
384
+ nlay = 3
385
+ nrow = 3
386
+ ncol = 3
387
+ delr = 10.0
388
+ delc = 10.0
389
+ top = 0
390
+ botm = [- 10 , - 20 , - 30 ]
391
+ xoff = 100000000.0
392
+ yoff = 100000000.0
393
+ disvkwargs = get_disv_kwargs (nlay , nrow , ncol , delr , delc , top , botm , xoff , yoff )
394
+ idomain = np .ones ((nlay , nrow * ncol ), dtype = int )
395
+ idomain [0 , 1 ] = 0
396
+ disvkwargs ["idomain" ] = idomain
397
+
398
+ # build
399
+ ws = function_tmpdir / "ws"
400
+ for idx , (base_folder , test_info ) in enumerate (tests .items ()):
401
+ print (f"RUNNING TEST: { base_folder } " )
402
+ data_path = os .path .join (data_path_base , base_folder , test_info ["base_sim_dir" ])
403
+ # copy example data into working directory
404
+ base_model_folder = os .path .join (ws , f"{ base_folder } _base" )
405
+ test_model_folder = os .path .join (ws , f"{ base_folder } _test" )
406
+ shutil .copytree (data_path , base_model_folder )
407
+
408
+ sim = flopy .mf6 .MFSimulation (
409
+ sim_name = name ,
410
+ version = "mf6" ,
411
+ exe_name = "mf6" ,
412
+ sim_ws = ws ,
413
+ )
414
+ tdis = flopy .mf6 .ModflowTdis (sim , start_date_time = "2041-01-01t00:00:00-05:00" )
415
+ gwf = flopy .mf6 .ModflowGwf (sim , modelname = name )
416
+ ims = flopy .mf6 .ModflowIms (sim , print_option = "SUMMARY" )
417
+ disv = flopy .mf6 .ModflowGwfdisv (gwf , ** disvkwargs )
418
+ ic = flopy .mf6 .ModflowGwfic (gwf , strt = 0.0 )
419
+ npf = flopy .mf6 .ModflowGwfnpf (gwf )
420
+ spd = {0 : [[(0 , 0 ), 1.0 ], [(0 , nrow * ncol - 1 ), 0.0 ]]}
421
+ chd = flopy .mf6 .modflow .mfgwfchd .ModflowGwfchd (gwf , stress_period_data = spd )
422
+ oc = flopy .mf6 .ModflowGwfoc (
423
+ gwf ,
424
+ head_filerecord = f"{ name } .hds" ,
425
+ saverecord = [("HEAD" , "ALL" )],
426
+ )
427
+
428
+ sim .set_sim_path (test_model_folder )
429
+ sim .write_simulation (netcdf = test_info ["netcdf_type" ])
430
+
431
+ # compare generated files
432
+ gen_files = [
433
+ f
434
+ for f in os .listdir (test_model_folder )
435
+ if os .path .isfile (os .path .join (test_model_folder , f ))
436
+ ]
437
+ base_files = [
438
+ f
439
+ for f in os .listdir (base_model_folder )
440
+ if os .path .isfile (os .path .join (base_model_folder , f ))
441
+ ]
442
+ # assert len(gen_files) == len(base_files)
443
+ for f in base_files :
444
+ print (f"cmp => { f } " )
445
+ base = os .path .join (base_model_folder , f )
446
+ gen = os .path .join (test_model_folder , f )
447
+ if f != test_info ["netcdf_output_file" ]:
448
+ with open (base , "r" ) as file1 , open (gen , "r" ) as file2 :
449
+ # Skip first line
450
+ next (file1 )
451
+ next (file2 )
452
+
453
+ for line1 , line2 in zip (file1 , file2 ):
454
+ assert line1 == line2
455
+ else :
456
+ # TODO compare nc files
457
+ assert os .path .exists (gen )
0 commit comments