I can read in an existing MODFLOW 6 simulation using flopy.mf6.MFSimulation.load. Now I want to find out how many stress periods it has, as an integer, as defined by nper in the tdis package. What's the easiest way to do this?
Asked
Active
Viewed 237 times
1 Answers
1
So here is the trick, in flopy classes for MODFLOW 6, all of the information is stored as objects, including integers, arrays, floats, etc. This gives us some nice advantages, but it also makes some of the syntax a little difficult, though we are working to improve that.
Here is a very simple model:
import flopy
sim = flopy.mf6.MFSimulation()
tdis = flopy.mf6.ModflowTdis(sim, nper=10)
gwf = flopy.mf6.ModflowGwf(sim)
dis = flopy.mf6.ModflowGwfdis(gwf)
If we try to get at nper like this:
nper = tdis.nper
print(nper)
then we get back the repr, which looks like this:
{internal}
(10)
The way we get the actual data is to append array:
nper = tdis.nper.array
print(nper)
print(type(nper))
In which case we get the desired information:
10
<class 'int'>
For scalars we are considering changing this behavior so that it behaves like you would think (returning the value directly), but we haven't implemented that yet.

Christian Langevin
- 128
- 4
-
Since I'm reading an existing simulation, I got the TDIS package by calling `tdis = MFSimulation.get_package('TDIS')`. Then I found I could get nper as an int via `nper = tdis.nper.get_data()`. It looks like `tdis.nper.array` calls `tdis.nper.get_data()`. Is it preferable to use `array` over `get_data()`? – unjedai Apr 23 '19 at 14:42
-
This is good to know. I'm digging into a MF6 model for the first time and using the new `mf6` tools is considerably different that for the traditional MODFLOW models. The code base is quite a bit more complex and I haven't wrapped my head around it yet. – Jason Bellino Apr 25 '19 at 14:17
-
You're right. The .get_data() method makes more sense than the .array attribute, especially for scalar variables. – Christian Langevin Apr 27 '19 at 11:40