Skip to content

Commit

Permalink
feat(ModflowAg): Add ModflowAg module for upcoming NWT release (#805)
Browse files Browse the repository at this point in the history
* feat(mf6 checker): input data check for mf6 (#779)

* feat(input data check for mf6): refactored mf2005 input data check to support both mf2005 and mf6

* feat(input data check for mf6): refactor of mf2005 code to work with mf6

* feat(input data check for mf6): autotest updates

* feat(input data check for mf6)

* fix(codacy fixes)

* fix(check too complex)

* fix(codacy): simplified check code

* fix(mtssm.py): handle 1st stress period with incrch equal to -1 (#780)

* fix(mtssm.py): handle 1st stress period when no crch data

Initializes crch with a scalar of 0.0 rather than a Transient2d obj equal to 0
Using a test dataset from #743 that was demonstrating the problem
Updated an autotest to load and write an SSM file with no data specified for crch

#743

* fix(mtssm.py): fix multi-species handling of incrch

* fix(gridgen): x, y center was not correct for rotated grids (#783)

* added a more robust method for determining cell centers for rotated grids
* closes #782

* fix(remove_package): fixed remove_package to rebuild namefile recarray correctly after removing package - issue #776 (#784)

Close #776

* feat(zb netcdf): zonebudget netcdf export support added  (#781)

* Updates to netcdf.py and utilities for zonebudget data

* Update requirements.travis.txt to test netCDF4 error

* update requirements.travis.txt for netCDF error testing

* Update travis/install.sh and requirements.travis.txt for binary conflicts

* updates for binary HDF binary conflict testing

* Feat(ZoneBudgetOutput): Added ZoneBudgetOutput to read in zonebudget output files

* added postprocessing methods to prepare budget data for netcdf writing
* updated NetCdf to include zonebudget group
* updated export/utils.py for zonebudget netcdf exporting

* Update(test_zonebudget_output_to_netcdf): for linux os

* Debug travis error with coverage package

* Debug coverage package issue due to 5.0.2 update (known issue in coveragepy repository)

* Update(test_zonebudget_output_to_netcdf): fix file case issue for travis-ci

* Update travis install.sh to check if coverage issue has been fixed

* fix(mf6): update create packages to support additional models (#790)

* refactor(grid_intersect): fixes for shapely updates

* Improved parsing of shapely intersection results
* Added tests for vertex grid
* Added example for vertex grid in notebook
* Improve docstrings, minor fixes, autopep8

* fix(vtk): change in export_cbc output file name (#795)

* Feat(ModflowAg): Added the modflow-nwt ModflowAg package module to flopy-dev.iml
* Updated ModflowUzf1 for recent additions to UZF1 in MODFLOW-NWT.exe

* update(ModflowAg): updated docstrings

Co-authored-by: spaulins-usgs <spaulinski@usgs.gov>
Co-authored-by: Eric Morway <emorway@usgs.gov>
Co-authored-by: langevin-usgs <langevin@usgs.gov>
Co-authored-by: Hughes, J.D <jdhughes@usgs.gov>
Co-authored-by: Davíd Brakenhoff <d.brakenhoff@artesia-water.nl>
Co-authored-by: rodrperezi <rodrperez@ing.uchile.cl>
  • Loading branch information
7 people committed Apr 10, 2020
1 parent 73f7051 commit 1c41d74
Show file tree
Hide file tree
Showing 76 changed files with 157,978 additions and 2,103 deletions.
1 change: 1 addition & 0 deletions autotest/t024_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_bcs_check():
ibound[1, 1, 1] = 1 # fully isolated cell
ibound[0:2, 4, 4] = 1 # cell connected vertically to one other cell
bas = flopy.modflow.ModflowBas(mf, ibound=ibound)
mf._mg_resync = True
chk = bas.check()
assert chk.summary_array['desc'][0] == 'isolated cells in ibound array'
assert chk.summary_array.i[0] == 1 and chk.summary_array.i[0] == 1 and \
Expand Down
104 changes: 104 additions & 0 deletions autotest/t039_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,109 @@ def test_get_model_shape():
return


def test_zonebudget_output_to_netcdf():
from flopy.utils import HeadFile, ZoneBudgetOutput
from flopy.modflow import Modflow
from flopy.mf6 import MFSimulation
from flopy.export.utils import output_helper

model_ws = os.path.join("..", "examples", "data",
"freyberg_multilayer_transient")
zb_ws = os.path.join("..", "examples", "data", "zonbud_examples")

hds = "freyberg.hds"
nam = "freyberg.nam"
zon = "zonef_mlt.zbr"

hds = HeadFile(os.path.join(model_ws, hds))
ml = Modflow.load(nam, model_ws=model_ws)
zone_array = read_zbarray(os.path.join(zb_ws, zon))

# test with standard zonebudget output
zbout = "freyberg_mlt.txt"
ncf_name = zbout + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
vdf = zb.volumetric_flux()

netobj = zb.dataframe_to_netcdf_fmt(vdf, flux=False)

export_dict = {"hds": hds,
"zonebud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)

# test with zonebudget csv 1 output
zbout = "freyberg_mlt.1.csv"
ncf_name = zbout + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)

netobj = zb.dataframe_to_netcdf_fmt(zb.dataframe)

export_dict = {"hds": hds,
"zonebud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)

# test with zonebudget csv 2 output
zbout = "freyberg_mlt.2.csv"
ncf_name = zbout + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
vdf = zb.volumetric_flux(extrapolate_kper=True)

netobj = zb.dataframe_to_netcdf_fmt(vdf, flux=False)

export_dict = {"hds": hds,
"zonebud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)

# test built in export function
zbout = "freyberg_mlt.2.csv"
ncf_name = zbout + ".bi1" + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
zb.export(os.path.join(outpth, ncf_name), ml)

# test built in export function with NetCdf output object
zbout = "freyberg_mlt.2.csv"
ncf_name = zbout + ".bi2" + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
export_dict = {"hds": hds}
ncfobj = output_helper(os.path.join(outpth, ncf_name), ml, export_dict)
zb.export(ncfobj, ml)

# test with modflow6/zonebudget6
sim_ws = os.path.join("..", "examples", 'data',
'mf6', 'test005_advgw_tidal')
hds = "advgw_tidal.hds"
nam = "mfsim"
zon = "zonebudget6.csv"
ncf_name = zon + ".nc"

zone_array = np.ones((3, 15, 10), dtype=int)
zone_array = np.add.accumulate(zone_array, axis=0)
sim = MFSimulation.load(nam, sim_ws=sim_ws, exe_name='mf6')
sim.set_sim_path(outpth)
sim.write_simulation()
sim.run_simulation()
hds = HeadFile(os.path.join(outpth, hds))

ml = sim.get_model("gwf_1")

zb = ZoneBudgetOutput(os.path.join(zb_ws, zon), sim.tdis, zone_array)
vdf = zb.volumetric_flux()

netobj = zb.dataframe_to_netcdf_fmt(vdf, flux=False)
export_dict = {"hds": hds,
"zbud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)


if __name__ == '__main__':
# test_compare2mflist_mlt()
test_compare2zonebudget()
Expand All @@ -244,3 +347,4 @@ def test_get_model_shape():
test_dataframes()
test_get_budget()
test_get_model_shape()
test_zonebudget_output_to_netcdf()
86 changes: 52 additions & 34 deletions autotest/t065_test_gridintersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,36 @@
print("Shapely not installed, tests cannot be run.")
from flopy.utils.gridintersect import GridIntersect

triangle_exe = None

def get_tri_grid(angrot=0., xyoffset=0., triangle_exe=None):
if not triangle_exe:
return -1
maximum_area = 50.
x0, x1, y0, y1 = (0.0, 20.0, 0.0, 20.0)
domainpoly = [(x0, y0), (x0, y1), (x1, y1), (x1, y0)]
tri = Triangle(maximum_area=maximum_area, angle=45, model_ws=".",
exe_name=triangle_exe)
tri.add_polygon(domainpoly)
tri.build(verbose=False)
cell2d = tri.get_cell2d()
vertices = tri.get_vertices()
cell2d = [[0, 16.666666666666668, 13.333333333333334, 3, 4, 2, 7],
[1, 3.3333333333333335, 6.666666666666667, 3, 4, 0, 5],
[2, 6.666666666666667, 16.666666666666668, 3, 1, 8, 4],
[3, 3.3333333333333335, 13.333333333333334, 3, 5, 1, 4],
[4, 6.666666666666667, 3.3333333333333335, 3, 6, 0, 4],
[5, 13.333333333333334, 3.3333333333333335, 3, 4, 3, 6],
[6, 16.666666666666668, 6.666666666666667, 3, 7, 3, 4],
[7, 13.333333333333334, 16.666666666666668, 3, 8, 2, 4]]
vertices = [[0, 0.0, 0.0],
[1, 0.0, 20.0],
[2, 20.0, 20.0],
[3, 20.0, 0.0],
[4, 10.0, 10.0],
[5, 0.0, 10.0],
[6, 10.0, 0.0],
[7, 20.0, 10.0],
[8, 10.0, 20.0]]
else:
maximum_area = 50.
x0, x1, y0, y1 = (0.0, 20.0, 0.0, 20.0)
domainpoly = [(x0, y0), (x0, y1), (x1, y1), (x1, y0)]
tri = Triangle(maximum_area=maximum_area, angle=45, model_ws=".",
exe_name=triangle_exe)
tri.add_polygon(domainpoly)
tri.build(verbose=False)
cell2d = tri.get_cell2d()
vertices = tri.get_vertices()
tgr = fgrid.VertexGrid(vertices, cell2d,
botm=np.atleast_2d(np.zeros(len(cell2d))),
top=np.ones(len(cell2d)), xoff=xyoffset,
Expand All @@ -33,8 +49,8 @@ def get_tri_grid(angrot=0., xyoffset=0., triangle_exe=None):


def get_rect_grid(angrot=0., xyoffset=0.):
delc = 10*np.ones(2, dtype=np.float)
delr = 10*np.ones(2, dtype=np.float)
delc = 10 * np.ones(2, dtype=np.float)
delr = 10 * np.ones(2, dtype=np.float)
sgr = fgrid.StructuredGrid(
delc, delr, top=None, botm=None, xoff=xyoffset, yoff=xyoffset,
angrot=angrot)
Expand Down Expand Up @@ -229,7 +245,7 @@ def test_tri_grid_point_outside():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -244,7 +260,7 @@ def test_tri_grid_point_on_outer_boundary():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -260,7 +276,7 @@ def test_tri_grid_point_on_inner_boundary():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -276,7 +292,7 @@ def test_tri_grid_multipoint_in_one_cell():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -292,7 +308,7 @@ def test_tri_grid_multipoint_in_multiple_cells():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand Down Expand Up @@ -520,7 +536,7 @@ def test_tri_grid_linestring_outside():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -535,7 +551,7 @@ def test_tri_grid_linestring_in_2cells():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -553,7 +569,7 @@ def test_tri_grid_linestring_on_outer_boundary():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -571,7 +587,7 @@ def test_tri_grid_linestring_on_inner_boundary():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -589,7 +605,7 @@ def test_tri_grid_multilinestring_in_one_cell():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand Down Expand Up @@ -829,7 +845,7 @@ def test_tri_grid_polygon_outside():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -845,7 +861,7 @@ def test_tri_grid_polygon_in_2cells():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -862,7 +878,7 @@ def test_tri_grid_polygon_on_outer_boundary():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -873,7 +889,7 @@ def test_tri_grid_polygon_on_outer_boundary():


def test_tri_grid_polygon_on_inner_boundary():
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -890,7 +906,7 @@ def test_tri_grid_multipolygon_in_one_cell():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -909,7 +925,7 @@ def test_tri_grid_multipolygon_in_multiple_cells():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand All @@ -928,7 +944,7 @@ def test_tri_grid_polygon_with_hole():
import shapely
except:
return
gr = get_tri_grid(triangle_exe=triangle_exe)
gr = get_tri_grid()
if gr == -1:
return
ix = GridIntersect(gr)
Expand Down Expand Up @@ -979,7 +995,7 @@ def test_polygon_offset_rot_structured_grid():
return
sgr = get_rect_grid(angrot=45., xyoffset=10.)
p = Polygon([(5, 10. + np.sqrt(200.)), (15, 10. + np.sqrt(200.)),
(15, 10. + 1.5*np.sqrt(200.)), (5, 10. + 1.5*np.sqrt(200.))])
(15, 10. + 1.5 * np.sqrt(200.)), (5, 10. + 1.5 * np.sqrt(200.))])
ix = GridIntersect(sgr, method="structured")
result = ix.intersect_polygon(p)
# assert len(result) == 3.
Expand Down Expand Up @@ -1022,12 +1038,13 @@ def test_polygon_offset_rot_structured_grid_shapely():
return
sgr = get_rect_grid(angrot=45., xyoffset=10.)
p = Polygon([(5, 10. + np.sqrt(200.)), (15, 10. + np.sqrt(200.)),
(15, 10. + 1.5*np.sqrt(200.)), (5, 10. + 1.5*np.sqrt(200.))])
(15, 10. + 1.5 * np.sqrt(200.)), (5, 10. + 1.5 * np.sqrt(200.))])
ix = GridIntersect(sgr, method="strtree")
result = ix.intersect_polygon(p)
# assert len(result) == 3.
return result


def test_rasters():
from flopy.utils import Raster
import os
Expand All @@ -1038,7 +1055,7 @@ def test_rasters():

try:
rio = Raster.load(os.path.join(ws, "dem", raster_name))
except ImportError:
except:
return

ml = fp.modflow.Modflow.load("sagehen.nam", version="mfnwt",
Expand Down Expand Up @@ -1093,4 +1110,5 @@ def test_rasters():


if __name__ == "__main__":
test_rasters()
# test_rasters()
pass
Loading

0 comments on commit 1c41d74

Please sign in to comment.