Skip to content

Commit ab1594a

Browse files
committed
support list or tuple cell ids
1 parent f98516a commit ab1594a

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

autotest/test_cellbudgetfile.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -700,32 +700,33 @@ def test_cellbudgetfile_get_ts_aux_vars_mf6_readme_example(function_tmpdir):
700700
ModflowTdis,
701701
)
702702

703-
name = 'mymodel'
704-
sim = MFSimulation(sim_name=name, sim_ws=function_tmpdir, exe_name='mf6')
703+
name = "mymodel"
704+
sim = MFSimulation(sim_name=name, sim_ws=function_tmpdir, exe_name="mf6")
705705
tdis = ModflowTdis(sim)
706706
ims = ModflowIms(sim)
707707
gwf = ModflowGwf(sim, modelname=name, save_flows=True)
708708
dis = ModflowGwfdis(gwf, nrow=10, ncol=10)
709709
ic = ModflowGwfic(gwf)
710710
npf = ModflowGwfnpf(gwf, save_specific_discharge=True)
711-
chd = ModflowGwfchd(gwf, stress_period_data=[[(0, 0, 0), 1.],
712-
[(0, 9, 9), 0.]])
713-
budget_file = name + '.bud'
714-
head_file = name + '.hds'
715-
oc = ModflowGwfoc(gwf,
716-
budget_filerecord=budget_file,
717-
head_filerecord=head_file,
718-
saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')])
711+
chd = ModflowGwfchd(gwf, stress_period_data=[[(0, 0, 0), 1.0], [(0, 9, 9), 0.0]])
712+
budget_file = name + ".bud"
713+
head_file = name + ".hds"
714+
oc = ModflowGwfoc(
715+
gwf,
716+
budget_filerecord=budget_file,
717+
head_filerecord=head_file,
718+
saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")],
719+
)
719720
sim.write_simulation(silent=True)
720721
sim.run_simulation(silent=True)
721722

722723
hds = gwf.output.head().get_data()
723724
cbc = gwf.output.budget()
724725

725-
cellid = (0,5,5)
726+
cellid = (0, 5, 5)
726727

727728
head = hds.get_ts(idx=cellid)
728-
spdis = cbc.get_ts(idx=cellid, text='DATA-SPDIS')
729+
spdis = cbc.get_ts(idx=cellid, text="DATA-SPDIS")
729730

730731

731732
@pytest.fixture
@@ -802,7 +803,9 @@ def test_cellbudgetfile_get_ts_aux_vars_mf6_dis(dis_sim):
802803
spdis_qy = cbc.get_ts(idx=cellid, text=text, variable="qy")
803804
spdis_qz = cbc.get_ts(idx=cellid, text=text, variable="qz")
804805

805-
chd_q = cbc.get_ts(idx=cellid, )
806+
chd_q = cbc.get_ts(
807+
idx=cellid,
808+
)
806809

807810
assert spdis_q.shape == spdis_qx.shape == spdis_qy.shape == spdis_qz.shape
808811
assert spdis_q.shape[1] == 2 # time + 1 data column

flopy/pakbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def __getitem__(self, item):
515515
# Oc88 but is not a MfList
516516
spd = getattr(self, "stress_period_data")
517517
if isinstance(item, MfList):
518-
if not isinstance(item, list) and not isinstance(item, tuple):
518+
if not isinstance(item, (list, tuple)):
519519
msg = f"package.__getitem__() kper {item} not in data.keys()"
520520
assert item in list(spd.data.keys()), msg
521521
return spd[item]

flopy/utils/binaryfile/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ def _cellids(self, idx):
17471747
cellid = []
17481748
for item in idx_list:
17491749
if grid_type == "structured":
1750-
if not isinstance(item, tuple) or len(item) != 3:
1750+
if not isinstance(item, (list, tuple)) or len(item) != 3:
17511751
raise ValueError(
17521752
f"Expected DIS cell index (layer, row, col), got: {item}"
17531753
)
@@ -1760,7 +1760,7 @@ def _cellids(self, idx):
17601760
raise ValueError(f"Column index {j} out of range [0, {self.ncol})")
17611761
cellid.append((k, i, j))
17621762
elif grid_type == "vertex":
1763-
if not isinstance(item, tuple) or len(item) != 2:
1763+
if not isinstance(item, (list, tuple)) or len(item) != 2:
17641764
raise ValueError(
17651765
f"Expected DISV cell index (layer, cellid), got: {item}"
17661766
)

0 commit comments

Comments
 (0)