Beispiel #1
0
def modflow_to_vtk(input_folder,
                   mf_namfile,
                   output_folder,
                   hds_file=None,
                   cbc_file=None):

    # load a modflow model
    mf = flopy.modflow.Modflow.load(mf_namfile, model_ws=input_folder)

    # Choose an output folder to store the outputs
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    # Export the modflow model to vtk
    mf.export(
        output_folder, fmt='vtk'
    )  # modflow output, uses modified export_package function in vtk.py

    # Optional: export hds file if specified
    if hds_file is not None:
        hf = os.path.join(input_folder, hds_file)
        cbc = os.path.join(input_folder, cbc_file)
        fvtk.export_heads(mf,
                          hf,
                          cbc,
                          output_folder,
                          binary=True,
                          nanval=-999.99,
                          smooth=True,
                          true2d=False)
Beispiel #2
0
def paraview_export():
    pass

    """
    Export to paraview
    """
    pv_folder = os.path.join("../" , '11_pv_test')
    if not os.path.exists(pv_folder):
        os.mkdir(pv_folder)
    
    
    gwf.dis.top.export(pv_folder, fmt='vtk')
    
    # 3D Array export
    # export model bottoms
    gwf.dis.botm.export(pv_folder, fmt='vtk')
    
    # transient 2d array
    # export recharge
    gwf.rch.export(pv_folder, fmt='vtk')#doesn't work
    # gwf.rch.rech.export(pv_folder, fmt='vtk')#doesn't work
    # 3D Array export
    # hk export, with points
    gwf.npf.k.export(pv_folder, smooth=True, fmt='vtk', name='HK', point_scalars=True)
    
    # npf export, with points
    gwf.npf.export(pv_folder, smooth=True, fmt='vtk', name='NPF', point_scalars=True)
    
    # DRN export, with points
    gwf.drn_gal.export(pv_folder, fmt='vtk', name='drn_gal_w', point_scalars=False)#doesn't work
    # fp.export.utils.package_export(pv_folder, gwf.drn_gal,fmt='vtk')
    
    # 3D Array export
    # hk export, with points
    gwf.sto.export(pv_folder, smooth=True, fmt='vtk', name='STO', point_scalars=True)
    
    # ghb export, with points
    gwf.ghb_0.export(pv_folder, smooth=True, fmt='vtk', name='ghb_0', point_scalars=True)#doesn't work
    
    # chd export, with points
    gwf.chd.export(pv_folder, smooth=True, fmt='vtk', name='CHD', point_scalars=True)#doesn't work
    
    # model export
    gwf.export(pv_folder, fmt='vtk', binary=True) #works for dis, ic, npf, sto
    
    # head export
    
    heads_output_folder = os.path.join(pv_folder, 'heads_output_test')
    vtk.export_heads(gwf, head_file, heads_output_folder, binary=True, nanval=-1e30)#doesn't work beru well,pvd error, many values nan
    
    
    #with points
    vtk.export_heads(gwf, head_file,
                      heads_output_folder,
                      kstpkper=[(0,0), (0, 49), (0, 99), (0, 999)],#review time steps
                      point_scalars=True, nanval=1e30)#doesn't work many values nan
Beispiel #3
0
def test_vtk_binary_head_export():
    # test mf 2005 freyberg
    mpth = os.path.join('..', 'examples', 'data',
                        'freyberg_multilayer_transient')
    namfile = 'freyberg.nam'
    hdsfile = os.path.join(mpth, 'freyberg.hds')
    m = flopy.modflow.Modflow.load(namfile, model_ws=mpth, verbose=False,
                                   load_only=['dis', 'bas6'])
    filenametocheck = 'freyberg_head_KPER455_KSTP1.vtu'

    # export and check
    otfolder = os.path.join(cpth, 'heads_test')
    vtk.export_heads(m, hdsfile, otfolder, nanval=-999.99, kstpkper=[(0, 0),
                                                                     (0, 199),
                                                                     (0, 354),
                                                                     (0, 454),
                                                                     (0,
                                                                      1089)])
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes = os.path.getsize(filetocheck)
    # assert(totalbytes==993215)
    nlines = count_lines_in_file(filetocheck)
    assert(nlines==8486)

    # with point scalars
    otfolder = os.path.join(cpth, 'heads_test_1')
    vtk.export_heads(m, hdsfile, otfolder,
                     kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0,
                                                                      1089)],
                     point_scalars=True, nanval=-999.99)
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes1 = os.path.getsize(filetocheck)
    # assert(totalbytes1==1331858)
    nlines1 = count_lines_in_file(filetocheck)
    assert(nlines1==10605)

    # with smoothing
    otfolder = os.path.join(cpth, 'heads_test_2')
    vtk.export_heads(m, hdsfile, otfolder,
                     kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0,
                                                                      1089)],
                     smooth=True, nanval=-999.99)
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes2 = os.path.getsize(filetocheck)
    # assert(totalbytes2==993077)
    nlines2 = count_lines_in_file(filetocheck)
    assert(nlines2==8486)

    # with smoothing and binary
    otfolder = os.path.join(cpth, 'heads_test_3')
    vtk.export_heads(m, hdsfile, otfolder,
                     kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0,
                                                                      1089)],
                     smooth=True, binary=True, nanval=-999.99)
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes3 = os.path.getsize(filetocheck)
    # assert(totalbytes3==493853)
    # nlines3 = count_lines_in_file(filetocheck, binary=True)
    # assert(nlines3==1781)
    assert(os.path.exists(filetocheck))

    # with smoothing and binary, single time
    otfolder = os.path.join(cpth, 'heads_test_4')
    vtk.export_heads(m, hdsfile, otfolder, kstpkper=(0, 0),
                     point_scalars=False, smooth=True, binary=True,
                     nanval=-999.99)
    filetocheck = os.path.join(otfolder, 'freyberg_head_KPER1_KSTP1.vtu')
    # totalbytes4 = os.path.getsize(filetocheck)
    # assert(totalbytes4==493853)
    # nlines4 = count_lines_in_file(filetocheck, binary=True)
    # assert(nlines4==1787)
    assert(os.path.exists(filetocheck))

    return
Beispiel #4
0
def test_vtk_binary_head_export():
    # test mf 2005 freyberg
    mpth = os.path.join("..", "examples", "data",
                        "freyberg_multilayer_transient")
    namfile = "freyberg.nam"
    hdsfile = os.path.join(mpth, "freyberg.hds")
    m = flopy.modflow.Modflow.load(namfile,
                                   model_ws=mpth,
                                   verbose=False,
                                   load_only=["dis", "bas6"])
    filenametocheck = "freyberg_head_KPER455_KSTP1.vtu"

    # export and check
    otfolder = os.path.join(cpth, "heads_test")
    vtk.export_heads(
        m,
        hdsfile,
        otfolder,
        nanval=-999.99,
        kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0, 1089)],
    )
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes = os.path.getsize(filetocheck)
    # assert(totalbytes==993215)
    nlines = count_lines_in_file(filetocheck)
    assert nlines == 8486

    # with point scalars
    otfolder = os.path.join(cpth, "heads_test_1")
    vtk.export_heads(
        m,
        hdsfile,
        otfolder,
        kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0, 1089)],
        point_scalars=True,
        nanval=-999.99,
    )
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes1 = os.path.getsize(filetocheck)
    # assert(totalbytes1==1331858)
    nlines1 = count_lines_in_file(filetocheck)
    assert nlines1 == 10605

    # with smoothing
    otfolder = os.path.join(cpth, "heads_test_2")
    vtk.export_heads(
        m,
        hdsfile,
        otfolder,
        kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0, 1089)],
        smooth=True,
        nanval=-999.99,
    )
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes2 = os.path.getsize(filetocheck)
    # assert(totalbytes2==993077)
    nlines2 = count_lines_in_file(filetocheck)
    assert nlines2 == 8486

    # with smoothing and binary
    otfolder = os.path.join(cpth, "heads_test_3")
    vtk.export_heads(
        m,
        hdsfile,
        otfolder,
        kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454), (0, 1089)],
        smooth=True,
        binary=True,
        nanval=-999.99,
    )
    filetocheck = os.path.join(otfolder, filenametocheck)
    # totalbytes3 = os.path.getsize(filetocheck)
    # assert(totalbytes3==493853)
    # nlines3 = count_lines_in_file(filetocheck, binary=True)
    # assert(nlines3==1781)
    assert os.path.exists(filetocheck)

    # with smoothing and binary, single time
    otfolder = os.path.join(cpth, "heads_test_4")
    vtk.export_heads(
        m,
        hdsfile,
        otfolder,
        kstpkper=(0, 0),
        point_scalars=False,
        smooth=True,
        binary=True,
        nanval=-999.99,
    )
    filetocheck = os.path.join(otfolder, "freyberg_head_KPER1_KSTP1.vtu")
    # totalbytes4 = os.path.getsize(filetocheck)
    # assert(totalbytes4==493853)
    # nlines4 = count_lines_in_file(filetocheck, binary=True)
    # assert(nlines4==1787)
    assert os.path.exists(filetocheck)

    return
Beispiel #5
0
def test_vtk_binary_head_export():
    """test vet export of heads"""

    freyberg_pth = os.path.join('..', 'examples', 'data',
                                'freyberg_multilayer_transient')

    hdsfile = os.path.join(freyberg_pth, 'freyberg.hds')

    m = flopy.modflow.Modflow.load('freyberg.nam',
                                   model_ws=freyberg_pth,
                                   verbose=False)
    otfolder = os.path.join(cpth, 'heads_test')

    vtk.export_heads(m,
                     hdsfile,
                     otfolder,
                     nanval=-999.99,
                     kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454),
                               (0, 1089)])
    # test with points
    otfolder = os.path.join(cpth, 'heads_test_1')
    vtk.export_heads(m,
                     hdsfile,
                     otfolder,
                     kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454),
                               (0, 1089)],
                     point_scalars=True,
                     nanval=-999.99)

    # test vtk export heads with smoothing and no point scalars
    otfolder = os.path.join(cpth, 'heads_test_2')
    vtk.export_heads(m,
                     hdsfile,
                     otfolder,
                     kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454),
                               (0, 1089)],
                     point_scalars=False,
                     smooth=True,
                     nanval=-999.99)

    # test binary output
    otfolder = os.path.join(cpth, 'heads_test_3')
    vtk.export_heads(m,
                     hdsfile,
                     otfolder,
                     kstpkper=[(0, 0), (0, 199), (0, 354), (0, 454),
                               (0, 1089)],
                     point_scalars=False,
                     smooth=True,
                     binary=True,
                     nanval=-999.99)

    otfolder = os.path.join(cpth, 'heads_test_4')
    vtk.export_heads(m,
                     hdsfile,
                     otfolder,
                     kstpkper=(0, 0),
                     point_scalars=False,
                     smooth=True,
                     binary=True,
                     nanval=-999.99)

    return