Skip to main content

NLDI Flowtools

Project description

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

Project details


Download files

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

Source Distribution

nldi_flowtools-0.3.7.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nldi_flowtools-0.3.7-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file nldi_flowtools-0.3.7.tar.gz.

File metadata

  • Download URL: nldi_flowtools-0.3.7.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nldi_flowtools-0.3.7.tar.gz
Algorithm Hash digest
SHA256 391f627cf3181229ef14375b6501818ba882b20325e1e927d0101b1a671c2aa4
MD5 3fb96e497a501d38dbc1dc56a9afb758
BLAKE2b-256 a0ca184da913fda5f8bf67e16cdde0955f813505bdbe8257e420b7cd52fa1991

See more details on using hashes here.

File details

Details for the file nldi_flowtools-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: nldi_flowtools-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nldi_flowtools-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 16bc9f4260189e545281d3b27ea6008392c1b382c0e3c7c2e26bd5d0d4b709e2
MD5 51315b537545058abf0ed1404c018b2a
BLAKE2b-256 4f3c8bd8c6df1de6b52a61fc5498d800e3800e5fc881054e74748db5eb4d3e0b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page