Skip to main content

A Python package to automatically extract channel centerlines and banklines from water index images of rivers

Project description

rivabar

Description

rivabar is a Python package that aims to automatically extract channel centerlines and banklines from water index images of rivers. The focus is on getting good representations of the banklines, as centerlines are not physical features and how they are exactly derived is subjective. This is achieved in part by viewing channels as boundaries between polygons that correspond to islands or bars, as this allows us to take advantage of algorithms developed for spatial analysis. In this view, even a single-thread channel becomes the boundary between two land domains.

rivabar relies on the following Python packages, among others:

rivabar can be used to map single-thread and multithread rivers, in an almost entirely automated fashion. It requires a water mask as input and a start (source) and end (sink) points for the channel / channel belt / delta.

The images below illustrate how rivabar extracts both centerlines and banklines from a Landsat image of the Brahmaputra River, and creates an island neighborhood graph in addition to the centerline graph.


Brahmaputra River - water index


Rook graph and centerline polygons


Centerline graph and bar polygons

Installation

You can install rivabar directly from PyPI:

pip install rivabar

Alternatively, you can install from source:

git clone https://github.com/zsylvester/rivabar.git
cd rivabar
pip install -e .

Getting started

Here are some basic examples of how to use rivabar:

Basic Usage

import rivabar as rb

# Extract channel centerlines and banklines
# Define start and end points of the channel you want to extract
start_x, start_y = 675796.2, 98338.8 # UTM coordinates of the channel start
end_x, end_y = 628190.3, -91886.6 # UTM coordinates of the channel end
fname="LC08_L2SP_232060_20140219_20200911_02_T1_SR", # assumes that the Landsat bands are located in a folder with this name
dirname="../data/Branco/", # parent folder of the 'LC08...' folder


# Extract the channel centerline and related graphs
D_primal, G_rook, G_primal, mndwi, dataset, left_utm_x, right_utm_x, lower_utm_y, upper_utm_y, xs, ys = rb.extract_centerline(
    fname=fname,
    dirname=dirname,
    start_x=start_x,
    start_y=start_y,
    end_x=end_x,
    end_y=end_y,
    file_type='multiple_tifs',
    flip_outlier_edges=True,
    mndwi_threshold=0.0,
    ch_belt_smooth_factor=1e8,
    ch_belt_half_width=2000,
    remove_smaller_components=True,\
    delete_pixels_polys=False,
    small_hole_threshold=64,
    solidity_filter=False,
    plot_D_primal=True
)

# Save the extracted centerlines and banklines as shapefiles
rb.save_shapefiles(
    dirname="output_directory",
    fname="output_prefix",
    G_rook=G_rook,
    dataset=dataset
)

Analyzing Channel Widths and Morphology

# Get the main path through the channel network
edge_path = rb.get_main_path(D_primal)

# Analyze channel width - wavelength scaling
df, curv, s, loc_zero_curv, xsmooth, ysmooth = rb.analyze_width_and_wavelength(
    D_primal=D_primal,
    main_path=edge_path,
    ax,
    delta_s=5,
    smoothing_factor=0.5*1e7,
    min_sinuosity=1.1,
    dx=30
)

# Extract and plot channel widths along main path
xl, yl, w1l, w2l, w, s = rb.get_channel_widths_along_path(D_primal, D_primal.graph['main_path'])
plt.figure(figsize=(12, 4))
plt.plot(s, np.array(w)*30.0)
plt.xlabel('along-channel distance (m)')
plt.ylabel('channel width (m)');

For more examples and detailed usage, check out the example notebooks in the notebooks directory.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

rivabar-0.1.1.tar.gz (51.6 kB view details)

Uploaded Source

Built Distribution

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

rivabar-0.1.1-py3-none-any.whl (49.9 kB view details)

Uploaded Python 3

File details

Details for the file rivabar-0.1.1.tar.gz.

File metadata

  • Download URL: rivabar-0.1.1.tar.gz
  • Upload date:
  • Size: 51.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.15

File hashes

Hashes for rivabar-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7d279ccf5475dd76efee5758328cdbe013ef46b72a05669db323603bbdd842f8
MD5 1b374a2a437e1c51754fc268882a223d
BLAKE2b-256 6851dd35db27ec2c15e5d51c055b18ce3fbff32474c4e35bc2dc24af73cb16d5

See more details on using hashes here.

File details

Details for the file rivabar-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rivabar-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 49.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.15

File hashes

Hashes for rivabar-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 246ce7fedde84ad480a2556ec80a9d41ac53ee688b45c78e75389d1c27bcba04
MD5 13e7558c6aef5fce49ad85b48e22eff2
BLAKE2b-256 c2bd6bd2d4189e9d6a4ed4b48b1e3a577138a672e7f517f8252d67aa50eca136

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