napari_track_edit.data_views.dims_utils

Relating the axes of a Tracks object to the axes of the napari viewer.

The viewer can have more dimensions than the tracks do, e.g. because of multi-channel images being present in the same viewer as the tracks layers. Napari aligns every layer on its trailing dimensions, so the tracks occupy the last ndim_tracks world axes of the viewer. All additional leading dimensions are for visualization only.

dims.order only permutes how axes are displayed. dims.point, dims.current_step and dims.range stay indexed by world axis, and roll() and transpose() touch nothing but order. So rolling or transposing with the napari buttons never moves an axis from one world index to another, and the map between tracks axes and world axes does not have to be remembered across a roll. A roll can put an extra axis on screen, so any code reading a displayed axis has to ask whether it is a tracks axis at all before using it.

Classes

TracksDims

Where a Tracks object's axes sit among the viewer's world axes.

Module Contents

class napari_track_edit.data_views.dims_utils.TracksDims

Where a Tracks object’s axes sit among the viewer’s world axes.

The tracks take the last ndim_tracks world axes; ndim_offset counts the extra ones in front, which are for visualization only. Meant to be built at the point of use rather than stored, because ndim_world changes when layers are added or removed.

ndim_world

Number of dimensions of the viewer.

Type:

int

ndim_tracks

Number of dimensions of the tracks, time included. The tracking layers all have exactly this many dimensions, so this doubles as the number of axes any of them spans.

Type:

int

ndim_world: int
ndim_tracks: int
__post_init__() → None
property ndim_offset: int

Number of extra world axes in front of the tracks’ own axes.

Also the index of the first tracks axis, so values[dims.ndim_offset:] is the tracks’ part of anything indexed by world axis (dims.point, dims.current_step, dims.range, the axis labels).

property time_axis: int

World axis carrying time, which is the tracks’ first axis.

to_tracks_axis(world_axis: int) → int | None

Map a viewer (world) axis onto a tracks axis, or None if there is none.

Parameters:

world_axis (int) – Axis index in the viewer’s world coordinate system.

Returns:

The corresponding tracks axis, or None if the tracks do not

span this world axis.

Return type:

int | None

embed_point(location: collections.abc.Sequence[float], point: collections.abc.Sequence[float]) → list[float]

Write a tracks-space location into a full-length viewer point.

The extra leading axes keep whatever the viewer is currently showing, only the trailing tracks axes are replaced.

Parameters:
  • location (Sequence[float]) – Position in tracks space, time included.

  • point (Sequence[float]) – The viewer’s current dims.point.

Returns:

A point of length ndim_world, ready to assign to

viewer.dims.point.

Return type:

list[float]

Raises:

ValueError – If either sequence has the wrong length, which would otherwise silently produce a point napari cannot use.