From 4a1440786e5d7211fbfd9a3e57e32dda54facb9d Mon Sep 17 00:00:00 2001 From: jdub Date: Sun, 8 Aug 2021 20:24:27 -0600 Subject: [PATCH 1/3] fix(loading mflist from file) --- flopy/utils/util_list.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flopy/utils/util_list.py b/flopy/utils/util_list.py index 4470ceba95..58499ce921 100644 --- a/flopy/utils/util_list.py +++ b/flopy/utils/util_list.py @@ -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 From ca6e12f58a3d95214fa1d5d5ed2786b1a0545a4b Mon Sep 17 00:00:00 2001 From: jdub Date: Mon, 9 Aug 2021 09:07:03 -0600 Subject: [PATCH 2/3] sigh --- flopy/utils/util_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flopy/utils/util_list.py b/flopy/utils/util_list.py index 58499ce921..3aaee15df8 100644 --- a/flopy/utils/util_list.py +++ b/flopy/utils/util_list.py @@ -1086,7 +1086,7 @@ def to_array(self, kper=0, mask=False): kper = self.__find_last_kper(kper) sarr = self.data[kper] - if (isinstance(sarr,str)): + if isinstance(sarr, str): sarr = self.__fromfile(sarr) if np.isscalar(sarr): From 508a79a7f785da7d07f45a22394a280a3b3a96fe Mon Sep 17 00:00:00 2001 From: jdub Date: Mon, 9 Aug 2021 13:34:13 -0600 Subject: [PATCH 3/3] added test --- autotest/t004_test_utilarray.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/autotest/t004_test_utilarray.py b/autotest/t004_test_utilarray.py index cc413fa546..ad47b701d5 100644 --- a/autotest/t004_test_utilarray.py +++ b/autotest/t004_test_utilarray.py @@ -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()