def test_vtk_export_true2d_nonregxy(): import flopy.utils.binaryfile as bf from flopy.utils import postprocessing as pp output_dir = os.path.join(cpth, 'true2d_nonregxy') cbc_unit_nb = 53 # model with one layer, non-regular grid in x and y name = 'nonregxy' m = flopy.modflow.Modflow(name, model_ws=output_dir, exe_name='mf2005') nlay, nrow, ncol = 1, 10, 10 delr = np.concatenate((np.ones((5,)), 2.*np.ones((5,)))) delc = delr top = 50. botm = 0. dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, delr=delr, delc=delc, top=top, botm=botm) ibound = np.ones((nlay, nrow, ncol), dtype=np.int32) ibound[:, :, 0] = -1 ibound[:, :, -1] = -1 strt = np.linspace(1., 0., ncol).reshape(1, 1, ncol) strt = strt * np.ones((nlay, nrow, ncol)) bas = flopy.modflow.ModflowBas(m, ibound=ibound, strt=strt) lpf = flopy.modflow.ModflowLpf(m, hk=1., vka=1., ipakcb=cbc_unit_nb) spd = {(0, 0): ['print head', 'print budget', 'save head', 'save budget']} oc = flopy.modflow.ModflowOc(m, stress_period_data=spd, compact=True) pcg = flopy.modflow.ModflowPcg(m) m.write_input() m.run_model(silent=True) # export and check head with point scalar hdsfile = os.path.join(output_dir, name + '.hds') hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array(m, head, output_dir, name + '_head', point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + '_head.vtr') # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==4997) nlines = count_lines_in_file(filetocheck) assert(nlines==59) # export and check specific discharge given at vertices cbcfile = os.path.join(output_dir, name + '.cbc') q = pp.get_specific_discharge(m, cbcfile, position='vertices') vtk.export_vector(m, q, output_dir, name + '_q', point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + '_q.vtr') # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==5772) nlines1 = count_lines_in_file(filetocheck) assert(nlines1==54) return
def test_vtk_vector(): from flopy.utils import postprocessing as pp # test mf 2005 freyberg mpth = os.path.join('..', 'examples', 'data', 'freyberg_multilayer_transient') namfile = 'freyberg.nam' cbcfile = os.path.join(mpth, 'freyberg.cbc') hdsfile = os.path.join(mpth, 'freyberg.hds') m = flopy.modflow.Modflow.load(namfile, model_ws=mpth, verbose=False, load_only=['dis', 'bas6', 'upw']) q = pp.get_specific_discharge(m, cbcfile=cbcfile) output_dir = os.path.join(cpth, 'freyberg_vector') filenametocheck = 'discharge.vtu' # export and check with point scalar vtk.export_vector(m, q, output_dir, 'discharge', point_scalars=True) filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==2247857) nlines = count_lines_in_file(filetocheck) assert(nlines==10605) # with point scalars and binary vtk.export_vector(m, q, output_dir + '_bin', 'discharge', point_scalars=True, binary=True) filetocheck = os.path.join(output_dir + '_bin', filenametocheck) # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==942413) # nlines1 = count_lines_in_file(filetocheck, binary=True) # assert(nlines1==3824) assert(os.path.exists(filetocheck)) # with values directly given at vertices q = pp.get_specific_discharge(m, cbcfile=cbcfile, hdsfile=hdsfile, position='vertices') nancount = np.count_nonzero(np.isnan(q[0])) assert(nancount==308) overall = np.nansum(q[0]) + np.nansum(q[1]) + np.nansum(q[2]) assert np.allclose(overall, -15.467904755216372) output_dir = os.path.join(cpth, 'freyberg_vector') filenametocheck = 'discharge_verts.vtu' vtk.export_vector(m, q, output_dir, 'discharge_verts') filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==1990047) nlines2 = count_lines_in_file(filetocheck) assert(nlines2==10598) # with values directly given at vertices and binary vtk.export_vector(m, q, output_dir + '_bin', 'discharge_verts', binary=True) filetocheck = os.path.join(output_dir + '_bin', filenametocheck) # totalbytes3 = os.path.getsize(filetocheck) # assert(totalbytes3==891486) # nlines3 = count_lines_in_file(filetocheck, binary=True) # assert(nlines3==3012) assert(os.path.exists(filetocheck)) return
def test_vtk_export_true2d_regular(): mpath = os.path.join('..', 'examples', 'data', 'mf2005_test') output_dir = os.path.join(cpth, 'true2d_regular') # test mf 2005 test1ss, which has one layer with non-constant elevations namfile = 'test1ss.nam' m = flopy.modflow.Modflow.load(namfile, model_ws=mpath, verbose=False, load_only=['dis', 'bas6']) # export and check (.vti, with point scalars) m.dis.botm.export(output_dir, name='test1ss_botm', fmt='vtk', point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, 'test1ss_botm.vti') # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==3371) nlines = count_lines_in_file(filetocheck) assert(nlines==32) # vector (.vti, with point scalars) vect = (m.dis.botm.array, m.dis.botm.array) vtk.export_vector(m, vect, output_dir, 'test1ss_botm_vect', point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, 'test1ss_botm_vect.vti') # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==6022) nlines1 = count_lines_in_file(filetocheck) assert(nlines1==32) # vector directly at vertices (.vti) vect = [m.dis.botm.array, m.dis.botm.array] for i, vcomp in enumerate(vect): vect[i] = m.modelgrid.array_at_verts(vcomp) vtk.export_vector(m, vect, output_dir, 'test1ss_botm_vectv', true2d=True) filetocheck = os.path.join(output_dir, 'test1ss_botm_vectv.vti') # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==3496) nlines2 = count_lines_in_file(filetocheck) assert(nlines2==27) # export and check (force .vtu, with point scalars) m.dis.botm.export(output_dir, name='test1ss_botm', fmt='vtk', point_scalars=True, vtk_grid_type='UnstructuredGrid', true2d=True) filetocheck = os.path.join(output_dir, 'test1ss_botm.vtu') # totalbytes3 = os.path.getsize(filetocheck) # assert(totalbytes3==23827) nlines3 = count_lines_in_file(filetocheck) assert(nlines3==608) # test mf 2005 swiex3, which has one row namfile = 'swiex3.nam' m = flopy.modflow.Modflow.load(namfile, model_ws=mpath, verbose=False, load_only=['dis', 'bas6']) # export and check (.vtr) m.dis.botm.export(output_dir, name='swiex3_botm', fmt='vtk', true2d=True) filetocheck = os.path.join(output_dir, 'swiex3_botm.vtr') # totalbytes4 = os.path.getsize(filetocheck) # assert(totalbytes4==8022) nlines4 = count_lines_in_file(filetocheck) assert(nlines4==229) # export and check (force .vtu) m.dis.botm.export(output_dir, name='swiex3_botm', fmt='vtk', vtk_grid_type='UnstructuredGrid', true2d=True) filetocheck = os.path.join(output_dir, 'swiex3_botm.vtu') # totalbytes5 = os.path.getsize(filetocheck) # assert(totalbytes5==85446) nlines5 = count_lines_in_file(filetocheck) assert(nlines5==2426) return
def test_vtk_vti(): # create model with regular and equal grid spacing in x, y and z directions name = 'test_vti' m = flopy.modflow.Modflow(name) nlay, nrow, ncol = 2, 3, 4 delr = np.ones(ncol) delc = np.ones(nrow) top = 2. * np.ones((nrow, ncol)) botm1 = np.ones((1, nrow, ncol)) botm2 = np.zeros((1, nrow, ncol)) botm = np.concatenate((botm1, botm2)) dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, delr=delr, delc=delc, top=top, botm=botm) output_dir = os.path.join(cpth, m.name) filenametocheck = 'DIS.vti' # export and check dis.export(output_dir, fmt='vtk') filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==1075) nlines = count_lines_in_file(filetocheck) assert(nlines==21) # with point scalar dis.export(output_dir + '_points', fmt='vtk', point_scalars=True) filetocheck = os.path.join(output_dir + '_points', filenametocheck) # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==2474) nlines1 = count_lines_in_file(filetocheck) assert(nlines1==38) # with binary dis.export(output_dir + '_bin', fmt='vtk', binary=True) filetocheck = os.path.join(output_dir + '_bin', filenametocheck) # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==1144) # nlines2 = count_lines_in_file(filetocheck, binary=True) # assert(nlines2==18) assert(os.path.exists(filetocheck)) # force .vtr filenametocheck = 'DIS.vtr' dis.export(output_dir, fmt='vtk', vtk_grid_type='RectilinearGrid') filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes3 = os.path.getsize(filetocheck) # assert(totalbytes3==1606) nlines3 = count_lines_in_file(filetocheck) assert(nlines3==41) # force .vtu filenametocheck = 'DIS.vtu' dis.export(output_dir, fmt='vtk', vtk_grid_type='UnstructuredGrid') filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes4 = os.path.getsize(filetocheck) # assert(totalbytes4==5723) nlines4 = count_lines_in_file(filetocheck) assert(nlines4==129) # vector filenametocheck = 'vect.vti' ones_array = np.ones(m.modelgrid.shape) v = (ones_array, 2.*ones_array, 3.*ones_array) vtk.export_vector(m, v, output_dir, 'vect', point_scalars=True) filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes5 = os.path.getsize(filetocheck) # assert(totalbytes5==1578) nlines5 = count_lines_in_file(filetocheck) assert(nlines5==20) # vector with point scalars and binary vtk.export_vector(m, v, output_dir + '_bin', 'vect', point_scalars=True, binary=True) filetocheck = os.path.join(output_dir + '_bin', filenametocheck) # totalbytes6 = os.path.getsize(filetocheck) # assert(totalbytes6==2666) # nlines6 = count_lines_in_file(filetocheck, binary=True) # assert(nlines6==18) assert(os.path.exists(filetocheck)) return
def test_vtk_export_true2d_nonregyz(): import flopy.utils.binaryfile as bf from flopy.utils import postprocessing as pp output_dir = os.path.join(cpth, "true2d_nonregyz") cbc_unit_nb = 53 # model with one col, non-regular grid in y and stepwise z name = "nonregyz" m = flopy.modflow.Modflow(name, model_ws=output_dir, exe_name="mf2005") nlay, nrow, ncol = 2, 10, 1 delr = 1.0 delc = np.concatenate((2.0 * np.ones((5, )), np.ones((5, )))) top = np.linspace(3.0, 2.0, nrow).reshape((1, nrow, 1)) botm1 = np.linspace(2.5, 1.0, nrow).reshape((1, nrow, 1)) botm2 = np.linspace(0.5, 0.0, nrow).reshape((1, nrow, 1)) botm = np.concatenate((botm1, botm2)) dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, delr=delr, delc=delc, top=top, botm=botm) ibound = np.ones((nlay, nrow, ncol), dtype=np.int32) ibound[:, 0, :] = -1 ibound[:, -1, :] = -1 strt = np.linspace(1.0, 0.0, nrow).reshape(1, nrow, 1) strt = strt * np.ones((nlay, nrow, ncol)) bas = flopy.modflow.ModflowBas(m, ibound=ibound, strt=strt) lpf = flopy.modflow.ModflowLpf(m, hk=1.0, vka=1.0, ipakcb=cbc_unit_nb) spd = {(0, 0): ["print head", "print budget", "save head", "save budget"]} oc = flopy.modflow.ModflowOc(m, stress_period_data=spd, compact=True) pcg = flopy.modflow.ModflowPcg(m) m.write_input() m.run_model(silent=True) # export and check head hdsfile = os.path.join(output_dir, name + ".hds") hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array(m, head, output_dir, name + "_head", true2d=True) filetocheck = os.path.join(output_dir, name + "_head.vtu") # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==4217) nlines = count_lines_in_file(filetocheck) assert nlines == 105 # export and check head with point scalar hdsfile = os.path.join(output_dir, name + ".hds") hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array( m, head, output_dir, name + "_head_points", point_scalars=True, true2d=True, ) filetocheck = os.path.join(output_dir, name + "_head_points.vtu") # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==6155) nlines1 = count_lines_in_file(filetocheck) assert nlines1 == 129 # export and check specific discharge given at vertices cbcfile = os.path.join(output_dir, name + ".cbc") cbc = bf.CellBudgetFile(cbcfile) keys = ["FLOW FRONT FACE", "FLOW LOWER FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] vectors.insert(0, None) q = pp.get_specific_discharge(vectors, m, position="vertices") vtk.export_vector(m, q, output_dir, name + "_q", point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + "_q.vtu") # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==7032) nlines2 = count_lines_in_file(filetocheck) assert nlines2 == 123 return
def test_vtk_export_true2d_nonregxy(): import flopy.utils.binaryfile as bf from flopy.utils import postprocessing as pp output_dir = os.path.join(cpth, "true2d_nonregxy") cbc_unit_nb = 53 # model with one layer, non-regular grid in x and y name = "nonregxy" m = flopy.modflow.Modflow(name, model_ws=output_dir, exe_name="mf2005") nlay, nrow, ncol = 1, 10, 10 delr = np.concatenate((np.ones((5, )), 2.0 * np.ones((5, )))) delc = delr top = 50.0 botm = 0.0 dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, delr=delr, delc=delc, top=top, botm=botm) ibound = np.ones((nlay, nrow, ncol), dtype=np.int32) ibound[:, :, 0] = -1 ibound[:, :, -1] = -1 strt = np.linspace(1.0, 0.0, ncol).reshape(1, 1, ncol) strt = strt * np.ones((nlay, nrow, ncol)) bas = flopy.modflow.ModflowBas(m, ibound=ibound, strt=strt) lpf = flopy.modflow.ModflowLpf(m, hk=1.0, vka=1.0, ipakcb=cbc_unit_nb) spd = {(0, 0): ["print head", "print budget", "save head", "save budget"]} oc = flopy.modflow.ModflowOc(m, stress_period_data=spd, compact=True) pcg = flopy.modflow.ModflowPcg(m) m.write_input() m.run_model(silent=True) # export and check head with point scalar hdsfile = os.path.join(output_dir, name + ".hds") hds = bf.HeadFile(hdsfile) head = hds.get_data() vtk.export_array(m, head, output_dir, name + "_head", point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + "_head.vtr") # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==4997) nlines = count_lines_in_file(filetocheck) assert nlines == 59 # export and check specific discharge given at vertices cbcfile = os.path.join(output_dir, name + ".cbc") cbc = bf.CellBudgetFile(cbcfile) keys = ["FLOW RIGHT FACE", "FLOW FRONT FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] q = pp.get_specific_discharge(vectors, m, position="vertices") vtk.export_vector(m, q, output_dir, name + "_q", point_scalars=True, true2d=True) filetocheck = os.path.join(output_dir, name + "_q.vtr") # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==5772) nlines1 = count_lines_in_file(filetocheck) assert nlines1 == 54 return
def test_vtk_export_true2d_regular(): mpath = os.path.join("..", "examples", "data", "mf2005_test") output_dir = os.path.join(cpth, "true2d_regular") # test mf 2005 test1ss, which has one layer with non-constant elevations namfile = "test1ss.nam" m = flopy.modflow.Modflow.load(namfile, model_ws=mpath, verbose=False, load_only=["dis", "bas6"]) # export and check (.vti, with point scalars) m.dis.botm.export( output_dir, name="test1ss_botm", fmt="vtk", point_scalars=True, true2d=True, ) filetocheck = os.path.join(output_dir, "test1ss_botm.vti") # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==3371) nlines = count_lines_in_file(filetocheck) assert nlines == 32 # vector (.vti, with point scalars) vect = (m.dis.botm.array, m.dis.botm.array) vtk.export_vector( m, vect, output_dir, "test1ss_botm_vect", point_scalars=True, true2d=True, ) filetocheck = os.path.join(output_dir, "test1ss_botm_vect.vti") # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==6022) nlines1 = count_lines_in_file(filetocheck) assert nlines1 == 32 # vector directly at vertices (.vti) vect = [m.dis.botm.array, m.dis.botm.array] for i, vcomp in enumerate(vect): vect[i] = m.modelgrid.array_at_verts(vcomp) vtk.export_vector(m, vect, output_dir, "test1ss_botm_vectv", true2d=True) filetocheck = os.path.join(output_dir, "test1ss_botm_vectv.vti") # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==3496) nlines2 = count_lines_in_file(filetocheck) assert nlines2 == 27 # export and check (force .vtu, with point scalars) m.dis.botm.export( output_dir, name="test1ss_botm", fmt="vtk", point_scalars=True, vtk_grid_type="UnstructuredGrid", true2d=True, ) filetocheck = os.path.join(output_dir, "test1ss_botm.vtu") # totalbytes3 = os.path.getsize(filetocheck) # assert(totalbytes3==23827) nlines3 = count_lines_in_file(filetocheck) assert nlines3 == 608 # test mf 2005 swiex3, which has one row namfile = "swiex3.nam" m = flopy.modflow.Modflow.load(namfile, model_ws=mpath, verbose=False, load_only=["dis", "bas6"]) # export and check (.vtr) m.dis.botm.export(output_dir, name="swiex3_botm", fmt="vtk", true2d=True) filetocheck = os.path.join(output_dir, "swiex3_botm.vtr") # totalbytes4 = os.path.getsize(filetocheck) # assert(totalbytes4==8022) nlines4 = count_lines_in_file(filetocheck) assert nlines4 == 229 # export and check (force .vtu) m.dis.botm.export( output_dir, name="swiex3_botm", fmt="vtk", vtk_grid_type="UnstructuredGrid", true2d=True, ) filetocheck = os.path.join(output_dir, "swiex3_botm.vtu") # totalbytes5 = os.path.getsize(filetocheck) # assert(totalbytes5==85446) nlines5 = count_lines_in_file(filetocheck) assert nlines5 == 2426 return
def test_vtk_vector(): from flopy.utils import postprocessing as pp from flopy.utils import HeadFile, CellBudgetFile # test mf 2005 freyberg mpth = os.path.join("..", "examples", "data", "freyberg_multilayer_transient") namfile = "freyberg.nam" cbcfile = os.path.join(mpth, "freyberg.cbc") hdsfile = os.path.join(mpth, "freyberg.hds") cbc = CellBudgetFile(cbcfile) keys = ["FLOW RIGHT FACE", "FLOW FRONT FACE", "FLOW LOWER FACE"] vectors = [cbc.get_data(text=t)[0] for t in keys] hds = HeadFile(hdsfile) head = hds.get_data() m = flopy.modflow.Modflow.load(namfile, model_ws=mpth, verbose=False, load_only=["dis", "bas6", "upw"]) q = pp.get_specific_discharge(vectors, m, head) output_dir = os.path.join(cpth, "freyberg_vector") filenametocheck = "discharge.vtu" # export and check with point scalar vtk.export_vector(m, q, output_dir, "discharge", point_scalars=True) filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes = os.path.getsize(filetocheck) # assert(totalbytes==2247857) nlines = count_lines_in_file(filetocheck) assert nlines == 10605 # with point scalars and binary vtk.export_vector(m, q, output_dir + "_bin", "discharge", point_scalars=True, binary=True) filetocheck = os.path.join(output_dir + "_bin", filenametocheck) # totalbytes1 = os.path.getsize(filetocheck) # assert(totalbytes1==942413) # nlines1 = count_lines_in_file(filetocheck, binary=True) # assert(nlines1==3824) assert os.path.exists(filetocheck), "file (0) does not exist: {}".format( filetocheck) # with values directly given at vertices q = pp.get_specific_discharge(vectors, m, head, position="vertices") nancount = np.count_nonzero(np.isnan(q[0])) assert nancount == 472, "nancount != 472 ({})".format(nancount) overall = np.nansum(q[0]) + np.nansum(q[1]) + np.nansum(q[2]) assert np.allclose( overall, -15.849639024891047), "vertices overall = {}".format(overall) output_dir = os.path.join(cpth, "freyberg_vector") filenametocheck = "discharge_verts.vtu" vtk.export_vector(m, q, output_dir, "discharge_verts") filetocheck = os.path.join(output_dir, filenametocheck) # totalbytes2 = os.path.getsize(filetocheck) # assert(totalbytes2==1990047) nlines2 = count_lines_in_file(filetocheck) assert nlines2 == 10598, "nlines != 10598 ({})".format(nlines2) # with values directly given at vertices and binary vtk.export_vector(m, q, output_dir + "_bin", "discharge_verts", binary=True) filetocheck = os.path.join(output_dir + "_bin", filenametocheck) # totalbytes3 = os.path.getsize(filetocheck) # assert(totalbytes3==891486) # nlines3 = count_lines_in_file(filetocheck, binary=True) # assert(nlines3==3012) assert os.path.exists(filetocheck), "file (1) does not exist: {}".format( filetocheck) return