Metadata-Version: 2.5
Name: BERATools
Version: 0.7.0
Summary: An advanced forest line feature analysis platform
Project-URL: Homepage, https://github.com/BERATool/beratools
Author-email: AppliedGRG <appliedgrg@gmail.com>, Richard Zeng <richardqzeng@gmail.com>
License: GPL-3.0-or-later
License-File: LICENSE
Keywords: BERA,Line
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.12
Requires-Dist: gdal<4,>=3.12; platform_system != 'Windows'
Requires-Dist: geopandas
Requires-Dist: igraph
Requires-Dist: jsonschema
Requires-Dist: laspy
Requires-Dist: lazrs
Requires-Dist: networkit
Requires-Dist: numba
Requires-Dist: numpy<2.4,>=1.26
Requires-Dist: packaging
Requires-Dist: pandas>=2.0
Requires-Dist: psutil
Requires-Dist: pyogrio>=0.12.0
Requires-Dist: pyqt5
Requires-Dist: rasterio>=1.5.0
Requires-Dist: scikit-image>=0.24.0
Requires-Dist: scipy
Requires-Dist: tabulate
Requires-Dist: tqdm
Requires-Dist: xarray-spatial
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: isort; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: pytest-qt; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: tox; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Provides-Extra: doc
Requires-Dist: mkdocstrings; extra == 'doc'
Requires-Dist: mkdocstrings-python; extra == 'doc'
Requires-Dist: pymdown-extensions; extra == 'doc'
Requires-Dist: zensical==0.0.53; extra == 'doc'
Provides-Extra: r
Requires-Dist: rpy2; extra == 'r'
Requires-Dist: rpy2-rinterface!=3.6.7; (sys_platform == 'win32' and python_version == '3.13') and extra == 'r'
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Requires-Dist: pytest-qt; extra == 'test'
Requires-Dist: pywinauto; (platform_system == 'Windows') and extra == 'test'
Description-Content-Type: text/markdown

# BERA Tools

BERA Tools is successor of [Forest Line Mapper](https://github.com/appliedgrg/flm). It is a toolset for enhanced delineation and attribution of linear disturbances in forests.

<div align="center">

[![Python Integration Tests](https://img.shields.io/github/actions/workflow/status/BERATool/beratools/python-integration-tests.yml?branch=main)](https://github.com/BERATool/beratools/actions/workflows/python-integration-tests.yml)
[![GitHub Pages](https://img.shields.io/github/deployments/BERATool/beratools/github-pages?label=docs)](https://beratool.github.io/beratools/)
[![Conda Version](https://img.shields.io/conda/v/bera_tools/beratools?cacheSeconds=3600)](https://anaconda.org/bera_tools/beratools)
[![PyPI](https://img.shields.io/pypi/v/BERATools?cacheSeconds=3600)](https://pypi.org/project/BERATools/)
[![Python Version](https://img.shields.io/badge/python-3.12--3.14-blue)](https://www.python.org/downloads/)
[![License: GPL-3.0](https://img.shields.io/badge/License-GPL%203.0-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

</div>

## [Quick Start](https://beratool.github.io/beratools/)

Here are the ways to install BERA Tools:

- Windows installer
- Install with Anaconda.

### Windows Installer

Windows installer is provided with releases. Check the [latest release](https://github.com/BERATool/beratools/releases/latest). Signing is currently off by default; unsigned assets are named `beratools-installer-x.y.z-unsigned.exe` and identified as unsigned in the release notes. Windows may display an unknown-publisher or SmartScreen warning. Maintainers can enable SignPath per run according to the BERA Tools [Code signing policy](CODE_SIGNING_POLICY.md).

### Install with Anaconda

Install with Anaconda works on Windows, macOS, and Linux.

- Install Miniconda. Download Miniconda from [Miniconda](https://docs.anaconda.com/miniconda/) and install on your machine.
- Download and save the file [environment.yml](https://raw.githubusercontent.com/BERATool/beratools/main/environment.yml).
- Launch **Anaconda Prompt** and **Change directory** to where environment.yml is saved.
- Run the command to install BERA Tools.

   ```bash
   $ conda env create -n bera -f environment.yml
   ```

   After the installation is done, a new environment named **bera** is created and BERA Tools is installed within it.
- Activate the **bera** environment and launch BERA Tools main GUI:

  ```bash
  $ conda activate bera
  $ beratools gui
  ```

![BERA Tools Main GUI](beratools/gui/assets/BERA_GUI_Main.png)

- [Download latest example data](https://github.com/BERATool/beratools/releases/latest/download/test_data.zip) to try with BERA Tools.

For more information about installation, check the [BERA Tools Installation](https://beratool.github.io/beratools/user/installation/).

#### Troubleshooting: `CondaEnvException: Pip failed`

`environment.yml` installs `rpy2` with pip at the end of `conda env create`. If that step fails
(e.g. `Pip subprocess error`), create the environment without pip first, then install `rpy2` yourself:

1. Open `environment.yml` and comment out the pip section:

   ```yaml
   #  - pip:
   #      - rpy2
   ```

2. Create and activate the environment:

   ```bash
   $ conda env create -n bera -f environment.yml
   $ conda activate bera
   ```

3. Set the R paths (Windows **Anaconda Prompt**):

   ```bat
   set "R_HOME=%CONDA_PREFIX%\Lib\R"
   set "PATH=%R_HOME%\bin\x64;%PATH%"
   ```

4. Install `rpy2` with pip:

   ```bash
   $ python -m pip install rpy2
   ```

If pip still fails, check that the environment's Python starts with `python -c "print('ok')"`. A
Python that does not start (e.g. "The file or directory is corrupted and unreadable") is the real
cause. Rebuild the environment with a different Python version.

## PC2Products (LiDAR) Tools

The **PC2Products** (Point Cloud to Products) category turns LiDAR point clouds (`.las` / `.laz`) into
rasters such as a DTM, DSM, CHM and hummock/hollow maps. The tools run R and
[lidR](https://r-lidar.github.io/lidRbook/) through [rpy2](https://rpy2.github.io/); `environment.yml`
and `pixi.toml` include R, and the tools install the R packages they need the first time they run
(see [R for the PC2Products tools](https://beratool.github.io/beratools/user/installation/#r-for-the-pc2products-lidar-tools)).

| Tool | `bt` subcommand |
|------|-----------------|
| [LiDAR data info](https://beratool.github.io/beratools/pc2products/user/las_info/) | `las_info` |
| [Raster Cell size from LiDAR data](https://beratool.github.io/beratools/pc2products/user/cellsize/) | `cellsize` |
| [Build LiDAR Spatial Index](https://beratool.github.io/beratools/pc2products/user/lidar_index/) | `lidar_index` |
| [Tile LiDAR Data](https://beratool.github.io/beratools/pc2products/user/lidar_tile/) | `tile` |
| [Ground Classify Using CSF](https://beratool.github.io/beratools/pc2products/user/gnd_csf/) | `gnd_csf` |
| [Generate DTM from LiDAR Data](https://beratool.github.io/beratools/pc2products/user/dtm/) | `dtm` |
| [Normalize LiDAR Data](https://beratool.github.io/beratools/pc2products/user/normalize/) | `normalize` |
| [Generate CHM or DSM from LiDAR Data](https://beratool.github.io/beratools/pc2products/user/chm_dsm/) | `chm_dsm` |
| [Detect Hummock and Hollow from LiDAR Data](https://beratool.github.io/beratools/pc2products/user/hummock_hollow/) | `hh` |
| [Surface Water Mapping](https://beratool.github.io/beratools/pc2products/user/surface_water/) | `surface_water` |
| [Depth-to-Water from Surface Water](https://beratool.github.io/beratools/pc2products/user/dtw/) | `dtw` |
| [Seismic Line Disturbance Analysis](https://beratool.github.io/beratools/pc2products/user/seismic_line_analysis/) | `line_analysis` |

```bash
$ beratools dtm --in_las_folder tests/data/LiDAR --out_folder tests/data/LiDAR/Raster_Output --style tin
```

Sample tiles are in `tests/data/LiDAR/`, and `examples/` has two scripts that run the LiDAR tools in
sequence (see [examples/README.md](examples/README.md)).

### Things to consider for running the R tools in parallel

Ground classification, DTM, normalization, CHM/DSM and hummock/hollow split the point cloud into
tiles and process them with several R workers. How many workers a computer runs depends mostly on
its **free memory** and the **point density**, as each worker must hold the densest tile it gets.
A few files or tiles much denser than the rest don't hold the whole run back: they are processed
after the others with fewer workers.

- **Memory per worker**: about (1.6 GB + bytes per point × the points in a tile with its buffer)
  ÷ 0.6 of free memory, as the tools share 60% of the memory free when they start. The bytes per
  point were measured for each tool: 260 for ground classification and IDW normalization, 160 for
  the IDW DTM, up to 670 for the tools that triangulate the ground points (TIN DTM, TIN
  normalization and hummock/hollow; less for data with less ground, which they sample before
  planning; the table below is for all ground), 850 for the pit-free CHM/DSM, and about 120 plus 450 per raster cell for
  the TIN CHM/DSM (see
  [How all the tools behave](https://beratool.github.io/beratools/pc2products/technical/tool_behaviour/)).
  Tiles are 100 to 500 m, chosen for each 500 m block from the density, so dense areas get small
  tiles. Free memory needed per worker at the smallest tile (100 m, read with a 20 m buffer for
  ground classification and 30 m for the other tools), with one thread:

  | Point density | Typical data | Ground classification | IDW normalization | TIN tools | Pit-free CHM/DSM |
  |---|---|---|---|---|---|
  | 20 pts/m² | airborne LiDAR | 2.8 GB | 2.9 GB | 3.2 GB | 3.4 GB |
  | 100 pts/m² | dense airborne LiDAR | 3.5 GB | 3.8 GB | 5.5 GB | 6.3 GB |
  | 300 pts/m² | drone LiDAR | 5.2 GB | 6.0 GB | 11.2 GB | 13.5 GB |
  | 700 pts/m² | photogrammetry point clouds | 8.6 GB | 10.4 GB | 22.7 GB | 28.1 GB |

- **RAM**: installed RAM ≈ workers × memory per worker + 5 to 6 GB for Windows and other
  programs. For example, airborne LiDAR runs 2 to 4 workers with 16 GB; a 700 pts/m² point cloud
  needs 32 GB for 2 workers with little else open, and 48 to 64 GB for 4 (for ground
  classification; a TIN DTM of it needs about 32 GB for 1 worker). Close other programs
  before a long run, as the tools plan for the memory free when they start.
- **CPU**: the `processes` allowed (all cores by default) are shared between the workers, so
  when memory allows fewer workers than cores, each worker gets the spare cores as lidR threads
  (about 0.2 GB more each). A worker is started only for every 20 million points of input, so
  small jobs use one worker.
- **Disk**: a hard disk works; an SSD helps when several workers read LAZ files at once. Each
  input file gets a `.lax` spatial index next to it (built once, see
  [Build LiDAR Spatial Index](https://beratool.github.io/beratools/pc2products/user/lidar_index/)), so the
  input folder must be writable for the fastest reading.
- **Memory limit**: each tool and its workers are limited to 80% of the free memory, so a tile
  that needs more stops the tool with an error (`std::bad_alloc` or "cannot allocate") instead of
  running the computer out of memory.
- **Resuming**: a run stops at the first tile that fails, or when you cancel it. Free memory, then
  run the tool again with `skip_existing` set to `true` and the same parameters: the tiles whose
  outputs are complete are skipped (each output is written as `<name>.partial.<ext>` and renamed
  when complete, so a tile cut off while writing is made again), and the 500 m blocks that have outputs keep the tile sizes of the plan the run
  saved next to its outputs (`tiles_<suffix>.csv`); the other blocks are tiled again for the
  memory free now.
- **Kriging**: the memory figures were measured for ground classification. Kriging (DTM and
  normalization) needs far more, over 7.8 GB for 14 million points, so use TIN or IDW on large
  or dense data.
- **Uniform tiles**: tiled point cloud outputs (ground classification, normalization) vary in size
  with the density, from 500 m down to 100 m, and the next tool processes them best as they are,
  since each one fits in memory. To deliver them as uniform tiles, for example for GIS or to match
  a tile index, run [Tile LiDAR Data](https://beratool.github.io/beratools/pc2products/user/lidar_tile/) on the
  output folder once the chain of tools is done. Every tile size divides the 500 m blocks, so the
  outputs combine into exact 500 m (or 1 km) tiles; the points are streamed, using little memory,
  but each is read and written once more:

  ```bash
  bt tile --in_las_folder Classified_PC --out_folder Classified_PC_500m --tile_size 500 --buffer 0
  ```

  The raster tools don't need this: they also write one merged `Merged_*.tif`.

[How the LiDAR tools tile a point cloud](docs/files/technical/lidar_density_tiling.md)
explains the tiling with diagrams, and
[How all the tools behave](https://beratool.github.io/beratools/pc2products/technical/tool_behaviour/) has the
details of tiling, workers and progress.

## Raster2Products Tools

The **Raster2Products** category makes rasters from other rasters, such as a DTM from
[Generate DTM from LiDAR Data](https://beratool.github.io/beratools/pc2products/user/dtm/). The tools run in
Python and need no R; they read large rasters in tiles and process each tile in parallel.

| Tool | `bt` subcommand |
|------|-----------------|
| [Normalized DTM from DTM Raster](https://beratool.github.io/beratools/raster2products/user/ndtm_fr_dtmraster/) | `ndtm_fr_dtmraster` |

```bash
$ bt ndtm_fr_dtmraster --in_dtm Raster_Output/Merged_TIN_DTM.tif --out_folder NDTM --Smooth_by median --Min_ws 3
$ bt ndtm_fr_dtmraster --in_dtm Raster_Output --out_folder NDTM --Smooth_by median --Min_ws 3   # its DTM tiles, one output each
```

## Pipelines

The **Pipeline** tab, next to **Tool history** in the GUI, chains tools into steps that run one after
another. Drag tools in from the tool tree, set each step's parameters in the tool form, and link a
step's inputs to an earlier step's output. Each input links to the latest earlier step that makes what
it needs, for example the checked lines from **Check Seed Lines** into **Centerline**, and the
links are reset whenever a step is added, moved or removed.

![BERA Tools Pipeline panel](docs/files/screenshots/bt_pipeline.png)

The example above chains the six mapping tools into a ground footprint workflow. Each step lists the
step it reads from (`← step 5`), and the selected step's linked inputs are shown under
**Inputs from earlier steps** and greyed out in the tool form. Use **Run Pipeline** to run all steps
in order.

Pipelines save as `.json` files and also run without the GUI:

```bash
$ python -m beratools.core.pipeline my_pipeline.json --processes 4
```

See [Building a pipeline](https://beratool.github.io/beratools/user_guide/#building-a-pipeline).

## BERA Tools Guide

Check the online [BERA Tools Guide](https://beratool.github.io/beratools/) for user, developer and technical guides.

## Sponsors

<table>
  <tr>
    <td align="center">
      <a href="https://about.signpath.io/">
        <img src="https://avatars.githubusercontent.com/u/34448643?s=48&amp;v=4" alt="SignPath logo" width="48">
      </a>
    </td>
    <td>
      Free code signing on Windows provided by <a href="https://about.signpath.io/">SignPath.io</a>, certificate by <a href="https://signpath.org/">SignPath Foundation</a>.
    </td>
  </tr>
</table>

## Credits

<table>
  <tr>
    <td><img src="https://github.com/BERATool/beratools/raw/main/docs/files/icons/bera_logo.png" alt="Logos" width="80"></td>
    <td>
      <p>
        This tool is part of the <strong><a href="http://www.beraproject.org/">Boreal Ecosystem Recovery & Assessment (BERA)</a></strong>.
        It is actively developed by the <a href="https://www.appliedgrg.ca/"><strong>Applied Geospatial Research Group</strong></a>.
      </p>
      <p>
        © 2026 Applied Geospatial Research Group. All rights reserved.
      </p>
    </td>
  </tr>
</table>
