flopy.utils.gridgen module¶
- class Gridgen(dis, model_ws='.', exe_name='gridgen', surface_interpolation='replicate', vertical_pass_through=False, **kwargs)[source]¶
Bases:
object
Class to work with the gridgen program to create layered quadtree grids.
- Parameters
dis (flopy.modflow.ModflowDis) – Flopy discretization object
model_ws (str) – workspace location for creating gridgen files (default is ‘.’)
exe_name (str) – path and name of the gridgen program. (default is gridgen)
surface_interpolation (str) – Default gridgen method for interpolating elevations. Valid options include ‘replicate’ (default) and ‘interpolate’
vertical_pass_through (bool) – If true, Gridgen’s GRID_TO_USGDATA command will connect layers where intermediate layers are inactive. (default is False)
**kwargs –
- verical_smoothing_levelint
maximum level difference between two vertically adjacent cells. Adjust with caution, as adjustments can cause unexpected results to simulated flows
- horizontal_smoothing_levelint
maximum level difference between two horizontally adjacent cells. Adjust with caution, as adjustments can cause unexpected results to simulated flows
Notes
For the surface elevations, the top of a layer uses the same surface as the bottom of the overlying layer.
- add_active_domain(feature, layers)[source]¶
- Parameters
feature (str or list) –
- feature can be:
a string containing the name of a polygon a list of polygons flopy.utils.geometry.Collection object of Polygons shapely.geometry.Collection object of Polygons geojson.GeometryCollection object of Polygons list of shapefile.Shape objects shapefile.Shapes object
layers (list) – A list of layers (zero based) for which this active domain applies.
- Return type
None
- add_refinement_features(features, featuretype, level, layers)[source]¶
- Parameters
features (str, list, or collection object) –
- features can be
a string containing the name of a shapefile a list of points, lines, or polygons flopy.utils.geometry.Collection object a list of flopy.utils.geometry objects shapely.geometry.Collection object geojson.GeometryCollection object a list of shapefile.Shape objects shapefile.Shapes object
featuretype (str) – Must be either ‘point’, ‘line’, or ‘polygon’
level (int) – The level of refinement for this features
layers (list) – A list of layers (zero based) for which this refinement features applies.
- Return type
None
- build(verbose=False)[source]¶
Build the quadtree grid
- Parameters
verbose (bool) – If true, print the results of the gridgen command to the terminal (default is False)
- Return type
None
- export(verbose=False)[source]¶
Export the quadtree grid to shapefiles, usgdata, and vtk
- Parameters
verbose (bool) – If true, print the results of the gridgen command to the terminal (default is False)
- Return type
None
- get_angldegx(fldr=None)[source]¶
Get the angldegx array
- Parameters
fldr (ndarray) – Flow direction indicator array. If None, then it is read from gridgen output.
- Returns
angldegx – A 1D vector indicating the angle (in degrees) between the x axis and an outward normal to the face.
- Return type
ndarray
- get_area()[source]¶
Get the area array
- Returns
area – A 1D vector of cell areas of size nodes
- Return type
ndarray
- get_bot()[source]¶
Get the bot array
- Returns
bot – A 1D vector of cell bottom elevations of size nodes
- Return type
ndarray
- get_cellxy(ncells)[source]¶
- Parameters
ncells (int) – Number of cells for which to create the list of cell centers
- Returns
cellxy – x and y cell centers. Shape is (ncells, 2)
- Return type
ndarray
- get_center(nodenumber)[source]¶
Return the cell center x and y coordinates
- Parameters
nodenumber –
- Returns
(x, y)
- Return type
tuple
- get_cl12()[source]¶
Get the cl12 array
- Returns
cl12 – A 1D vector of the cell connection distances, which are from the center of cell n to its shared face will cell m
- Return type
ndarray
- get_disu(model, nper=1, perlen=1, nstp=1, tsmult=1, steady=True, itmuni=4, lenuni=2)[source]¶
Create a MODFLOW-USG DISU flopy object.
- Parameters
model (Flopy model object) – The Flopy model object (of type
flopy.modflow.mf.Modflow
) to which this package will be added.nper (int) – Number of model stress periods (default is 1).
perlen (float or array of floats (nper)) – A single value or array of the stress period lengths (default is 1).
nstp (int or array of ints (nper)) – Number of time steps in each stress period (default is 1).
tsmult (float or array of floats (nper)) – Time step multiplier (default is 1.0).
steady (boolean or array of boolean (nper)) – True or False indicating whether or not stress period is steady state (default is True).
itmuni (int) – Time units, default is days (4)
lenuni (int) – Length units, default is meters (2)
- Returns
disu
- Return type
Flopy ModflowDisU object.
- get_fahl()[source]¶
Get the fahl array
- Returns
fahl – A 1D vector of the cell connection information, which is flow area for a vertical connection and horizontal length for a horizontal connection
- Return type
ndarray
- get_fldr()[source]¶
Get the fldr array
- Returns
fldr – A 1D vector indicating the direction of the connection 1, 2, and 3 are plus x, y, and z directions. -1, -2, and -3 are negative x, y, and z directions.
- Return type
ndarray
- get_gridprops_disu5()[source]¶
Get a dictionary of information needed to create a MODFLOW-USG DISU Package. The returned dictionary can be unpacked directly into the ModflowDisU constructor. The ja dictionary entry will be returned as zero-based.
- Returns
gridprops
- Return type
dict
- get_gridprops_disu6(repair_asymmetry=True)[source]¶
Get a dictionary of information needed to create a MODFLOW 6 DISU Package. The returned dictionary can be unpacked directly into the ModflowGwfdisu constructor.
- Parameters
repair_asymmetry (bool) – MODFLOW 6 checks for symmetry in the hwva array, and round off errors in the floating point calculations can result in small errors. If this flag is true, then symmetry will be forced by setting the symmetric counterparts to the same value (the first one encountered).
- Returns
gridprops
- Return type
dict
- get_gridprops_disv()[source]¶
Get a dictionary of information needed to create a MODFLOW 6 DISV Package. The returned dictionary can be unpacked directly into the ModflowGwfdisv constructor.
- Returns
gridprops
- Return type
dict
- get_gridprops_unstructuredgrid()[source]¶
Get a dictionary of information needed to create a flopy UnstructuredGrid. The returned dictionary can be unpacked directly into the flopy.discretization.UnstructuredGrid() constructor.
- Returns
gridprops
- Return type
dict
- get_gridprops_vertexgrid()[source]¶
Get a dictionary of information needed to create a flopy VertexGrid. The returned dictionary can be unpacked directly into the flopy.discretization.VertexGrid() constructor.
- Returns
gridprops
- Return type
dict
- get_hwva(ja=None, ihc=None, fahl=None, top=None, bot=None)[source]¶
Get the hwva array
- Parameters
ja (ndarray) – Cell connectivity. If None, it will be read from gridgen output.
ihc (ndarray) – Connection horizontal indicator array. If None it will be read and calculated from gridgen output.
fahl (ndarray) – Flow area, horizontal width array required by MODFLOW-USG. If none then it will be read from the gridgen output. Default is None.
top (ndarray) – Cell top elevation. If None, it will be read from gridgen output.
bot (ndarray) – Cell bottom elevation. If None, it will be read from gridgen output.
- Returns
fahl – A 1D vector of the cell connection information, which is flow area for a vertical connection and horizontal length for a horizontal connection
- Return type
ndarray
- get_iac()[source]¶
Get the iac array
- Returns
iac – A 1D vector of the number of connections (plus 1) for each cell
- Return type
ndarray
- get_ihc(nodelay=None, ia=None, fldr=None)[source]¶
Get the ihc array
- Parameters
fldr (ndarray) – Flow direction indicator array. If None, then it is read from gridgen output.
- Returns
ihc – A 1D vector indicating the direction of the connection where 0 is vertical, 1 is a regular horizontal connection and 2 is a vertically staggered horizontal connection.
- Return type
ndarray
- get_ivc(fldr=None)[source]¶
Get the MODFLOW-USG ivc array
- Parameters
fldr (ndarray) – Flow direction indicator array. If None, then it is read from gridgen output.
- Returns
ivc – A 1D vector indicating the direction of the connection where 1 is vertical and 0 is horizontal.
- Return type
ndarray
- get_ja(nja=None)[source]¶
Get the zero-based ja array
- Parameters
nja (int) – Number of connections. If None, then it is read from gridgen output.
- Returns
ja – A 1D vector of the cell connectivity (one-based)
- Return type
ndarray
- get_nod_recarray()[source]¶
Load the qtg.nod file and return as a numpy recarray
- Returns
node_ra – Recarray representation of the node file with zero-based indexing
- Return type
ndarray
- get_nodelay()[source]¶
Return the nodelay array, which is an array of size nlay containing the number of nodes in each layer.
- Returns
nodelay – Number of nodes in each layer
- Return type
ndarray
- get_top()[source]¶
Get the top array
- Returns
top – A 1D vector of cell top elevations of size nodes
- Return type
ndarray
- get_vertices(nodenumber)[source]¶
Return a list of 5 vertices for the cell. The first vertex should be the same as the last vertex.
- Parameters
nodenumber –
- Returns
list of vertices
- Return type
list
- get_verts_iverts(ncells, verbose=False)[source]¶
Return a 2d array of x and y vertices and a list of size ncells that has the list of vertices for each cell.
- Parameters
ncells (int) – The number of entries in iverts. This should be ncpl for a layered model and nodes for a disu model.
verbose (bool) – Print information as its working
- Returns
verts, iverts – verts is a 2d array of x and y vertex pairs (nvert, 2) and iverts is a list of vertices that comprise each cell
- Return type
tuple
- intersect(features, featuretype, layer)[source]¶
- Parameters
features (str or list) – features can be either a string containing the name of a shapefile or it can be a list of points, lines, or polygons
featuretype (str) – Must be either ‘point’, ‘line’, or ‘polygon’
layer (int) – Layer (zero based) to intersect with. Zero based.
- Returns
result – Recarray of the intersection properties.
- Return type
np.recarray
- plot(ax=None, layer=0, edgecolor='k', facecolor='none', cmap='Dark2', a=None, masked_values=None, **kwargs)[source]¶
Plot the grid. This method will plot the grid using the shapefile that was created as part of the build method.
Note that the layer option is not working yet.
- Parameters
ax (matplotlib.pyplot axis) – The plot axis. If not provided it, plt.gca() will be used. If there is not a current axis then a new one will be created.
layer (int) – Layer number to plot
cmap (string) – Name of colormap to use for polygon shading (default is ‘Dark2’)
edgecolor (string) – Color name. (Default is ‘scaled’ to scale the edge colors.)
facecolor (string) – Color name. (Default is ‘scaled’ to scale the face colors.)
a (numpy.ndarray) – Array to plot.
masked_values (iterable of floats, ints) – Values to mask.
kwargs (dictionary) – Keyword arguments that are passed to PatchCollection.set(
**kwargs
). Some common kwargs would be ‘linewidths’, ‘linestyles’, ‘alpha’, etc.
- Returns
pc
- Return type
matplotlib.collections.PatchCollection
- set_surface_interpolation(isurf, type, elev=None, elev_extent=None)[source]¶
- Parameters
isurf (int) – surface number where 0 is top and nlay + 1 is bottom
type (str) – Must be ‘INTERPOLATE’, ‘REPLICATE’ or ‘ASCIIGRID’.
elev (numpy.ndarray of shape (nr, nc) or str) – Array that is used as an asciigrid. If elev is a string, then it is assumed to be the name of the asciigrid.
elev_extent (list-like) – List of xmin, xmax, ymin, ymax extents of the elev grid. Must be specified for ASCIIGRID; optional otherwise.
- Return type
None
- features_to_shapefile(features, featuretype, filename)[source]¶
Write a shapefile for the features of type featuretype.
- Parameters
features (list) –
point, line, or polygon features. Method accepts feature can be:
a list of geometries flopy.utils.geometry.Collection object shapely.geometry.Collection object geojson.GeometryCollection object list of shapefile.Shape objects shapefile.Shapes object
featuretype (str) – Must be ‘point’, ‘line’, ‘linestring’, or ‘polygon’
filename (string) – name of the shapefile to write
- Return type
None