Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reboost core API #26

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
81d9825
add function to extract function strin (and packages to import) and a…
tdixon97 Jan 26, 2025
5065e76
add the functionality for step grouping
tdixon97 Jan 26, 2025
a1bab98
add evaluate object function
tdixon97 Jan 26, 2025
115b36d
add method for evaluating columns
tdixon97 Jan 26, 2025
6c36d05
change elm to glm everywhere to avoid confusion with the detector wid…
tdixon97 Jan 27, 2025
d6d2ac6
namedtuple to AttrsDict and also test evaluations
tdixon97 Jan 27, 2025
58bf133
refactor code to extract module names and test getting objects and eval
tdixon97 Jan 28, 2025
bfdd069
small fixes to tests
tdixon97 Jan 28, 2025
56b7a92
add optional dependencies
tdixon97 Jan 28, 2025
b9ddba5
fix to dependencies
tdixon97 Jan 28, 2025
8dad6c3
add the test data
tdixon97 Jan 28, 2025
a1def17
trick to keep tab.eval happy
tdixon97 Jan 28, 2025
a560524
add functionality to extract detector mappings
tdixon97 Jan 28, 2025
ae5bfc7
require new lgdo
tdixon97 Jan 28, 2025
8884e47
Merge branch 'main' into reorganise
tdixon97 Jan 28, 2025
6456c5d
fix typo
tdixon97 Jan 28, 2025
a9b7265
should fix mac
tdixon97 Jan 28, 2025
9d88103
Update src/reboost/core.py
tdixon97 Jan 28, 2025
af08742
[tests] very basic test for build_hit and some small fixes
tdixon97 Jan 29, 2025
deded2d
small fix in tests
tdixon97 Jan 29, 2025
4f4f4b0
change evaluate_expression name
tdixon97 Jan 29, 2025
57b8ba2
add processors for distance to surface and gaussian convolution
tdixon97 Jan 29, 2025
8e2b3ad
fix type conversion
tdixon97 Jan 29, 2025
0947e88
some functionalty to time profile
tdixon97 Jan 29, 2025
94ce427
sort isnt needed for group by evtid
tdixon97 Jan 30, 2025
607b5d7
fix to the gaussian sampling types
tdixon97 Jan 30, 2025
fc3aa18
Style changed suggested by Manuel
tdixon97 Jan 30, 2025
c6428fe
style: pre-commit fixes
pre-commit-ci[bot] Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install non-python (homebrew) dependencies
if: ${{ matrix.os == 'macOS-latest' }}
run: |
brew install opencascade cgal gmp mpfr boost
- name: Get dependencies and install reboost
run: |
python -m pip install --upgrade pip wheel setuptools
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"numpy",
"scipy",
"numba",
"legend-pydataobj>=1.11.3",
"legend-pydataobj>=1.11.6",
"legend-pygeom-optics>=0.6.5",
"hist",
"dbetto",
Expand Down Expand Up @@ -69,6 +69,11 @@ test = [
"pre-commit",
"pytest>=6.0",
"pytest-cov",
"legend-pygeom-hpges",
"legend-pygeom-tools",
"pyg4ometry",
"pylegendtestdata",

]

[project.scripts]
Expand Down
4 changes: 2 additions & 2 deletions src/reboost/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from reboost import build_hit, core, iterator, optmap
from reboost import build_hit, core, iterator, math, optmap
from reboost._version import version as __version__

__all__ = ["__version__", "build_hit", "core", "iterator", "optmap"]
__all__ = ["__version__", "build_hit", "core", "iterator", "math", "optmap"]
49 changes: 26 additions & 23 deletions src/reboost/build_elm.py → src/reboost/build_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
log = logging.getLogger(__name__)


def get_elm_rows(stp_evtids: ArrayLike, vert: ArrayLike, *, start_row: int = 0) -> ak.Array:
"""Get the rows of the event lookup map (elm).
def get_glm_rows(stp_evtids: ArrayLike, vert: ArrayLike, *, start_row: int = 0) -> ak.Array:
"""Get the rows of the event lookup map (glm).

Parameters
----------
Expand All @@ -26,7 +26,7 @@ def get_elm_rows(stp_evtids: ArrayLike, vert: ArrayLike, *, start_row: int = 0)

Returns
-------
an awkward array of the `elm`.
an awkward array of the `glm`.
"""
# convert inputs
if not isinstance(stp_evtids, np.ndarray):
Expand Down Expand Up @@ -166,15 +166,16 @@ def get_stp_evtids(
return start_row, chunk_start, evtids_proc


def build_elm(
def build_glm(
stp_file: str,
elm_file: str | None,
glm_file: str | None,
*,
out_table_name: str = "glm",
id_name: str = "g4_evtid",
evtid_buffer: int = 10000,
stp_buffer: int = 1000,
) -> ak.Array | None:
"""Builds a g4_evtid look up (elm) from the stp data.
"""Builds a g4_evtid look up (glm) from the stp data.

This object is used by `reboost` to efficiency iterate through the data.
It consists of a :class:`LGDO.VectorOfVectors` for each lh5_table in the input files.
Expand All @@ -185,8 +186,10 @@ def build_elm(
----------
stp_file
path to the stp (input) file.
elm_file
path to the elm data, can also be `None` in which case an `ak.Array` is returned in memory.
glm_file
path to the glm data, can also be `None` in which case an `ak.Array` is returned in memory.
out_table_name
name for the output table.
id_name
name of the evtid file, default `g4_evtid`.
stp_buffer
Expand All @@ -205,10 +208,10 @@ def build_elm(
lh5_table_list = [table for table in lh5.ls(stp_file, "stp/") if table != "stp/vertices"]

# get rows in the table
if elm_file is None:
elm_sum = {lh5_table.replace("stp/", ""): None for lh5_table in lh5_table_list}
if glm_file is None:
glm_sum = {lh5_table.replace("stp/", ""): None for lh5_table in lh5_table_list}
else:
elm_sum = None
glm_sum = None

# start row for each table
start_row = {lh5_tab: 0 for lh5_tab in lh5_table_list}
Expand Down Expand Up @@ -238,27 +241,27 @@ def build_elm(
# set the start row for the next chunk
start_row[lh5_table] = start_row_tmp

# now get the elm rows
elm = get_elm_rows(evtids, vert_ak, start_row=chunk_row)
# now get the glm rows
glm = get_glm_rows(evtids, vert_ak, start_row=chunk_row)

for field in ["evtid", "n_rows", "start_row"]:
out_tab.add_field(field, Array(elm[field].to_numpy()))
out_tab.add_field(field, Array(glm[field].to_numpy()))

# write the output file
mode = "of" if (vidx == 0 and idx == 0) else "append"

lh5_subgroup = lh5_table.replace("stp/", "")

if elm_file is not None:
store.write(out_tab, f"elm/{lh5_subgroup}", elm_file, wo_mode=mode)
if glm_file is not None:
store.write(out_tab, f"{out_table_name}/{lh5_subgroup}", glm_file, wo_mode=mode)
else:
elm_sum[lh5_subgroup] = (
copy.deepcopy(elm)
if elm_sum[lh5_subgroup] is None
else ak.concatenate((elm_sum[lh5_subgroup], elm))
glm_sum[lh5_subgroup] = (
copy.deepcopy(glm)
if glm_sum[lh5_subgroup] is None
else ak.concatenate((glm_sum[lh5_subgroup], glm))
)

# return if it was requested to keep elm in memory
if elm_sum is not None:
return ak.Array(elm_sum)
# return if it was requested to keep glm in memory
if glm_sum is not None:
return ak.Array(glm_sum)
return None
Loading
Loading