Read and write model files


In [1]:
import os
import numpy as np
import flopy

First, we need to create a model for test


In [4]:
base_dir = "base_model_dir"
nlay, nrow, ncol = 1, 1, 10
#ml = flopy.modflow.Modflow(modelname="base", model_ws=base_dir,
#                           external_path="ref")
ml = flopy.modflow.Modflow(modelname="base", model_ws=base_dir,external_path="ref")
dis = flopy.modflow.ModflowDis(ml, nrow=1, ncol=10,
                               nlay=nlay, nper=2, perlen=[1,1],
                               steady=[True,True])
bas = flopy.modflow.ModflowBas(ml, ibound=1)
hk = np.zeros((nlay, nrow, ncol))+2.5
#the full relative path to the external hk array
#np.savetxt(os.path.join(base_dir,"hk.ref"),hk.flatten(),fmt="%15.6E",delimiter='')

# but we have to pass on the filename as the namefile sees it
lpf = flopy.modflow.ModflowLpf(ml, hk=hk,vka=hk)

well_data = {}
well_data[0] = [0, 0, 9, 0.5]
well_data[1] = [0, 0, 9, 1.0]
wel = flopy.modflow.ModflowWel(ml, stress_period_data=well_data)

ghb_data = {}
ghb_data[0] = [0, 0, 0, 0.5, 1000.0]
ghb = flopy.modflow.ModflowGhb(ml, stress_period_data=ghb_data)
print ghb.stress_period_data.data
ml.write_input()


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-4-b85397f17e46> in <module>()
      3 #ml = flopy.modflow.Modflow(modelname="base", model_ws=base_dir,
      4 #                           external_path="ref")
----> 5 ml = flopy.modflow.Modflow(modelname="base", model_ws=base_dir,external_path="ref")
      6 dis = flopy.modflow.ModflowDis(ml, nrow=1, ncol=10,
      7                                nlay=nlay, nper=2, perlen=[1,1],

/Users/jwhite/anaconda/lib/python2.7/site-packages/flopy/modflow/mf.pyc in __init__(self, modelname, namefile_ext, version, exe_name, listunit, model_ws, external_path, verbose, load, silent)
    119         if external_path is not None:
    120             assert model_ws == '.', "ERROR: external cannot be used " +\
--> 121                 "with model_ws"
    122 
    123             #external_path = os.path.join(model_ws, external_path)

AssertionError: ERROR: external cannot be used with model_ws

In [2]:

Now, lets load the base model


In [3]:
ml_loaded = flopy.modflow.Modflow.load("base.nam",model_ws=base_dir)


Creating new model with name: base
--------------------------------------------------

   DIS  package load...success
   LIST package load...skipped
   BAS6 package load...success
   LPF  package load...success
   WEL  package load...success
   GHB  package load...success


   The following 5 packages were successfully loaded.
      base.dis
      base.bas
      base.lpf
      base.wel
      base.ghb
   The following 1 packages were not loaded.
      base.list



In [ ]: