Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions dependencies/flopy/datbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,43 @@ class DataInterface:
@abc.abstractmethod
def data_type(self):
raise NotImplementedError(
"must define dat_type in child " "class to use this base class"
"must define dat_type in child class to use this base class"
)

@property
@abc.abstractmethod
def dtype(self):
def dtype(self):
raise NotImplementedError(
"must define dtype in child " "class to use this base class"
"must define dtype in child class to use this base class"
)

@property
@abc.abstractmethod
def array(self):
raise NotImplementedError(
"must define array in child " "class to use this base class"
"must define array in child class to use this base class"
)

@property
@abc.abstractmethod
def name(self):
raise NotImplementedError(
"must define name in child " "class to use this base class"
"must define name in child class to use this base class"
)

@property
@abc.abstractmethod
def model(self):
raise NotImplementedError(
"must define name in child " "class to use this base class"
"must define name in child class to use this base class"
)

@property
@abc.abstractmethod
def plottable(self):
raise NotImplementedError(
"must define plottable in child " "class to use this base class"
"must define plottable in child class to use this base class"
)


Expand All @@ -63,15 +63,15 @@ class DataListInterface:
@abc.abstractmethod
def package(self):
raise NotImplementedError(
"must define package in child " "class to use this base class"
"must define package in child class to use this base class"
)

@property
@abc.abstractmethod
def to_array(self, kper=0, mask=False):
def to_array(self):
raise NotImplementedError(
"must define to_array in child " "class to use this base class"
"must define to_array in child class to use this base class"
)

@abc.abstractmethod
Expand Down
61 changes: 46 additions & 15 deletions dependencies/flopy/discretization/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def __init__(

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

###################################
# access to basic grid properties
Expand All @@ -192,16 +193,16 @@ def __repr__(self):
and self.angrot is not None
):
items += [
"xll:" + str(self.xoffset),
"yll:" + str(self.yoffset),
"rotation:" + str(self.angrot),
f"xll:{self.xoffset!s}",
f"yll:{self.yoffset!s}",
f"rotation:{self.angrot!s}",
]
if self.proj4 is not None:
items.append("proj4_str:" + str(self.proj4))
items.append(f"proj4_str:{self.proj4}")
if self.units is not None:
items.append("units:" + str(self.units))
items.append(f"units:{self.units}")
if self.lenuni is not None:
items.append("lenuni:" + str(self.lenuni))
items.append(f"lenuni:{self.lenuni}")
return "; ".join(items)

@property
Expand Down Expand Up @@ -258,7 +259,7 @@ def proj4(self):
else:
proj4 = self._proj4
elif self.epsg is not None:
proj4 = "epsg:{}".format(self.epsg)
proj4 = f"epsg:{self.epsg}"
return proj4

@proj4.setter
Expand All @@ -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 Expand Up @@ -317,6 +325,11 @@ def saturated_thick(self, array, mask=None):
thick = self.thick
top = self.top_botm[:-1].reshape(thick.shape)
bot = self.top_botm[1:].reshape(thick.shape)
thick = self.remove_confining_beds(thick)
top = self.remove_confining_beds(top)
bot = self.remove_confining_beds(bot)
array = self.remove_confining_beds(array)

idx = np.where((array < top) & (array > bot))
thick[idx] = array[idx] - bot[idx]
idx = np.where(array <= bot)
Expand Down Expand Up @@ -443,6 +456,32 @@ def xyzvertices(self):
def cross_section_vertices(self):
return self.xyzvertices[0], self.xyzvertices[1]

def remove_confining_beds(self, array):
"""
Method to remove confining bed layers from an array

Parameters
----------
array : np.ndarray
array to remove quasi3d confining bed data from. Shape of axis 0
should be (self.lay + ncb) to remove beds
Returns
-------
np.ndarray
"""
if self.laycbd is not None:
ncb = np.count_nonzero(self.laycbd)
if ncb > 0:
if array.shape[0] == self.shape[0] + ncb:
cb = 0
idx = []
for ix, i in enumerate(self.laycbd):
idx.append(ix + cb)
if i > 0:
cb += 1
array = array[idx]
return array

def cross_section_lay_ncpl_ncb(self, ncb):
"""
Get PlotCrossSection compatible layers, ncpl, and ncb
Expand Down Expand Up @@ -706,19 +745,11 @@ def attribs_from_namfile_header(self, namefile):
elif "xul" in item.lower():
try:
xul = float(item.split(":")[1])
warnings.warn(
"xul/yul have been deprecated. Use xll/yll instead.",
DeprecationWarning,
)
except:
pass
elif "yul" in item.lower():
try:
yul = float(item.split(":")[1])
warnings.warn(
"xul/yul have been deprecated. Use xll/yll instead.",
DeprecationWarning,
)
except:
pass
elif "rotation" in item.lower():
Expand Down
45 changes: 8 additions & 37 deletions dependencies/flopy/discretization/structuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@
import numpy as np
from .grid import Grid, CachedData

try:
from numpy.lib import NumpyVersion

numpy115 = NumpyVersion(np.__version__) >= "1.15.0"
except ImportError:
numpy115 = False

if not numpy115:

def flip_numpy115(m, axis=None):
"""Provide same behavior for np.flip since numpy 1.15.0."""
import numpy.core.numeric as _nx
from numpy.core.numeric import asarray

if not hasattr(m, "ndim"):
m = asarray(m)
if axis is None:
indexer = (np.s_[::-1],) * m.ndim
else:
axis = _nx.normalize_axis_tuple(axis, m.ndim)
indexer = [np.s_[:]] * m.ndim
for ax in axis:
indexer[ax] = np.s_[::-1]
indexer = tuple(indexer)
return m[indexer]

np.flip = flip_numpy115


def array_at_verts_basic2d(a):
"""
Expand Down Expand Up @@ -189,15 +161,15 @@ def __init__(
self.__nlay = nlay
else:
if laycbd is not None:
self.__nlay = len(botm) - np.sum(laycbd > 0)
self.__nlay = len(botm) - np.count_nonzero(laycbd)
else:
self.__nlay = len(botm)
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 +436,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 Expand Up @@ -1562,7 +1534,7 @@ def get_plottable_layer_array(self, a, layer):
plotarray = plotarray[layer, :, :]
else:
raise Exception("Array to plot must be of dimension 1, 2, or 3")
msg = "{} /= {}".format(plotarray.shape, required_shape)
msg = f"{plotarray.shape} /= {required_shape}"
assert plotarray.shape == required_shape, msg
return plotarray

Expand Down Expand Up @@ -1643,11 +1615,10 @@ def from_binary_grid_file(cls, file_path, verbose=False):

grb_obj = MfGrdFile(file_path, verbose=verbose)
if grb_obj.grid_type != "DIS":
err_msg = (
"Binary grid file ({}) ".format(os.path.basename(file_path))
+ "is not a structured (DIS) grid."
raise ValueError(
f"Binary grid file ({os.path.basename(file_path)}) "
"is not a structured (DIS) grid."
)
raise ValueError(err_msg)

idomain = grb_obj.idomain
xorigin = grb_obj.xorigin
Expand Down
25 changes: 11 additions & 14 deletions dependencies/flopy/discretization/unstructuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,13 @@ def __init__(

if iverts is not None:
if self.grid_varies_by_layer:
msg = "Length of iverts must equal grid nodes ({} {})".format(
len(iverts), self.nnodes
msg = (
"Length of iverts must equal grid nodes "
f"({len(iverts)} {self.nnodes})"
)
assert len(iverts) == self.nnodes, msg
else:
msg = "Length of iverts must equal ncpl ({} {})".format(
len(iverts), self.ncpl
)
msg = f"Length of iverts must equal ncpl ({len(iverts)} {self.ncpl})"
assert np.all([cpl == len(iverts) for cpl in self.ncpl]), msg

return
Expand Down Expand Up @@ -208,7 +207,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 Expand Up @@ -809,11 +808,10 @@ def from_binary_grid_file(cls, file_path, verbose=False):

grb_obj = MfGrdFile(file_path, verbose=verbose)
if grb_obj.grid_type != "DISU":
err_msg = (
"Binary grid file ({}) ".format(os.path.basename(file_path))
+ "is not a vertex (DISU) grid."
raise ValueError(
f"Binary grid file ({os.path.basename(file_path)}) "
"is not a vertex (DISU) grid."
)
raise ValueError(err_msg)

iverts = grb_obj.iverts
if iverts is not None:
Expand Down Expand Up @@ -842,8 +840,7 @@ def from_binary_grid_file(cls, file_path, verbose=False):
angrot=angrot,
)
else:
err_msg = (
"{} binary grid file".format(os.path.basename(file_path))
+ " does not include vertex data"
raise TypeError(
f"{os.path.basename(file_path)} binary grid file "
"does not include vertex data"
)
raise TypeError(err_msg)
21 changes: 9 additions & 12 deletions dependencies/flopy/discretization/vertexgrid.py
Original file line number Diff line number Diff line change
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 Expand Up @@ -273,7 +273,7 @@ def intersect(self, x, y, local=False, forgive=False):
if Path is None:
s = (
"Could not import matplotlib. Must install matplotlib "
+ " in order to use VertexGrid.intersect() method"
"in order to use VertexGrid.intersect() method"
)
raise ImportError(s)

Expand Down Expand Up @@ -314,9 +314,7 @@ def get_cell_vertices(self, cellid):
"""
while cellid >= self.ncpl:
if cellid > self.nnodes:
err = "cellid {} out of index for size {}".format(
cellid, self.nnodes
)
err = f"cellid {cellid} out of index for size {self.nnodes}"
raise IndexError(err)

cellid -= self.ncpl
Expand Down Expand Up @@ -491,7 +489,7 @@ def get_plottable_layer_array(self, a, layer):
plotarray = plotarray[layer, :]
else:
raise Exception("Array to plot must be of dimension 1 or 2")
msg = "{} /= {}".format(plotarray.shape[0], required_shape)
msg = f"{plotarray.shape[0]} /= {required_shape}"
assert plotarray.shape == required_shape, msg
return plotarray

Expand All @@ -518,11 +516,10 @@ def from_binary_grid_file(cls, file_path, verbose=False):

grb_obj = MfGrdFile(file_path, verbose=verbose)
if grb_obj.grid_type != "DISV":
err_msg = (
"Binary grid file ({}) ".format(os.path.basename(file_path))
+ "is not a vertex (DISV) grid."
raise ValueError(
f"Binary grid file ({os.path.basename(file_path)}) "
"is not a vertex (DISV) grid."
)
raise ValueError(err_msg)

idomain = grb_obj.idomain
xorigin = grb_obj.xorigin
Expand Down
Loading