1414from flopy .utils .gridutil import get_disv_kwargs
1515
1616
17- def check_netcdf (path , mesh = None ):
17+ def check_netcdf (path , mobj , mesh = None ):
1818 """Check for functional equivalence"""
1919 ds = xr .open_dataset (path , engine = "netcdf4" )
2020 packages = [
@@ -47,13 +47,39 @@ def check_netcdf(path, mesh=None):
4747 p = varname .rsplit ("_" , 2 )[0 ]
4848
4949 if p in packages :
50+ l = - 1
5051 assert "modflow_input" in da .attrs
5152 if mesh is None :
5253 assert "layer" not in da .attrs
5354 else :
5455 lstr = varname .rsplit ("_" , 1 )[1 ]
5556 if lstr [0 ] == "l" :
5657 assert "layer" in da .attrs
58+ l = da .attrs ["layer" ] - 1
59+
60+ tag = da .attrs ["modflow_input" ].rsplit ("/" , 1 )[1 ].lower ()
61+ pobj = getattr (mobj , p )
62+ d = getattr (pobj , tag )
63+ if p == "ghbg_0" :
64+ spd = d .get_data ()
65+ for per in spd :
66+ if spd [per ] is not None :
67+ istp = sum (mobj .modeltime .nstp [0 :per ])
68+ if l >= 0 :
69+ assert np .allclose (
70+ ds .data_vars [varname ][istp ].fillna (3.00000000e30 ).data ,
71+ spd [per ][l ],
72+ )
73+ else :
74+ assert np .allclose (
75+ ds .data_vars [varname ][istp ].fillna (3.00000000e30 ).data ,
76+ spd [per ],
77+ )
78+ else :
79+ if l >= 0 :
80+ assert np .allclose (ds .data_vars [varname ].values , d .get_data ()[l ])
81+ else :
82+ assert np .allclose (ds .data_vars [varname ].values , d .get_data ())
5783
5884
5985def update_dataset (dataset , pobj ):
@@ -120,7 +146,7 @@ def test_uzf01_sim_scope_nomesh(function_tmpdir, example_data_path):
120146 sim .set_sim_path (ws )
121147 sim .write_simulation (netcdf = netcdf )
122148
123- check_netcdf (ws / fname )
149+ check_netcdf (ws / fname , sim . get_model ( sim_name ) )
124150
125151
126152@pytest .mark .regression
@@ -139,7 +165,7 @@ def test_uzf01_sim_scope_mesh(function_tmpdir, example_data_path):
139165 sim .set_sim_path (ws )
140166 sim .write_simulation (netcdf = netcdf )
141167
142- check_netcdf (ws / fname , mesh = netcdf )
168+ check_netcdf (ws / fname , sim . get_model ( sim_name ), mesh = netcdf )
143169
144170
145171@pytest .mark .regression
@@ -162,7 +188,7 @@ def test_uzf01_sim_scope_fname(function_tmpdir, example_data_path):
162188 sim .set_sim_path (ws )
163189 sim .write_simulation (netcdf = netcdf )
164190
165- check_netcdf (ws / fname )
191+ check_netcdf (ws / fname , sim . get_model ( sim_name ) )
166192
167193
168194@pytest .mark .regression
@@ -181,7 +207,7 @@ def test_uzf02_sim_scope(function_tmpdir, example_data_path):
181207 sim .set_sim_path (ws )
182208 sim .write_simulation (netcdf = netcdf )
183209
184- check_netcdf (ws / fname , mesh = netcdf )
210+ check_netcdf (ws / fname , sim . get_model ( sim_name ), mesh = netcdf )
185211
186212
187213@pytest .mark .regression
@@ -204,7 +230,7 @@ def test_uzf02_sim_scope_fname(function_tmpdir, example_data_path):
204230 sim .set_sim_path (ws )
205231 sim .write_simulation (netcdf = netcdf )
206232
207- check_netcdf (ws / fname , mesh = netcdf )
233+ check_netcdf (ws / fname , sim . get_model ( sim_name ), mesh = netcdf )
208234
209235
210236@pytest .mark .regression
@@ -232,7 +258,7 @@ def test_uzf01_model_scope_nomesh(function_tmpdir, example_data_path):
232258 # write dataset to netcdf
233259 ds .to_netcdf (ws / fname , format = "NETCDF4" , engine = "netcdf4" )
234260
235- check_netcdf (ws / fname )
261+ check_netcdf (ws / fname , sim . get_model ( sim_name ) )
236262
237263
238264@pytest .mark .regression
@@ -261,7 +287,7 @@ def test_uzf01_model_scope_mesh(function_tmpdir, example_data_path):
261287 # write dataset to netcdf
262288 ds .to_netcdf (ws / fname , format = "NETCDF4" , engine = "netcdf4" )
263289
264- check_netcdf (ws / fname , mesh = mesh )
290+ check_netcdf (ws / fname , sim . get_model ( sim_name ), mesh = mesh )
265291
266292
267293@pytest .mark .regression
@@ -290,7 +316,7 @@ def test_uzf02_model_scope(function_tmpdir, example_data_path):
290316 # write dataset to netcdf
291317 ds .to_netcdf (ws / fname , format = "NETCDF4" , engine = "netcdf4" )
292318
293- check_netcdf (ws / fname , mesh = mesh )
319+ check_netcdf (ws / fname , sim . get_model ( sim_name ), mesh = mesh )
294320
295321
296322@pytest .mark .regression
@@ -338,7 +364,7 @@ def test_uzf01_pkg_scope(function_tmpdir, example_data_path):
338364 # write dataset to netcdf
339365 ds .to_netcdf (ws / fname , format = "NETCDF4" , engine = "netcdf4" )
340366
341- check_netcdf (ws / fname )
367+ check_netcdf (ws / fname , sim . get_model ( sim_name ) )
342368
343369
344370@pytest .mark .regression
@@ -417,7 +443,7 @@ def test_uzf01_pkg_scope_modify(function_tmpdir, example_data_path):
417443 # write dataset to netcdf
418444 ds .to_netcdf (ws / fname , format = "NETCDF4" , engine = "netcdf4" )
419445
420- check_netcdf (ws / fname )
446+ check_netcdf (ws / fname , sim . get_model ( sim_name ) )
421447 assert (
422448 ds ["npf_k_updated" ].attrs ["standard_name" ]
423449 == "soil_hydraulic_conductivity_at_saturation"
@@ -440,15 +466,14 @@ def test_uzf01_cycle(function_tmpdir, example_data_path):
440466 sim .set_sim_path (ws )
441467 sim .write_simulation (netcdf = netcdf )
442468
443- check_netcdf (ws / fname )
469+ check_netcdf (ws / fname , sim . get_model ( sim_name ) )
444470
445471 # set simulation path and rewrite base simulation
446472 sim .set_sim_path (ws / "mf6" )
447- # gwf = sim.get_model(sim_name)
448- # gwf.name_file.nc_filerecord = None
449473 sim .write_simulation ()
450474
451475 assert not (ws / "mf6" / fname ).exists ()
452476
477+ # codegen isn't using latest modflow dev branch
453478 # success, buff = sim.run_simulation(silent=True, report=True)
454479 # assert success, pformat(buff)
0 commit comments