opengate-gate-tree
opengate-gate-tree is a utility for processing GATE 9 output ROOT file with trees (Hits, Singles,Coincidences)
Supported GATE Versions
The package targets the C++ line of GATE, version 9.4.2 and newer. GATE 10, the Python implementation, is not supported.
Output files are not meant to be read back by GATE. They are conversions of the simulation output into whichever format suits the analysis that follows:
| Format | Typical consumer |
|---|---|
root |
further analysis in C++ with the ROOT framework |
hdf5 |
analysis in Python or MATLAB, large datasets, columnar access |
csv |
quick inspection, spreadsheets, plain pandas.read_csv |
Quick Start
Install From PyPI
pip3 install opengate-gate-tree
Install From Source
make init
make install
Command-Line Options
The CLI accepts the following options:
| Option | Type | Required | Allowed values | Description |
|---|---|---|---|---|
--input-gate-root-file |
path | yes | file with .root extension |
Path to the GATE ROOT input file. |
--output-dir |
path | yes | existing directory or new path | Directory where output file will be saved. If it does not exist, it is created automatically. |
--output-file-title |
string | yes | non-empty string | Base name of the output file (without extension). |
--gate-tree |
enum-like string | yes | Hits, Singles, Coincidences |
Name of the tree to process from the input ROOT file. |
--output-file-format |
enum-like string | yes | root, hdf5, csv |
Output file format. |
--branches-to-extract |
list of strings | no | branch names valid for selected tree | Space-separated list of branches to extract. |
Validation behavior:
- the input file must exist, end with
.rootand be readable as a ROOT file - the output directory is created if it does not exist
- an existing output file is overwritten without a prompt
- all required options above must be provided
- the selected tree must be present in the input file; if it is not, the error lists the trees the file actually holds
- branch names are validated against the branches present in the input file
- branches whose length varies per entry are reported as unsupported
The output file holds the extracted tree only. Histograms stored next to the trees in a GATE file are not copied over.
Fixed-width array branches, such as volumeID, keep their shape in the root
and hdf5 output. CSV has no cell for an array, so they are written there as
one column per component, named volumeID_0 to volumeID_9.
Examples:
opengate-gate-tree \
--input-gate-root-file ./data/simulation.root \
--output-dir ./out \
--output-file-title patient_01 \
--gate-tree Hits \
--output-file-format csv
opengate-gate-tree \
--input-gate-root-file ./data/simulation.root \
--output-dir ./out \
--output-file-title patient_01 \
--gate-tree Singles \
--output-file-format hdf5 \
--branches-to-extract eventID trackID edep posX
Library Usage
Besides the command-line interface, the package can be used directly from
Python code. Everything the command line does is reachable from
opengate_gate_tree.
Loading And Exporting Files
from pathlib import Path
from opengate_gate_tree import (
GateTree,
OutputFileFormat,
read_tree,
write_tree,
)
# Load selected branches of the "Hits" tree from a GATE ROOT file.
data = read_tree(
Path("simulation.root"),
GateTree.HITS,
["eventID", "edep", "posX", "posY", "posZ"],
)
print(data.entry_count, data.branch_names)
# Work with the data as NumPy arrays or as a pandas.DataFrame.
energies = data["edep"]
frame = data.to_dataframe()
# Export to the format that fits the downstream analysis.
write_tree(data, Path("out/hits.hdf5"), OutputFileFormat.HDF5)
Omit the branch list to read every branch of the tree:
data = read_tree(Path("simulation.root"), GateTree.HITS)
When several trees come from the same file, open it once with RootFile:
from opengate_gate_tree import RootFile
with RootFile(Path("simulation.root")) as root_file:
print(root_file.tree_names)
hits = root_file.read(GateTree.HITS, ["eventID", "edep"])
Failures while reading or writing files are reported through a subclass of
GateTreeError, so one except clause covers them. Malformed arguments, such as
an empty branch name, raise ValueError instead:
from opengate_gate_tree import GateTreeError, TreeNotFoundError
try:
data = read_tree(Path("simulation.root"), GateTree.SINGLES)
except TreeNotFoundError as error:
print(f"tree missing: {error}")
except GateTreeError as error:
print(f"could not process the file: {error}")
The package does not configure logging on import. Applications that want the defaults used by the command line can ask for them:
from opengate_gate_tree.logging_setup import configure_logging
configure_logging()
The package ships a py.typed marker, so type checkers see its annotations.
Available Package Capabilities (Cumulative)
This section is append-only.
Add a capability entry only when its roadmap stage status changes from planned to completed.
Current development stage: version-0.2.0
Available capabilities:
- 0.1.0: project structure initialized and minimal buildable package code added.
- 0.2.0: GATE ROOT files can be loaded and validated, trees and branches extracted into a NumPy-backed representation with a pandas view, and written to ROOT, HDF5 or CSV. Usable both as a command-line tool and as a library, with user documentation on ReadTheDocs.
Development
Common development commands:
make lint
make format
make typecheck
make test
make check
Pre-commit setup
You can install and activate pre-commit in two supported ways.
Option A (recommended): use uv in this repository
uv add --dev pre-commit
uv sync
uv run pre-commit install --hook-type pre-commit
Optional one-time verification on all files:
uv run pre-commit run --all-files
Option B: install pre-commit from Debian packages
sudo apt update
sudo apt install -y pre-commit
pre-commit --version
pre-commit install --hook-type pre-commit
Optional one-time verification on all files:
pre-commit run --all-files
The configured hook runs make check before each commit and blocks the commit if validation fails.
Documentation
The user documentation is built with Sphinx:
make docs # build docs/_build/html
make docs-check # build with warnings treated as errors, as ReadTheDocs does
Project conventions and contribution standards:
License
MIT License
Contact: GitHub
Author
The project was designed and implemented by Mateusz Jakub Bała.
Contact: GitHub
Contribution
To contribute new functionality:
- create a branch from
develop - follow the commit conventions
- open a PR using the PR template
- follow the contribution guide
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opengate_gate_tree-0.2.0.tar.gz.
File metadata
- Download URL: opengate_gate_tree-0.2.0.tar.gz
- Upload date:
- Size: 176.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15aa378e47f31760d3a303e5fd908dd1910bda6cd240cfadc528dfde216a1b4d
|
|
| MD5 |
1483a1037859ee8363837fc2ddfd75e0
|
|
| BLAKE2b-256 |
4ac14996f137a9884ec167ed4c81f35c12dd5425e778a0a82146a07fdf143b22
|
Provenance
The following attestation bundles were made for opengate_gate_tree-0.2.0.tar.gz:
Publisher:
publish.yml on MateuszBala/opengate-gate-tree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opengate_gate_tree-0.2.0.tar.gz -
Subject digest:
15aa378e47f31760d3a303e5fd908dd1910bda6cd240cfadc528dfde216a1b4d - Sigstore transparency entry: 2654891041
- Sigstore integration time:
-
Permalink:
MateuszBala/opengate-gate-tree@afbf15cd6c2fab44cf62771ad0ce2478153c0ec0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/MateuszBala
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@afbf15cd6c2fab44cf62771ad0ce2478153c0ec0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opengate_gate_tree-0.2.0-py3-none-any.whl.
File metadata
- Download URL: opengate_gate_tree-0.2.0-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b9690efdaf70cdea6d3143885467e2165d5f5d3c7d4b96127f658aeb151de88
|
|
| MD5 |
3d1ce1180d9040c13421c71081c5b9d8
|
|
| BLAKE2b-256 |
7872c765867f533dd321fcf2fba4f124156f4b29c0e18521e3a33029f15c145d
|
Provenance
The following attestation bundles were made for opengate_gate_tree-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on MateuszBala/opengate-gate-tree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opengate_gate_tree-0.2.0-py3-none-any.whl -
Subject digest:
1b9690efdaf70cdea6d3143885467e2165d5f5d3c7d4b96127f658aeb151de88 - Sigstore transparency entry: 2654891077
- Sigstore integration time:
-
Permalink:
MateuszBala/opengate-gate-tree@afbf15cd6c2fab44cf62771ad0ce2478153c0ec0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/MateuszBala
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@afbf15cd6c2fab44cf62771ad0ce2478153c0ec0 -
Trigger Event:
release
-
Statement type: