The iotools API

pygridtools.iotools.read_boundary(gisfile, betacol='beta', reachcol=None, sortcol=None, upperleftcol=None, filterfxn=None)[source]

Loads boundary points from a GIS File.

Parameters:
gisfile : string

Path to the GIS file containaing boundary points. Expected schema of the file…

  • order: numeric sort order of the points
  • beta: the ‘beta’ parameter used in grid generation to define turning points
betacol : string (default=’beta’)

Column in the attribute table specifying the beta parameter’s value at each point.

sortcol : optional string or None (default)

Column in the attribute table specifying the sort order of the points.

reachcol : optional string or None (default)

Column in the attribute table specifying the names of the reaches of the river/esturary system.

upperleftcol : optional string or None (default)

Column in the attribute table toggling if the a point should be consider the upper-left corner of the system. Only one row of this column should evaluare to True.

filterfxn : function or lambda expression or None (default)

Removed. Use the query method of the result.

Returns:
gdf : geopandas.GeoDataFrame

A GeoDataFrame of the boundary points with the following columns:

  • x (easting)
  • y (northing)
  • beta (turning parameter)
  • order (for sorting)
  • reach
  • upperleft
pygridtools.iotools.read_polygons(gisfile, filterfxn=None, squeeze=True, as_gdf=False)[source]

Load polygons (e.g., water bodies, islands) from a GIS file.

Parameters:
gisfile : string

Path to the gisfile containaing boundary points.

filterfxn : function or lambda expression or None (default)

Removed. Use the as_gdf and the query method of the resulting GeoDataFrame.

squeeze : optional bool (default = True)

Set to True to return an array if only 1 record is present. Otherwise, a list of arrays will be returned.

as_gdf : optional bool (default = False)

Set to True to return a GeoDataFrame instead of arrays.

Returns:
boundary : array or list of arrays, or GeoDataFrame

Notes

Multipart geometries are not supported. If a multipart geometry is present in a record, only the first part will be loaded.

Z-coordinates are also not supported. Only x-y coordinates will be loaded.

pygridtools.iotools.read_grid(gisfile, icol='ii', jcol='jj', othercols=None, expand=1, as_gdf=False)[source]
pygridtools.iotools.interactive_grid_shape(grid, max_n=200, plotfxn=None, **kwargs)[source]

Interactive ipywidgets for select the shape of a grid

Parameters:
grid : pygridgen.Gridgen

The base grid from which the grids of new shapes (resolutions) will be generated.

max_n : int (default = 200)

The maximum number of possible cells in each dimension.

plotfxn : callable, optional

Function that plots the grid to provide user feedback. The call signature of this function must accept to positional parameters for the x- and y-arrays of node locations, and then accept any remaining keyword arguments. If not provided, pygridtools.viz.plot_cells is used.

Returns:
newgrid : pygridgen.Gridgen

The reshaped grid

widget : ipywidgets.interactive

Collection of IntSliders for changing the number cells along each axis in the grid.

Examples

>>> from pygridgen import grid
>>> from pygridtools import viz, iotools
>>> def make_fake_bathy(shape):
...     j_cells, i_cells = shape
...     y, x = numpy.mgrid[:j_cells, :i_cells]
...     z = (y - (j_cells // 2))** 2 - x
...     return z
>>> def plot_grid(x, y, ax=None):
...     shape = x[1:, 1:].shape
...     bathy = make_fake_bathy(shape)
...     if not ax:
...         fig, ax = pyplot.subplots(figsize=(8, 8))
...     ax.set_aspect('equal')
...     return viz.plot_cells(x, y, ax=ax, cmap='Blues', colors=bathy, lw=0.5, ec='0.3')
>>> d = numpy.array([
... (13, 16,  1.00), (18, 13,  1.00), (12,  7,  0.50),
... (10, 10, -0.25), ( 5, 10, -0.25), ( 5,  0,  1.00),
... ( 0,  0,  1.00), ( 0, 15,  0.50), ( 8, 15, -0.25),
... (11, 13, -0.25)])
>>> g = grid.Gridgen(d[:, 0], d[:, 1], d[:, 2], (75, 75), ul_idx=1, focus=None)
>>> new_grid, widget = iotools.interactive_grid_shape(g, plotfxn=plot_grid)
pygridtools.iotools.interactive_grid_focus(g, n_points, plotfxn=None, **kwargs)[source]

Interactive ipywidgets for changing focus points.

Parameters:
grid : pygridgen.Gridgen

The base grid from which the grids of new focus points will be generated.

n_points : int

The number of focal points to add to the grid.

plotfxn : callable, optional

Function that plots the grid to provide user feedback. The call signature of this function must accept to positional parameters for the x- and y-arrays of node locations, and then accept any remaining keyword arguments. If not provided, pygridtools.viz.plot_points is used.

Returns:
newgrid : pygridgen.Gridgen

The reshaped grid

widget : ipywidgets.interactive

Collection of Tab / IntSliders for changing the number focus points along each axis in the grid.

Examples

>>> from pygridgen import grid
>>> from pygridtools import viz, iotools
>>> d = numpy.array([
... (13, 16,  1.00), (18, 13,  1.00), (12,  7,  0.50),
... (10, 10, -0.25), ( 5, 10, -0.25), ( 5,  0,  1.00),
... ( 0,  0,  1.00), ( 0, 15,  0.50), ( 8, 15, -0.25),
... (11, 13, -0.25)])
>>> g = grid.Gridgen(d[:, 0], d[:, 1], d[:, 2], (75, 75), ul_idx=1, focus=None)
>>> n = 4 # number of focus objects
>>> new_grid, widget = iotools.interactive_grid_focus(g, n)