Skip to main content

River Trace

Identifies rivers in satellite images and generates a profile of pixel values along its length.

Example river trace

Installation

Install from PYPI

pip install rivertrace

Install from GitHub

  • Clone the repository to your local machine using the command:

git clone git@github.com:JamesRunnalls/river-trace.git

Note that the repository will be copied to your current working directory.

  • Use Python 3 and install the requirements with:

pip install -r requirements.txt

The python version can be checked by running the command python --version. In case python is not installed or only an older version of it, it is recommend to install python through the anaconda distribution which can be downloaded here.

Usage

River trace can be used to find the shortest path through any 2D binary array where 1 represents water and 0 represents not water.

Basic Example (source)

import numpy as np
from rivertrace import trace
from rivertrace.functions import plot_matrix

square = np.zeros((20, 20), dtype=np.uint8)
square[0:2, 0:5] = 1
square[0:8, 5:8] = 1
square[6:9, 8:12] = 1
square[8:15, 10:14] = 1
square[15:20, 12:15] = 1
square[18:20, 15:20] = 1

path = trace(square, [0, 0], [19, 19])

for p in path:
    square[p[0], p[1]] = 2

plot_matrix(square, "Final path plotted on original data")

Satellite Imagery

River trace was primarily developed to trace river paths from satellite imagery. You can see an example here of how to extract data from a satellite image.

Below are the preparation steps for producing a turbidity long section using Sentinel 2 imagery.

  1. Download the Sentinel 2 image for your desired location and date.
  2. Use a processing algorithm to calculate your desired output parameter (e.g. Polymer, C2RCC, ACOLITE)
  3. Create a water classification band (e.g. NDWI, SWI)
  4. Import the band into python and convert to a binary array
  5. Use rivertrace to track the shortest path through the river network

How it works

River trace relies heavily on scikit-image for the initial morphological thinning of the binary matrix. This outputs a 1px wide "centerline" of available river sections.

This centerline is abstracted to nodes and edges and networkx is used to calculate the dijkstra (shortest) path through the network. This is the re-assembled as complete path. For some rivers there may be gaps in the water surface due to clouds/ bridges/ vegetation, so where a complete path is not avaialble the algorithm progressively allows greater and greater "jumps" between connected river sections.

Projects

See the following repository for examples of where river trace has been used to track river pollution events from tailings dam failures.

Release files for rivertrace 1.1.1

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

Source distribution (sdist)

Source distribution for rivertrace 1.1.1
File Size Uploaded
rivertrace-1.1.1.tar.gz 42.8 kB Details

Built distribution (wheel)

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

Total release size:73.5 kB

Release files / rivertrace-1.1.1.tar.gz

Download URL rivertrace-1.1.1.tar.gz
Size 42.8 kB
Tags Source
SHA-256 checksum
How to use checksums
09a63a47a8d0d0328f9f0b292ccaa692a0e087aa0adde29b98e0d5ba1108e66e
BLAKE2b-256 checksum
How to use checksums
0908e5885dd5e2fdfd8306407862e5bc790adb21133dacca84a8da5754d43fd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.2

Release files / rivertrace-1.1.1-py3-none-any.whl

Download URL rivertrace-1.1.1-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f64b9e0a3e54b010fb6f3f6f222310e4d22cf94feafde905769899a784ba3edc
BLAKE2b-256 checksum
How to use checksums
cceb1f76ba128524a8d719eeb047809da520ab5a5801fc5144283d66aff2f81c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.2

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

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