Skip to content

Python API Reference

This page documents the frame's Python API. Each module's API is on its own site (see Modules).

Pipeline

Copyright (C) 2025 Applied Geospatial Research Group.

This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.

Description

This script is part of the BERA Tools. Webpage: https://github.com/BERATool/beratools

The purpose of this script is to provide user-built pipelines: an ordered list of tool steps, saved as JSON and run one after another. A step's input can be linked to an earlier step's output, so the pipeline can be rerun on other data by changing only the first step's input.

Which inputs can be linked to which outputs comes from the modules' tools.json files, so a new tool takes part in pipelines without changes here: - an input parameter with "accepts": "" can be linked; - an output parameter with "produces": {"": [patterns]} provides that kind. An empty list means the output folder itself (e.g. a folder of point clouds); otherwise the first pattern that matches files in the output folder is used, newest file first.

Usage

python -m beratools.core.pipeline my_pipeline.json [--processes 4]

linkable_inputs

linkable_inputs(tool_api)

{input variable: kind} for the tool's inputs that can come from an earlier step.

produced_kinds

produced_kinds(tool_api)

{kind: (output variable, file patterns)} for what the tool writes.

link_sources(steps, kind)

Steps (from the given list) that produce kind.

default_links(steps, tool_api)

Link each of the tool's linkable inputs to the latest step (from steps) that produces its kind.

relink(steps)

Reset every step's links to the defaults for its place in the list.

Called after adding, moving or removing a step.

validate_pipeline

validate_pipeline(steps)

Return a list of problems with the step links; empty when the pipeline can run.

missing_inputs

missing_inputs(steps)

Return a problem for each input file or folder a step reads that doesn't exist.

Linked inputs are skipped, since an earlier step writes them while the pipeline runs.

describe_link(steps, step, variable)

What a linked input will read, e.g. 'D:/rasters/Merged_*_DTM.tif', for showing in the GUI.

resolve_link(steps, step, variable)

The path a linked input reads; call it after the source step has run.

resolve_step_args

resolve_step_args(steps, index)

Step arguments with the linked inputs filled in from the earlier steps' outputs.

tool_command

tool_command(tool_api, args, processes, call_mode='CLI')

Arguments to run one tool script in its own process, as the GUI does.

Constants

Copyright (C) 2025 Applied Geospatial Research Group.

This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.

Author: Richard Zeng

Description

This script is part of the BERA Tools. Webpage: https://github.com/BERATool/beratools

The purpose of this script is to provide common constants.

CenterlineStrategy

Bases: Enum

Guided strategy for centerline extraction.

CenterlineMethod

Bases: Enum

Least-cost path and corridor raster method for centerline extraction.

CenterlineChmMode

Bases: Enum

CHM preprocessing mode for centerline extraction.

CenterlineFlags

Bases: Flag

Flags for the centerline algorithm.

ParallelMode

Bases: IntEnum

Defines the parallel mode for the algorithms.

Logger

Copyright (C) 2025 Applied Geospatial Research Group.

This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.

Author: Richard Zeng

Description

This script is part of the BERA Tools. Webpage: https://github.com/BERATool/beratools

This module provides logger configuration and convenience functions for BERA Tools.

Each named logger can write to:

  1. A log file using a detailed timestamped format.
  2. The console using a concise message-only format.

The module also adds two convenience methods to each configured logger:

logger.file_only(...)
logger.debug_file_only(...)

These methods bypass console handlers and write directly to the logger's file handler.

NoParsingFilter

Bases: Filter

Exclude messages beginning with the word parsing.

This reduces console and file noise from repetitive parsing messages. The comparison is case-sensitive to retain the behavior of the original implementation.

filter

filter(record: LogRecord) -> bool

Return False for messages beginning with parsing.

Parameters

record : logging.LogRecord Logging record being evaluated.

Returns

bool True when the record should be logged. False when the record should be discarded.

Logger

Logger(logger_name, queue=None, file_level=DEFAULT_FILE_LEVEL, console_level=DEFAULT_CONSOLE_LEVEL)

Configure a named BERA Tools logger.

The logger uses two handlers:

  • File handler: Stores timestamped messages at file_level or higher.

  • Console handler: Displays concise messages at console_level or higher.

Each logger is configured only once. Creating another Logger instance with the same name reuses the existing handlers.

Parameters

logger_name : str Name of the logger.

int, default logging.INFO

Minimum logging level written to the log file.

int, default logging.INFO

Minimum logging level written to the console.

get_logger

get_logger() -> Logger

Return the configured logger.

Two convenience methods are attached to the logger:

logger.file_only(message, *args, level=logging.INFO) Write only to file handlers.

logger.debug_file_only(message, *args) Write a DEBUG message only to file handlers.

Returns

logging.Logger Configured logger instance.

print

print(message, flush: bool = True) -> None

Log a message at INFO level.

This method provides compatibility with code that previously used print() for progress or status messages.

Parameters

message : object Message or object to log.

bool, default True

Flush all configured handlers after logging.

flush

flush() -> None

Flush all handlers associated with this logger.

Flushing should normally be used only for important progress messages, shutdown handling, or debugging. Flushing every log record can significantly reduce performance.

debug_file_only staticmethod

debug_file_only(message, *args, logger_name: Optional[str] = None) -> None

Write a DEBUG message only to file handlers.

The message is not sent to console handlers.

Parameters

message : object Log message or formatting template.

*args Values used with standard logging percent formatting.

str

Name of an existing configured logger.

file_only staticmethod

file_only(message, *args, level: int = INFO, logger_name: Optional[str] = None) -> None

Write a message directly to the logger's file handlers.

Console handlers are intentionally bypassed.

Unlike a regular logger call, this method sends the record directly to each file handler. This allows a DEBUG file-only record to be written even when the logger's effective level is INFO or WARNING, provided the file handler accepts that level.

Parameters

message : object Log message or formatting template.

*args Values used with standard logging percent formatting.

int, default logging.INFO

Logging level associated with the record.

str

Name of an existing configured logger.

Notes

This method does not flush the file handler after every message. Operating-system and Python buffering improve performance during large multiprocessing jobs. Use Logger.flush() when an immediate flush is required.

Tool Base

Copyright (C) 2025 Applied Geospatial Research Group.

This script is licensed under the GNU General Public License v3.0. See https://gnu.org/licenses/gpl-3.0 for full license details.

Author: Richard Zeng

Description

This script is part of the BERA Tools. Webpage: https://github.com/BERATool/beratools

The purpose of this script is to provide fundamental utilities for tools.

ToolBase

ToolBase()

Bases: object

Base class for tools.

configure_worker_logging

configure_worker_logging(queue)

Configure worker process logger.