I am using Flopy to set up a MODFLOW model in Python 2.7. I am trying to add head observations via the HOB package. The following example code is taken directly from the function documentation at https://modflowpy.github.io/flopydoc/mfhob.html:
import flopy
model = flopy.modflow.Modflow()
dis = flopy.modflow.ModflowDis(model, nlay=1, nrow=11, ncol=11,
nper=2, perlen=[1,1])
obs = flopy.modflow.mfhob.HeadObservation(model, layer=0, row=5,
column=5,
time_series_data=[[1.,54.4],
[2., 55.2]])
Using this example code for the function, I am getting the following error:
ValueError: Can't cast from structure to non-structure, except if the structure only has a single field.
I get the same error when I try to create a head observation for my model, which is steady-state and has some different input values. Unfortunately, I haven't been able to find a working example to compare with. Any ideas?
Edit: jdhughes's code works like a charm; BUT I had also neglected to update Flopy to the most recent version - I tried updating numpy first, but didn't get rid of the ValueError until I updated Flopy from 3.2.8 to 3.2.9. Works now, thank you!!!
You need to create one or more instances of a HeadObservation type and pass that to ModflowHob
. An example with two observation locations is shown below.
# create a new hob object
obs_data = []
# observation location 1
tsd = [[1., 1.], [87163., 2.], [348649., 3.],
[871621., 4.], [24439070., 5.], [24439072., 6.]]
names = ['o1.1', 'o1.2', 'o1.3', 'o1.4', 'o1.5', 'o1.6']
obs_data.append(flopy.modflow.HeadObservation(mf, layer=0, row=2, column=0,
time_series_data=tsd,
names=names, obsname='o1'))
# observation location 2
tsd = [[0., 126.938], [87163., 126.904], [871621., 126.382],
[871718.5943, 115.357], [871893.7713, 112.782]]
names = ['o2.1', 'o2.2', 'o2.3', 'o2.4', 'o2.5']
obs_data.append(flopy.modflow.HeadObservation(mf, layer=0, row=3, column=3,
time_series_data=tsd,
names=names, obsname='o2'))
hob = flopy.modflow.ModflowHob(mf, iuhobsv=51, obs_data=obs_data)
Will submit an issue to update the documentation and docstrings.