flopy.discretization.vertexgrid module

class VertexGrid(vertices=None, cell2d=None, top=None, botm=None, idomain=None, lenuni=None, crs=None, prjfile=None, xoff=0.0, yoff=0.0, angrot=0.0, nlay=None, ncpl=None, cell1d=None, **kwargs)[source]

Bases: Grid

class for a vertex model grid

Parameters:
  • vertices – list of vertices that make up the grid

  • cell2d – list of cells and their vertices

  • top (list or ndarray) – top elevations for all cells in the grid.

  • botm (list or ndarray) – bottom elevations for all cells in the grid.

  • idomain (int or ndarray) – ibound/idomain value for each cell

  • lenuni (int or ndarray) – model length units

  • crs (pyproj.CRS, int, str, 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

  • **kwargs (dict, optional) –

    Support deprecated keyword options.

    Deprecated since version 3.5: The following keyword options will be removed for FloPy 3.6:

    • prj (str or PathLike): use prjfile instead.

    • epsg (int): use crs instead.

    • proj4 (str): use crs instead.

  • Properties

  • ----------

  • vertices – returns list of vertices that make up the grid

  • cell2d – returns list of cells and their vertices

get_cell_vertices(cellid)[source]

returns vertices for a single cell at cellid.

property cell1d
property cell2d
convert_grid(factor)[source]

Method to scale the model grid based on user supplied scale factors

Parameters:

factor

Return type:

Grid object

property extent
classmethod from_binary_grid_file(file_path, verbose=False)[source]

Instantiate a VertexGrid model grid from a MODFLOW 6 binary grid (*.grb) file.

Parameters:
  • file_path (str) – file path for the MODFLOW 6 binary grid file

  • verbose (bool) – Write information to standard output. Default is False.

Returns:

return

Return type:

VertexGrid

property geo_dataframe

DEPRECATED – Use to_geodataframe() instead. Will be removed in 3.11

Returns a geopandas GeoDataFrame of the model grid

Return type:

GeoDataFrame

get_cell_vertices(cellid=None, node=None)[source]

Get a set of cell vertices for a single cell.

Parameters:
  • cellid (int or tuple, optional) – Cell identifier. Can be: - cell2d index (int, 0 to ncpl-1) - node number (int, >= ncpl) - will be converted to cell2d - (cell2d,) single-element tuple - (layer, cell2d) tuple (layer is ignored, vertices are 2D)

  • node (int, optional) – Node number, mutually exclusive with cellid

Returns:

list of (x, y) cell vertex coordinates

Return type:

list

Examples

>>> import flopy
>>> from flopy.utils.gridutil import get_disv_kwargs
>>> disv_props = get_disv_kwargs(1, 10, 10, 1.0, 1.0, 1.0, [0.0])
>>> vg = flopy.discretization.VertexGrid(**disv_props)
>>> vg.get_cell_vertices(5)  # cell2d index
>>> vg.get_cell_vertices((0, 5))  # (layer, cell2d) tuple
>>> vg.get_cell_vertices(node=105)  # node number
>>> vg.get_cell_vertices(cellid=(1, 5))  # explicit cellid kwarg
get_node(cellids, node2d=False)[source]

Get node number from a list of zero-based MODFLOW (layer, cell2d) tuples.

Parameters:
  • cellid_list (tuple of int or list of tuple of int) – Zero-based (layer, cell2d) tuples

  • node2d (bool, optional) – If True, return 2D node numbers (cell2d values). If False (default), return 3D node numbers.

Returns:

list of MODFLOW nodes for each (layer, cell2d) tuple in the input list

Return type:

list

Examples

>>> import flopy
>>> vg = flopy.discretization.VertexGrid(nlay=3, ncpl=100, ...)
>>> vg.get_node((0, 5))
[5]
>>> vg.get_node((1, 5))
[105]
>>> vg.get_node([(0, 5), (1, 5)], node2d=True)
[5, 5]
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:

int

get_plottable_layer_array(a, layer)[source]
get_xcellcenters_for_layer(layer)[source]
get_xvertices_for_layer(layer)[source]
get_ycellcenters_for_layer(layer)[source]
get_yvertices_for_layer(layer)[source]
grid_line_geodataframe()[source]

Method to get a GeoDataFrame of grid lines

Return type:

GeoDataFrame

property grid_lines

Creates a series of grid line vertices for drawing a model grid line collection

Returns:

grid line vertices

Return type:

list

intersect(x, y, z=None, local=False, forgive=False)[source]

Get the CELL2D number of a point with coordinates x and y

When the point is on the edge of two cells, the cell with the lowest CELL2D number is returned.

Supports both scalar and array inputs for vectorized operations.

Parameters:
  • x (float or array-like) – The x-coordinate(s) of the requested point(s)

  • y (float or array-like) – The y-coordinate(s) of the requested point(s)

  • z (float, array-like, or None) – optional, z-coordinate(s) of the requested point(s) will return (lay, icell2d)

  • 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:

  • icell2d (int or ndarray) – The CELL2D number(s). Returns int for scalar input, ndarray for array input.

  • lay (int or ndarray (only if z is provided)) – The layer number(s). Returns int for scalar input, ndarray for array input.

property is_complete
property is_valid
property iverts
property map_polygons

Get a list of matplotlib Polygon patches for plotting

Return type:

list of Polygon objects

property ncpl
property nlay
property nnodes
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:

matplotlib.collections.LineCollection

property shape
to_geodataframe()[source]

Returns a geopandas GeoDataFrame of the model grid

Return type:

GeoDataFrame

property top_botm
property verts
property xyzcellcenters

Method to get cell centers and set to grid

property xyzvertices

Method to get all grid vertices in a layer, arranged per cell

Returns:

list of size sum(nvertices per cell)