Skip to main content

A lightweight Python wrapper for WhiteboxTools command-line interface

Project description

PyWBT: WhiteboxTools Wrapper for Python

PyPI CondaCIcodecovDocumentation Status

Features

PyWBT is a lightweight Python wrapper (only using Python's built-in modules) for the command-line interface of WhiteboxTools (WBT), a powerful Rust library for geospatial analysis. It is designed to simplify the use of WhiteboxTools by providing a Pythonic interface, allowing users to easily run tools and create custom workflows.

Installation

PyWBT can be installed using pip:

pip install pywbt

or micromamba (conda or mamba can also be used):

micromamba install -c conda-forge pywbt

Usage

PyWBT provides a simple interface to WhiteboxTools. There is just a single function called whitebox_tools that can be used to run different tools. Considering that WBT is a command-line tool, it can generate intermediate files. A good practice for using PyWBT is to use Python's built-in tempfile module to create a temporary directory that gets deleted after the execution of the tools and only store the files that are necessary for further analysis. For example, if we have a DEM file called dem.tif in the current directory, we can use the following code to calculate the Strahler stream order:

import tempfile
from pywbt import whitebox_tools


with tempfile.TemporaryDirectory(dir=".") as work_dir:
    shutil.copy("dem.tif", work_dir)
    wbt_args = {
        "BreachDepressions": ["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", "-o=strahler.tif"],
    }
    whitebox_tools(wbt_args, work_dir=work_dir)
    shutil.copy(Path(work_dir) / "strahler.tif", "strahler.tif")

straher

For more examples, please visit PyWBT's documentation and for more information about the whitebox_tools function and its arguments, please visit the API Reference. Additionally, for more information on different tools that WBT offers and their arguments, please visit its documentation.

Contributing

Contributions are welcome! For more information on how to contribute to PyWBT, please see the CONTRIBUTING.md and CODE_OF_CONDUCT.md files.

License

PyWBT is licensed under the MIT License. For more information, please see the LICENSE file.

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.1.1.tar.gz (312.5 kB view hashes)

Uploaded Source

Built Distribution

pywbt-0.1.1-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page