FlwdirRaster#

FlwdirRaster(idxs_ds, shape, ftype[, ...])

Flow-direction raster parsed into a common actionable format.

Input/Output#

from_array(data[, ftype, check_ftype, mask, ...])

Parse a flow-direction raster into the actionable FlwDirRaster format.

from_dem(data[, nodata, max_depth, ...])

Derive local D8 flow directions from digital elevation data.

FlwdirRaster.to_array([ftype])

Return 2D flow direction raster.

FlwdirRaster.load(fn)

Load serialized FlwdirRaster object from file

FlwdirRaster.dump(fn)

Serialize the flow-direction graph to a file using pickle.

Flow direction attributes#

The following attributes describe the flow direction and are at the core to the object.

FlwdirRaster.idxs_ds

Linear indices of downstream cell.

FlwdirRaster.idxs_us_main

Linear indices of main upstream cell, i.e. the upstream cell with the largest contributing area.

FlwdirRaster.idxs_seq

Linear indices of valid cells ordered from down- to upstream.

FlwdirRaster.idxs_pit

Linear indices of pits/outlets.

FlwdirRaster.ncells

Number of valid cells in the flow-direction raster.

FlwdirRaster.nnodes

Number of valid cells.

FlwdirRaster.rank

Cell Rank, i.e. distance to the outlet in no.

FlwdirRaster.isvalid

True if the flow direction map is valid.

FlwdirRaster.mask

Boolean array of valid cells in flow direction raster.

FlwdirRaster.area

Cell area [m2].

FlwdirRaster.distnc

Distance to outlet [m]

FlwdirRaster.n_upstream

Number of immediate upstream connections for each node.

Flow direction methods#

FlwdirRaster.order_cells([method])

Order cells from down- to upstream.

FlwdirRaster.main_upstream([uparea])

Return the main upstream node for each node.

FlwdirRaster.add_pits([idxs, xy, streams])

Add pits to the flow-direction raster.

FlwdirRaster.repair_loops()

Repair loops by setting a pit at every cell which does not drain to a pit.

FlwdirRaster.vectorize([mask, xs, ys, direction])

Return each selected flow path as a LineString feature.

Raster & geospatial attributes and methods#

The FlwdirRaster object contains FlwdirRaster.shape, FlwdirRaster.transform and FlwdirRaster.latlon attributes describing its geospatial location. The first attribute is required at initializiation, while the others can be set later.

FlwdirRaster.set_transform(transform[, latlon])

Set the affine transform and coordinate-system type.

FlwdirRaster.index(xs, ys, **kwargs)

Returns linear cell indices based on x, y coordinates.

FlwdirRaster.xy(idxs, **kwargs)

Returns x, y coordinates of the cell center based on linear cell indices.

FlwdirRaster.bounds

Returns the raster bounding box [xmin, ymin, xmax, ymax].

FlwdirRaster.extent

Returns the raster extent in cartopy format [xmin, xmax, ymin, ymax].

Streams and flow paths#

FlwdirRaster.stream_order([type, mask])

Return the Strahler (default) or classic stream-order map.

FlwdirRaster.path([idxs, xy, mask, ...])

Trace paths downstream or upstream from starting cells.

FlwdirRaster.snap([idxs, xy, mask, ...])

Snap starting cells to a downstream or upstream target.

FlwdirRaster.outflow_idxs(region)

Return linear indices of the most downstream cells within a region.

FlwdirRaster.inflow_idxs(region)

Return linear indices of the most upstream cells within a region.

FlwdirRaster.stream_distance([mask, unit])

Return the distance to the outlet or the next downstream True cell in mask.

FlwdirRaster.streams([mask, min_sto, xs, ...])

Return stream segments as LineString geographic features.

FlwdirRaster.geofeatures(flowpaths[, xs, ys])

Return geographic features for flow paths represented by linear indices.

(Sub)basins#

FlwdirRaster.basins([idxs, xy, ids])

Return a basin map with a unique ID for each basin.

FlwdirRaster.subbasins(riv_mask)

Return a subbasin map with unique IDs starting from 1.

FlwdirRaster.subbasins_streamorder([strord, ...])

Return subbasins defined by stream-order changes and their outlet indices.

FlwdirRaster.subbasins_pfafstetter([depth, ...])

Return subbasins using the Pfafstetter coding system.

FlwdirRaster.subbasins_area(area_min[, uparea])

Return subbasins with a minimum contributing area of area_min.

FlwdirRaster.basin_outlets(basins)

Return basin IDs and the linear index of each outlet cell.

FlwdirRaster.basin_bounds([basins])

Return the bounding boxes of basins.

FlwdirRaster.interbasin_mask(region[, stream])

Return a mask for the most downstream contiguous area within a region.

Up- and downstream values#

FlwdirRaster.downstream(data)

Return the next downstream node's value for each node.

FlwdirRaster.upstream_sum(data[, mv])

Return the sum of values at each node's immediate upstream neighbors.

Up- and downstream arithmetics#

FlwdirRaster.accuflux(data[, nodata, direction])

Return accumulated data values along the flow directions.

FlwdirRaster.upstream_area([unit])

Return the upstream-area raster for the flow directions.

FlwdirRaster.moving_average(data, n[, ...])

Take the moving weighted average over the flow direction network

FlwdirRaster.moving_median(data, n[, ...])

Take the moving median over the flow direction network

FlwdirRaster.smooth_rivlen(rivlen, min_rivlen)

Return smoothed river length, by taking the window average of river length.

FlwdirRaster.fillnodata(data, nodata[, ...])

Fill no-data nodes with values from valid upstream or downstream neighbors.

Upscale and subgrid methods#

FlwdirRaster.upscale(scale_factor[, method, ...])

Upscale a flow-direction network to a lower resolution.

FlwdirRaster.upscale_error(other, idxs_out)

Return an error map for the upscaled flow directions.

FlwdirRaster.subgrid_rivlen(idxs_out[, ...])

Returns the subgrid river length [m] based on unit catchment outlet locations.

FlwdirRaster.subgrid_rivslp(idxs_out, elevtn)

Return the subgrid river slope [m/m] estimated at unit-catchment outlets.

FlwdirRaster.subgrid_rivavg(idxs_out, data)

Return the average value over the subgrid river at unit-catchment outlets.

FlwdirRaster.subgrid_rivmed(idxs_out, data)

Return the median value over the subgrid river at unit-catchment outlets.

FlwdirRaster.ucat_area(idxs_out[, unit])

Return the high-resolution unit-catchment map and low-resolution cell areas.

FlwdirRaster.ucat_volume(idxs_out, hand[, ...])

Return the high-resolution unit-catchment map and flood volumes by depth.

FlwdirRaster.ucat_outlets(cellsize[, ...])

Return linear indices of unit-catchment outlet pixels.

Elevation#

FlwdirRaster.dem_adjust(elevtn)

Returns the hydrologically adjusted elevation where each downstream cell has the same or lower elevation as the current cell.

FlwdirRaster.dem_dig_d4(elevtn[, rivmsk, nodata])

Return elevation adjusted to satisfy D4 connectivity along river cells.

FlwdirRaster.hand(drain, elevtn)

Return the height above the nearest drain (HAND).

FlwdirRaster.floodplains(elevtn[, uparea, ...])

Identify floodplain cells using an upstream-area-scaled HAND threshold.