Skip to content

Commit 4c1e0ff

Browse files
mjrenomjreno
mjreno
authored and
mjreno
committed
fix utlncf create test
1 parent 9aa5d90 commit 4c1e0ff

File tree

15 files changed

+117
-247
lines changed

15 files changed

+117
-247
lines changed

autotest/regression/test_model_netcdf.py

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import math
21
import os
32
import shutil
4-
from traceback import format_exc
5-
from warnings import warn
63

74
import numpy as np
85
import pytest
@@ -13,7 +10,6 @@
1310
import flopy
1411
from flopy.discretization.structuredgrid import StructuredGrid
1512
from flopy.discretization.vertexgrid import VertexGrid
16-
from flopy.utils.datautil import DatumUtil
1713
from flopy.utils.gridutil import get_disv_kwargs
1814
from flopy.utils.model_netcdf import create_dataset
1915

@@ -47,13 +43,6 @@ def compare_netcdf(base, gen, projection=False, update=None):
4743
else:
4844
attr = "crs_wkt"
4945
assert attr in xrg.data_vars[varname].attrs
50-
51-
# TODO
52-
# crs_b = CRS.from_wkt(da.attrs[attr])
53-
# epsg_b = crs_b.to_epsg(min_confidence=90)
54-
# crs_g = CRS.from_wkt(xrg.data_vars[varname].attrs[attr])
55-
# epsg_g = crs_g.to_epsg(min_confidence=90)
56-
# assert epsg_b == epsg_g
5746
continue
5847

5948
compare_netcdf_var(
@@ -143,7 +132,6 @@ def test_load_gwfsto01(function_tmpdir, example_data_path):
143132

144133
# load example
145134
sim = flopy.mf6.MFSimulation.load(sim_ws=base_path)
146-
# gwf = sim.get_model("gwf_sto01")
147135

148136
# set simulation path and write simulation
149137
sim.set_sim_path(test_path)
@@ -902,10 +890,6 @@ def test_disv01b(function_tmpdir, example_data_path):
902890

903891
nlay, nrow, ncol = 3, 3, 3
904892
ncpl = nrow * ncol
905-
# delr = 10.0
906-
# delc = 10.0
907-
# xoff = 100000000.0
908-
# yoff = 100000000.0
909893

910894
vertices = [
911895
(0, 1.0000000e08, 1.0000003e08),
@@ -1244,8 +1228,25 @@ def test_utlncf_create(function_tmpdir, example_data_path):
12441228
"test_utlncf_create": {
12451229
"base_sim_dir": "disv01b",
12461230
"netcdf_output_file": "disv01b.in.nc",
1231+
"netcdf_type": "mesh2d",
12471232
},
12481233
}
1234+
1235+
name = "disv01b"
1236+
nlay = 3
1237+
nrow = 3
1238+
ncol = 3
1239+
delr = 10.0
1240+
delc = 10.0
1241+
top = 0
1242+
botm = [-10, -20, -30]
1243+
xoff = 100000000.0
1244+
yoff = 100000000.0
1245+
disvkwargs = get_disv_kwargs(nlay, nrow, ncol, delr, delc, top, botm, xoff, yoff)
1246+
idomain = np.ones((nlay, nrow * ncol), dtype=int)
1247+
idomain[0, 1] = 0
1248+
disvkwargs["idomain"] = idomain
1249+
12491250
ws = function_tmpdir / "ws"
12501251
for dirname, test in tests.items():
12511252
data_path = os.path.join(data_path_base, dirname, test["base_sim_dir"])
@@ -1255,8 +1256,40 @@ def test_utlncf_create(function_tmpdir, example_data_path):
12551256
test_path = os.path.join(ws, f"{dirname}_test")
12561257
shutil.copytree(data_path, base_path)
12571258

1258-
# load example
1259-
sim = flopy.mf6.MFSimulation.load(sim_ws=base_path)
1259+
# create example
1260+
sim = flopy.mf6.MFSimulation(
1261+
sim_name=name,
1262+
version="mf6",
1263+
exe_name="mf6",
1264+
sim_ws=ws,
1265+
)
1266+
tdis = flopy.mf6.ModflowTdis(sim, start_date_time="2041-01-01t00:00:00-05:00")
1267+
kwargs = {}
1268+
kwargs["crs"] = "EPSG:26918"
1269+
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, **kwargs)
1270+
ims = flopy.mf6.ModflowIms(sim, print_option="SUMMARY")
1271+
disv = flopy.mf6.ModflowGwfdisv(gwf, **disvkwargs)
1272+
ncf = flopy.mf6.ModflowUtlncf(
1273+
disv,
1274+
deflate=9,
1275+
shuffle=True,
1276+
chunk_time=1,
1277+
chunk_face=3,
1278+
filename=f"{name}.disv.ncf",
1279+
)
1280+
ic = flopy.mf6.ModflowGwfic(gwf, strt=0.0)
1281+
npf = flopy.mf6.ModflowGwfnpf(gwf)
1282+
spd = {0: [[(0, 0), 1.0], [(0, nrow * ncol - 1), 0.0]]}
1283+
chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd(gwf, stress_period_data=spd)
1284+
oc = flopy.mf6.ModflowGwfoc(
1285+
gwf,
1286+
head_filerecord=f"{name}.hds",
1287+
saverecord=[("HEAD", "ALL")],
1288+
)
1289+
1290+
# set path and write simulation
1291+
sim.set_sim_path(test_path)
1292+
sim.write_simulation(netcdf=test["netcdf_type"])
12601293

12611294
# set simulation path and write simulation
12621295
sim.set_sim_path(test_path)

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.chd

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.disv

Lines changed: 0 additions & 63 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.disv.ncf

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.ic

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.ims

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.nam

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.npf

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.oc

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/disv01b.tdis

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/data/mf6/netcdf/test_utlncf_create/disv01b/mfsim.nam

Lines changed: 0 additions & 19 deletions
This file was deleted.

flopy/mf6/data/mfdataarray.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,9 @@ def store_internal(
610610
):
611611
layer_list.append(index)
612612
if (
613-
#TODO NETCDF-DEV improve
614-
len(layer_list) == 1
613+
storage.netcdf
614+
and len(layer_list) == 1
615615
and layer_list[0] == 0
616-
and storage.netcdf
617616
):
618617
layer_list[0] = -1
619618
else:
@@ -957,9 +956,6 @@ def _set_data(
957956
else:
958957
layer_data = aux_var_data
959958
try:
960-
#NETCDF-DEV
961-
if storage.netcdf:
962-
multiplier = 1.0
963959
storage.set_data(
964960
layer_data,
965961
[layer],
@@ -1076,7 +1072,6 @@ def load(
10761072
nc_dataset=None
10771073
if self.structure.netcdf:
10781074
if (
1079-
# TODO use util splitting method e.g. see mffileaccess #NETCDF-DEV
10801075
hasattr(self._model_or_sim, "_nc_dataset")
10811076
and len(first_line.split()) > 1
10821077
and first_line.split()[1].lower() == "netcdf"
@@ -1625,7 +1620,7 @@ def plot(
16251620
def _set_storage_netcdf(self, nc_dataset, create=False):
16261621
if create:
16271622
# add array to netcdf dataset
1628-
# TODO: fix, this won't work for multi-packages #NETCDF-DEV
1623+
# TODO: update to use pname for (stress) multi-packages
16291624
nc_dataset.create_array(
16301625
self.structure.get_package(),
16311626
self.structure.name.lower(),

flopy/mf6/data/mfdatastorage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,6 @@ def external_to_internal(
20112011
self._model_or_sim.modeldiscrit,
20122012
)[0]
20132013
elif self.layer_storage[layer].nc_dataset is not None:
2014-
# TODO: ensure multiplier only set by open/close #NETCDF-DEV
20152014
data_out = (
20162015
file_access.read_netcdf_array(
20172016
self.layer_storage[layer].nc_dataset,

flopy/mf6/mfmodel.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,21 +934,18 @@ def load_base(
934934
if nc_filerecord:
935935
from ..utils.model_netcdf import open_dataset
936936

937-
dis_str = {
937+
grid_str = {
938938
"dis6": "structured",
939939
"disv6": "vertex",
940-
#"disu6": "unstructured",
941940
}
942941
dis_type = None
943942
for t in instance.name_file.packages.get_data():
944943
if t[0].lower().startswith("dis"):
945944
dis_type = t[0].lower()
946945
break
947-
if dis_type and dis_type in dis_str:
946+
if dis_type and dis_type in grid_str:
948947
nc_fpth = os.path.join(instance.model_ws, nc_filerecord[0][0])
949-
# TODO: verify a partial dataset (not all griddata vars) don't
950-
# break everything
951-
instance._nc_dataset = open_dataset(nc_fpth, dis_type=dis_str[dis_type])
948+
instance._nc_dataset = open_dataset(nc_fpth, grid_type=grid_str[dis_type])
952949
else:
953950
message = (
954951
"Invalid discretization type "

0 commit comments

Comments
 (0)