flopy.discretization.unstructuredgrid module

class UnstructuredGrid(vertices=None, iverts=None, xcenters=None, ycenters=None, top=None, botm=None, idomain=None, lenuni=None, ncpl=None, crs=None, prjfile=None, xoff=0.0, yoff=0.0, angrot=0.0, iac=None, ja=None, **kwargs)[source]

Bases: Grid

Class for an unstructured model grid

Parameters:
  • vertices (list) – list of vertices that make up the grid. Each vertex consists of three entries [iv, xv, yv] which are the vertex number, which should be zero-based, and the x and y vertex coordinates.

  • iverts (list) – list of vertex numbers that comprise each cell. This list must be of size nodes, if the grid_varies_by_nodes argument is true, or it must be of size ncpl[0] if the same 2d spatial grid is used for each layer.

  • xcenters (list or ndarray) – list of x center coordinates for all cells in the grid if the grid varies by layer or for all cells in a layer if the same grid is used for all layers

  • ycenters (list or ndarray) – list of y center coordinates for all cells in the grid if the grid varies by layer or for all cells in a layer if the same grid is used for all layers

  • 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

  • ncpl (ndarray) – one dimensional array of size nlay with the number of cells in each layer. This can also be passed in as a tuple or list as long as it can be set using ncpl = np.array(ncpl, dtype=int). The sum of ncpl must be equal to the number of cells in the grid. ncpl is optional and if it is not passed in, then it is is set using ncpl = np.array([len(iverts)], dtype=int), which means that all cells in the grid are contained in a single plottable layer. If the model grid defined in verts and iverts applies for all model layers, then the length of iverts can be equal to ncpl[0] and there is no need to repeat all of the vertex information for cells in layers

  • 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). beneath the top layer.

  • 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

  • iac (list or ndarray) – optional number of connections per node array

  • ja (list or ndarray) – optional jagged connection array

  • **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.

Notes

This class handles spatial representation of unstructured grids. It is based on the concept of being able to support multiple model layers that may have a different number of cells in each layer. The array ncpl is of size nlay and and its sum must equal nodes. If the length of iverts is equal to ncpl[0] and the number of cells per layer is the same for each layer, then it is assumed that the grid does not vary by layer. In this case, the xcenters and ycenters arrays must also be of size ncpl[0]. This makes it possible to efficiently store spatial grid information for multiple layers.

If the spatial grid is different for each model layer, then the grid_varies_by_layer flag will automatically be set to false, and iverts must be of size nodes. The arrays for xcenters and ycenters must also be of size nodes.

convert_grid(factor)[source]

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

Parameters:

factor

Return type:

Grid object

cross_section_adjust_indicies(k, cbcnt)[source]

Method to get adjusted indices by layer and confining bed for PlotCrossSection plotting

Parameters:
  • k (int) – zero based model layer

  • cbcnt (int) – confining bed counter

Returns:

  • tuple ((int, int, int) (adjusted layer, nodeskip layer, node)

  • adjustment value based on number of confining beds and the layer)

cross_section_lay_ncpl_ncb(ncb)[source]

Get PlotCrossSection compatible layers, ncpl, and ncb variables

Parameters:

ncb (int) – number of confining beds

Returns:

tuple

Return type:

(int, int, int) layers, ncpl, ncb

cross_section_nodeskip(nlay, xypts)[source]

Get a nodeskip list for PlotCrossSection. This is a correction for UnstructuredGridPlotting

Parameters:
  • nlay (int) – nlay is nlay + ncb

  • xypts (dict) – dictionary of node number and xyvertices of a cross-section

Returns:

list

Return type:

n-dimensional list of nodes to not plot for each layer

cross_section_set_contour_arrays(plotarray, xcenters, head, elev, projpts)[source]

Method to set contour array centers for rare instances where matplotlib contouring is preferred over trimesh plotting

Parameters:
  • plotarray (np.ndarray) – array of data for contouring

  • xcenters (np.ndarray) – xcenters array

  • head (np.ndarray) – head array to adjust cell centers location

  • elev (np.ndarray) – cell elevation array

  • projpts (dict) – dictionary of projected cross sectional vertices

Returns:

  • tuple ((np.ndarray, np.ndarray, np.ndarray, bool))

  • plotarray, xcenter array, ycenter array, and a boolean flag

  • for contouring

property cross_section_vertices

Method to get vertices for cross-sectional plotting

Return type:

xvertices, yvertices

property extent
classmethod from_argus_export(file_path, nlay=1)[source]

Create a new UnstructuredGrid from an Argus One Trimesh file

Parameters:
  • file_path (Path-like) – Path to trimesh file

  • nlay (int) – Number of layers to create

Return type:

An UnstructuredGrid

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

Instantiate a UnstructuredGrid 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:

UnstructuredGrid

classmethod from_gridspec(file_path: str | PathLike)[source]

Create an UnstructuredGrid from a grid specification file.

Parameters:

file_path (str or PathLike) – Path to the grid specification file

Return type:

An UnstructuredGrid

property geo_dataframe

Returns a geopandas GeoDataFrame of the model grid

Return type:

GeoDataFrame

get_cell_vertices(cellid)[source]
Method to get a set of cell vertices for a single cell

used in the Shapefile export utilities

Parameters:

cellid – (int) cellid number

Returns ——- list of x,y cell vertices

get_layer_node_range(layer)[source]
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_plottable_layer_shape(layer=None)[source]

Determine the shape that is required in order to plot in 2d for this grid.

Parameters:

layer (int) – Has no effect unless grid changes by layer

Returns:

shape – required shape of array to plot for a layer

Return type:

tuple

get_xcellcenters_for_layer(layer)[source]
get_xvertices_for_layer(layer)[source]
get_ycellcenters_for_layer(layer)[source]
get_yvertices_for_layer(layer)[source]
property grid_lines

Creates a series of grid line vertices for drawing a model grid line collection. If the grid varies by layer, then return a dictionary with keys equal to layers and values equal to grid lines. Otherwise, just return the grid lines

Returns:

grid lines or dictionary of lines by layer

Return type:

dict

property grid_varies_by_layer
property iac
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.

Parameters:
  • x (float) – The x-coordinate of the requested point

  • y (float) – The y-coordinate of the requested point

  • z (float, None) – optional, z-coordiante of the requested point

  • 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 – The CELL2D number

Return type:

int

property is_complete
property is_valid
property iverts
property ja
property map_polygons

Property to get Matplotlib polygon objects for the modelgrid

Return type:

list or dict of matplotlib.collections.Polygon

property ncpl
static ncpl_from_ihc(ihc, iac)[source]

Use the ihc and iac arrays to calculate the number of cells per layer array (ncpl) assuming that the plottable layer number is stored in the diagonal position of the ihc array.

Parameters:
  • ihc (ndarray) – horizontal indicator array. If the plottable layer number is stored in the diagonal position, then this will be used to create the returned ncpl array. plottable layer numbers must increase monotonically and be consecutive with node number

  • iac (ndarray) – array of size nodes that has the number of connections for a cell, plus one for the cell itself

Returns:

ncpl – number of cells per plottable layer

Return type:

ndarray

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

set_ncpl(ncpl)[source]
property shape
property top_botm
property verts
property xyzcellcenters

Method to get cell centers and set to grid

property xyzvertices

Method to get model grid vertices

Returns:

list of dimension ncpl by nvertices