Skip to main content

PyForestScan: Airborne Point Cloud Analysis for Forest Structure

Binder PyPI Docker Pulls Contributors Tests Coverage PyPI Downloads

Calculate Forest Structural Metrics from lidar point clouds in Python

Height Above Ground

Overview

PyForestScan is a Python library designed for analyzing and visualizing forest structure using airborne 3D point cloud data. The library helps derive important forest metrics such as Canopy Height, Plant Area Index (PAI), Canopy Cover, Plant Area Density (PAD), Foliage Height Diversity (FHD), and Rumple Index.

Features

  • Forest Metrics: Calculate and visualize key metrics like Canopy Height, PAI, PAD, FHD, Canopy Cover, and Rumple Index.
  • Large Point Cloud Support: Utilizes efficient data formats such as EPT for large point cloud processing.
  • Visualization: Create 2D and 3D visualizations of forest structure and structural metrics
  • Extensibility: Easily add custom filters and visualization techniques to suit your needs.

Installation

Install PyForestScan using pip:

pip install pyforestscan

Dependencies

[!IMPORTANT] You MUST have installed both PDAL and GDAL to use PyForestScan. If you use conda to install PDAL, make sure you install pyforestscan in the conda environment with PDAL (and GDAL if using conda). See https://pdal.io/en/latest/ for more information on PDAL and https://gdal.org/en/stable/.

  • PDAL >= 2.7
  • GDAL >= 3.5
  • Python >= 3.11

Quick Start

Calculate, Export, and Plot Plant Area Index

The following snippet shows how you can load a las file, create 5m by 5m by 1m voxels with points assigned to them, and generate plant area density at 1m layers and plant area index for each 5m grid cell before writing the resulting PAI layer to a geotiff and plotting.

from pyforestscan.handlers import read_lidar, create_geotiff
from pyforestscan.calculate import assign_voxels, calculate_pad, calculate_pai
from pyforestscan.visualize import plot_metric

arrays = read_lidar("example_data/20191210_5QKB020880.laz", "EPSG:32605", hag=True)
voxel_resolution = (5, 5, 1)
voxels, extent = assign_voxels(arrays[0], voxel_resolution)
pad = calculate_pad(voxels, voxel_resolution[-1])
pai = calculate_pai(pad)
create_geotiff(pai, "output_pai.tiff", "EPSG:32605", extent)
plot_metric('Plant Area Index', pai, extent, metric_name='PAI', cmap='viridis', fig_size=None)

Plant Area Index

Documentation

For detailed instructions and examples, visit our documentation.

Editing and Publishing Documentation

If you want to add new documentation or update existing docs for PyForestScan, follow these steps:

1. Editing Documentation

  • Documentation sources are typically found in the docs/ directory.
  • You can add new Markdown (.md) files or update existing ones as needed.
  • To add a new doc page, simply create a new file in the docs/ folder and link to it from the relevant index or summary page if needed.

2. Building and Viewing Docs Locally

PyForestScan uses a static site generator like MkDocs (or similar) for documentation.

  • Make sure you have the required dependencies listed in requirements-doc.txt.
  • Install dependencies if needed:
    pip install -r requirements-doc.txt
    
  • Build and serve the documentation locally:
    mkdocs serve
    
  • Visit http://127.0.0.1:8000 in your browser to preview your changes.

3. Publishing/Updating the Documentation

  • Once you are satisfied with your changes, commit and push them to your fork or branch:

    git add docs/
    git commit -m "Update documentation"
    git push
    
  • Open a Pull Request (PR) if contributing to the main repository.

  • On merge to the main branch, documentation deployment is usually handled automatically (for example, via GitHub Actions or Read the Docs). Check the repository’s specific instructions or workflows if manual steps are required.

Tip: If you encounter issues with the docs build or deployment, refer to any Contributing Guidelines, mkdocs.yml configuration, or open an issue for help.

Developer Guides

To build locally and contribute to PyForestScan, you will need the following dependencies:

  • PDAL and Python PDAL bindings
  • GDAL
  • Python
  • Python requirements (requirements.txt and requirements-dev.txt)

Testing

PyForestScan uses pytest for running tests. To run the tests, you can follow the steps below:

Running Tests

  1. Install the development dependencies:

    pip install -r requirements-dev.txt
    
  2. Run the tests using pytest:

    pytest
    

This will run all the test cases under the tests/ directory. The tests include functionality checks for filters, forest metrics, and other core components of the PyForestScan library.

You can also run specific tests by passing the test file or function name:

pytest tests/test_calculate.py

Contributing

We welcome contributions! Please check our Contributing Guidelines to get started.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

Release files for pyforestscan 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyforestscan 0.4.1
File Size Uploaded
pyforestscan-0.4.1.tar.gz 42.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyforestscan 0.4.1
File Interpreter ABI Platform
pyforestscan-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 88.1 kB

Release files / pyforestscan-0.4.1.tar.gz

Download URL pyforestscan-0.4.1.tar.gz
Size 42.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ddd4c8922b8e504ef5a4ddaf26b16007c1e2476649df87cf61e31928174a8a70
BLAKE2b-256 checksum
How to use checksums
3e5aefe87c21261889df2a3033da4c378d2e7d27170e5790fa50718d0661bd30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyforestscan-0.4.1-py3-none-any.whl

Download URL pyforestscan-0.4.1-py3-none-any.whl
Size 45.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e88d6adf033828a9dd55b4216735f84c6e85a5203abe7708b04002b5798c1ec0
BLAKE2b-256 checksum
How to use checksums
6bef32105044479453c63c958f163fdfa46240530d5c5213c06ae87a52635a26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page