napari_track_edit.data_views.views.layers.track_graph

Classes

TrackGraph

Extended tracks layer that holds the track information and emits and responds

Functions

update_napari_tracks(tracks)

Function to take a networkx graph with assigned track_ids and return the data

Module Contents

napari_track_edit.data_views.views.layers.track_graph.update_napari_tracks(tracks: funtracks.data_model.Tracks)

Function to take a networkx graph with assigned track_ids and return the data needed to add to a napari tracks layer.

Parameters:

tracks (Tracks) – tracks that have track_ids and have a tree structure

Returns:

array (N, D+1)

Coordinates for N points in D+1 dimensions. ID,T,(Z),Y,X. The first axis is the integer ID of the track. D is either 3 or 4 for planar or volumetric timeseries respectively.

graph: dict {int: list}

Graph representing associations between tracks. Dictionary defines the mapping between a track ID and the parents of the track. This can be one (the track has one parent, and the parent has >=1 child) in the case of track splitting, or more than one (the track has multiple parents, but only one child) in the case of track merging.

node_ids: list[int]

The node id of each row of data, in the same order, so the layer can be colored per node.

Return type:

data

class napari_track_edit.data_views.views.layers.track_graph.TrackGraph(name: str, tracks_viewer: napari_track_edit.data_views.views_coordinator.tracks_viewer.TracksViewer)

Bases: napari.layers.Tracks

Extended tracks layer that holds the track information and emits and responds to dynamics visualization signals

_type_string = 'tracks'
tracks_viewer
full_division_edges
visible_tracks: object = 'all'
_refresh()

Refreshes the displayed tracks based on the graph in the current tracks_viewer.tracks

_apply_node_colors(node_ids: list[int]) → None

Color the track lines per node instead of per track id.

napari colors a Tracks layer by mapping one vertex property array through a colormap. We need to color by node id instead of tracklet_id to ensure

that this colormap follows the other views.

node_ids must be in the same row order as the data that was just assigned: napari sorts the vertices by (track id, time) and reorders the properties to match, using the order it recorded for that data.

_set_division_edges(division_edges: dict[int, list[int]]) → None

Hand the graph to napari.

The Tracks.graph setter revalidates every entry and then rebuilds every graph vertex, looking each track id up against all points: 2.0 s for 34k entries over 325k points. Only called by update_track_visibility once it has confirmed the visible set actually changed, so that cost is paid only when it must be.

_set_track_alpha(visible: list[int] | str) → None

Set track opacity so that only visible tracks are drawn.

update_track_visibility(visible: list[int] | str) → None

Optionally show only the tracks of a current lineage.

Do nothing if the set is already visible, to avoid unnecessary computation.