Skip to content

Commit 40c77b0

Browse files
mjrenomjreno
authored andcommitted
baseline tests check ascii parity
1 parent 1d9f1a5 commit 40c77b0

File tree

6 files changed

+99
-53
lines changed

6 files changed

+99
-53
lines changed

autotest/regression/test_mf6_netcdf.py

Lines changed: 72 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,32 @@ def test_load_netcdf_gwfsto01(function_tmpdir, example_data_path):
8484
next(file2)
8585

8686
for line1, line2 in zip(file1, file2):
87-
assert line1 == line2
87+
assert line1.lower() == line2.lower()
8888
else:
8989
# TODO compare nc files
9090
assert os.path.exists(gen)
91-
continue
9291

9392

9493
@requires_pkg("xarray")
9594
@requires_exe("mf6")
9695
@pytest.mark.regression
9796
def test_create_netcdf_gwfsto01(function_tmpdir, example_data_path):
9897
xr = import_optional_dependency("xarray")
99-
100-
cases = ["structured", "mesh2d"]
98+
data_path_base = example_data_path / "mf6" / "netcdf"
99+
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+
),
110+
}
111+
name = "gwf_sto01"
112+
cases = ["mesh2d", "structured"]
101113

102114
# static model data
103115
# temporal discretization
@@ -174,17 +186,29 @@ def test_create_netcdf_gwfsto01(function_tmpdir, example_data_path):
174186
ske = [6e-4, 3e-4, 6e-4]
175187

176188
# build
177-
for name in cases:
178-
# name = cases[0]
179-
ws = function_tmpdir / name
189+
ws = function_tmpdir / "ws"
190+
for idx, (base_folder, test_info) in enumerate(tests.items()):
191+
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+
)
196+
# copy example data into working directory
197+
base_model_folder = os.path.join(ws, f"{base_folder}_base")
198+
test_model_folder = os.path.join(ws, f"{base_folder}_test")
199+
shutil.copytree(data_path, base_model_folder)
180200

181201
# build MODFLOW 6 files
182202
sim = flopy.mf6.MFSimulation(
183203
sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws
184204
)
185205
# create tdis package
186206
tdis = flopy.mf6.ModflowTdis(
187-
sim, time_units="DAYS", nper=nper, perioddata=tdis_rc
207+
sim,
208+
time_units="DAYS",
209+
start_date_time="2041-01-01t00:00:00-05:00",
210+
nper=nper,
211+
perioddata=tdis_rc,
188212
)
189213

190214
# create gwf model
@@ -276,21 +300,43 @@ def test_create_netcdf_gwfsto01(function_tmpdir, example_data_path):
276300
printrecord=[("HEAD", "LAST"), ("BUDGET", "ALL")],
277301
)
278302

279-
sim.write_simulation(netcdf=name)
280-
281-
try:
282-
success, buff = flopy.run_model(
283-
"mf6",
284-
ws / "mfsim.nam",
285-
model_ws=ws,
286-
report=True,
287-
)
288-
except Exception:
289-
warn(
290-
"MODFLOW 6 serial test",
291-
name,
292-
f"failed with error:\n{format_exc()}",
293-
)
294-
success = False
295-
296-
assert success
303+
sim.set_sim_path(test_model_folder)
304+
sim.write_simulation(netcdf=netcdf)
305+
306+
# compare generated files
307+
gen_files = [
308+
f
309+
for f in os.listdir(test_model_folder)
310+
if os.path.isfile(os.path.join(test_model_folder, f))
311+
]
312+
base_files = [
313+
f
314+
for f in os.listdir(base_model_folder)
315+
if os.path.isfile(os.path.join(base_model_folder, f))
316+
]
317+
# assert len(gen_files) == len(base_files)
318+
for f in base_files:
319+
print(f"cmp => {f}")
320+
base = os.path.join(base_model_folder, f)
321+
gen = os.path.join(test_model_folder, f)
322+
if f != test_info.netcdf_output_file:
323+
with open(base, "r") as file1, open(gen, "r") as file2:
324+
# Skip first line
325+
next(file1)
326+
next(file2)
327+
328+
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
338+
else:
339+
# TODO compare nc files
340+
assert os.path.exists(
341+
os.path.join(test_model_folder, "gwf_sto01.in.nc")
342+
)

examples/data/mf6/netcdf/test_gwf_sto01_mesh/gwf_sto01/gwf_sto01.nam

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ BEGIN options
66
END options
77

88
BEGIN packages
9-
dis6 gwf_sto01.dis dis
10-
ic6 gwf_sto01.ic ic
11-
npf6 gwf_sto01.npf npf
12-
sto6 gwf_sto01.sto sto
13-
rch6 gwf_sto01.rcha rcha_0
14-
wel6 gwf_sto01.wel wel_0
15-
chd6 gwf_sto01.chd chd_0
16-
oc6 gwf_sto01.oc oc
9+
DIS6 gwf_sto01.dis dis
10+
IC6 gwf_sto01.ic ic
11+
NPF6 gwf_sto01.npf npf
12+
STO6 gwf_sto01.sto sto
13+
RCH6 gwf_sto01.rcha rcha_0
14+
WEL6 gwf_sto01.wel wel_0
15+
CHD6 gwf_sto01.chd chd_0
16+
OC6 gwf_sto01.oc oc
1717
END packages

examples/data/mf6/netcdf/test_gwf_sto01_mesh/gwf_sto01/gwf_sto01.oc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
BEGIN options
33
BUDGET FILEOUT gwf_sto01.cbc
44
HEAD FILEOUT gwf_sto01.hds
5-
HEAD PRINT_FORMAT COLUMNS 10 WIDTH 15 DIGITS 6 general
5+
HEAD PRINT_FORMAT COLUMNS 10 WIDTH 15 DIGITS 6 GENERAL
66
END options
77

88
BEGIN period 1
9-
SAVE head all
10-
SAVE budget all
11-
PRINT head all
12-
PRINT budget all
9+
SAVE HEAD ALL
10+
SAVE BUDGET ALL
11+
PRINT HEAD LAST
12+
PRINT BUDGET ALL
1313
END period 1
1414

examples/data/mf6/netcdf/test_gwf_sto01_structured/gwf_sto01/gwf_sto01.nam

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ BEGIN options
66
END options
77

88
BEGIN packages
9-
dis6 gwf_sto01.dis dis
10-
ic6 gwf_sto01.ic ic
11-
npf6 gwf_sto01.npf npf
12-
sto6 gwf_sto01.sto sto
13-
rch6 gwf_sto01.rcha rcha_0
14-
wel6 gwf_sto01.wel wel_0
15-
chd6 gwf_sto01.chd chd_0
16-
oc6 gwf_sto01.oc oc
9+
DIS6 gwf_sto01.dis dis
10+
IC6 gwf_sto01.ic ic
11+
NPF6 gwf_sto01.npf npf
12+
STO6 gwf_sto01.sto sto
13+
RCH6 gwf_sto01.rcha rcha_0
14+
WEL6 gwf_sto01.wel wel_0
15+
CHD6 gwf_sto01.chd chd_0
16+
OC6 gwf_sto01.oc oc
1717
END packages

examples/data/mf6/netcdf/test_gwf_sto01_structured/gwf_sto01/gwf_sto01.oc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
BEGIN options
33
BUDGET FILEOUT gwf_sto01.cbc
44
HEAD FILEOUT gwf_sto01.hds
5-
HEAD PRINT_FORMAT COLUMNS 10 WIDTH 15 DIGITS 6 general
5+
HEAD PRINT_FORMAT COLUMNS 10 WIDTH 15 DIGITS 6 GENERAL
66
END options
77

88
BEGIN period 1
9-
SAVE head all
10-
SAVE budget all
11-
PRINT head last
12-
PRINT budget all
9+
SAVE HEAD ALL
10+
SAVE BUDGET ALL
11+
PRINT HEAD LAST
12+
PRINT BUDGET ALL
1313
END period 1
1414

flopy/utils/model_netcdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _create_layered_var(
177177
):
178178
try:
179179
for layer in range(data.shape[0]):
180-
layer_vname = f"{varname}_l{layer+1}"
180+
layer_vname = f"{varname}_l{layer + 1}"
181181
var_d = {layer_vname: (nc_shape, data[layer].flatten())}
182182
self._dataset = self._dataset.assign(var_d)
183183
self._dataset[layer_vname].attrs["modflow6_input"] = tag

0 commit comments

Comments
 (0)