flopy.discretization.grid module

class CachedData(data)[source]

Bases: object

property data
property data_nocopy
update_data(data)[source]
class Grid(grid_type=None, top=None, botm=None, idomain=None, lenuni=None, crs=None, prjfile=None, xoff=0.0, yoff=0.0, angrot=0.0, **kwargs)[source]

Bases: object

Base class for a structured or unstructured model grid

Parameters:
  • grid_type (enumeration) – type of model grid (‘structured’, ‘vertex’, ‘unstructured’)

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

grid_type

type of model grid (‘structured’, ‘vertex’, ‘unstructured’)

Type:

enumeration

top

top elevations of cells in topmost layer

Type:

float or ndarray

botm

bottom elevations of all cells

Type:

float or ndarray

idomain

ibound/idomain value for each cell

Type:

int or ndarray

lenuni

modflow lenuni parameter

Type:

int

xoffset

x coordinate of the origin point in the spatial reference coordinate system

Type:

float

yoffset

y coordinate of the origin point in the spatial reference coordinate system

Type:

float

angrot

rotation angle of model grid, as it is rotated around the origin point

Type:

float

angrot_radians

rotation angle of model grid, in radians

Type:

float

xcenters

returns x coordinate of cell centers

Type:

ndarray

ycenters

returns y coordinate of cell centers

Type:

ndarray

ycenters

returns z coordinate of cell centers

Type:

ndarray

xyzcellcenters

returns the cell centers of all model cells in the model grid. if the model grid contains spatial reference information, the cell centers are in the coordinate system provided by the spatial reference information. otherwise the cell centers are based on a 0,0 location for the upper left corner of the model grid. returns a list of three ndarrays for the x, y, and z coordinates

Type:

[ndarray, ndarray, ndarray]

get_coords(x, y)[source]

transform point or array of points x, y from model coordinates to spatial coordinates

grid_lines : (point_type=PointType.spatialxyz) : list

returns the model grid lines in a list. each line is returned as a list containing two tuples in the format [(x1,y1), (x2,y2)] where x1,y1 and x2,y2 are the endpoints of the line.

Notes

Examples

property angrot
property angrot_radians
attribs_from_namfile_header(namefile)[source]
property botm
property cell_thickness

Get the cell thickness for a structured, vertex, or unstructured grid.

Returns:

thick

Return type:

calculated thickness

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 layer number

  • 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

  • zcenters (np.ndarray) – zcenters 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
property crs

Coordinate reference system (CRS) for the model grid.

If pyproj is not installed this property is always None; see epsg for an alternative CRS definition.

property epsg

EPSG integer code registered to a coordinate reference system.

This property is derived from crs if pyproj is installed, otherwise it preserved from the constructor.

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

Method returns a geopandas GeoDataFrame of the Grid

Return type:

GeoDataFrame

get_coords(x, y)[source]

Given x and y array-like values, apply rotation, scale and offset, to convert them from model coordinates to real-world coordinates.

get_lni(nodes)[source]

Get the layer index and within-layer node index (both 0-based) for the given nodes

Parameters:

nodes (node numbers (array-like)) –

Return type:

list of tuples (layer index, node index)

get_local_coords(x, y)[source]

Given x and y array-like values, apply rotation, scale and offset, to convert them from real-world coordinates to model coordinates.

get_number_plottable_layers(a)[source]
get_plottable_layer_array(plotarray, layer)[source]
get_plottable_layer_shape(layer=None)[source]

Determine the shape that is required in order to plot a 2d array for this grid. For a regular MODFLOW grid, this is (nrow, ncol). For a vertex grid, this is (ncpl,) and for an unstructured grid this is (ncpl[layer],).

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
property grid_type
property idomain
intersect(x, y, local=False, forgive=False)[source]
property is_complete
property is_valid
property iverts
property laycbd
property lenuni
load_coord_info(namefile=None, reffile='usgs.model.reference')[source]

Attempts to load spatial reference information from the following files (in order): 1) usgs.model.reference 2) NAM file (header comment) 3) defaults

property map_polygons
property ncpl
neighbors(node=None, **kwargs)[source]

Method to get nearest neighbors of a cell

Parameters:
  • node (int) – model grid node number

  • kwargs (**) –

    methodstr

    ”rook” for shared edge neighbors and “queen” for shared vertex neighbors

    resetbool

    flag to reset the neighbor calculation

Returns:

list or dict – neighbors

Return type:

list of cell node numbers or dict of all cells and

property nlay
property nnodes
property nvert
property prj
property prjfile

Path to a .prj file containing WKT for a coordinate reference system.

property proj4

PROJ string for a coordinate reference system.

This property is derived from crs if pyproj is installed, otherwise it preserved from the constructor.

read_usgs_model_reference_file(reffile='usgs.model.reference')[source]

read spatial reference info from the usgs.model.reference file https://water.usgs.gov/ogw/policy/gw-model/modelers-setup.html

remove_confining_beds(array)[source]

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

Return type:

np.ndarray

saturated_thick(array, mask=None)[source]

Raises AttributeError, use saturated_thickness().

saturated_thickness(array, mask=None)[source]

Get the saturated thickness for a structured, vertex, or unstructured grid. If the optional array is passed then thickness is returned relative to array values (saturated thickness). Returned values ranges from zero to cell thickness if optional array is passed.

Parameters:
  • array (ndarray) – array of elevations that will be used to adjust the cell thickness

  • mask (float, list, tuple, ndarray) – array values to replace with a nan value.

Returns:

thickness

Return type:

calculated saturated thickness

set_coord_info(xoff=None, yoff=None, angrot=None, crs=None, prjfile=None, merge_coord_info=True, **kwargs)[source]

Set coordinate information for a grid.

Parameters:
  • xoff (float, optional) – X and Y coordinate of the origin point in the spatial reference coordinate system.

  • yoff (float, optional) – X and Y coordinate of the origin point in the spatial reference coordinate system.

  • angrot (float, optional) – Rotation angle of model grid, as it is rotated around the origin point.

  • crs (pyproj.CRS, int, str, optional) – 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) – ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).

  • merge_coord_info (bool, default True) – If True, retaining previous properties. If False, overwrite properties with defaults, unless specified.

  • **kwargs (dict, optional) –

    Support deprecated keyword options.

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

    • epsg (int): use crs instead.

    • proj4 (str): use crs instead.

property shape
property size
property thick

Raises AttributeError, use cell_thickness().

property top
property top_botm
property units
property verts
write_shapefile(filename='grid.shp', crs=None, prjfile=None, **kwargs)[source]

Write a shapefile of the grid with just the row and column attributes.

property xcellcenters
property xoffset
property xvertices
property xyzcellcenters
property xyzextent
property xyzvertices
property ycellcenters
property yoffset
property yvertices
property zcellcenters
property zvertices