Skip to main content

A lightweight Python wrapper for WhiteboxTools command-line interface

Project description

PyWBT: Python Wrapper for WhiteboxTools

PyPI Conda License: MIT Binder

codecov CI Documentation Status Downloads

Overview

PyWBT is a Python wrapper for the WhiteboxTools (WBT) geospatial analysis library. It simplifies geospatial workflows by providing an easy-to-use Pythonic interface while maintaining a minimal dependency footprint—relying only on Python's built-in modules.

You can try PyWBT directly in your browser by clicking the Binder badge above.

Key Features

  • Lightweight Python interface for WBT’s command-line tools.
  • Seamless integration with WBT for custom geospatial workflows.
  • Minimal dependencies for ease of installation.
  • Optional dem_utils module for obtaining and preprocessing DEM data from 3DEP (US only at any resolutions) and NASADEM (global coverage at 30 m resolution).

Installation

Install PyWBT via pip or micromamba:

Using pip:

pip install pywbt

Using micromamba (or conda/mamba):

micromamba install -c conda-forge pywbt

Quick Start

PyWBT enables the execution of WBT tools with the whitebox_tools function, which manages the environment setup, including downloading the WBT executable for your operating system.

Basic Usage

The whitebox_tools function requires two key arguments:

  • src_dir: Directory containing the input files.
  • arg_dict: Dictionary where tool names are keys and argument lists are values.

Example usage:

import pywbt
from pathlib import Path

src_dir = Path("path/to/input_files/")
wbt_args = {
    "BreachDepressions": ["-i=dem.tif", "--fill_pits", "-o=dem_corr.tif"],
    # Additional tools...
}

pywbt.whitebox_tools(src_dir, wbt_args)

For more detailed workflows and usage patterns, refer to the documentation.

Managing Output Files

To manage the output, specify which intermediate files to keep using the files_to_save argument. Only those files listed will be saved, and the rest will be deleted. By default, all files are stored in save_dir (the current working directory, by default).

Tool Lookup

Use list_tools and tool_parameters to explore available tools and their arguments. Here's an example using pandas for querying tools:

import pandas as pd

tools = pd.Series(pywbt.list_tools())
tools[tools.str.contains("depression", case=False)]

Get parameters for a specific tool:

pd.DataFrame(pywbt.tool_parameters("BreachDepressions"))

DEM Utilities

The dem_utils module supports downloading and reading DEM data from 3DEP and NASADEM. Install optional dependencies for DEM utilities:

pip install pywbt[dem]

Or using micromamba:

micromamba install -c conda-forge pywbt geopandas seamless-3dep planetary-computer pystac-client rioxarray

Example Workflow

We can delineate the stream network and calculate the Strahler stream order for a region in London using PyWBT, as shown below:

import pywbt
from pathlib import Path

bbox = (0.0337, 51.5477, 0.1154, 51.6155)
src_dir = Path("path/to/input_files/")
pywbt.dem_utils.get_nasadem(bbox, src_dir / "dem.tif", to_utm=True)
wbt_args = {
    "BreachDepressions": ["-i=dem.tif", "--fill_pits", "-o=dem_corr.tif"],
    "D8Pointer": ["-i=dem_corr.tif", "-o=fdir.tif"],
    "D8FlowAccumulation": ["-i=fdir.tif", "--pntr", "-o=d8accum.tif"],
    "ExtractStreams": [
        "--flow_accum=d8accum.tif",
        "--threshold=600.0",
        "-o=streams.tif",
    ],
    "StrahlerStreamOrder": [
        "--d8_pntr=fdir.tif",
        "--streams=streams.tif",
        "--zero_background",
        "-o=strahler.tif",
    ],
}
pywbt.whitebox_tools(src_dir, wbt_args)

Strahler Stream Order

For more examples, visit the documentation.

Contributing

We welcome contributions! For guidelines, please refer to the CONTRIBUTING.md and CODE_OF_CONDUCT.md.

License

PyWBT 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

pywbt-0.3.0.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

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

pywbt-0.3.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file pywbt-0.3.0.tar.gz.

File metadata

  • Download URL: pywbt-0.3.0.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywbt-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4b84dccd24cd5fda7d7812421cdb42ffd5ba9f38cfd013f31ff60d843be03cc0
MD5 08cfb7d8197c41aac74246f7b7e617b1
BLAKE2b-256 60f40298e963cc369e8d38c71cb9cfaa09f440220b01427f261e4446a1b005d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywbt-0.3.0.tar.gz:

Publisher: release.yml on cheginit/pywbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywbt-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pywbt-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywbt-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52de7af2661e94ad5b22a451f1b1c06eaf4b8b6722e8bf7bae27415c387dab40
MD5 bc6f120b0188386e88f91eaead97cdb0
BLAKE2b-256 ec352315fcf9192096f034a90e37609051f5c7fa2cffc3a705091be5fa8485cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywbt-0.3.0-py3-none-any.whl:

Publisher: release.yml on cheginit/pywbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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