In [1]:
    
import sys
import os
import numpy as np
try:
    import pandas as pd
except:
    pass
import flopy
print(sys.version)
print('numpy version: {}'.format(np.__version__))
try:
    print('pandas version: {}'.format(pd.__version__))
except:
    pass
print('flopy version: {}'.format(flopy.__version__))
    
    
In [2]:
    
m = flopy.modflow.Modflow('mnw2example', model_ws='temp')
dis = flopy.modflow.ModflowDis(nrow=5, ncol=5, nlay=3, nper=3, top=10, botm=0, model=m)
    
(this could be prepared externally from well reconds and read in from a csv or excel file)
In [3]:
    
node_data = pd.DataFrame([[1, 1, 9.5, 7.1, 'well1', 'skin', -1, 0, 0, 0, 1., 2., 5., 6.2],
                   [1, 1, 7.1, 5.1, 'well1', 'skin', -1, 0, 0, 0, 0.5, 2., 5., 6.2],
 [3, 3, 9.1, 3.7, 'well2', 'skin', -1, 0, 0, 0, 1., 2., 5., 4.1]], 
             columns=['i', 'j', 'ztop', 'zbotm', 'wellid', 'losstype', 'pumploc', 'qlimit', 'ppflag', 'pumpcap', 
                    'rw', 'rskin', 'kskin', 'zpump'])
node_data
    
    Out[3]:
In [4]:
    
node_data = node_data.to_records()
node_data
    
    Out[4]:
In [5]:
    
stress_period_data = pd.DataFrame([[0, 'well1', 0],
                          [1, 'well1', 100.0],
                          [0, 'well2', 0],
                          [1, 'well2', 1000.]], columns=['per', 'wellid', 'qdes'])
stress_period_data
    
    Out[5]:
In [6]:
    
pers = stress_period_data.groupby('per')
stress_period_data = {i: pers.get_group(i).to_records() for i in [0, 1]}
stress_period_data
    
    Out[6]:
In [7]:
    
mnw2 = flopy.modflow.ModflowMnw2(model=m, mnwmax=2,
                 node_data=node_data, 
                 stress_period_data=stress_period_data, 
                 itmp=[2, 2, -1], # reuse second per pumping for last stress period
                 )
    
In [8]:
    
# "nodtot" is computed automatically
mnw2.nodtot
    
    Out[8]:
In [9]:
    
pd.DataFrame(mnw2.node_data)
    
    Out[9]:
In [10]:
    
pd.DataFrame(mnw2.stress_period_data[0])
    
    Out[10]:
In [11]:
    
pd.DataFrame(mnw2.stress_period_data[1])
    
    Out[11]:
In [12]:
    
tmp = flopy.modflow.ModflowMnw2(model=m,
                 itmp=[1, 1, -1], # reuse second per pumping for last stress period
                 )
    
    
In [13]:
    
node_data = tmp.get_empty_node_data(3)
node_data
    
    Out[13]:
at the base of the flopy mnw2 module is the Mnw object class, which describes a single multi-node well. A list or dict of Mnw objects can be used to build a package (using the example above):
flopy.modflow.ModflowMnw2(model=m, mnwmax=2,
                 mnw=<dict or list of Mnw objects>,
                 itmp=[1, 1, -1], # reuse second per pumping for last stress period
                 )
or if node_data and stress_period_data are supplied, the Mnw objects are created on initialization of the ModflowMnw2 class instance, and assigned to the .mnw attribute, as items in a dictionary keyed by wellid.
In [14]:
    
mnw2.mnw
    
    Out[14]:
In [15]:
    
mnw2.mnw['well1'].__dict__
    
    Out[15]:
In [16]:
    
pd.DataFrame(mnw2.mnw['well1'].node_data)
    
    Out[16]:
In [17]:
    
pd.DataFrame(mnw2.mnw['well2'].stress_period_data)
    
    Out[17]:
In [18]:
    
mnw2fromobj = flopy.modflow.ModflowMnw2(model=m, mnwmax=2,
                 mnw=mnw2.mnw,
                 itmp=[2, 2, -1], # reuse second per pumping for last stress period
                 )
    
    
In [19]:
    
pd.DataFrame(mnw2fromobj.node_data)
    
    Out[19]:
In [20]:
    
pd.DataFrame(mnw2fromobj.stress_period_data[0])
    
    Out[20]:
In [21]:
    
pd.DataFrame(mnw2fromobj.stress_period_data[1])
    
    Out[21]:
node_data and stress_period_data tables attached to the ModflowMnw2 package class are definitivemnw2.write_file()), the Mnw objects are regenerated from the tables. This setting is controlled by the default argument use_tables=True. To write the package file using the Mnw objects (ignoring the tables), use mnw2.write_file(use_tables=False). 
In [22]:
    
per1 = flopy.modflow.ModflowMnw2.get_empty_stress_period_data(itmp=2)
per1
    
    Out[22]:
In [23]:
    
mnw2.write_file(os.path.join('temp/test.mnw2'))
    
In [24]:
    
junk = [print(l.strip('\n')) for l in open('temp/test.mnw2').readlines()]
    
    
In [25]:
    
path = os.path.join('..', '..', 'examples', 'data', 'mnw2_examples')
cpth = os.path.join('..', '..', 'autotest', 'temp')
m = flopy.modflow.Modflow('MNW2-Fig28', model_ws=cpth)
dis = flopy.modflow.ModflowDis.load(os.path.join(path, 'MNW2-Fig28.dis'), m)
    
In [26]:
    
m.get_package_list()
    
    Out[26]:
In [27]:
    
mnw2pth = os.path.join(path, 'MNW2-Fig28.mnw2')
mnw2 = flopy.modflow.ModflowMnw2.load(mnw2pth, m)
    
In [28]:
    
pd.DataFrame(mnw2.node_data)
    
    Out[28]:
In [29]:
    
pd.DataFrame(mnw2.stress_period_data[0])
    
    Out[29]:
In [30]:
    
mnw2.mnw
    
    Out[30]:
In [31]:
    
pd.DataFrame(mnw2.mnw['Well-A'].stress_period_data)
    
    Out[31]:
In [32]:
    
path = os.path.join('..', '..', 'examples', 'data', 'mnw2_examples')
cpth = os.path.join('temp')
m = flopy.modflow.Modflow('br', model_ws=cpth)
mnw2 = flopy.modflow.ModflowMnw2.load(path + '/BadRiver_cal.mnw2', m)
    
In [33]:
    
df = pd.DataFrame(mnw2.node_data)
df.loc[:, df.sum(axis=0) != 0]
    
    Out[33]: