Skip to content

Commit

Permalink
add baseline testing for utl-ncf options
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and mjreno committed Dec 17, 2024
1 parent 5a7e1b2 commit 7445034
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 32 deletions.
4 changes: 2 additions & 2 deletions autotest/test_netcdf_gwe_cnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")


def build_models(idx, test, export, gridded_input):
Expand Down Expand Up @@ -59,7 +59,7 @@ def check_output(idx, test, export, gridded_input):
name = "gwe-" + test.name

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{name}.nc") as ds:
with nc.Dataset(test.workspace / f"{name}.nc") as ds:
assert ds.data_model == "NETCDF4"

if gridded_input == "netcdf":
Expand Down
20 changes: 17 additions & 3 deletions autotest/test_netcdf_gwf_disv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")

wkt = (
'PROJCS["NAD83 / UTM zone 18N", '
Expand Down Expand Up @@ -54,7 +54,15 @@ def build_models(idx, test, export, gridded_input):
gwf.name_file.nc_mesh2d_filerecord = f"{name}.nc"

# netcdf config
ncf = flopy.mf6.ModflowUtlncf(gwf.disv, wkt=wkt, filename=f"{name}.disv.ncf")
ncf = flopy.mf6.ModflowUtlncf(
gwf.disv,
deflate=9,
shuffle=True,
chunk_time=1,
chunk_face=3,
wkt=wkt,
filename=f"{name}.disv.ncf",
)

# output control
oc = flopy.mf6.ModflowGwfoc(
Expand All @@ -74,8 +82,14 @@ def check_output(idx, test, export, gridded_input):
name = test.name

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{name}.nc") as ds:
with nc.Dataset(test.workspace / f"{name}.nc") as ds:
assert ds.data_model == "NETCDF4"
cmpr = ds.variables["head_l1"].filters()
chnk = ds.variables["head_l1"].chunking()
assert cmpr["shuffle"]
assert cmpr["complevel"] == 9
assert chnk == [1, 3]
assert ds.variables["projection"].getncattr("wkt").lower() == wkt.lower()

if gridded_input == "netcdf":
# re-run the simulation with model netcdf input
Expand Down
4 changes: 2 additions & 2 deletions autotest/test_netcdf_gwf_lak_wetlakbedarea02.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")


def build_models(idx, test, export, gridded_input):
Expand Down Expand Up @@ -63,7 +63,7 @@ def check_output(idx, test, export, gridded_input):
gwfname = "gwf-" + name

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{gwfname}.nc") as ds:
with nc.Dataset(test.workspace / f"{gwfname}.nc") as ds:
assert ds.data_model == "NETCDF4"

if gridded_input == "netcdf":
Expand Down
4 changes: 2 additions & 2 deletions autotest/test_netcdf_gwf_rch01.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")


def build_models(idx, test, export, gridded_input):
Expand Down Expand Up @@ -60,7 +60,7 @@ def check_output(idx, test, export, gridded_input):
name = "rch"

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{name}.nc") as ds:
with nc.Dataset(test.workspace / f"{name}.nc") as ds:
assert ds.data_model == "NETCDF4"

if gridded_input == "netcdf":
Expand Down
4 changes: 2 additions & 2 deletions autotest/test_netcdf_gwf_rch03.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")


def build_models(idx, test, export, gridded_input):
Expand Down Expand Up @@ -61,7 +61,7 @@ def check_output(idx, test, export, gridded_input):
name = "rch"

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{name}.nc") as ds:
with nc.Dataset(test.workspace / f"{name}.nc") as ds:
assert ds.data_model == "NETCDF4"

if gridded_input == "netcdf":
Expand Down
45 changes: 36 additions & 9 deletions autotest/test_netcdf_gwf_sto01.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")

htol = [None for _ in range(len(cases))]

Expand Down Expand Up @@ -53,15 +53,28 @@ def build_models(idx, test, export, gridded_input):

if export == "ugrid":
gwf.name_file.nc_mesh2d_filerecord = f"{name}.nc"
ncf = flopy.mf6.ModflowUtlncf(
gwf.dis,
deflate=5,
shuffle=True,
chunk_time=1,
chunk_face=10,
wkt=wkt,
filename=f"{name}.dis.ncf",
)
elif export == "structured":
gwf.name_file.nc_structured_filerecord = f"{name}.nc"

# netcdf config
ncf = flopy.mf6.ModflowUtlncf(
gwf.dis,
wkt=wkt,
filename=f"{name}.dis.ncf",
)
ncf = flopy.mf6.ModflowUtlncf(
gwf.dis,
deflate=5,
shuffle=True,
chunk_time=1,
chunk_z=1,
chunk_y=5,
chunk_x=5,
wkt=wkt,
filename=f"{name}.dis.ncf",
)

return sim, dummy

Expand All @@ -70,8 +83,22 @@ def check_output(idx, test, export, gridded_input):
from test_gwf_sto01 import check_output as check

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / "gwf_sto01.nc") as ds:
with nc.Dataset(test.workspace / "gwf_sto01.nc") as ds:
assert ds.data_model == "NETCDF4"
if export == "structured":
cmpr = ds.variables["head"].filters()
chnk = ds.variables["head"].chunking()
assert chnk == [1, 1, 5, 5]
assert (
ds.variables["projection"].getncattr("crs_wkt").lower() == wkt.lower()
)
elif export == "ugrid":
cmpr = ds.variables["head_l1"].filters()
chnk = ds.variables["head_l1"].chunking()
assert chnk == [1, 10]
assert ds.variables["projection"].getncattr("wkt").lower() == wkt.lower()
assert cmpr["shuffle"]
assert cmpr["complevel"] == 5

if gridded_input == "netcdf":
# re-run the simulation with model netcdf input
Expand Down
4 changes: 2 additions & 2 deletions autotest/test_netcdf_gwf_vsc03_sfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")


def build_models(idx, test, export, gridded_input):
Expand Down Expand Up @@ -63,7 +63,7 @@ def check_output(idx, test, export, gridded_input):
name = "gwf-" + test.name

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{name}.nc") as ds:
with nc.Dataset(test.workspace / f"{name}.nc") as ds:
assert ds.data_model == "NETCDF4"

if gridded_input == "netcdf":
Expand Down
38 changes: 30 additions & 8 deletions autotest/test_netcdf_gwt_dsp01.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")


def build_models(idx, test, export, gridded_input):
Expand All @@ -30,14 +30,26 @@ def build_models(idx, test, export, gridded_input):

if export == "ugrid":
gwt.name_file.nc_mesh2d_filerecord = f"{gwtname}.nc"
ncf = flopy.mf6.ModflowUtlncf(
gwt.dis,
deflate=3,
shuffle=False,
chunk_time=1,
chunk_face=5,
filename=f"{gwtname}.dis.ncf",
)
elif export == "structured":
gwt.name_file.nc_structured_filerecord = f"{gwtname}.nc"

# netcdf config
ncf = flopy.mf6.ModflowUtlncf(
gwt.dis,
filename=f"{gwtname}.dis.ncf",
)
ncf = flopy.mf6.ModflowUtlncf(
gwt.dis,
deflate=3,
shuffle=False,
chunk_time=1,
chunk_z=1,
chunk_y=1,
chunk_x=20,
filename=f"{gwtname}.dis.ncf",
)

oc = flopy.mf6.ModflowGwtoc(
gwt,
Expand All @@ -58,8 +70,18 @@ def check_output(idx, test, export, gridded_input):
gwtname = "gwt_" + name

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{gwtname}.nc") as ds:
with nc.Dataset(test.workspace / f"{gwtname}.nc") as ds:
assert ds.data_model == "NETCDF4"
if export == "structured":
cmpr = ds.variables["concentration"].filters()
chnk = ds.variables["concentration"].chunking()
assert chnk == [1, 1, 1, 20]
elif export == "ugrid":
cmpr = ds.variables["concentration_l1"].filters()
chnk = ds.variables["concentration_l1"].chunking()
assert chnk == [1, 5]
assert not cmpr["shuffle"]
assert cmpr["complevel"] == 3

if gridded_input == "netcdf":
# re-run the simulation with model netcdf input
Expand Down
4 changes: 2 additions & 2 deletions autotest/test_netcdf_gwt_prudic2004t2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

xa = pytest.importorskip("xarray")
xu = pytest.importorskip("xugrid")
netcdf4 = pytest.importorskip("netCDF4")
nc = pytest.importorskip("netCDF4")


def build_models(idx, test, export, gridded_input):
Expand Down Expand Up @@ -49,7 +49,7 @@ def check_output(idx, test, export, gridded_input):
gwtname = "gwt_" + name

# verify format of generated netcdf file
with netcdf4.Dataset(test.workspace / f"{gwtname}.nc") as ds:
with nc.Dataset(test.workspace / f"{gwtname}.nc") as ds:
assert ds.data_model == "NETCDF4"

if gridded_input == "netcdf":
Expand Down

0 comments on commit 7445034

Please sign in to comment.