flopy.plot.plotutil module¶
Module containing helper functions for plotting model data using ModelMap and ModelCrossSection. Functions for plotting shapefiles are also included.
-
class
PlotUtilities
[source]¶ Bases:
object
Class which groups a collection of plotting utilities which Flopy and Flopy6 can use to generate map based plots
-
static
centered_specific_discharge
(Qx, Qy, Qz, delr, delc, sat_thk)[source]¶ DEPRECATED. Use postprocessing.get_specific_discharge() instead.
Using the MODFLOW discharge, calculate the cell centered specific discharge by dividing by the flow width and then averaging to the cell center.
Parameters: - Qx (numpy.ndarray) – MODFLOW ‘flow right face’
- Qy (numpy.ndarray) – MODFLOW ‘flow front face’. The sign on this array will be flipped by this function so that the y axis is positive to north.
- Qz (numpy.ndarray) – MODFLOW ‘flow lower face’. The sign on this array will be flipped by this function so that the z axis is positive in the upward direction.
- delr (numpy.ndarray) – MODFLOW delr array
- delc (numpy.ndarray) – MODFLOW delc array
- sat_thk (numpy.ndarray) – Saturated thickness for each cell
Returns: (qx, qy, qz) – Specific discharge arrays that have been interpolated to cell centers.
Return type: tuple of numpy.ndarrays
-
static
saturated_thickness
(head, top, botm, laytyp, mask_values=None)[source]¶ Calculate the saturated thickness.
Parameters: - head (numpy.ndarray) – head array
- top (numpy.ndarray) – top array of shape (nrow, ncol)
- botm (numpy.ndarray) – botm array of shape (nlay, nrow, ncol)
- laytyp (numpy.ndarray) – confined (0) or convertible (1) of shape (nlay)
- mask_values (list of floats) – If head is one of these values, then set sat to top - bot
Returns: sat_thk – Saturated thickness of shape (nlay, nrow, ncol).
Return type: numpy.ndarray
-
static
-
class
SwiConcentration
(model=None, botm=None, istrat=1, nu=None)[source]¶ Bases:
object
The binary_header class is a class to create headers for MODFLOW binary files
-
calc_conc
(zeta, layer=None)[source]¶ Calculate concentrations for a given time step using passed zeta.
Parameters: - zeta (dictionary of numpy arrays) – Dictionary of zeta results. zeta keys are zero-based zeta surfaces.
- layer (int) – Concentration will be calculated for the specified layer. If layer is None, then the concentration will be calculated for all layers. (default is None).
Returns: conc – Calculated concentration.
Return type: numpy array
Examples
>>> import flopy >>> m = flopy.modflow.Modflow.load('test') >>> c = flopy.plot.SwiConcentration(model=m) >>> conc = c.calc_conc(z, layer=0)
-
-
class
UnstructuredPlotUtilities
[source]¶ Bases:
object
Collection of unstructured grid and vertex grid compatible plotting helper functions
-
static
arctan2
(verts)[source]¶ Reads 2 dimensional set of verts and orders them using the arctan 2 method
Parameters: verts (np.array of floats) – Nx2 array of verts Returns: verts – Nx2 array of verts Return type: np.array of float
-
static
irregular_shape_patch
(xverts, yverts)[source]¶ Patch for vertex cross section plotting when we have an irregular shape type throughout the model grid or multiple shape types.
Parameters: - xverts (list) – xvertices
- yverts (list) – yvertices
Returns: Return type: xverts, yverts as np.ndarray
-
static
line_intersect_grid
(ptsin, xgrid, ygrid)[source]¶ Uses cross product method to find which cells intersect with the line and then uses the parameterized line equation to caluculate intersection x, y vertex points. Should be quite fast for large model grids!
Parameters: - pts (list) – list of tuple line vertex pairs (ex. [(1, 0), (10, 0)]
- xgrid (np.array) – model grid x vertices
- ygrid (np.array) – model grid y vertices
Returns: vdict
Return type: dict of cell vertices
-
static
-
advanced_package_bc_helper
(pkg, modelgrid, kper)[source]¶ Helper function for plotting boundary conditions from “advanced” packages
Parameters: - pkg (flopy Package objects) –
- modelgrid (flopy.discretization.Grid object) –
-
cell_value_points
(pts, xedge, yedge, vdata)[source]¶ Intersect a list of polyline vertices with a rectilinear MODFLOW grid. Vertices at the intersection of the polyline with the grid cell edges is returned. Optionally the original polyline vertices are returned.
Parameters: - pts (list) – A list of x, y points and polyline length to extract defining the vertices of a polyline that
- xedge (numpy.ndarray) – x-coordinate of the edge of each MODFLOW column. The shape of xedge is (NCOL + 1). If xedge is not a numpy.ndarray it is converted to a numpy.ndarray.
- yedge (numpy.ndarray) – y-coordinate of the edge of each MODFLOW row. The shape of yedge is (NROW + 1). If yedge is not a numpy.ndarray it is converted to a numpy.ndarray.
- vdata (numpy.ndarray) – Data (i.e., head, hk, etc.) for a rectilinear MODFLOW model grid. The shape of vdata is (NROW, NCOL). If vdata is not a numpy.ndarray it is converted to a numpy.ndarray.
Returns: vcell – numpy.ndarray of of data values from the vdata numpy.ndarray at x- and y-coordinate locations in pts.
Return type: numpy.ndarray
Examples
>>> import flopy >>> vcell = flopy.plotutil.cell_value_points(xpts, xedge, yedge, head[0, :, :])
-
cvfd_to_patch_collection
(verts, iverts)[source]¶ Create a patch collection from control volume vertices and incidence list
Parameters: - verts (ndarray) – 2d array of x and y points.
- iverts (list of lists) – should be of len(ncells) with a list of vertex numbers for each cell
-
findrowcolumn
(pt, xedge, yedge)[source]¶ Find the MODFLOW cell containing the x- and y- point provided.
Parameters: - pt (list or tuple) – A list or tuple containing a x- and y- coordinate
- xedge (numpy.ndarray) – x-coordinate of the edge of each MODFLOW column. xedge is dimensioned to NCOL + 1. If xedge is not a numpy.ndarray it is converted to a numpy.ndarray.
- yedge (numpy.ndarray) – y-coordinate of the edge of each MODFLOW row. yedge is dimensioned to NROW + 1. If yedge is not a numpy.ndarray it is converted to a numpy.ndarray.
Returns: irow, jcol – Row and column location containing x- and y- point passed to function.
Return type: int
Examples
>>> import flopy >>> irow, jcol = flopy.plotutil.findrowcolumn(pt, xedge, yedge)
-
line_intersect_grid
(ptsin, xedge, yedge, returnvertices=False)[source]¶ Intersect a list of polyline vertices with a rectilinear MODFLOW grid. Vertices at the intersection of the polyline with the grid cell edges is returned. Optionally the original polyline vertices are returned.
Parameters: - ptsin (list) – A list of x, y points defining the vertices of a polyline that will be intersected with the rectilinear MODFLOW grid
- xedge (numpy.ndarray) – x-coordinate of the edge of each MODFLOW column. xedge is dimensioned to NCOL + 1. If xedge is not a numpy.ndarray it is converted to a numpy.ndarray.
- yedge (numpy.ndarray) – y-coordinate of the edge of each MODFLOW row. yedge is dimensioned to NROW + 1. If yedge is not a numpy.ndarray it is converted to a numpy.ndarray.
- returnvertices (bool) – Return the original polyline vertices in the list of numpy.ndarray containing vertices resulting from intersection of the provided polygon and the MODFLOW model grid if returnvertices=True. (default is False).
Returns: (x, y, dlen) – numpy.ndarray of tuples containing the x, y, and segment length of the intersection of the provided polyline with the rectilinear MODFLOW grid.
Return type: numpy.ndarray of tuples
Examples
>>> import flopy >>> ptsout = flopy.plotutil.line_intersect_grid(ptsin, xedge, yedge)
-
plot_cvfd
(verts, iverts, ax=None, layer=0, cmap='Dark2', edgecolor='scaled', facecolor='scaled', a=None, masked_values=None, **kwargs)[source]¶ Generic function for plotting a control volume finite difference grid of information.
Parameters: - verts (ndarray) – 2d array of x and y points.
- iverts (list of lists) – should be of len(ncells) with a list of vertex number for each cell
- ax (matplotlib.pylot axis) – matplotlib.pyplot axis instance. Default is None
- layer (int) – layer to extract. Used in combination to the optional ncpl parameter. Default is 0
- 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
Examples
-
plot_shapefile
(shp, ax=None, radius=500.0, cmap='Dark2', edgecolor='scaled', facecolor='scaled', a=None, masked_values=None, idx=None, **kwargs)[source]¶ Generic function for plotting a shapefile.
Parameters: - shp (string) – Name of the shapefile to plot.
- ax (matplolib.pyplot.axes object) –
- radius (float) – Radius of circle for points. (Default is 500.)
- 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.
- idx (iterable int) – A list or array that contains shape numbers to include in the patch collection. Return all shapes if not specified.
- 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
Examples
-
shapefile_extents
(shp)[source]¶ Determine the extents of a shapefile
Parameters: shp (string) – Name of the shapefile to convert to a PatchCollection. Returns: extents – tuple with xmin, xmax, ymin, ymax from shapefile. Return type: tuple Examples
>>> import flopy >>> fshp = 'myshapefile' >>> extent = flopy.plot.plotutil.shapefile_extents(fshp)
-
shapefile_get_vertices
(shp)[source]¶ Get vertices for the features in a shapefile
Parameters: shp (string) – Name of the shapefile to extract shapefile feature vertices. Returns: vertices – Vertices is a list with vertices for each feature in the shapefile. Individual feature vertices are x, y tuples and contained in a list. A list with a single x, y tuple is returned for point shapefiles. A list with multiple x, y tuples is returned for polyline and polygon shapefiles. Return type: list Examples
>>> import flopy >>> fshp = 'myshapefile' >>> lines = flopy.plot.plotutil.shapefile_get_vertices(fshp)
-
shapefile_to_patch_collection
(shp, radius=500.0, idx=None)[source]¶ Create a patch collection from the shapes in a shapefile
Parameters: - shp (string) – Name of the shapefile to convert to a PatchCollection.
- radius (float) – Radius of circle for points in the shapefile. (Default is 500.)
- idx (iterable int) – A list or array that contains shape numbers to include in the patch collection. Return all shapes if not specified.
Returns: pc – Patch collection of shapes in the shapefile
Return type: matplotlib.collections.PatchCollection