The Grid Module

Module for working with model grids. For examples of how to easily set up a StructuredGrid instance, see Basic usage of SFRmaker in a scripting context.

class sfrmaker.grid.Grid(df, model_units='undefined', crs_units=None, bounds=None, crs=None, prjfile=None, **kwargs)[source]

Bases: object

Base class for model grids. Has methods and attributes that are common to both Structured and Unstructured Grids. Not meant to be called directly.

property active_area

Shapely Polygon delinating area where SFR will be simulated.

property bounds
create_active_area_polygon_from_isfr()[source]

The StructuredGrid and UnstructuredGrid classes have their own ways of doing this.

get_node(k, i, j)[source]
property lenuni
property size
property spatial_index

Rtree index for intersecting features with model grid.

units_dict = {'feet': 1, 'meters': 2, 0: 'undefined'}
write_active_area_shapefile(outshp='active_area.shp')[source]
write_grid_shapefile(outshp='grid.shp')[source]
class sfrmaker.grid.StructuredGrid(df, xul=None, yul=None, dx=None, dy=None, rotation=0.0, uniform=None, model_units='undefined', crs_units=None, bounds=None, active_area=None, crs=None, prjfile=None, **kwargs)[source]

Bases: Grid

Class representing a model grid that has a row/column structure.

Parameters:
dfDataFrame

Pandas DataFrame that is the primary container for information about the model grid. Must have the following columns:

k

int

model layer (zero-based)

i

int

model row (zero-based)

j

int

model column (zero-based)

isfr

int

flag indicating whether the cell can have SFR reaches (0=False, 1=True)

geometry

obj

shapely Polygons of model cells

xulfloat, optional

Upper left corner of the grid x-coordinate. Only used for creating the transform attribute, by default None

yul[type], optional

Upper left corner of the grid y-coordinate. Only used for creating the transform attribute, by default None

dxfloat, optional

Uniform spacing in the x-direction (if the grid is uniform), Only used for creating the transform attribute, by default None

dyfloat, optional

Uniform spacing in the x-direction (if the grid is uniform), Only used for creating the transform attribute, by default None

rotationfloat, optional

Grid rotation angle in degrees, counter-clockwise about the origin, by default 0. Only used for creating the transform attribute, by default None

uniformbool, optional

Optional flag indicating the grid is uniform, by default None

model_unitsstr, optional, {‘meters’, ‘feet’, ..}

Model length units, by default ‘undefined’

crs_unitsstr, optional, {‘meters’, ‘feet’, ..}

Coordinate reference system length. Usually these are read from the CRS information below, by default None

boundstuple, optional

(left, bottom, top, right) edges of the grid bounding box, if known. Otherwise, the bounds attribute is computed from the shapely Polygons in the Grid DataFrame attribute. by default None

active_areashapely Polygon, list of Polygons, or shapefile path, optional

Polygon defining the active portion of the model grid. Polygons must be in same CRS as linework; shapefile features will be reprojected if their crs is different. by default None, in which case the entire grid is assumed to be active.

crsobj, optional

Coordinate reference object for df. Can be any of: - PROJ string - Dictionary of PROJ parameters - PROJ keyword arguments for parameters - JSON string with PROJ parameters - CRS WKT string - An authority string [i.e. ‘epsg:4326’] - An EPSG integer code [i.e. 4326] - A tuple of (“auth_name”: “auth_code”) [i.e (‘epsg’, ‘4326’)] - An object with a to_wkt method. - A pyproj.crs.CRS class

prjfile: str, optional

ESRI-style projection file with coordinate reference information for df.

create_active_area_polygon_from_isfr()[source]

Convert 2D numpy array representing active area where SFR will be simulated (isfr) to a polygon (if multiple polygons area created, the largest one by area is retained).

classmethod from_dataframe(df=None, uniform=None, kcol='k', icol='i', jcol='j', isfr_col='isfr', geometry_column='geometry', active_area=None, crs=None, prjfile=None, **kwargs)[source]
classmethod from_json(jsonfile, active_area=None, isfr=None, crs=None, prjfile=None, **kwargs)[source]
classmethod from_modelgrid(mg=None, active_area=None, isfr=None, crs=None, prjfile=None)[source]

Create StructureGrid class instance from a flopy.discretization.StructuredGrid instance.

classmethod from_shapefile(shapefile=None, node_col='node', kcol='k', icol='i', jcol='j', isfr_col='isfr', active_area=None, crs=None, prjfile=None, **kwargs)[source]
classmethod from_sr(**kwargs)[source]
property isfr
property transform

Rasterio-style affine transform object. https://www.perrygeo.com/python-affine-transforms.html

property uniform

Check if cells are uniform by comparing their areas.

class sfrmaker.grid.UnstructuredGrid(df, model_units='undefined', crs_units=None, bounds=None, active_area=None, crs=None, prjfile=None, **kwargs)[source]

Bases: Grid

Class representing an unstructured model grid.

create_active_area_polygon_from_isfr()[source]

Create active area polygon from union of cells where isfr=1.

classmethod from_dataframe(df=None, node_col='node', isfr_col='isfr', geometry_column='geometry', model_units='feet', active_area=None, crs=None, prjfile=None, **kwargs)[source]