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

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=None)[source]

Patch for vertex cross-section plotting when we have an irregular shape type throughout the model grid or multiple shape types. This method is also used by the model splitter as a helper function for remapping the cell2d array.

Parameters:
  • xverts (list) – xvertices

  • yverts (list or None) – yvertices

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 calculate 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

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) –

filter_modpath_by_travel_time(recarray, travel_time)[source]

Helper method for filtering particles by travel time. Used in modpath plotting routines

Parameters:
  • recarray (np.recarray) – recarray of modpath particle information

  • travel_time (str, float) – travel time logical argument to filter modpath output

Return type:

np.recarray

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

parse_modpath_selection_options(ep, direction, selection, selection_direction)[source]
Returns:

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 or os.PathLike) – Path 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

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: str | PathLike, radius=500.0, idx=None)[source]

Create a patch collection from the shapes in a shapefile

Parameters:
  • shp (str or PathLike) – 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

to_mp7_endpoints(data: recarray | DataFrame) recarray | DataFrame[source]

Convert MODFLOW 6 PRT pathline data to MODPATH 7 endpoint format.

Parameters:

data (np.recarray or pd.DataFrame) – MODFLOW 6 PRT pathline data

Return type:

np.recarray or pd.DataFrame (consistent with input type)

to_mp7_pathlines(data: recarray | DataFrame) recarray | DataFrame[source]

Convert MODFLOW 6 PRT pathline data to MODPATH 7 pathline format.

Parameters:

data (np.recarray or pd.DataFrame) – MODFLOW 6 PRT pathline data

Return type:

np.recarray or pd.DataFrame (consistent with input type)

to_prt_pathlines(data: recarray | DataFrame) recarray | DataFrame[source]

Convert MODPATH 7 pathline or endpoint data to MODFLOW 6 PRT pathline format.

Parameters:

data (np.recarray or pd.DataFrame) – MODPATH 7 pathline or endpoint data

Return type:

np.recarray or pd.DataFrame (consistent with input type)