Skip to content

tile module

Module to re-organize FLDPLN segment-based library into tile-based library for fast mapping.

CalculateFspSegmentDownstreamDistance(libFolder)

Cleanup segments (some segments don't exist in FSPs) and save library FSP and segment information as two csv files (fsp_info.csv & segment_info.csv). It reads in the SpatialReference.prj and save it in CellSizeSpatialReference.json. For stage interpolation, it also calculates FSP and segment downstream distance (i.e., distance to library outlet(s)) which involves:

1
2
3
4
1. Calculate FSP's within-segment downstream distance
2. Calculate segment length which is more accurate than "CellCount" * cell size
3. Calculate segment's downstream distance (to watershed outlet) for speeding up 
4. Calculate FSP's downstream distance

Note that FSPs and segments are based on raster cell centers. Segment and its downstream segment has a gap (1 cell or sqrt(2) cell).

Parameters:

Name Type Description Default
libFolder str

folder containing the tiled library.

required

Returns:

Type Description
tuple

FSP data frame. segment data frame.

CalculateLibraryExtent(segLibFolder, cellSize)

Calculate library external border extent. Also calculate segment extents (FPP cell center) and save them in a data frame.

Parameters:

Name Type Description Default
segLibFolder str

folder containing the segment-based library.

required
cellSize float

cell size in meters.

required

Returns:

Type Description
tuple

external border extent (minX, maxX,minY, maxY), data frame of segment extent of ['MinX','MaxX','MinY','MaxY','FileName'] defined by FPP cell center.

CalculateTileBoundary(minX, maxX, minY, maxY, tileSizeX, tileSizeY, padding=True)

Calculate each tile's boundary as (minX, maxX,minY, maxY).

Parameters:

Name Type Description Default
minX float

min x of the external border (not the cell center) coordinates of the area needs to be tiled.

required
maxX float

max x of the external border (not the cell center) coordinates of the area needs to be tiled.

required
minY float

min y of the external border (not the cell center) coordinates of the area needs to be tiled.

required
maxY float

max y of the external border (not the cell center) coordinates of the area needs to be tiled.

required
tileSizeX float

tile external border size (not the cell center size) in x axis.

required
tileSizeY float

tile external border size (not the cell center size) in y axis.

required
padding bool

whether the tiles have the same size and not reduced to the border of the tiled area. Default is True.

True

Returns:

Type Description
list

list of tile boundaries of (minX, maxX,minY, maxY)

GenerateSegmentShapefilesFromFspSegmentInfoFiles(segInfoFile, fspInfoFile, crs, outShpFile)

Generate segment shapefiles from FSP and segment info files.

Parameters:

Name Type Description Default
segInfoFile str

segment info file.

required
fspInfoFile str

FSP info file.

required
crs str

coordinate reference system.

required
outShpFile str

output shapefile.

required

GetStreamOrdersForFspsSegments(libFolder, strOrdShpFile, shpSegIdName, shpStrOrdColName)

Get stream order for FSPs and segments from segment stream order shapefile and save them in fsp_info.csv and segment_info.csv files. It also creates file stream_order_info.csv which stores the network info at the level of stream orders for FSP DOF interpolation.

Parameters:

Name Type Description Default
libFolder str

library folder.

required
strOrdShpFile str

stream order shapefile.

required
shpSegIdName str

segment ID column name in the shapefile.

required
shpStrOrdColName str

stream order column name in the shapefile.

required

Returns:

Type Description
tuple

FSP data frame, segment data frame, stream order network data frame.

ReadMatFile(matFile, varName)

Read matlab files with different versions. scipy.io DOES NOT support MATLAB files version 7.3 yet! Some of the libraries are in 7.3 while the others are not.

Parameters:

Name Type Description Default
matFile str

matlab file name.

required
varName str

variable name in the matlab file.

required

Returns:

Type Description
data frame

variable matrix in the matlab file.

TileLibrary(segLibFolder, cellSize, tiledLibFolder, tileSize, fileFormat)

Tile a library. Turn segment-based FSP-FPP relations to tile-based. Note that 'snappy' format needs to install the 'fastparquet' python package

Parameters:

Name Type Description Default
segLibFolder str

folder containing the segment-based library.

required
cellSize float

cell size in meters.

required
tiledLibFolder str

folder for the tiled library.

required
tileSize int

number of cells in a tile.

required
fileFormat str

'snappy' or 'mat'.

required

Returns:

Type Description
dict

metadata of the tiled library