flopy.utils.triangle module

class Triangle(model_ws='.', exe_name='triangle', maximum_area=None, angle=20.0, additional_args=None)[source]

Bases: object

Class to work with the triangle program to unstructured triangular grids. Information on the triangle program can be found at https://www.cs.cmu.edu/~quake/triangle.html

Parameters:
  • model_ws (str) – workspace location for creating triangle files (default is ‘.’)
  • exe_name (str) – path and name of the triangle program. (default is triangle, which means that the triangle program must be in your path)
  • maximum_area (float) – the maximum area for any triangle. The default value is None, which means that the user must specify maximum areas for each region.
  • angle (float) – Triangle will continue to add vertices until no angle is less than this specified value. (default is 20 degrees)
  • additional_args (list) – list of additional command line switches to pass to triangle
Returns:

Return type:

None

add_hole(hole)[source]

Add a point that will turn enclosing polygon into a hole

Parameters:hole (tuple) – (x, y)
Returns:
Return type:None
add_polygon(polygon)[source]

Add a polygon

Parameters:polygon (list, geojson, shapely.geometry, shapefile.Shape) –

add polygon method accepts any of these geometries:

a list of (x, y) points geojson Polygon object shapely Polygon object shapefile Polygon shape flopy.utils.geometry.Polygon object

Returns:
Return type:None
add_region(point, attribute=0, maximum_area=None)[source]

Add a point that will become a region with a maximum area, if specified.

Parameters:
  • point (tuple) – (x, y)
  • attribute (integer or float) – integer value assigned to output elements
  • maximum_area (float) – maximum area of elements in region
Returns:

Return type:

None

build(verbose=False)[source]

Build the triangular mesh

Parameters:verbose (bool) – If true, print the results of the triangle command to the terminal (default is False)
Returns:
Return type:None
clean()[source]

Remove the input and output files created by this class and by the Triangle program

Returns:
Return type:None
get_attribute_array()[source]

Return an array containing the attribute value for each cell. These are the attribute values that are passed into the add_region() method.

Returns:attribute_array
Return type:ndarray
get_boundary_marker_array()[source]

Get an integer array that has boundary markers

Returns:iedge – integer array of size ncpl containing a boundary ids. The array contains zeros for cells that do not touch a boundary. The boundary ids are the segment numbers for each segment in each polygon that is added with the add_polygon method.
Return type:ndarray
get_cell2d()[source]

Get a list of the information needed for the MODFLOW DISV Package.

Returns:cell2d – innermost list contains cell number, x, y, number of vertices, and then the vertex numbers comprising the cell.
Return type:list (of lists)
get_cell_edge_length(n, ibm)[source]

Get the length of the edge for cell n that corresponds to boundary marker ibm

Parameters:
  • n (int) – cell number. 0 <= n < self.ncpl
  • ibm (integer) – boundary marker number
Returns:

length – Length of the edge along that boundary marker. Will return None if cell n does not touch boundary marker.

Return type:

float

get_edge_cells(ibm)[source]

Get a list of cell numbers that correspond to the specified boundary marker.

Parameters:ibm (integer) – boundary marker value
Returns:cell_list – list of zero-based cell numbers
Return type:list
get_vertices()[source]

Get a list of vertices in the form needed for the MODFLOW DISV Package.

Returns:vertices – innermost list contains vertex number, x, and y
Return type:list (of lists)
get_xcyc()[source]

Get a 2-dimensional array of x and y cell center coordinates.

Returns:xcyc – column 0 contains the x coordinates and column 1 contains the y coordinates
Return type:ndarray
label_cells(ax=None, onebased=True, **kwargs)[source]

Label the cells with their cell numbers

Parameters:
  • ax (matplotlib.pyplot.Axes) – axis to add the plot to. (default is plt.gca())
  • onebased (bool) – Make the labels one-based if True so that they correspond to what would be written to MODFLOW.
  • kwargs (dictionary) – dictionary of arguments to pass to ax.text()
Returns:

Return type:

None

label_vertices(ax=None, onebased=True, **kwargs)[source]

Label the mesh vertices with their vertex numbers

Parameters:
  • ax (matplotlib.pyplot.Axes) – axis to add the plot to. (default is plt.gca())
  • onebased (bool) – Make the labels one-based if True so that they correspond to what would be written to MODFLOW.
  • kwargs (dictionary) – dictionary of arguments to pass to ax.text()
Returns:

Return type:

None

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:

Return type:

None

plot_boundary(ibm, ax=None, **kwargs)[source]

Plot a line and vertices for the specified boundary marker

Parameters:
  • ibm (integer) – plot the boundary for this boundary marker
  • ax (matplotlib.pyplot.Axes) – axis to add the plot to. (default is plt.gca())
  • kwargs (dictionary) – dictionary of arguments to pass to ax.plot()
Returns:

Return type:

None

plot_centroids(ax=None, **kwargs)[source]

Plot the cell centroids

Parameters:
  • ax (matplotlib.pyplot.Axes) – axis to add the plot to. (default is plt.gca())
  • kwargs (dictionary) – dictionary of arguments to pass to ax.plot()
Returns:

Return type:

None

plot_vertices(ax=None, **kwargs)[source]

Plot the mesh vertices

Parameters:
  • ax (matplotlib.pyplot.Axes) – axis to add the plot to. (default is plt.gca())
  • kwargs (dictionary) – dictionary of arguments to pass to ax.plot()
Returns:

Return type:

None