pyflwdir.FlwdirRaster#

class pyflwdir.FlwdirRaster(idxs_ds, shape, ftype, idxs_pit=None, idxs_outlet=None, idxs_seq=None, nnodes=None, transform=Affine(1.0, 0.0, 0.0, 0.0, -1.0, 0.0), latlon=False, cache=True)[source]#

Flow direction raster array parsed to general actionable format.

Flow direction raster array

Parameters:
  • idxs_ds (1D-array of int) – linear index of next downstream cell

  • shape (tuple of int) – shape of raster

  • ftype ({'d8', 'ldd', 'nextxy'}) – name of flow direction type

  • idxs_pit (2D array of int, optional) – linear indices of all pits/outlets, outlets exclude pits of incomplete basins at the domain boundary

  • idxs_outlet (2D array of int, optional) – linear indices of all pits/outlets, outlets exclude pits of incomplete basins at the domain boundary

  • idxs_seq (2D array of int, optional) – linear indices of valid cells ordered from down- to upstream

  • nnodes (integer) – number of valid cells

  • transform (affine transform) – Two dimensional affine transform for 2D linear mapping, by default using the identity transform.

  • latlon (bool, optional) – True if WGS84 coordinate reference system, by default False. If True it converts the cell areas from degree to metres, otherwise it assumes cell areas are in unit metres.

__init__(idxs_ds, shape, ftype, idxs_pit=None, idxs_outlet=None, idxs_seq=None, nnodes=None, transform=Affine(1.0, 0.0, 0.0, 0.0, -1.0, 0.0), latlon=False, cache=True)[source]#

Flow direction raster array

Parameters:
  • idxs_ds (1D-array of int) – linear index of next downstream cell

  • shape (tuple of int) – shape of raster

  • ftype ({'d8', 'ldd', 'nextxy'}) – name of flow direction type

  • idxs_pit (2D array of int, optional) – linear indices of all pits/outlets, outlets exclude pits of incomplete basins at the domain boundary

  • idxs_outlet (2D array of int, optional) – linear indices of all pits/outlets, outlets exclude pits of incomplete basins at the domain boundary

  • idxs_seq (2D array of int, optional) – linear indices of valid cells ordered from down- to upstream

  • nnodes (integer) – number of valid cells

  • transform (affine transform) – Two dimensional affine transform for 2D linear mapping, by default using the identity transform.

  • latlon (bool, optional) – True if WGS84 coordinate reference system, by default False. If True it converts the cell areas from degree to metres, otherwise it assumes cell areas are in unit metres.

Methods

__init__(idxs_ds, shape, ftype[, idxs_pit, ...])

Flow direction raster array

accuflux(data[, nodata, direction])

Return accumulated data values along the flow directions.

add_pits([idxs, xy, streams])

Add pits the flow direction raster.

basin_bounds([basins])

Returns a the basin boundaries.

basin_outlets(basins)

Returns the linear index of the outlet cell of basins.

basins([idxs, xy, ids])

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

classify_estuaries(elevtn, rivwth[, rivdst, ...])

Classifies estuaries based on a minimum width convergence.

dem_adjust(elevtn)

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

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.

downstream(data)

Returns next downstream value.

dump(fn)

Serialize object to file using pickle library.

fillnodata(data, nodata[, direction, how])

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

floodplains(elevtn[, uparea, upa_min, b])

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

geofeatures(flowpaths[, xs, ys])

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

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.

index(xs, ys, **kwargs)

Returns linear cell indices based on x, y coordinates.

inflow_idxs(region)

Returns linear indices of most upstream cells within region

interbasin_mask(region[, stream])

Returns most downstream contiguous area within region, i.e.: if a stream flows in and out of the region, only the most downstream contiguous area within region will be True in output mask.

load(fn)

Load serialized FlwdirRaster object from file

main_upstream([uparea])

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

Take the moving weighted average over the flow direction network

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

Take the moving median over the flow direction network

order_cells([method])

Order cells from down- to upstream.

outflow_idxs(region)

Returns linear indices of most downstream cells within region

path([idxs, xy, mask, max_length, unit, ...])

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.

repair_loops()

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

river_depth(qbankfull, rivwth[, zs, rivdst, ...])

Return an estimated river depth based on mannings equations or a gradually varying flow (gvf) solver a assuming a rectangular river profile.

set_transform(transform[, latlon])

Set transform affine.

smooth_rivlen(rivlen, min_rivlen[, ...])

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

snap([idxs, xy, mask, max_length, unit, ...])

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

stream_distance([mask, unit])

Returns distance to outlet or next downstream True cell in mask

stream_order([type, mask])

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

streams([mask, min_sto, xs, ys, idxs_out, ...])

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

subbasins_area(area_min[, uparea])

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

subbasins_pfafstetter([depth, uparea, upa_min])

Returns the pfafstetter subbasins.

subbasins_streamorder([strord, mask, min_sto])

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

subgrid_rivavg(idxs_out, data[, weights, ...])

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

subgrid_rivlen(idxs_out[, mask, direction, unit])

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

subgrid_rivmed(idxs_out, data[, weights, ...])

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

subgrid_rivslp(idxs_out, elevtn[, length, ...])

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

to_array([ftype])

Return 2D flow direction raster.

ucat_area(idxs_out[, unit])

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

ucat_outlets(cellsize[, uparea, method])

Returns linear indices of unit catchment outlet pixel.

upscale(scale_factor[, method, uparea])

Upscale flow direction network to lower resolution.

upscale_error(other, idxs_out)

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

upstream_area([unit])

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

upstream_sum(data[, mv])

Returns sum of next upstream values.

vectorize([mask, xs, ys])

Returns each flow direction as a linestring geo-feature

xy(idxs, **kwargs)

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

Attributes

area

Cell area [m]

bounds

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

distnc

Distance to outlet [m]

extent

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

idxs_ds

Linear indices of downstream cell.

idxs_pit

Linear indices of pits/outlets.

idxs_seq

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

idxs_us_main

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

isvalid

True if the flow direction map is valid.

mask

Boolean array of valid cells in flow direction raster.

n_upstream

Number of upstream connection

ncells

nnodes

Number of valid cells.

rank

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