Skip to content

Commit

Permalink
add deprecation warnings for gridlist_to_disv_gridprops
Browse files Browse the repository at this point in the history
  • Loading branch information
langevin-usgs committed Jul 26, 2024
1 parent 0cb3f71 commit 13e69f0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 63 deletions.
90 changes: 46 additions & 44 deletions autotest/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,50 +1718,52 @@ def test_vtk_export_disv1_model(function_tmpdir):
idomain=np.ones((nlay, nrow, ncol)),
)

from flopy.utils.cvfdutil import gridlist_to_disv_gridprops

gridprops = gridlist_to_disv_gridprops([mg])
gridprops["top"] = 0
gridprops["botm"] = np.zeros((nlay, nrow * ncol), dtype=float) - 1
gridprops["nlay"] = nlay

disv = ModflowGwfdisv(gwf, **gridprops)
ic = ModflowGwfic(gwf, strt=10)
npf = ModflowGwfnpf(gwf)

# Export model without specifying packages_names parameter
# create the vtk output
gwf = sim.get_model()
vtkobj = Vtk(gwf, binary=False)
vtkobj.add_model(gwf)
f = function_tmpdir / "gwf.vtk"
vtkobj.write(f)

# load the output using the vtk standard library
gridreader = vtkUnstructuredGridReader()
gridreader.SetFileName(str(f))
gridreader.Update()
grid = gridreader.GetOutput()

# get the points
vtk_points = grid.GetPoints()
vtk_points = vtk_points.GetData()
vtk_points = vtk_to_numpy(vtk_points)

# get cell locations (ia format of point to cell relationship)
cell_locations = vtk_to_numpy(grid.GetCellLocationsArray())
cell_locations_answer = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64])
print(f"Found cell locations {cell_locations} in vtk file.")
print(f"Expecting cell locations {cell_locations_answer}")
errmsg = "vtk cell locations do not match expected result."
assert np.allclose(cell_locations, cell_locations_answer), errmsg

cell_types = vtk_to_numpy(grid.GetCellTypesArray())
cell_types_answer = np.array(9 * [42])
print(f"Found cell types {cell_types} in vtk file.")
print(f"Expecting cell types {cell_types_answer}")
errmsg = "vtk cell types do not match expected result."
assert np.allclose(cell_types, cell_types_answer), errmsg
with pytest.deprecated_call():

from flopy.utils.cvfdutil import gridlist_to_disv_gridprops

gridprops = gridlist_to_disv_gridprops([mg])
gridprops["top"] = 0
gridprops["botm"] = np.zeros((nlay, nrow * ncol), dtype=float) - 1
gridprops["nlay"] = nlay

disv = ModflowGwfdisv(gwf, **gridprops)
ic = ModflowGwfic(gwf, strt=10)
npf = ModflowGwfnpf(gwf)

# Export model without specifying packages_names parameter
# create the vtk output
gwf = sim.get_model()
vtkobj = Vtk(gwf, binary=False)
vtkobj.add_model(gwf)
f = function_tmpdir / "gwf.vtk"
vtkobj.write(f)

# load the output using the vtk standard library
gridreader = vtkUnstructuredGridReader()
gridreader.SetFileName(str(f))
gridreader.Update()
grid = gridreader.GetOutput()

# get the points
vtk_points = grid.GetPoints()
vtk_points = vtk_points.GetData()
vtk_points = vtk_to_numpy(vtk_points)

# get cell locations (ia format of point to cell relationship)
cell_locations = vtk_to_numpy(grid.GetCellLocationsArray())
cell_locations_answer = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64])
print(f"Found cell locations {cell_locations} in vtk file.")
print(f"Expecting cell locations {cell_locations_answer}")
errmsg = "vtk cell locations do not match expected result."
assert np.allclose(cell_locations, cell_locations_answer), errmsg

cell_types = vtk_to_numpy(grid.GetCellTypesArray())
cell_types_answer = np.array(9 * [42])
print(f"Found cell types {cell_types} in vtk file.")
print(f"Expecting cell types {cell_types_answer}")
errmsg = "vtk cell types do not match expected result."
assert np.allclose(cell_types, cell_types_answer), errmsg


@pytest.mark.mf6
Expand Down
40 changes: 21 additions & 19 deletions autotest/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,25 +943,27 @@ def test_tocvfd3():
yoff=200,
idomain=idomain,
)
gridprops = gridlist_to_disv_gridprops([sg1, sg2])
assert "ncpl" in gridprops
assert "nvert" in gridprops
assert "vertices" in gridprops
assert "cell2d" in gridprops

ncpl = gridprops["ncpl"]
nvert = gridprops["nvert"]
vertices = gridprops["vertices"]
cell2d = gridprops["cell2d"]
assert ncpl == 121
assert nvert == 148
assert len(vertices) == nvert
assert len(cell2d) == 121

# spot check information for cell 28 (zero based)
answer = [28, 250.0, 150.0, 7, 38, 142, 143, 45, 46, 44, 38]
for i, j in zip(cell2d[28], answer):
assert i == j, f"{i} not equal {j}"

with pytest.deprecated_call():
gridprops = gridlist_to_disv_gridprops([sg1, sg2])
assert "ncpl" in gridprops
assert "nvert" in gridprops
assert "vertices" in gridprops
assert "cell2d" in gridprops

ncpl = gridprops["ncpl"]
nvert = gridprops["nvert"]
vertices = gridprops["vertices"]
cell2d = gridprops["cell2d"]
assert ncpl == 121
assert nvert == 148
assert len(vertices) == nvert
assert len(cell2d) == 121

# spot check information for cell 28 (zero based)
answer = [28, 250.0, 150.0, 7, 38, 142, 143, 45, 46, 44, 38]
for i, j in zip(cell2d[28], answer):
assert i == j, f"{i} not equal {j}"


@requires_pkg("shapely")
Expand Down
12 changes: 12 additions & 0 deletions flopy/utils/cvfdutil.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
import numpy as np
import pandas as pd

Expand Down Expand Up @@ -390,6 +391,10 @@ def gridlist_to_disv_gridprops(gridlist):
be numbered according to consecutive numbering of active cells in the
grid list.
This function is deprecated in 3.8 and will be removed in 3.9. Use the
functionality in flopy.utils.cvfdutil.Lgr() to create a DISV mesh for a
nested grid.
Parameters
----------
gridlist : list
Expand All @@ -403,6 +408,13 @@ def gridlist_to_disv_gridprops(gridlist):
modflow6 disv package.
"""
warnings.warn(
"the gridlist_to_disv_gridprops function is deprecated and will be "
"removed in version 3.9. Use flopy.utils.cvfdutil.Lgr() instead, which "
"allows a nested grid to be created and exported to a DISV mesh.",
PendingDeprecationWarning,
)

verts, iverts = gridlist_to_verts(gridlist)
gridprops = get_disv_gridprops(verts, iverts)
return gridprops

0 comments on commit 13e69f0

Please sign in to comment.