Skip to main content

NLDI Flowtools

NLDI Flowtools provides basin delineation and flow path tracing services.

PyPI conda Status Python Version License

Read the documentation at https://nldi-flowtools.readthedocs.io/ pre-commit Ruff uv

Description

NLDI Flowtools is a Python package for basin delineation and flow path tracing from any point within CONUS. It can return either the full upstream drainage basin or just the portion within the local NHD catchment (i.e., splitcatchment). The flow path tracing tool follows terrain downhill until it intersects the nearest NHD stream line, returning both the traced path and the intersected stream segment (upstream, downstream, or full geometry). NLDI Flowtools uses NHDPlus V2 data and NLDI services.

Documentation

Check out our Read the Docs documentation page.

Requirements

  • python = ">=3.10,<=3.14"
  • click = ">=7.1.2"
  • geojson = "^2.5.0"
  • numpy = ">=2.0.0"
  • pyproj = "^3.4.0"
  • rasterio = "^1.3.9"
  • requests = "^2.32.0"
  • Shapely = ">=2.0.0"

Installation

For users:

You can install NLDI-Flowtools via pip from PyPI:

$ pip install nldi-flowtools

For Developers:

First, clone the repo. Navigate to the repo directory and install UV, then sync the project with its dev dependencies:

$ uv sync --group dev

Activate the virtual environment:

$ source .venv/bin/activate

Nox is used for organizing the suite of testing libraries used. To list all of the Nox test options, run:

$ nox --list

To run all of the Nox tests, simply run:

$ nox

To only run a single test, run:

$ nox -s mypy

Features

Split Catchment

Delineate the drainage basin upstream of any point within CONUS. Given a longitude/latitude coordinate pair, splitcatchment returns a GeoJSON FeatureCollection containing:

  • The local NHD catchment the point falls within.
  • Either the portion of that catchment that drains to the point (upstream=False), or the full upstream drainage basin including all upstream NHD catchments (upstream=True).

Flow Trace

Trace the path water takes from any point downhill to the nearest NHD stream. Given a longitude/latitude coordinate pair, flowtrace returns a GeoJSON FeatureCollection containing:

  • The raindrop path from the input point to the NHD flowline.
  • The intersected NHD stream segment — either the full geometry, or just the upstream or downstream portion depending on the direction parameter.

Both functions return metadata about the intersected stream, including COMID, reach code, GNIS name, and the reach measure at the point of intersection.

Usage

Import the two main functions:

from nldi_flowtools.nldi_flowtools import splitcatchment, flowtrace

Split Catchment

# Local split only (portion of catchment draining to the point)
result = splitcatchment(lon=-93.0, lat=45.0, upstream=False, simplified=False)

# Full upstream drainage basin
result = splitcatchment(lon=-93.0, lat=45.0, upstream=True, simplified=True)

The returned FeatureCollection contains two features:

Feature ID Description
catchment The local NHD catchment polygon, with a catchmentID property
splitCatchment The portion of the catchment upstream of the point (when upstream=False)
drainageBasin The full upstream drainage basin (when upstream=True and the point is on a flowline)

Flow Trace

# Downstream portion of the intersected stream
result = flowtrace(lon=-93.0, lat=45.0, direction="down")

# Upstream portion
result = flowtrace(lon=-93.0, lat=45.0, direction="up")

# Full stream segment
result = flowtrace(lon=-93.0, lat=45.0, direction="none")

The returned FeatureCollection contains two features:

Feature ID Description
downstreamFlowline / upstreamFlowline / nhdFlowline The NHD stream segment (varies by direction)
raindropPath The traced flow path from the input point to the stream

The flowline feature includes properties like comid, gnis_name, reachcode, measure, and raindrop_pathDist (distance in meters).

See the package documentation for additional details.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the CC0 1.0 Universal license, NLDI Flowtools is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Disclaimer

DISCLAIMER.md

Authors

Anders Hopkins - Lead Developer - USGS Web Informatics & Mapping

Citation

Hopkins, A.L., 2025, NLDI Flowtools, U.S. Geological Survey Software Release, https://doi.org/10.5066/P9W5UK7Z.

Credits

Acknowledgments

Metadata

Release files for nldi-flowtools 0.3.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nldi-flowtools 0.3.9
File Size Uploaded
nldi_flowtools-0.3.9.tar.gz 1.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for nldi-flowtools 0.3.9
File Interpreter ABI Platform
nldi_flowtools-0.3.9-py3-none-any.whl Python 3 none any Details

Total release size: 1.3 MB

Release files / nldi_flowtools-0.3.9.tar.gz

Download URL nldi_flowtools-0.3.9.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
e98cb5eb0029eb1b463e70da009a68bcb126a44ca033823e801080778b2a517b
BLAKE2b-256 checksum
How to use checksums
5e4d7e0e7152645883ae8198d7e7d4b0ff2953b328d2ed097bdb811e8eabb03d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nldi_flowtools-0.3.9-py3-none-any.whl

Download URL nldi_flowtools-0.3.9-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
068d1acbc8af831400dae41e1fca9b9b3f8af2b4eb9575fc041947866c47a179
BLAKE2b-256 checksum
How to use checksums
f8fbe7b6ca04c9df344eff1720b522637e93f9cd54d3149192136177ae1a362c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page