flopy.utils.reference Module

Module spatial referencing for flopy model objects

class flopy.utils.reference.SpatialReference(delr=array([], dtype=float64), delc=array([], dtype=float64), lenuni=1, xul=None, yul=None, xll=None, yll=None, rotation=0.0, proj4_str='EPSG:4326', epsg=None, units=None, length_multiplier=1.0)

a class to locate a structured model grid in x-y space

Parameters:

delr : numpy ndarray

the model discretization delr vector (An array of spacings along a row)

delc : numpy ndarray

the model discretization delc vector (An array of spacings along a column)

lenuni : int

the length units flag from the discretization package

xul : float

the x coordinate of the upper left corner of the grid Enter either xul and yul or xll and yll.

yul : float

the y coordinate of the upper left corner of the grid Enter either xul and yul or xll and yll.

xll : float

the x coordinate of the lower left corner of the grid Enter either xul and yul or xll and yll.

yll : float

the y coordinate of the lower left corner of the grid Enter either xul and yul or xll and yll.

rotation : float

the counter-clockwise rotation (in degrees) of the grid

proj4_str: str

a PROJ4 string that identifies the grid in space. warning: case sensitive!

units : string

Units for the grid. Must be either feet or meters

epsg : int

EPSG code that identifies the grid in space. Can be used in lieu of proj4. PROJ4 attribute will auto-populate if there is an internet connection(via get_proj4 method). See https://www.epsg-registry.org/ or spatialreference.org

length_multiplier : float

multiplier to convert model units to spatial reference units. delr and delc above will be multiplied by this value. (default=1.)

Notes

xul and yul can be explicitly (re)set after SpatialReference instantiation, but only before any of the other attributes and methods are accessed

Attributes

vertices Returns a list of vertices for
xedge (ndarray) array of column edges
yedge (ndarray) array of row edges
xgrid (ndarray) numpy meshgrid of xedges
ygrid (ndarray) numpy meshgrid of yedges
xcenter (ndarray) array of column centers
ycenter (ndarray) array of row centers
xcentergrid (ndarray) numpy meshgrid of column centers
ycentergrid (ndarray) numpy meshgrid of row centers
bounds

Return bounding box in shapely order.

contour_array(ax, a, **kwargs)

Create a QuadMesh plot of the specified array using pcolormesh

Parameters:

ax : matplotlib.axes.Axes

ax to add the contours

a : np.ndarray

array to contour

Returns:

contour_set : ContourSet

get_extent()

Get the extent of the rotated and offset grid

Return (xmin, xmax, ymin, ymax)

get_grid_line_collection(**kwargs)

Get a LineCollection of the grid

get_grid_lines()

Get the grid lines as a list

get_grid_map_plotter()

Create a QuadMesh plotting object for this grid

Returns:quadmesh : matplotlib.collections.QuadMesh
get_rc(x, y)

Return the row and column of a point or sequence of points in real-world coordinates.

Parameters:

x : scalar or sequence of x coordinates

y : scalar or sequence of y coordinates

Returns:

r : row or sequence of rows (zero-based)

c : column or sequence of columns (zero-based)

get_xcenter_array()

Return a numpy one-dimensional float array that has the cell center x coordinate for every column in the grid in model space - not offset or rotated.

get_xedge_array()

Return a numpy one-dimensional float array that has the cell edge x coordinates for every column in the grid in model space - not offset or rotated. Array is of size (ncol + 1)

get_ycenter_array()

Return a numpy one-dimensional float array that has the cell center x coordinate for every row in the grid in model space - not offset of rotated.

get_yedge_array()

Return a numpy one-dimensional float array that has the cell edge y coordinates for every row in the grid in model space - not offset or rotated. Array is of size (nrow + 1)

interpolate(a, xi, method='nearest')

Use the griddata method to interpolate values from an array onto the points defined in xi. For any values outside of the grid, use ‘nearest’ to find a value for them.

Parameters:

a : numpy.ndarray

array to interpolate from. It must be of size nrow, ncol

xi : numpy.ndarray

array containing x and y point coordinates of size (npts, 2). xi also works with broadcasting so that if a is a 2d array, then xi can be passed in as (xgrid, ygrid).

method : {‘linear’, ‘nearest’, ‘cubic’}

method to use for interpolation (default is ‘nearest’)

Returns:

b : numpy.ndarray

array of size (npts)

plot_array(a, ax=None)

Create a QuadMesh plot of the specified array using pcolormesh

Parameters:a : np.ndarray
Returns:quadmesh : matplotlib.collections.QuadMesh
static rotate(x, y, theta, xorigin=0.0, yorigin=0.0)

Given x and y array-like values calculate the rotation about an arbitrary origin and then return the rotated coordinates. theta is in degrees.

set_spatialreference(xul=None, yul=None, xll=None, yll=None, rotation=0.0, length_multiplier=1.0)

set spatial reference - can be called from model instance

transform(x, y)

Given x and y array-like values, apply rotation, scale and offset, to convert them from model coordinates to real-world coordinates.

vertices

Returns a list of vertices for

write_gridSpec(filename)

write a PEST-style grid specification file

write_shapefile(filename='grid.shp', epsg=None, prj=None)

Write a shapefile of the grid with just the row and column attributes

class flopy.utils.reference.SpatialReferenceUnstructured(xc, yc, verts, iverts, ncpl, layered=True, lenuni=1, proj4_str='EPSG:4326', epsg=None, units=None, length_multiplier=1.0)

a class to locate an unstructured model grid in x-y space

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

ncpl : ndarray

array containing the number of cells per layer. ncpl.sum() must be equal to the total number of cells in the grid.

layered : boolean

flag to indicated that the grid is layered. In this case, the vertices define the grid for single layer, and all layers use this same grid. In this case the ncpl value for each layer must equal len(iverts). If not layered, then verts and iverts are specified for all cells and all layers in the grid. In this case, npcl.sum() must equal len(iverts).

lenuni : int

the length units flag from the discretization package

proj4_str: str

a PROJ4 string that identifies the grid in space. warning: case sensitive!

units : string

Units for the grid. Must be either feet or meters

epsg : int

EPSG code that identifies the grid in space. Can be used in lieu of proj4. PROJ4 attribute will auto-populate if there is an internet connection(via get_proj4 method). See https://www.epsg-registry.org/ or spatialreference.org

length_multiplier : float

multiplier to convert model units to spatial reference units. delr and delc above will be multiplied by this value. (default=1.)

Attributes

xcenter (ndarray) array of x cell centers
ycenter (ndarray) array of y cell centers
bounds

Return bounding box in shapely order.

contour_array(ax, a, **kwargs)

Create a QuadMesh plot of the specified array using pcolormesh

Parameters:

ax : matplotlib.axes.Axes

ax to add the contours

a : np.ndarray

array to contour

Returns:

contour_set : ContourSet

classmethod from_argus_export(fname, nlay=1)

Create a new SpatialReferenceUnstructured grid from an Argus One Trimesh file

Parameters:

fname : string

File name

nlay : int

Number of layers to create

Returns:

sru : flopy.utils.reference.SpatialReferenceUnstructured

classmethod from_gridspec(fname)

Create a new SpatialReferenceUnstructured grid from an PEST grid specification file

Parameters:

fname : string

File name for grid specification file

Returns:

sru : flopy.utils.reference.SpatialReferenceUnstructured

get_extent()

Get the extent of the grid

Returns:

extent : tuple

min and max grid coordinates

get_grid_line_collection(**kwargs)

Get a patch collection of the grid

get_grid_lines()

Get the grid lines as a list

get_grid_map_plotter()

Create a QuadMesh plotting object for this grid

Returns:quadmesh : matplotlib.collections.QuadMesh
get_rc(x, y)

Return the row and column of a point or sequence of points in real-world coordinates.

Parameters:

x : scalar or sequence of x coordinates

y : scalar or sequence of y coordinates

Returns:

r : row or sequence of rows (zero-based)

c : column or sequence of columns (zero-based)

get_xcenter_array()

Return a numpy one-dimensional float array that has the cell center x coordinate for every cell in the grid in model space - not offset or rotated.

get_xedge_array()

Return a numpy one-dimensional float array that has the cell edge x coordinates for every column in the grid in model space - not offset or rotated. Array is of size (ncol + 1)

get_ycenter_array()

Return a numpy one-dimensional float array that has the cell center x coordinate for every cell in the grid in model space - not offset of rotated.

get_yedge_array()

Return a numpy one-dimensional float array that has the cell edge y coordinates for every row in the grid in model space - not offset or rotated. Array is of size (nrow + 1)

interpolate(a, xi, method='nearest')

Use the griddata method to interpolate values from an array onto the points defined in xi. For any values outside of the grid, use ‘nearest’ to find a value for them.

Parameters:

a : numpy.ndarray

array to interpolate from. It must be of size nrow, ncol

xi : numpy.ndarray

array containing x and y point coordinates of size (npts, 2). xi also works with broadcasting so that if a is a 2d array, then xi can be passed in as (xgrid, ygrid).

method : {‘linear’, ‘nearest’, ‘cubic’}

method to use for interpolation (default is ‘nearest’)

Returns:

b : numpy.ndarray

array of size (npts)

plot_array(a, ax=None)

Create a QuadMesh plot of the specified array using patches

Parameters:a : np.ndarray
Returns:quadmesh : matplotlib.collections.QuadMesh
rotate(x, y, theta, xorigin=0.0, yorigin=0.0)

Given x and y array-like values calculate the rotation about an arbitrary origin and then return the rotated coordinates. theta is in degrees.

set_spatialreference(xul=None, yul=None, xll=None, yll=None, rotation=0.0, length_multiplier=1.0)

set spatial reference - can be called from model instance

transform(x, y)

Given x and y array-like values, apply rotation, scale and offset, to convert them from model coordinates to real-world coordinates.

vertices

Returns a list of vertices for

write_gridSpec(filename)

Write a PEST-style grid specification file

Parameters:

filename : string

filename for grid specification file

write_shapefile(filename='grid.shp')

Write shapefile of the grid

Parameters:

filename : string

filename for shapefile

class flopy.utils.reference.epsgRef

Sets up a local database of projection file text referenced by epsg code. The database is located in the site packages folder in epsgref.py, which contains a dictionary, prj, of projection file text keyed by epsg value.

add(epsg, prj)

add an epsg code to epsgref.py

remove(epsg)

removes an epsg entry from epsgref.py

flopy.utils.reference.get_spatialreference(epsg, text='esriwkt')

Gets text for given epsg code and text format from spatialreference.org Fetches the reference text using the url:

See: https://www.epsg-registry.org/

Parameters:

epsg : int

epsg code for coordinate system

text : str

string added to url

Returns:

url : str

flopy.utils.reference.getprj(epsg, addlocalreference=True, text='esriwkt')

Gets projection file (.prj) text for given epsg code from spatialreference.org See: https://www.epsg-registry.org/

Parameters:

epsg : int

epsg code for coordinate system

addlocalreference : boolean

adds the projection file text associated with epsg to a local database, epsgref.py, located in site-packages.

Returns:

prj : str

text for a projection (*.prj) file.

flopy.utils.reference.getproj4(epsg)

Gets projection file (.prj) text for given epsg code from spatialreference.org. See: https://www.epsg-registry.org/

Parameters:

epsg : int

epsg code for coordinate system

Returns:

prj : str

text for a projection (*.prj) file.