How to use the flopy.modflow function in flopy

To help you get started, we’ve selected a few flopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jtwhite79 / pyemu / tests / utils_tests.py View on Github external
def mflist_budget_test():
    import pyemu
    import os
    try:
        import flopy
    except:
        print("no flopy...")
        return
    model_ws = os.path.join("..","examples","Freyberg_transient")
    ml = flopy.modflow.Modflow.load("freyberg.nam",model_ws=model_ws,check=False)
    list_filename = os.path.join(model_ws,"freyberg.list")
    assert os.path.exists(list_filename)
    pyemu.gw_utils.setup_mflist_budget_obs(list_filename,start_datetime=ml.start_datetime)
github modflowpy / flopy / autotest / t068_test_ssm.py View on Github external
# creating MODFLOW model
    
    model_ws = os.path.join('.', 'temp', 't068a')
    modelname = 'model_mf'
    
    mf = flopy.modflow.Modflow(modelname, model_ws=model_ws,
                               exe_name=mf_exe_name)
    dis = flopy.modflow.ModflowDis(mf, nlay=nlay, nrow=nrow, ncol=ncol, 
                                   perlen=perlen, nper=nper, botm=botm, top=top, 
                                   steady=False)
    
    bas = flopy.modflow.ModflowBas(mf, ibound=ibound, strt=top)
    lpf = flopy.modflow.ModflowLpf(mf, hk=100, vka=100, ss=0.00001, sy=0.1)
    oc = flopy.modflow.ModflowOc(mf)
    pcg = flopy.modflow.ModflowPcg(mf)
    lmt = flopy.modflow.ModflowLmt(mf)
    
    # recharge
    rchrate = {}
    rchrate[0] = 0.0
    rchrate[5] = 0.001
    rchrate[6] = 0.0
    
    rch = flopy.modflow.ModflowRch(mf, rech=rchrate, nrchop=3)
    
    # define itype
    itype = flopy.mt3d.Mt3dSsm.itype_dict()
    ssm_data = {}
    
    # Now for the point of this test: Enter SSM data sometime
    # after the first stress period (this was crashing flopy
    # version 3.2.13
github modflowpy / flopy / autotest / t068_test_ssm.py View on Github external
perlen=perlen, nper=nper, botm=botm, top=top, 
                                   steady=False)
    
    bas = flopy.modflow.ModflowBas(mf, ibound=ibound, strt=top)
    lpf = flopy.modflow.ModflowLpf(mf, hk=100, vka=100, ss=0.00001, sy=0.1)
    oc = flopy.modflow.ModflowOc(mf)
    pcg = flopy.modflow.ModflowPcg(mf)
    lmt = flopy.modflow.ModflowLmt(mf)
    
    # recharge
    rchrate = {}
    rchrate[0] = 0.0
    rchrate[5] = 0.001
    rchrate[6] = 0.0
    
    rch = flopy.modflow.ModflowRch(mf, rech=rchrate, nrchop=3)
    
    # define itype
    itype = flopy.mt3d.Mt3dSsm.itype_dict()
    ssm_data = {}
    
    # Now for the point of this test: Enter SSM data sometime
    # after the first stress period (this was crashing flopy
    # version 3.2.13
    ghb_data = {}
    ssm_data[2] = [(nlay - 1, 4, 4, 1.0, itype['GHB'], 1.0, 100.0)]
    ghb_data[2] = [(nlay - 1, 4, 4, 0.1, 1.5)]
    ghb_data[5] = [(nlay - 1, 4, 4, 0.25, 1.5)]
    ssm_data[5] = [(nlay - 1, 4, 4, 0.5, itype['GHB'], 0.5, 200.0)]
    
    for k in range(nlay):
        for i in range(nrow):
github modflowpy / flopy / examples / Testing / test_SFR.py View on Github external
def test_sfr(mfnam, sfrfile, model_ws, outfolder='written_sfr'):

    m = flopy.modflow.Modflow.load(mfnam, model_ws=model_ws, verbose=True)
    sfr = m.get_package('SFR2')

    if not os.path.exists(outfolder):
        os.makedirs(outfolder)
    outpath = os.path.join(outfolder, sfrfile)
    sfr.write(outpath)

    sfr2 = flopy.modflow.ModflowSfr2.load(outpath, m)

    assert np.all(sfr2.reach_data == sfr.reach_data)
    assert np.all(sfr2.dataset_5 == sfr.dataset_5)
    for k, v in sfr2.segment_data.items():
        assert np.all(v == sfr.segment_data[k])
    for k, v in sfr2.channel_flow_data.items():
        assert np.all(v == sfr.channel_flow_data[k])
    for k, v in sfr2.channel_geometry_data.items():
        assert np.all(v == sfr.channel_geometry_data[k])

    return m, sfr
github modflowpy / flopy / autotest / t040_test_subwt.py View on Github external
nstp = [1, 60, 60]
    flopy.modflow.ModflowDis(ml, nlay=4, nrow=20, ncol=15, delr=2000.0,
                             delc=2000.0,
                             nper=3, steady=[True, False, False]
                             , perlen=perlen, nstp=nstp,
                             top=150.0, botm=[50, -100, -150.0, -350.0])

    flopy.modflow.ModflowLpf(ml, laytyp=[1, 0, 0, 0], hk=[4, 4, 0.01, 4]
                             , vka=[0.4, 0.4, 0.01, 0.4],
                             sy=0.3, ss=1.0e-6)

    # temp_ib = np.ones((ml.nrow,ml.ncol),dtype=np.int)
    # np.savetxt("temp_ib.dat",temp_ib,fmt="%1d")
    ibound = np.loadtxt(ibound_path)
    ibound[ibound == 5] = -1
    flopy.modflow.ModflowBas(ml, ibound=ibound, strt=100.0)

    sp1_wells = pd.DataFrame(data=np.argwhere(ibound == 2), columns=['i', 'j'])
    sp1_wells.loc[:, "k"] = 0
    sp1_wells.loc[:, "flux"] = 2200.0
    sp1_wells = sp1_wells.loc[:, ["k", "i", "j", "flux"]].values.tolist()

    sp2_wells = sp1_wells.copy()
    sp2_wells.append([1, 8, 9, -72000.0])
    sp2_wells.append([3, 11, 6, -72000.0])

    flopy.modflow.ModflowWel(ml, stress_period_data=
                            {0: sp1_wells, 1: sp2_wells, 2: sp1_wells})

    flopy.modflow.ModflowSwt(ml,iswtoc=1,nsystm=4,sgs=2.0,sgm=1.7,
                               lnwt=[0,1,2,3],thick=[45,70,50,90],icrcc=0,
                               cr=0.01,cc=0.25,istpcs=1,pcsoff=15.0,
github modflowpy / flopy / autotest / t060_test_lkt.py View on Github external
[0.0, 0.0, 0.0, 0.0],
                     [0.0, 0.0, 0.0, 0.0]]}
    
    lak = flopy.modflow.ModflowLak(mf, nlakes=nlakes, ipakcb=ipakcb,
                                   theta=theta,
                                    nssitr=nssitr, sscncr=sscncr,
                                   surfdep=surfdep,
                                    stages=stages, stage_range=stage_range,
                                   lakarr=lkarr,
                                    bdlknc=bdlknc, flux_data=flux_data,
                                   unit_number=16)
    
    ## Instantiate linkage with mass transport routing (LMT) package
    # for MODFLOW-NWT (generates linker file)
    
    lmt = flopy.modflow.ModflowLmt(mf, output_file_name='lkttest.ftl',
                                   output_file_header='extended',
                                   output_file_format='formatted',
                                   package_flows = ['lak'])
    
    
    ## Now work on MT3D-USGS file creation
    
    mt = flopy.mt3d.Mt3dms(modflowmodel=mf, modelname=modelname,
                           model_ws=modelpth,
                           version='mt3d-usgs', namefile_ext='mtnam',
                           exe_name=mtexe,
                           ftlfilename='lkttest.ftl', ftlfree=True)
    
    ## Instantiate basic transport (BTN) package for MT3D-USGS
    
    ncomp   =     2
github modflowpy / flopy / examples / Tutorials / Tutorial01 / tutorial01.py View on Github external
# Create the discretization object
dis = flopy.modflow.ModflowDis(mf, nlay, nrow, ncol, delr=delr, delc=delc,
                               top=ztop, botm=botm[1:])

# Variables for the BAS package
ibound = np.ones((nlay, nrow, ncol), dtype=np.int32)
ibound[:, :, 0] = -1
ibound[:, :, -1] = -1
strt = np.ones((nlay, nrow, ncol), dtype=np.float32)
strt[:, :, 0] = 10.
strt[:, :, -1] = 0.
bas = flopy.modflow.ModflowBas(mf, ibound=ibound, strt=strt)

# Add LPF package to the MODFLOW model
lpf = flopy.modflow.ModflowLpf(mf, hk=10., vka=10., ipakcb=53)

# Add OC package to the MODFLOW model
spd = {(0, 0): ['print head', 'print budget', 'save head', 'save budget']}
oc = flopy.modflow.ModflowOc(mf, stress_period_data=spd, compact=True)

# Add PCG package to the MODFLOW model
pcg = flopy.modflow.ModflowPcg(mf)

# Write the MODFLOW model input files
mf.write_input()

# Run the MODFLOW model
success, buff = mf.run_model()

# Post process the results
import matplotlib.pyplot as plt
github modflowpy / flopy / examples / Testing / flopy3_2L_CS.py View on Github external
version = 'mf2005'
exe_name = 'mf2005'
if platform.system() == 'Windows':
    exe_name = 'mf2005.exe'
mfexe = exe_name

#Set the paths
loadpth = os.path.join('..', 'Notebooks', 'data')
modelpth = os.path.join('data')
modelname = 'swiex4_s1'

#make sure modelpth directory exists
if not os.path.exists(modelpth):
    os.makedirs(modelpth)

ml = flopy.modflow.Modflow.load(modelname, model_ws=loadpth, exe_name=exe_name, version=version, verbose=True)
ml.change_model_ws(new_pth=modelpth)
ml.set_name('woohoo')
ml.write_input()
success, buff = ml.run_model()
success = True

if not success:
    print 'Something bad happened.'
files = [modelname+'.hds', modelname+'.zta']
for f in files:
    if os.path.isfile(os.path.join(modelpth, f)):
        msg = 'Output file located: {}'.format(f)
        print (msg)
    else:
        errmsg = 'Error. Output file cannot be found: {}'.format(f)
        print (errmsg)
github modflowpy / flopy / flopy / modflow / mf.py View on Github external
"gmg": flopy.modflow.ModflowGmg,
            "lmt6": flopy.modflow.ModflowLmt,
            "lmt7": flopy.modflow.ModflowLmt,
            "riv": flopy.modflow.ModflowRiv,
            "str": flopy.modflow.ModflowStr,
            "swi2": flopy.modflow.ModflowSwi2,
            "pcg": flopy.modflow.ModflowPcg,
            "pcgn": flopy.modflow.ModflowPcgn,
            "nwt": flopy.modflow.ModflowNwt,
            "pks": flopy.modflow.ModflowPks,
            "sms": flopy.modflow.ModflowSms,
            "sfr": flopy.modflow.ModflowSfr2,
            "lak": flopy.modflow.ModflowLak,
            "gage": flopy.modflow.ModflowGage,
            "sip": flopy.modflow.ModflowSip,
            "sor": flopy.modflow.ModflowSor,
            "de4": flopy.modflow.ModflowDe4,
            "oc": flopy.modflow.ModflowOc,
            "uzf": flopy.modflow.ModflowUzf1,
            "upw": flopy.modflow.ModflowUpw,
            "sub": flopy.modflow.ModflowSub,
            "swt": flopy.modflow.ModflowSwt,
            "hyd": flopy.modflow.ModflowHyd,
            "hob": flopy.modflow.ModflowHob,
            "chob": flopy.modflow.ModflowFlwob,
            "gbob": flopy.modflow.ModflowFlwob,
            "drob": flopy.modflow.ModflowFlwob,
            "rvob": flopy.modflow.ModflowFlwob,
            "vdf": flopy.seawat.SeawatVdf,
            "vsc": flopy.seawat.SeawatVsc
        }
        return