flopy.discretization.structuredgrid module
- class StructuredGrid(delc=None, delr=None, top=None, botm=None, idomain=None, lenuni=None, crs=None, epsg=None, proj4=None, prj=None, prjfile=None, xoff=0.0, yoff=0.0, angrot=0.0, nlay=None, nrow=None, ncol=None, laycbd=None)[source]
Bases:
Grid
class for a structured model grid
- Parameters:
delr (float or ndarray) – column spacing along a row.
delc (float or ndarray) – row spacing along a column.
top (float or ndarray) – top elevations of cells in topmost layer
botm (float or ndarray) – bottom elevations of all cells
idomain (int or ndarray) – ibound/idomain value for each cell
lenuni (int or ndarray) – model length units
crs (pyproj.CRS, optional if prjfile is specified) – Coordinate reference system (CRS) for the model grid (must be projected; geographic CRS are not supported). The value can be anything accepted by
pyproj.CRS.from_user_input()
, such as an authority string (eg “EPSG:26916”) or a WKT string.prjfile (str or pathlike, optional if crs is specified) – ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).
xoff (float) – x coordinate of the origin point (lower left corner of model grid) in the spatial reference coordinate system
yoff (float) – y coordinate of the origin point (lower left corner of model grid) in the spatial reference coordinate system
angrot (float) – rotation angle of model grid, as it is rotated around the origin point
Properties –
---------- –
nlay – returns the number of model layers
nrow – returns the number of model rows
ncol – returns the number of model columns
delc – returns the delc array
delr – returns the delr array
xyedges – returns x-location points for the edges of the model grid and y-location points for the edges of the model grid
- array_at_faces(a, direction, withnan=True)[source]
Computes values at the center of cell faces using linear interpolation.
- Parameters:
a (ndarray) – Values at cell centers, shape (nlay, row, ncol).
direction (str, possible values are 'x', 'y' and 'z') – Direction in which values will be interpolated at cell faces.
withnan (bool) – If True (default), the result value will be set to NaN where the cell face sits between inactive cells. If False, not.
- Returns:
afaces – Array values interpolated at cell vertices, shape as input extended by 1 along the specified direction.
- Return type:
ndarray
- array_at_verts(a)[source]
Interpolate array values at cell vertices.
- Parameters:
a (ndarray) – Array values. Allowed shapes are: (nlay, nrow, ncol), (nlay, nrow, ncol+1), (nlay, nrow+1, ncol) and (nlay+1, nrow, ncol). * When the shape is (nlay, nrow, ncol), input values are considered at cell centers, and output values are computed by trilinear interpolation. * When the shape is extended in one direction, input values are considered at the center of cell faces in this direction, and output values are computed by bilinear interpolation in planes defined by these cell faces.
- Returns:
averts – Array values interpolated at cell vertices, shape (nlay+1, nrow+1, ncol+1).
- Return type:
ndarray
Notes
Output values are smooth (continuous) even if top elevations or
bottom elevations are not constant across layers (i.e., in this case, vertices of neighboring cells are implicitly merged). * NaN values are assigned in accordance with inactive cells defined by idomain.
- array_at_verts_basic(a)[source]
Computes values at cell vertices using neighbor averaging.
- Parameters:
a (ndarray) – Array values at cell centers.
- Returns:
averts – Array values at cell vertices, shape (a.shape[0]+1, a.shape[1]+1, a.shape[2]+1). NaN values are assigned in accordance with inactive cells defined by idomain.
- Return type:
ndarray
- property cross_section_vertices
Get a set of xvertices and yvertices ordered by node for plotting cross sections
- Returns:
xverts, yverts
- Return type:
(np.ndarray, np.ndarray)
- property delc
- property delr
- property delz
- property extent
- classmethod from_binary_grid_file(file_path, verbose=False)[source]
Instantiate a StructuredGrid model grid from a MODFLOW 6 binary grid (*.grb) file.
- Parameters:
- Returns:
return
- Return type:
- classmethod from_gridspec(file_path: str | PathLike, lenuni=0)[source]
Instantiate a StructuredGrid from grid specification file.
- get_cell_vertices(*args, **kwargs)[source]
- Method to get a set of cell vertices for a single cell
used in the Shapefile export utilities and plotting code
- Parameters:
node – (int) node number
i – (int) cell row number
j – (int) cell column number
Returns ——- list of x,y cell vertices
- get_lrc(nodes)[source]
Get layer, row, column from a list of zero-based MODFLOW node numbers.
- Parameters:
- Returns:
list of tuples containing the layer (k), row (i), and column (j) for each node in the input list
- Return type:
Examples
>>> import flopy >>> sg = flopy.discretization.StructuredGrid(nlay=20, nrow=30, ncol=40) >>> sg.get_lrc(100) [(0, 2, 20)] >>> sg.get_lrc([100, 1000, 10_000]) [(0, 2, 20), (0, 25, 0), (8, 10, 0)]
- get_node(lrc_list)[source]
Get node number from a list of zero-based MODFLOW layer, row, column tuples.
- Parameters:
lrc_list (tuple of int or list of tuple of int) – Zero-based layer, row, column tuples
- Returns:
list of MODFLOW nodes for each layer (k), row (i), and column (j) tuple in the input list
- Return type:
Examples
>>> import flopy >>> sg = flopy.discretization.StructuredGrid(nlay=20, nrow=30, ncol=40) >>> sg.get_node((0, 2, 20)) [100] >>> sg.get_node([(0, 2, 20), (0, 25, 0), (8, 10, 0)]) [100, 1000, 10000]
- get_number_plottable_layers(a)[source]
Calculate and return the number of 2d plottable arrays that can be obtained from the array passed (a)
- Parameters:
a (ndarray) – array to check for plottable layers
- Returns:
nplottable – number of plottable layers
- Return type:
- property grid_lines
Get the grid lines as a list
- intersect(x, y, z=None, local=False, forgive=False)[source]
Get the row and column of a point with coordinates x and y
When the point is on the edge of two cells, the cell with the lowest row or column is returned.
- Parameters:
x (float) – The x-coordinate of the requested point
y (float) – The y-coordinate of the requested point
z (float) – Optional z-coordinate of the requested point (will return layer, row, column) if supplied
local (bool (optional)) – If True, x and y are in local coordinates (defaults to False)
forgive (bool (optional)) – Forgive x,y arguments that fall outside the model grid and return NaNs instead (defaults to False - will throw exception)
- Returns:
row (int) – The row number
col (int) – The column number
- property is_complete
- property is_rectilinear
Test whether the grid is rectilinear (it is always so in the x and y directions, but not necessarily in the z direction).
- property is_regular
Test if the grid spacing is regular and equal in x, y and z directions.
- property is_regular_x
Test whether the grid spacing is regular in the x direction.
- property is_regular_xy
Test if the grid spacing is regular and equal in x and y directions.
- property is_regular_xz
Test if the grid spacing is regular and equal in x and z directions.
- property is_regular_y
Test whether the grid spacing is regular in the y direction.
- property is_regular_yz
Test if the grid spacing is regular and equal in y and z directions.
- property is_regular_z
Test if the grid spacing is regular in z direction.
- property is_valid
- property iverts
- property map_polygons
Get a list of matplotlib Polygon patches for plotting
- Return type:
list of Polygon objects
- property ncol
- property ncpl
- neighbors(*args, **kwargs)[source]
Method to get nearest neighbors for a cell
- Parameters:
*args – lay (int), row (int), column (int) or node (int)
**kwargs –
- kint
layer number
- iint
row number
- jint
column number
- as_nodebool
flag to return neighbors as node numbers
- Return type:
list of neighboring cells
- property nlay
- property nnodes
- property nrow
- property nvert
- plot(**kwargs)[source]
Plot the grid lines.
- Parameters:
kwargs (ax, colors. The remaining kwargs are passed into the) – the LineCollection constructor.
- Returns:
lc
- Return type:
- property shape
- property top_botm
- property top_botm_withnan
Same as top_botm array but with NaN where idomain==0 both above and below a cell.
- property verts
- property xycenters
Return a list of two numpy one-dimensional float arrays for center x and y coordinates in model space - not offset or rotated.
- property xyedges
one with the cell edge x coordinate (size = ncol+1) and the other with the cell edge y coordinate (size = nrow+1) in model space - not offset or rotated.
- Type:
Return a list of two 1D numpy arrays
- property xyzcellcenters
two two-dimensional arrays for center x and y coordinates, and one three-dimensional array for center z coordinates. Coordinates are given in real-world coordinates.
- Type:
Return a list of three numpy float arrays
- property xyzvertices
Method to get all grid vertices in a layer
- Returns:
[] 2D array
- property zedges
Return zedges for (column, row)==(0, 0).
- property zverts_smooth
Get a unique z of cell vertices using bilinear interpolation of top and bottom elevation layers.
- Returns:
zverts – z of cell vertices. NaN values are assigned in accordance with inactive cells defined by idomain.
- Return type:
ndarray, shape (nlay+1, nrow+1, ncol+1)
- array_at_faces_1d(a, delta)[source]
Interpolate array at cell faces of a 1d grid using linear interpolation.
- Parameters:
a (1d ndarray) – Values at cell centers.
delta (1d ndarray) – Grid steps.
- Returns:
afaces – Array values interpolated at cell faces, shape as input extended by 1.
- Return type:
1d ndarray
- array_at_verts_basic2d(a)[source]
Computes values at cell vertices on 2d array using neighbor averaging.
- Parameters:
a (ndarray) – Array values at cell centers, could be a slice in any orientation.
- Returns:
averts – Array values at cell vertices, shape (a.shape[0]+1, a.shape[1]+1).
- Return type:
ndarray