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": "
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
link_sources(steps, kind)
Steps (from the given list) that produce kind.
default_links
default_links(steps, tool_api)
Link each of the tool's linkable inputs to the latest step (from steps) that produces its kind.
relink
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
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
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
CenterlineMethod
CenterlineChmMode
CenterlineFlags
ParallelMode
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:
- A log file using a detailed timestamped format.
- 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.
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_levelor higher. -
Console handler: Displays concise messages at
console_levelor 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(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
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
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.
configure_worker_logging
configure_worker_logging(queue)
Configure worker process logger.