Skip to content

Commit

Permalink
fix(grid, plotting): bugfixes for all grid instances and plotting code (
Browse files Browse the repository at this point in the history
#1174)

* grid fix iverts and verts; expose laycbd for use in utilities
* plotting add RuntimeError exception to matplotlib imports to fix Condor containerization issues with flopy
  • Loading branch information
jlarsen-usgs committed Aug 9, 2021
1 parent b76b340 commit fdc4608
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 14 deletions.
8 changes: 8 additions & 0 deletions flopy/discretization/grid.py
Expand Up @@ -180,6 +180,7 @@ def __init__(

self._iverts = None
self._verts = None
self._laycbd = None

###################################
# access to basic grid properties
Expand Down Expand Up @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions flopy/discretization/structuredgrid.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion flopy/discretization/unstructuredgrid.py
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions flopy/discretization/vertexgrid.py
Expand Up @@ -4,7 +4,7 @@

try:
from matplotlib.path import Path
except ImportError:
except (ImportError, RuntimeError):
Path = None

from .grid import Grid, CachedData
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion flopy/plot/crosssection.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy/plot/map.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy/plot/plotutil.py
Expand Up @@ -20,7 +20,7 @@

try:
import matplotlib.pyplot as plt
except ImportError:
except (ImportError, RuntimeError):
plt = None

warnings.simplefilter("ignore", RuntimeWarning)
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/check.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/gridintersect.py
Expand Up @@ -2,7 +2,7 @@

try:
import matplotlib.pyplot as plt
except ImportError:
except (ImportError, RuntimeError):
plt = None

from .geometry import transform
Expand Down
3 changes: 2 additions & 1 deletion 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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fdc4608

Please sign in to comment.