Skip to content

Meandering system morphodynamic analysis (Python meander Bend Dynamics)

License

Notifications You must be signed in to change notification settings

martin-lemay/pyBenD

Repository files navigation

CI docs

pyBenD (Python Bend Dynamics)

pyBenD is a Python library to process channel centerlines of meandering systems and quantify meander morphology and dynamics (bends, cross-sections, morphometry, kinematics, and apex detection). It replaces the legacy ChannelPy repository.

This project sets the data structure to store channel centerline properties and centerline evolution (a set of successive position of a river centerline) through time. It provides methods to create cross-sections and measure meander bend geomorphic and kinematic parameters.

The methodology for channel point tracking is inspired from zsylvester/meanderpy.

A full documentation of the code can be found here: https://mlemay-pybend.readthedocs.io/en/latest/

If you use pyBenD, please cite one of the related papers and/or its reference on Zenodo:

Quickstart

Install from GitHub:

pip install git+https://github.com/martin-lemay/pyBenD.git

Minimal example (single centerline from CSV and morphometry analysis):

from pybend.io import load_centerline_dataset_from_csv
from pybend import Centerline
from pybend import Morphometry

# 1) Load centerline points (must be ordered in flow direction)
# Default separator is ';' and default columns are X, Y (and optional Z)
dataset = load_centerline_dataset_from_csv(
  "path/to/centerline.csv",
  x_prop="X",
  y_prop="Y",
  z_prop="Z",
  sep=";",
)

# 2) Build a Centerline object (resampling + smoothing + bend detection)
cl = Centerline(
  age=0,
  dataset=dataset,
  spacing=50.0,         # target distance between points (m)
  smooth_distance=200., # smoothing distance (m)
  sinuo_thres=1.05,     # validity threshold for bends
  n=2,                  # exponent for curvature-distribution apex detection
  find_bends=True,
)

# 3) Morphometry analysis
morpho = Morphometry(cl)
# returns pandas DataFrame
metrics = morpho.compute_bends_morphometry(valid_bends=False) # morphometry computed only on valid bends if valid_bends is True

# 4) (Optional) Print average metrics
print("Centerline-averaged bend geometry")
print(metrics.mean(axis=0))
print()

Supported input formats:

  • CSV: use load_centerline_dataset_from_csv() (expects at least X/Y columns; optional Z). Default separator is ;.
  • KML: use load_centerline_dataset_from_kml().

Tip: example datasets are available in notebooks/data/ and tests/data/.

Installation

Requirements:

  • Python >= 3.12

Install from GitHub:

pip install git+https://github.com/martin-lemay/pyBenD.git

For development and tests:

pip install -e .[dev,test]

Contributing

Contributions are welcome — bug reports, feature requests, docs improvements, and code changes.

Workflow (issues + PR/MR)

  • Create an issue first to describe the bug / enhancement (with minimal reproducible example when relevant).
  • Create a Pull Request / Merge Request that addresses one issue.
    • Reference the issue in the PR description (e.g. Fixes #123).
    • Keep changes focused and include tests/docs updates when applicable.

Local setup

pip install -e .[dev,test]

If you plan to build the docs locally, install the doc build dependencies as well:

pip install -r requirements.txt

Formatting, linting, typing, tests

Run these from the repository root:

# Format
ruff format .

# Lint (optionally auto-fix)
ruff check .
ruff check --fix .

# Type-check
mypy .

# Tests
pytest

# To mirror CI more closely (includes doctests)
pytest ./ --doctest-modules

Build the docs locally

python -m sphinx -b html docs docs/_build/html

Then open docs/_build/html/index.html in your browser.

What is checked in CI

On each Pull Request, GitHub Actions runs:

  • ruff check (lint; currently non-blocking in CI)
  • mypy (static type checks)
  • pytest (tests + doctests)

Notebooks and related publications

The notebooks/ folder contains end-to-end case studies used in publications. If you use pyBenD in your research, please cite one of these articles:

Future work

  • Bend kinematics metrics

Credits

pyBenD was written by Martin Lemay
ORCID Badge

License

pyBenD is licensed under MIT license.

Packages

No packages published

Contributors 2

  •  
  •