FlwdirRaster#

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

Flow direction raster array parsed to general actionable format.

Input/Output#

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

Flow direction raster array parsed to actionable format.

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

Flow direction raster derived from digital elevation data based on steepest gradient.

FlwdirRaster.to_array([ftype])

Return 2D flow direction raster.

FlwdirRaster.load(fn)

Load serialized FlwdirRaster object from file

FlwdirRaster.dump(fn)

Serialize object to file using pickle library.

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

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 [m]

FlwdirRaster.distnc

Distance to outlet [m]

FlwdirRaster.n_upstream

Number of upstream connection

Flow direction methods#

FlwdirRaster.order_cells([method])

Order cells from down- to upstream.

FlwdirRaster.main_upstream([uparea])

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

Add pits 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])

Returns each flow direction as a linestring geo-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 transform affine.

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])

Returns the Strahler (default) or classic stream order map.

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

Returns paths of indices in down- or upstream direction from the starting points until: 1) a pit is found (including) or now more upstream cells are found; or 2) a True cell is found in mask (including); or 3) the max_length threshold is exceeded.

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

Returns the last index in down- or upstream direction from the starting points where:

FlwdirRaster.outflow_idxs(region)

Returns linear indices of most downstream cells within region

FlwdirRaster.inflow_idxs(region)

Returns linear indices of most upstream cells within region

FlwdirRaster.stream_distance([mask, unit])

Returns distance to outlet or next downstream True cell in mask

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

Returns a list of stream segment as linestring geo-features.

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

Returns a geo-features of flowpaths defined by a list of arrays of linear indices.

(Sub)basins#

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

Returns a (sub)basin map with a unique ID for every (sub)basin.

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

Returns a subbasin map with unique IDs and its outlet linear indices.

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

Returns the pfafstetter subbasins.

FlwdirRaster.subbasins_area(area_min[, uparea])

Returns map with basin IDs, with a minimal area of area_min.

FlwdirRaster.basin_outlets(basins)

Returns the linear index of the outlet cell of basins.

FlwdirRaster.basin_bounds([basins])

Returns a the basin boundaries.

Up- and downstream values#

FlwdirRaster.downstream(data)

Returns next downstream value.

FlwdirRaster.upstream_sum(data[, mv])

Returns sum of next upstream values.

Up- and downstream arithmetics#

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

Return accumulated data values along the flow directions.

FlwdirRaster.upstream_area([unit])

Returns the upstream area map based on the flow direction map.

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[, ...])

Returns data where cells with nodata value have been filled with the nearest up- or downstream valid neighbor value.

Upscale and subgrid methods#

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

Upscale flow direction network to lower resolution.

FlwdirRaster.upscale_error(other, idxs_out)

Returns an array with ones (True) where the upscaled flow directions are valid and zeros (False) where erroneous.

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

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

FlwdirRaster.subgrid_rivslp(idxs_out, elevtn)

Returns the subgrid river slope [m/m] estimated at unit catchment outlet pixel.

FlwdirRaster.subgrid_rivavg(idxs_out, data)

Returns the average value over the subgrid river, based on unit catchment outlet locations.

FlwdirRaster.subgrid_rivmed(idxs_out, data)

Returns the median value over the subgrid river, based on unit catchment outlet locations.

FlwdirRaster.ucat_area(idxs_out[, unit])

Returns the unit catchment map (highres) and area (lowres) [m2].

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

Returns linear indices of unit catchment outlet pixel.

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])

Returns the hydrologically adjusted elevation where for each cell river cell there is an adjacent D4 connected cell which has has the same or lower elevation as the current cell.

FlwdirRaster.hand(drain, elevtn)

Returns the height above the nearest drain (HAND), i.e.: the relative vertical distance (drop) to the nearest dowstream river based on drainage-normalized topography and flowpaths.

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

Returns floodplain boundaries based on a maximum treshold (h) of HAND which is scaled with upstream area (A) following h ~ A**b.