napari_track_edit.data_views.views.layers.track_graph ===================================================== .. py:module:: napari_track_edit.data_views.views.layers.track_graph Classes ------- .. autoapisummary:: napari_track_edit.data_views.views.layers.track_graph.TrackGraph Functions --------- .. autoapisummary:: napari_track_edit.data_views.views.layers.track_graph.update_napari_tracks Module Contents --------------- .. py:function:: 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. :param tracks: tracks that have track_ids and have a tree structure :type tracks: Tracks :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. :rtype: data .. py:class:: TrackGraph(name: str, tracks_viewer: napari_track_edit.data_views.views_coordinator.tracks_viewer.TracksViewer) Bases: :py:obj:`napari.layers.Tracks` Extended tracks layer that holds the track information and emits and responds to dynamics visualization signals .. py:attribute:: _type_string :value: 'tracks' .. py:attribute:: tracks_viewer .. py:attribute:: full_division_edges .. py:attribute:: visible_tracks :type: object :value: 'all' .. py:method:: _refresh() Refreshes the displayed tracks based on the graph in the current tracks_viewer.tracks .. py:method:: _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. .. py:method:: _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. .. py:method:: _set_track_alpha(visible: list[int] | str) -> None Set track opacity so that only `visible` tracks are drawn. .. py:method:: 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.