Skip to content

Commit

Permalink
netcdf util uses data type specific interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mjreno authored and mjreno committed Jan 15, 2025
1 parent 46dc0ed commit 8c59095
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 113 deletions.
4 changes: 2 additions & 2 deletions flopy/mf6/data/mfdataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,10 +1602,10 @@ def _set_storage_netcdf(self, nc_dataset, create=False):
input_tag = f"{m}/{p}/{n}".lower()

if create:
# cache data and update file before resetting storage
# add array to netcdf dataset
nc_varname = f"{p}_{n}".lower()
data = self._get_data()
nc_dataset.create_var(nc_varname, input_tag, 0, data, self.structure.shape)
nc_dataset.create_array(nc_varname, input_tag, 0, data, self.structure.shape)

storage._set_storage_netcdf(
nc_dataset, input_tag, self.structure.layered, storage.layer_storage.get_total_size() - 1
Expand Down
2 changes: 1 addition & 1 deletion flopy/mf6/data/mffileaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def load_netcdf_array(
nc_tag,
layer,
):
return nc_dataset.data(nc_tag, layer + 1)
return nc_dataset.array(nc_tag, layer + 1)

def get_data_string(self, data, data_type, data_indent=""):
layer_data_string = [str(data_indent)]
Expand Down
2 changes: 1 addition & 1 deletion flopy/mf6/data/mfstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ def __init__(self, data_item, model_data, package_type, dfn_list):
or "nodes" in data_item.shape
or len(data_item.layer_dims) > 1
)
# TODO: only gwf, gwt, gwe models
# TODO: only gwf, gwt, gwe models NETCDF-DEV
self.netcdf = (
("ncol" in data_item.shape
or "nrow" in data_item.shape
Expand Down
15 changes: 11 additions & 4 deletions flopy/mf6/mfmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,19 +940,26 @@ def load_base(
dis_str = {
"dis6": "structured",
"disv6": "vertex",
"disu6": "unstructured",
#"disu6": "unstructured",
}
dis_type = None
for t in instance.name_file.packages.get_data():
if t[0].lower().startswith("dis"):
dis_type = t[0].lower()
break
if dis_type:
if dis_type and dis_type in dis_str:
nc_fpth = os.path.join(instance.model_ws, nc_filerecord[0][0])
instance._nc_dataset = open_netcdf_dataset(nc_fpth, dis_type=dis_str[dis_type])
else:
pass
# TODO: set error "invalid dis for netcdf input"
message = (
"Invalid discretization type "
f"provided for model {modelname} "
"NetCDF input"
)
raise MFDataException(
model=modelname,
message=message,
)

# order packages
vnum = mfstructure.MFStructure().get_version_string()
Expand Down
Loading

0 comments on commit 8c59095

Please sign in to comment.