Hi, does anyone know how to specify an external file for the input of list-type data, for example, for the WEL Package? With the MODFLOW-6 part of Flopy, I can use the code below to write well package data to an external file and then supply that as input. This is convenient for working with the data outside of flopy (both in generating the initial version, and subsequently in parameter estimation or uncertainty quantification).
import pandas as pd
import flopy
mf6 = flopy.mf6
fm = flopy.modflow
# set up simulation
sim = mf6.MFSimulation(sim_name='testsim',
sim_ws='tmp')
tdis_rc = [(6.0, 2, 1.0), (6.0, 3, 1.0)]
tdis = mf6.ModflowTdis(sim, time_units='DAYS', nper=2,
perioddata=tdis_rc)
ims_package = mf6.ModflowIms(sim)
# create model instance
model = mf6.ModflowGwf(sim, modelname='testmodel')
dis = mf6.ModflowGwfdis(model, length_units='FEET', nlay=1,
nrow=1, ncol=10, delr=500.0,
delc=500.0,
top=100.0, botm=50.0)
# make wel package data and write the external file
wel_data = pd.DataFrame([(0,11,2, -50.0)],
columns=['#k', 'i', 'j', 'q'])
wel_data.to_csv('tmp/wel_000.dat', index=False, sep=' ')
# create the wel package instance from the external file
wel = flopy.mf6.ModflowGwfwel(model, pname='wel', print_input=True, print_flows=True,
maxbound=1,
stress_period_data={0: {'filename': 'wel_000.dat'}})
# access the stress period data
wel.stress_period_data.array
result:
[rec.array([((-1, 10, 1), -50.)],
dtype=[('cellid', 'O'), ('q', '<f8')]),
None]
But when I try doing the same thing in a MODFLOW-NWT context, for example, it doesn't seem like the external file input is being properly read.
nwt_model = fm.Modflow('nwt_testmodel')
dis = fm.ModflowDis(nwt_model, nlay=1, nrow=1, ncol=10, delr=500.0,
delc=500.0, top=100.0, botm=50.0)
wel = fm.ModflowWel(nwt_model, stress_period_data={0: 'wel_000.dat'})
wel.stress_period_data.array
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-20-440aa0c07f28> in <module>
----> 1 wel.stress_period_data.array
~/Documents/GitHub/flopy/flopy/utils/util_list.py in array(self)
1221 @property
1222 def array(self):
-> 1223 return self.masked_4D_arrays
1224
1225 @classmethod
~/Documents/GitHub/flopy/flopy/utils/util_list.py in masked_4D_arrays(self)
1176 def masked_4D_arrays(self):
1177 # get the first kper
-> 1178 arrays = self.to_array(kper=0, mask=True)
1179
1180 # initialize these big arrays
~/Documents/GitHub/flopy/flopy/utils/util_list.py in to_array(self, kper, mask)
1139 return arrays
1140 else:
-> 1141 raise Exception("MfList: something bad happened")
1142
1143 for name, arr in arrays.items():
Exception: MfList: something bad happened
Trying the MODFLOW-6 style input doesn't work either:
wel = fm.ModflowWel(nwt_model, stress_period_data={0: {'filename': 'wel_000.dat'}})
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-16-e93205e6bc63> in <module>
----> 1 wel = fm.ModflowWel(nwt_model, stress_period_data={0: {'filename': 'wel_000.dat'}})
~/Documents/GitHub/flopy/flopy/modflow/mfwel.py in __init__(self, model, ipakcb, stress_period_data, dtype, extension, options, binary, unitnumber, filenames)
262
263 # initialize MfList
--> 264 self.stress_period_data = MfList(
265 self, stress_period_data, binary=binary
266 )
~/Documents/GitHub/flopy/flopy/utils/util_list.py in __init__(self, package, data, dtype, model, list_free_format, binary)
95 self.__data = {}
96 if data is not None:
---> 97 self.__cast_data(data)
98 self.__df = None
99 if list_free_format is None:
~/Documents/GitHub/flopy/flopy/utils/util_list.py in __cast_data(self, data)
374 self.__vtype[kper] = None
375 else:
--> 376 raise Exception(
377 "MfList error: unsupported data type: "
378 + str(type(d))
Exception: MfList error: unsupported data type: <class 'dict'> at kper 0
Is there a way to do this? I couldn't find anything in the examples. Thanks in advance.
Hi, does anyone know how to specify an external file for the input of list-type data, for example, for the WEL Package? With the MODFLOW-6 part of Flopy, I can use the code below to write well package data to an external file and then supply that as input. This is convenient for working with the data outside of flopy (both in generating the initial version, and subsequently in parameter estimation or uncertainty quantification).
result:
But when I try doing the same thing in a MODFLOW-NWT context, for example, it doesn't seem like the external file input is being properly read.
Trying the MODFLOW-6 style input doesn't work either:
Is there a way to do this? I couldn't find anything in the examples. Thanks in advance.