diff --git a/flopy/discretization/grid.py b/flopy/discretization/grid.py index 9c4e72f9bf..7b8e587a02 100644 --- a/flopy/discretization/grid.py +++ b/flopy/discretization/grid.py @@ -180,6 +180,7 @@ def __init__( self._iverts = None self._verts = None + self._laycbd = None ################################### # access to basic grid properties @@ -285,6 +286,13 @@ def botm(self): def top_botm(self): raise NotImplementedError("must define top_botm in child class") + @property + def laycbd(self): + if self._laycbd is None: + return None + else: + return self._laycbd + @property def thick(self): """ diff --git a/flopy/discretization/structuredgrid.py b/flopy/discretization/structuredgrid.py index c85c78d013..389b2938c9 100644 --- a/flopy/discretization/structuredgrid.py +++ b/flopy/discretization/structuredgrid.py @@ -195,9 +195,9 @@ def __init__( else: self.__nlay = nlay if laycbd is not None: - self.__laycbd = laycbd + self._laycbd = laycbd else: - self.__laycbd = np.zeros(self.__nlay or (), dtype=int) + self._laycbd = np.zeros(self.__nlay or (), dtype=int) #################### # Properties @@ -464,7 +464,7 @@ def xyzcellcenters(self): z = np.empty((self.__nlay, self.__nrow, self.__ncol)) z[0, :, :] = (self._top[:, :] + self._botm[0, :, :]) / 2.0 ibs = np.arange(self.__nlay) - quasi3d = [cbd != 0 for cbd in self.__laycbd] + quasi3d = [cbd != 0 for cbd in self._laycbd] if np.any(quasi3d): ibs[1:] = ibs[1:] + np.cumsum(quasi3d)[: self.__nlay - 1] for l, ib in enumerate(ibs[1:], 1): diff --git a/flopy/discretization/unstructuredgrid.py b/flopy/discretization/unstructuredgrid.py index 0df3829858..3916479ec3 100644 --- a/flopy/discretization/unstructuredgrid.py +++ b/flopy/discretization/unstructuredgrid.py @@ -208,7 +208,7 @@ def verts(self): if self._vertices is None: return self._vertices else: - return np.array([t[1:] for t in self._vertices], dtype=float) + return np.array([list(t)[1:] for t in self._vertices], dtype=float) @property def ia(self): diff --git a/flopy/discretization/vertexgrid.py b/flopy/discretization/vertexgrid.py index ab865eb422..b4623028f9 100644 --- a/flopy/discretization/vertexgrid.py +++ b/flopy/discretization/vertexgrid.py @@ -4,7 +4,7 @@ try: from matplotlib.path import Path -except ImportError: +except (ImportError, RuntimeError): Path = None from .grid import Grid, CachedData @@ -128,11 +128,11 @@ def nvert(self): @property def iverts(self): - return [[t[0]] + t[4:] for t in self._cell2d] + return [[t[0]] + list(t)[4:] for t in self._cell2d] @property def verts(self): - return np.array([t[1:] for t in self._vertices], dtype=float) + return np.array([list(t)[1:] for t in self._vertices], dtype=float) @property def shape(self): diff --git a/flopy/plot/crosssection.py b/flopy/plot/crosssection.py index 39274bec79..1548f105c1 100644 --- a/flopy/plot/crosssection.py +++ b/flopy/plot/crosssection.py @@ -4,7 +4,7 @@ import matplotlib.pyplot as plt import matplotlib.colors from matplotlib.patches import Polygon -except (ImportError, ModuleNotFoundError): +except (ImportError, ModuleNotFoundError, RuntimeError): plt = None from flopy.plot import plotutil diff --git a/flopy/plot/map.py b/flopy/plot/map.py index 54820bda38..5b40708cf2 100644 --- a/flopy/plot/map.py +++ b/flopy/plot/map.py @@ -7,7 +7,7 @@ import matplotlib.colors from matplotlib.collections import PathCollection, LineCollection from matplotlib.path import Path -except (ImportError, ModuleNotFoundError): +except (ImportError, ModuleNotFoundError, RuntimeError): plt = None from . import plotutil diff --git a/flopy/plot/plotutil.py b/flopy/plot/plotutil.py index 43bcc5b666..9d329e8283 100644 --- a/flopy/plot/plotutil.py +++ b/flopy/plot/plotutil.py @@ -20,7 +20,7 @@ try: import matplotlib.pyplot as plt -except ImportError: +except (ImportError, RuntimeError): plt = None warnings.simplefilter("ignore", RuntimeWarning) diff --git a/flopy/plot/styles.py b/flopy/plot/styles.py index e6e82a74f4..0c21a2e555 100644 --- a/flopy/plot/styles.py +++ b/flopy/plot/styles.py @@ -1,7 +1,7 @@ try: import matplotlib.pyplot as plt import matplotlib as mpl -except (ImportError, ModuleNotFoundError): +except (ImportError, ModuleNotFoundError, RuntimeError): plt = None import os diff --git a/flopy/utils/check.py b/flopy/utils/check.py index 7e600272ca..1ac673e85f 100644 --- a/flopy/utils/check.py +++ b/flopy/utils/check.py @@ -437,7 +437,7 @@ def get_active(self, include_cbd=False): """ mg = self.model.modelgrid if mg.grid_type == "structured": - nlaycbd = mg._StructuredGrid__laycbd.sum() if include_cbd else 0 + nlaycbd = mg.laycbd.sum() if include_cbd else 0 inds = (mg.nlay + nlaycbd, mg.nrow, mg.ncol) elif mg.grid_type == "vertex": inds = (mg.nlay, mg.ncpl) diff --git a/flopy/utils/gridintersect.py b/flopy/utils/gridintersect.py index dffbdcf329..f217df436b 100644 --- a/flopy/utils/gridintersect.py +++ b/flopy/utils/gridintersect.py @@ -2,7 +2,7 @@ try: import matplotlib.pyplot as plt -except ImportError: +except (ImportError, RuntimeError): plt = None from .geometry import transform diff --git a/flopy/utils/voronoi.py b/flopy/utils/voronoi.py index d313876b97..a7fa126042 100644 --- a/flopy/utils/voronoi.py +++ b/flopy/utils/voronoi.py @@ -1,5 +1,4 @@ import numpy as np -import matplotlib.pyplot as plt from scipy.spatial import Voronoi from .cvfdutil import get_disv_gridprops @@ -282,6 +281,8 @@ def plot(self, ax=None, plot_title=True, **kwargs): axes that contains the voronoi model grid """ + import matplotlib.pyplot as plt + if ax is None: ax = plt.subplot(1, 1, 1, aspect="equal") pc = self.get_patch_collection(ax, **kwargs)