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"
  • numba = ">=0.65.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.6.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.6-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nldi_flowtools-0.3.6.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.6.tar.gz
Algorithm Hash digest
SHA256 6cf1c65c726fdbe58a2fbfb3ff5aad04bb98ab5098e43664b3802bfeb5b994cc
MD5 4943d7599f0d2f95b09863661ceacc16
BLAKE2b-256 32b53ee1339239d22f730c0a019cbb511ace1f186ee30814a9c9131a1d3118a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nldi_flowtools-0.3.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 189d19396cf6b5e49eb2b7bf3834e02e046d6ac556967fbd78d06dab5d4faf77
MD5 4d1c7b68b637cc0efb98f98cf37f61e4
BLAKE2b-256 adc1128de5a1af6dccbdf2b56e7dfab626e0163d8c0b7ce0807dcbaa5065d064

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