Skip to main content

Fast methods to work with hydro- and topography data in pure Python.

Project description


Fast methods to work with hydro- and topography data in pure Python.

Methods include:

  • flow direction upscaling
  • (sub)basin delineation
  • pfafstetter subbasins delineation
  • upstream accumulation
  • up- and downstream tracing and arithmetics
  • strahler stream order
  • hydrologically adjusting elevation
  • height above nearest drainage
  • vectorizing stream features
  • many more!


Here we show an example of a 30 arcsec D8 map of the Rhine basin which is saved in as 8-bit GeoTiff. We read the flow direction, including meta-data using rasterio to begin with.

import rasterio
with'data/rhine_d8.tif', 'r') as src:
    flwdir =
    transform = src.transform
    latlon = == 4326

Next, we parse this data to a FlwdirRaster object, the core object to work with flow direction data. The most common way to initialize a FlwdirRaster object is based on gridded flow direction data in D8, LDD or NEXTXY format using the pyflwdir.from_array method. Optional arguments describe the geospatial location of the gridded data. In this step the D8 data is parsed to an actionable format.

import pyflwdir
flw = pyflwdir.from_array(flwdir, ftype='d8', transform=transform, latlon=latlon)
# When printing the FlwdirRaster instance we see its attributes.

Now all pyflwdir FlwdirRaster methods are available, for instance the subbasins method which creates a map with unique IDs for subbasin with a minumum stream_order.

Browse the docs API for all methods

subbasins = flw.subbasins()

Getting started

Install the package from pip using

$ pip install pyflwdir

Install the package from conda using

$ conda install pyflwdir -c conda-forge

Development and Testing



See docs







Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyflwdir, version 0.4.6
Filename, size File type Python version Upload date Hashes
Filename, size pyflwdir-0.4.6.tar.gz (6.1 MB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page