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, reverse=False)[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) –
-
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
-
filter_modpath_by_travel_time
(recarray, travel_time)[source]¶ Parameters: - recarray –
- travel_time –
Returns:
-
intersect_modpath_with_crosssection
(recarrays, projpts, xvertices, yvertices, projection, ncpl, method='cell', starting=False)[source]¶ Method to intersect modpath output with a cross-section
Parameters: - recarrays (list) – list of numpy recarrays
- projpts (dict) – dict of crossectional cell vertices
- xvertices (np.array) – array of modelgrid xvertices
- yvertices (np.array) – array of modelgrid yvertices
- projection (str) – projection direction (x or y)
- ncpl (int) – number of cells per layer (cross sectional version)
- method (str) – intersection method (‘cell’ or ‘all’)
- starting (bool) – modpath starting location flag
Returns: dict
Return type: dictionary of intersecting recarrays
-
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
-
reproject_modpath_to_crosssection
(idict, projpts, xypts, projection, modelgrid, ncpl, geographic_coords, starting=False)[source]¶ Method to reproject modpath points onto cross sectional line
Parameters: - idict (dict) – dictionary of intersecting points
- projpts (dict) – dictionary of cross sectional cells
- xypts (dict) – dictionary of cross sectional line
- projection (str) – projection direction (x or y)
- modelgrid (Grid object) – flopy modelgrid object
- ncpl (int) – number of cells per layer (cross sectional version)
- geographic_coords (bool) – flag for plotting in geographic coordinates
- starting (bool) – flag for modpath position
Returns: Return type: dictionary of projected modpath lines or points
-
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