deeptrack.wrappers Module#

Wrappers for arrays with properties.

This module defines lightweight container classes that wrap arrays together with associated metadata (properties). A wrapper behaves similarly to a NumPy or PyTorch array while carrying additional contextual information such as spatial coordinates or simulation parameters.

Wrappers are designed to preserve metadata during arithmetic operations. When mathematical or logical operations are applied to wrappers, the underlying arrays are combined while the associated properties are propagated to the resulting wrapper.

The module is backend-agnostic and supports both NumPy and PyTorch arrays, allowing wrappers to be used consistently across DeepTrack pipelines regardless of the active numerical backend.

Key Features#

  • Array container with metadata

    The Wrapper class stores an array together with a dictionary of properties describing the array. These properties can include spatial coordinates, identifiers, or other contextual metadata.

  • Backend-independent behavior

    Wrappers support both NumPy and PyTorch arrays. Arithmetic and logical operations preserve the backend of the underlying array.

  • Property propagation

    Arithmetic operations between wrappers return new wrappers that preserve the original properties while operating on the underlying arrays.

Module Structure#

Classes:

  • Wrapper: Container for arrays with associated metadata.

    A lightweight data structure that stores an array together with a dictionary of properties. The class provides convenience attributes (such as shape and ndim) and supports arithmetic and logical operations while preserving metadata.

Examples#

>>> import deeptrack as dt

Create a wrapper from an array:

>>> import numpy as np
>>>
>>> array = np.arange(9).reshape(3, 3)
>>> wrapper = dt.Wrapper(array, properties={"position": (1, 2)})
Wrapper(array=array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]]), properties={'position': (1, 2)})

Access array attributes:

>>> wrapper.shape
(3, 3)
>>> wrapper.ndim
2

Access properties:

>>> wrapper.properties
{'position': (1, 2)}

Perform arithmetic operations:

>>> wrapper2 = wrapper + 2
>>> wrapper2
Wrapper(array=array([[ 2,  3,  4],
       [ 5,  6,  7],
       [ 8,  9, 10]]), properties={'position': (1, 2)})

Wrappers preserve metadata while modifying the underlying array.

Classes#

Wrapper(array, properties, ~typing.Any] =)

Base class for any structure needing properties.