ComputeAnchors#

class ComputeAnchors(cfg: dict | None = None)[source]#

Bases: object

Compute geometric anchors once per event and attach them to the sample.

Reads data_dict["coord"] and data_dict["energy"] and calls the package compute_anchors helper (with ANCHOR_DEFAULT_CFG merged with cfg) to detect salient structures (e.g. endpoints, branches, Bragg peaks), writing the resulting dict to data_dict["anchors"]. These anchors can later bias view sampling (see MultiViewGenerator). A no-op when the helper is unavailable or when coord/energy are missing. Registered as ComputeAnchors — use this string as the type in a transform=[...] config list.

Parameters:

cfg (dict, optional) – Overrides merged on top of ANCHOR_DEFAULT_CFG. Defaults to None (empty dict).

Example

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> data = {"coord": rng.random((50, 3), dtype="f4"),
...         "energy": rng.random((50, 1), dtype="f4")}
>>> out = ComputeAnchors()(data)
>>> list(out["anchors"].keys())  # dict of detected salient structures
['endpoints', 'branches_track', 'branches_shower', 'bragg', 'led']
# each value is an (M, 3) array of anchor coordinates; M varies per event