Subset#

class deeptrack.sources.base.Subset(source: Source, indices: Sequence[int])#

Bases: Source

A subset of a source defined by a list of indices.

Subset represents a restricted version of a parent Source, containing only the items at the specified indices. The subset is materialized: all fields are sliced at construction time and stored as new sequences.

The subset behaves like a normal Source while preserving activation compatibility with the parent source:

  • len(subset) equals the number of selected indices.

  • subset[i] returns the i-th element of the subset.

  • Dynamic field access (e.g., subset.a()) uses the subset’s own active item.

  • Activating an item from the subset also activates the corresponding item in the parent source.

This parent activation propagation preserves compatibility with pipelines built from the original source. For example, if a pipeline depends on source.a, evaluating it on subset[i] updates both subset.a and source.a.

Parameters#

source: Source

The original source to take a subset from.

indices: Sequence[int]

Indices of the items to include in the subset. Indices follow normal Python indexing rules for the original source (including negatives).

Attributes#

source: Source

The original source this subset was created from.

indices: list[int]

The indices used to construct the subset.

Examples#

>>> from deeptrack.sources import Source, Subset

Create a source: >>> source = Source(a=[1, 2, 3], b=[10, 20, 30])

Extract a subset: >>> subset = Subset(source, [0, 2]) >>> subset Subset(a=[1, 3], b=[10, 30])

Activate the first subset item. This updates both the subset and the parent source.

>>> subset[0]()
SourceItem({'a': 1, 'b': 10}, 1 callback(s))
>>> subset.a(), subset.b()
(1, 10)
>>> source.a(), source.b()
(1, 10)

Activate the second subset item. The corresponding parent item is also activated. >>> subset[1]() SourceItem({‘a’: 3, ‘b’: 30}, 1 callback(s))

>>> subset.a(), subset.b()
(3, 30)
>>> source.a(), source.b()
(3, 30)