Skip to content

Commit a880039

Browse files
authored
fix(recarrays with cellid): fixes bug when setting data as recarrays with cellids (#2029)
* fix(subpackages): fixed detection issue of subpackages in some filein records * fix(recarray cellid): fixed problem when setting data with a recarray with layer/row/column fields (instead of cellid tuple) * fix * fix
1 parent c223c97 commit a880039

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

autotest/test_mf6.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,12 +1685,41 @@ def test_sfr_connections(function_tmpdir, example_data_path):
16851685

16861686
# reload simulation
16871687
sim2 = MFSimulation.load(sim_ws=sim_ws)
1688-
sim.set_all_data_external()
1689-
sim.write_simulation()
1690-
success, buff = sim.run_simulation()
1688+
sim2.set_all_data_external()
1689+
sim2.write_simulation()
1690+
success, buff = sim2.run_simulation()
16911691
assert (
16921692
success
1693-
), f"simulation {sim.name} did not run after being reloaded"
1693+
), f"simulation {sim2.name} did not run after being reloaded"
1694+
1695+
# test sfr recarray data
1696+
model2 = sim2.get_model()
1697+
sfr2 = model2.get_package("sfr")
1698+
sfr_pd = sfr2.packagedata
1699+
rec_data = [
1700+
(0, 0, 0, 0, 1.0, 1.0, 0.01, 10.0, 1.0, 1.0, 1.0, 1, 1.0, 0),
1701+
(1, 0, 1, 0, 1.0, 1.0, 0.01, 10.0, 1.0, 1.0, 1.0, 2, 1.0, 0),
1702+
]
1703+
rec_type = [
1704+
("ifno", int),
1705+
("layer", int),
1706+
("row", int),
1707+
("column", int),
1708+
("rlen", float),
1709+
("rwid", float),
1710+
("rgrd", float),
1711+
("rtp", float),
1712+
("rbth", float),
1713+
("rhk", float),
1714+
("man", float),
1715+
("nconn", int),
1716+
("ustrf", float),
1717+
("nvd", int),
1718+
]
1719+
pkg_data = np.rec.array(rec_data, rec_type)
1720+
sfr_pd.set_record({"data": pkg_data})
1721+
data = sfr_pd.get_data()
1722+
assert data[0][1] == (0, 0, 0)
16941723

16951724

16961725
@requires_exe("mf6")
@@ -2232,24 +2261,16 @@ def test_multi_model(function_tmpdir):
22322261
assert fi_out[2][2] == "MIXED"
22332262

22342263
spca1 = ModflowUtlspca(
2235-
gwt2,
2236-
filename="gwt_model_1.rch1.spc",
2237-
print_input=True
2264+
gwt2, filename="gwt_model_1.rch1.spc", print_input=True
22382265
)
22392266
spca2 = ModflowUtlspca(
2240-
gwt2,
2241-
filename="gwt_model_1.rch2.spc",
2242-
print_input=False
2267+
gwt2, filename="gwt_model_1.rch2.spc", print_input=False
22432268
)
22442269
spca3 = ModflowUtlspca(
2245-
gwt2,
2246-
filename="gwt_model_1.rch3.spc",
2247-
print_input=True
2270+
gwt2, filename="gwt_model_1.rch3.spc", print_input=True
22482271
)
22492272
spca4 = ModflowUtlspca(
2250-
gwt2,
2251-
filename="gwt_model_1.rch4.spc",
2252-
print_input=True
2273+
gwt2, filename="gwt_model_1.rch4.spc", print_input=True
22532274
)
22542275

22552276
# test writing and loading spca packages

flopy/mf6/coordinates/modeldimensions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,10 @@ def _resolve_data_item_shape(
615615
if data is None:
616616
if (
617617
self.simulation_data.verbosity_level.value
618-
>= VerbosityLevel.normal.value
618+
>= VerbosityLevel.verbose.value
619619
):
620620
print(
621-
"WARNING: Unable to resolve "
621+
"INFORMATION: Unable to resolve "
622622
"dimension of {} based on shape "
623623
'"{}".'.format(
624624
data_item_struct.path, item[0]
@@ -651,10 +651,10 @@ def _resolve_data_item_shape(
651651
else:
652652
if (
653653
self.simulation_data.verbosity_level.value
654-
>= VerbosityLevel.normal.value
654+
>= VerbosityLevel.verbose.value
655655
):
656656
print(
657-
"WARNING: Unable to resolve "
657+
"INFORMATION: Unable to resolve "
658658
"dimension of {} based on shape "
659659
'"{}".'.format(
660660
data_item_struct.path, item[0]

flopy/mf6/data/mfdatastorage.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,10 @@ def store_internal(
12761276
self.layer_storage.first_item().data_storage_type = (
12771277
DataStorageType.internal_array
12781278
)
1279+
if data is None or isinstance(data, np.recarray):
1280+
if not self.tuple_cellids(data):
1281+
# fix data so cellid is a single tuple
1282+
data = self.make_tuple_cellids(data.tolist())
12791283
if data is None or isinstance(data, np.recarray):
12801284
if self._simulation_data.verify_data and check_data:
12811285
self._verify_list(data)
@@ -1602,9 +1606,15 @@ def make_tuple_cellids(self, data):
16021606
return new_data
16031607

16041608
def tuple_cellids(self, data):
1609+
if data is None or len(data) == 0:
1610+
return True
16051611
for data_entry, cellid in zip(data[0], self.recarray_cellid_list):
16061612
if cellid:
1607-
if isinstance(data_entry, int):
1613+
if (
1614+
isinstance(data_entry, int)
1615+
or isinstance(data_entry, np.int32)
1616+
or isinstance(data_entry, np.int64)
1617+
):
16081618
# cellid is stored in separate columns in the recarray
16091619
# (eg: one column for layer one column for row and
16101620
# one columne for column)

0 commit comments

Comments
 (0)