Skip to main content

Pourpoint

PyPI version Python ≥3.13 Documentation

Pourpoint is a Python package for delineating watersheds from existing hydrofabrics. A watershed is the area of land that drains to a particular outlet. A hydrofabric represents that landscape as connected sub-basins and rivers, sometimes accompanied by flow-direction and flow-accumulation rasters.

Starting from a point, Pourpoint follows those connections upstream to collect the contributing sub-basins. Where rasters are available, it can refine the watershed cell by cell to resolve the land draining to the chosen outlet. You can work with the resulting geometries in Python or export them with the river network to a portable QGIS project.

Pourpoint reads hydrofabrics through HydroFabric Exchange (HFX), which packages their geometries, connections, attributes and available rasters. The concepts guide explains how these pieces fit together, from a point watershed to the upstream contributing area of a region.

Install

Requires Python 3.13 or later. With uv, add Pourpoint to your project.

uv add pourpoint

Use with a coding agent

Copy the prompt below into your coding agent after installing Pourpoint.

Show agent prompt
Use Pourpoint to delineate watersheds from existing HFX hydrofabrics.

Check that pourpoint imports in the project's own Python environment
(Python 3.13 or newer) and note its installed version. Use the project's
runner, such as uv run python, not a separate agent environment. If setup
fails, report the error. Do not install or upgrade packages automatically.

Pourpoint reads compiled HFX bundles, not arbitrary source hydrofabrics or
DEMs. Use a local bundle directory or an accessible HTTP(S)/S3 bundle URL.
Check supported HFX versions and representations in the getting-started
guide. Remote reads need access to the host; cached data may be incomplete.
Only access data needed for the user's task and respect source-data terms.

Typical vector-only workflow, with the user's HFX bundle and outlet:
import pourpoint as pp

with pp.HydroFabric(dataset) as fabric:
    result = pp.delineate(fabric=fabric, target=point)
    watershed = result.geometry
    subbasins = result.subbasins

Here dataset is a bundle path or URL and point is a Shapely Point in
EPSG:4326 (longitude, latitude). Vector targets and outputs use that CRS;
native raster outputs retain their own CRS. Catchment level defaults to 1,
not the finest level. This example selects whole upstream sub-basins.
Snapping needs explicit snap_onto geometry; its radius is in metres.
refine=True needs covering direction and accumulation rasters and never
silently falls back to a coarse result. Consult the README's Rhine example
for snapping, refinement and QGIS export; do not run it just for onboarding.

Single-target OperationError exposes code and reason. Selection returns
SelectionResult (with .subbasins and .coverage) and delineate returns
DelineationResult (with .coverage). Incomplete, unverified or unassessed
upstream coverage fails by default unless allow_incomplete=True is passed;
retained UpstreamCoverage records affected unit IDs and cuts. For batches,
inspect issues and None result slots; valid empty selections are not failures.
Configuration and integrity errors raise. Do not treat partial batch success
as complete coverage or source attributes as recomputed for clipped areas.

Keep source-dependent work and exports inside the HydroFabric context.
QGISBundle writes a new folder and refuses to overwrite an existing one;
move the whole folder together. River selection is a separate operation.

Consult documentation as needed, checking signatures against the installed
version:
- HFX datasets, coordinates and caching:
  https://pourpoint-tools.github.io/getting-started/
- Selection, refinement, batches, failures and portable output:
  https://pourpoint-tools.github.io/operations/
- Exact API signatures and returned types:
  https://pourpoint-tools.github.io/reference/operations/
  https://pourpoint-tools.github.io/reference/results/

Continue the user's task without onboarding questions. If no task was
given, briefly confirm readiness.

Delineate the Rhine at Basel

The point at 47.5596° N, 7.5890° E lies on the Rhine in Basel, Switzerland. We will use the public GRIT hydrofabric to find its watershed and save a QGIS project. Pourpoint reads the required data from the hosted HFX bundle, so this example needs an internet connection.

Some flow directions in GRIT v1.0 form loops. In affected watersheds, cells that drain into a loop never reach the outlet, so raster refinement can leave holes and underestimate the contributing area. For whole upstream sub-basins, use delineate(..., refine=False). See the GRIT v1.0 refinement note.

A point chosen on a map can fall slightly beside the hydrofabric's river line. We first select nearby rivers and snap the point to the nearest segment within 100 metres. Coordinates use longitude followed by latitude.

from shapely.geometry import Point, box

import pourpoint as pp


dataset = "https://basin-delineations-public.upstream.tech/grit/hfx-v0.4.0/"
point = Point(7.5890, 47.5596)

with pp.HydroFabric(dataset) as fabric:
    nearby_rivers = pp.select_rivers(
        fabric=fabric,
        target=box(7.5790, 47.5496, 7.5990, 47.5696),
    )
    outlet = pp.snap(target=point, onto=nearby_rivers, radius=100)

    # Follow the sub-basin connections upstream from the outlet.
    selection = pp.select_upstream_subbasins(fabric=fabric, target=outlet)

    # Use native flow rasters to resolve the watershed within those sub-basins.
    refined = pp.refine(fabric=fabric, target=outlet, subbasins=selection)
    watershed = pp.merge(subbasins=refined.subbasins)

    # Select the supplied rivers inside the refined watershed.
    rivers = pp.select_rivers(fabric=fabric, target=watershed)

    bundle = pp.QGISBundle()
    bundle.add_result(refined)
    bundle.add_vector("watershed", watershed, crs="EPSG:4326")
    bundle.add_vector("rivers", rivers)
    bundle.add_vector("requested_point", point, crs="EPSG:4326")
    bundle.write("rhine-basel")

The code above generates the watershed shown below.

Open rhine-basel/watershed.qgz in QGIS. The folder contains the vector layers and native raster subsets alongside the project. Keep the folder together when moving or sharing it, and choose a new output folder for each export.

The raster-refined Rhine watershed above Basel in pale purple, with blue rivers and a red outlet point, over Switzerland and neighbouring country boundaries.

Boundaries: Natural Earth. Their depiction implies no position on territorial status.

Use the combined workflow

When you only need the final result, delineate combines snapping, upstream selection, refinement and merging. Using the same imports, dataset and point, the following produces the same watershed and river geometries in a second bundle.

with pp.HydroFabric(dataset) as fabric:
    nearby_rivers = pp.select_rivers(
        fabric=fabric,
        target=box(7.5790, 47.5496, 7.5990, 47.5696),
    )
    result = pp.delineate(
        fabric=fabric,
        target=point,
        snap_onto=nearby_rivers,
        radius=100,
        refine=True,
    )
    rivers = pp.select_rivers(fabric=fabric, target=result.subbasins)

    bundle = pp.QGISBundle()
    bundle.add_result(result)
    bundle.add_vector("rivers", rivers)
    bundle.add_vector("requested_point", point, crs="EPSG:4326")
    bundle.write("rhine-basel-combined")

add_result includes the merged watershed, individual sub-basin contributions, outlet cell and raster subsets. River selection remains a separate step, so you can choose which network to include.

Documentation

The documentation develops the concepts and workflows illustrated here.

  • Getting started covers datasets, coordinates and caching.
  • Concepts explains watershed selection and raster refinement.
  • Operations covers batches, river selection and portable output.
  • API reference describes the operations and their returned results.

Acknowledgements and data rights

GRIT is the work of Michel Wortmann, Louise Slater, Laurence Hawker, Yinxue Liu and Jeffrey Neal. We thank them for making their hydrography available, and Alden Keefe Sampson at Upstream Tech for hosting GRIT for public access. See the GRIT paper and data publication for citation and source details.

Pourpoint's code is licensed under MIT. GRIT data and derived outputs carry CC BY-NC 4.0 terms. Follow the source dataset's attribution and reuse conditions when sharing a watershed, map or QGIS bundle.

Metadata

Release files for pourpoint 0.5.0

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

Source distribution (sdist)

Source distribution for pourpoint 0.5.0
File Size Uploaded Provenance Actions
pourpoint-0.5.0.tar.gz 59.7 kB Without provenance Details for pourpoint-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pourpoint 0.5.0
File Interpreter ABI Platform Actions
pourpoint-0.5.0-py3-none-any.whl Python 3 none any Details for pourpoint-0.5.0-py3-none-any.whl

Total release size: 127.5 kB

Release files / pourpoint-0.5.0.tar.gz

Download URL pourpoint-0.5.0.tar.gz
Size 59.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dbc3aee97e966347e2f554ae8403ad815bbd8c1d0c84a62c92ac9a75fea89a14
BLAKE2b-256 checksum
How to use checksums
e61e8f2a5462f7e2d8c2e6cc643261dcc736becfa4ecd4d4f4646804c0eed8ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pourpoint-0.5.0-py3-none-any.whl

Download URL pourpoint-0.5.0-py3-none-any.whl
Size 67.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e04fe1db43366c72707c80b5b7105b6f522173067ed95728a8174eadf2952bf
BLAKE2b-256 checksum
How to use checksums
ec64dd529d2ea630e852430e9711b8e7b9cbb823af5b1ed8c910babff5f690a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pourpoint 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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