diff --git a/autotest/t080_test.py b/autotest/t080_test.py index 4aa8dd1d98..9e5675d95a 100644 --- a/autotest/t080_test.py +++ b/autotest/t080_test.py @@ -4,6 +4,7 @@ import os import platform +import numpy as np try: from shapely.geometry import Polygon @@ -128,5 +129,57 @@ def test_mfusg(): return +def test_usg_iverts(): + iverts = [ + [4, 3, 2, 1, 0, None], + [7, 0, 1, 6, 5, None], + [11, 10, 9, 8, 2, 3], + [1, 6, 13, 12, 8, 2], + [15, 14, 13, 6, 5, None], + [10, 9, 18, 17, 16, None], + [8, 12, 20, 19, 18, 9], + [22, 14, 13, 12, 20, 21], + [24, 17, 18, 19, 23, None], + [21, 20, 19, 23, 25, None] + ] + verts = [ + [0.0, 22.5], + [5.1072, 22.5], + [7.5, 24.0324], + [7.5, 30.0], + [0.0, 30.0], + [0.0, 7.5], + [4.684, 7.5], + [0.0, 15.0], + [14.6582, 21.588], + [22.5, 24.3766], + [22.5, 30.0], + [15.0, 30.0], + [15.3597, 8.4135], + [7.5, 5.6289], + [7.5, 0.0], + [0.0, 0.0], + [30.0, 30.0], + [30.0, 22.5], + [25.3285, 22.5], + [24.8977, 7.5], + [22.5, 5.9676], + [22.5, 0.0], + [15.0, 0.0], + [30.0, 7.5], + [30.0, 15.0], + [30.0, 0.0] + ] + + grid = flopy.discretization.UnstructuredGrid( + verts, iverts, ncpl=[len(iverts)] + ) + + iverts = grid.iverts + if any(None in l for l in iverts): + raise ValueError("None type should not be returned in iverts list") + + if __name__ == "__main__": test_mfusg() + test_usg_iverts() diff --git a/flopy/discretization/unstructuredgrid.py b/flopy/discretization/unstructuredgrid.py index 05983f3ede..ab1283fb6b 100644 --- a/flopy/discretization/unstructuredgrid.py +++ b/flopy/discretization/unstructuredgrid.py @@ -200,7 +200,8 @@ def nvert(self): @property def iverts(self): - return self._iverts + if self._iverts is not None: + return [list(filter((None).__ne__, i)) for i in self._iverts] @property def verts(self): @@ -559,7 +560,7 @@ def _build_grid_geometry_info(self): yvertices = [] # build xy vertex and cell center info - for iverts in self._iverts: + for iverts in self.iverts: xcellvert = [] ycellvert = [] diff --git a/flopy/discretization/vertexgrid.py b/flopy/discretization/vertexgrid.py index 207bc972ed..75870012cc 100644 --- a/flopy/discretization/vertexgrid.py +++ b/flopy/discretization/vertexgrid.py @@ -125,7 +125,20 @@ def nvert(self): @property def iverts(self): - return [[t[0]] + list(t)[4:] for t in self._cell2d] + if self._cell2d is not None: + return [[t[0]] + list(t)[4:] for t in self.cell2d] + elif self._cell1d is not None: + return [[t[0]] + list(t)[3:] for t in self.cell1d] + + @property + def cell1d(self): + if self._cell1d is not None: + return [list(filter((None).__ne__, t)) for t in self._cell1d] + + @property + def cell2d(self): + if self._cell2d is not None: + return [list(filter((None).__ne__, t)) for t in self._cell2d] @property def verts(self): @@ -342,7 +355,7 @@ def _build_grid_geometry_info(self): zcenters = [] zvertices = [] vertexdict = {v[0]: [v[1], v[2], v[3]] for v in self._vertices} - for cell1d in self._cell1d: + for cell1d in self.cell1d: cell1d = tuple(cell1d) xcenters.append(cell1d[1]) ycenters.append(cell1d[2]) @@ -350,8 +363,7 @@ def _build_grid_geometry_info(self): vert_number = [] for i in cell1d[3:]: - if i is not None: - vert_number.append(int(i)) + vert_number.append(int(i)) xcellvert = [] ycellvert = [] @@ -367,15 +379,14 @@ def _build_grid_geometry_info(self): else: vertexdict = {v[0]: [v[1], v[2]] for v in self._vertices} # build xy vertex and cell center info - for cell2d in self._cell2d: + for cell2d in self.cell2d: cell2d = tuple(cell2d) xcenters.append(cell2d[1]) ycenters.append(cell2d[2]) vert_number = [] for i in cell2d[4:]: - if i is not None: - vert_number.append(int(i)) + vert_number.append(int(i)) xcellvert = [] ycellvert = [] diff --git a/flopy/utils/gridintersect.py b/flopy/utils/gridintersect.py index 6e3d9141ab..115eaf4ea0 100644 --- a/flopy/utils/gridintersect.py +++ b/flopy/utils/gridintersect.py @@ -45,7 +45,6 @@ def ignore_shapely_warnings_for_object_array(): ) yield - elif SHAPELY_LT_18 and NUMPY_GE_121: @contextlib.contextmanager @@ -58,7 +57,6 @@ def ignore_shapely_warnings_for_object_array(): ) yield - else: @contextlib.contextmanager