Skip to content

Commit

Permalink
fix(loading mflist from file) (#1179)
Browse files Browse the repository at this point in the history
@aleaf @jtwhite79 has addressed this issue. See modified test (`t004_test_utilarray.py`) for an example of using external files for list data. Reopen if this does not solve your issue.

Closes #1073
  • Loading branch information
jtwhite79 committed Aug 9, 2021
1 parent fdc4608 commit 6d4e3b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 22 additions & 1 deletion autotest/t004_test_utilarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,30 @@ def test_util3d_reset():
ml.bas6.strt = arr


def test_mflist_fromfile():
"""test that when a file is passed to stress period data,
the .array attribute will load the file
"""
import pandas as pd
import flopy

wel_data = pd.DataFrame([(0,1,2, -50.0),(0,5,5, -50.0)],
columns=['k', 'i', 'j', 'flux'])
wel_data.to_csv('wel_000.dat', index=False, sep=' ',header=False)

nwt_model = flopy.modflow.Modflow('nwt_testmodel',verbose=True)
dis = flopy.modflow.ModflowDis(nwt_model, nlay=1, nrow=10, ncol=10, delr=500.0,
delc=500.0, top=100.0, botm=50.0)
wel = flopy.modflow.ModflowWel(nwt_model, stress_period_data={0: 'wel_000.dat'})
flx_array = wel.stress_period_data.array["flux"][0]
for k,i,j,flx in zip(wel_data.k,wel_data.i,wel_data.j,wel_data.flux):
assert flx_array[k,i,j] == flx


if __name__ == "__main__":
# test_util3d_reset()
test_mflist()
#test_mflist()
test_mflist_fromfile()
# test_new_get_file_entry()
# test_arrayformat()
# test_util2d_external_free_nomodelws()
Expand Down
2 changes: 2 additions & 0 deletions flopy/utils/util_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,8 @@ def to_array(self, kper=0, mask=False):
kper = self.__find_last_kper(kper)

sarr = self.data[kper]
if isinstance(sarr, str):
sarr = self.__fromfile(sarr)

if np.isscalar(sarr):
# if there are no entries for this kper
Expand Down

0 comments on commit 6d4e3b7

Please sign in to comment.