Skip to content

tracksdata.array

Array representation of graphical data.

Provides read-only array views of graph attributes, with lazy loading from original data sources.

Classes:

  • GraphArrayView

    Class used to view the content of a graph as an array.

GraphArrayView

GraphArrayView(graph: BaseGraph, shape: tuple[int, ...], attr_key: str, offset: int | ndarray = 0)

Bases: BaseReadOnlyArray

Class used to view the content of a graph as an array.

The resulting graph behaves as a read-only numpy array, displaying arbitrary attributes inside their respective instance mask.

The content is lazy loaded from the original data source as it's done with a zarr.Array

Parameters:

  • graph

    (BaseGraph) –

    The graph to view as an array.

  • shape

    (tuple[int, ...]) –

    The shape of the array.

  • attr_key

    (str) –

    The attribute key to view as an array.

  • offset

    (int | ndarray, default: 0 ) –

    The offset to apply to the array.

Methods:

  • __len__

    Returns the length of the first dimension of the array.

Attributes:

  • ndim (int) –

    Returns the number of dimensions of the array.

Source code in src/tracksdata/array/_graph_array.py
def __init__(
    self,
    graph: BaseGraph,
    shape: tuple[int, ...],
    attr_key: str,
    offset: int | np.ndarray = 0,
):
    if attr_key not in graph.node_attr_keys:
        raise ValueError(f"Attribute key '{attr_key}' not found in graph. Expected '{graph.node_attr_keys}'")

    self.graph = graph
    self._shape = shape
    self._attr_key = attr_key
    self._offset = offset
    self._dtype = np.int32

ndim property

ndim: int

Returns the number of dimensions of the array.

__len__

__len__() -> int

Returns the length of the first dimension of the array.

Source code in src/tracksdata/array/_base_array.py
def __len__(self) -> int:
    """Returns the length of the first dimension of the array."""
    return self.shape[0]