Skip to main content

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

Project description

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.

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

rivertrace-1.1.1.tar.gz (42.8 kB view details)

Uploaded Source

Built Distribution

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

rivertrace-1.1.1-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file rivertrace-1.1.1.tar.gz.

File metadata

  • Download URL: rivertrace-1.1.1.tar.gz
  • Upload date:
  • Size: 42.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for rivertrace-1.1.1.tar.gz
Algorithm Hash digest
SHA256 09a63a47a8d0d0328f9f0b292ccaa692a0e087aa0adde29b98e0d5ba1108e66e
MD5 40767a551d41f48c82334dc9d41f2b24
BLAKE2b-256 0908e5885dd5e2fdfd8306407862e5bc790adb21133dacca84a8da5754d43fd1

See more details on using hashes here.

File details

Details for the file rivertrace-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: rivertrace-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for rivertrace-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f64b9e0a3e54b010fb6f3f6f222310e4d22cf94feafde905769899a784ba3edc
MD5 8be760d9241e7f555973ccb67c430eca
BLAKE2b-256 cceb1f76ba128524a8d719eeb047809da520ab5a5801fc5144283d66aff2f81c

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