motile_plugin.data_model.tracks_controller
Classes
A set of high level functions to change the data model. |
Module Contents
- class motile_plugin.data_model.tracks_controller.TracksController(tracks: motile_plugin.data_model.solution_tracks.SolutionTracks)
A set of high level functions to change the data model. All changes to the data should go through this API.
- tracks
- action_history
- node_id_counter = 1
- add_nodes(attributes: motile_plugin.data_model.tracks.Attrs, pixels: list[motile_plugin.data_model.tracks.SegMask] | None = None) None
Calls the _add_nodes function to add nodes. Calls the refresh signal when finished.
- Args:
nodes (np.ndarray[int]):an array of node ids attributes (dict[str, np.ndarray]): dictionary containing at least time and position attributes
- _get_pred_and_succ(track_id: int, time: int) tuple[motile_plugin.data_model.tracks.Node | None, motile_plugin.data_model.tracks.Node | None]
Get the last node with the given track id before time, and the first node with the track id after time, if any. Does not assume that a node with the given track_id and time is already in tracks, but it can be.
- Args:
track_id (int): The track id to search for time (int): The time point to find the immediate predecessor and successor
for
- Returns:
tuple[Node | None, Node | None]: The last node before time with the given track id, and the first node after time with the given track id, or Nones if there are no such nodes.
- _add_nodes(attributes: motile_plugin.data_model.tracks.Attrs, pixels: list[motile_plugin.data_model.tracks.SegMask] | None = None) tuple[motile_plugin.data_model.actions.TracksAction, list[motile_plugin.data_model.tracks.Node]]
Add nodes to the graph. Includes all attributes and the segmentation. Will return the actions needed to add the nodes, and the node ids generated for the new nodes. If there is a segmentation, the attributes must include: - time - seg_id - track_id If there is not a segmentation, the attributes must include: - time - pos - track_id
Logic of the function: - remove edges (when we add a node in a track between two nodes
connected by a skip edge)
add the nodes
- add edges (to connect each node to its immediate
predecessor and successor with the same track_id, if any)
- Args:
nodes (list[Node]): a list of node ids attributes (Attributes): dictionary containing at least time and track id,
and either seg_id (if pixels are provided) or position (if not)
- pixels (list[SegMask] | None): A list of pixels associated with the node,
or None if there is no segmentation. These pixels will be updated in the tracks.segmentation, set to the provided seg_id
- delete_nodes(nodes: collections.abc.Iterable[Any]) None
Calls the _delete_nodes function and then emits the refresh signal
- Args:
nodes (np.ndarray): array of node_ids to be deleted
- _delete_nodes(nodes: numpy.ndarray[Any], pixels: list[motile_plugin.data_model.tracks.SegMask] | None = None) motile_plugin.data_model.actions.TracksAction
Delete the nodes provided by the array from the graph but maintain successor track_ids. Reconnect to the nearest predecessor and/or nearest successor on the same track, if any.
Function logic: - delete all edges incident to the nodes - delete the nodes - add edges to preds and succs of nodes if they have the same track id - update track ids if we removed a division by deleting the dge
- Args:
nodes (np.ndarray): array of node_ids to be deleted
- update_node_segs(nodes: collections.abc.Iterable[motile_plugin.data_model.tracks.Node], attributes: dict[str, numpy.ndarray]) None
Calls the _update_node_segs function to update the node attributtes in given array. Then calls the refresh signal.
Args: nodes (np.ndarray[int]):an array of node ids attributes (dict[str, np.ndarray]): dictionary containing the attributes to be updated
- update_node_attrs(nodes: collections.abc.Iterable[motile_plugin.data_model.tracks.Node], attributes: motile_plugin.data_model.tracks.Attrs)
- _update_node_attrs(nodes: collections.abc.Iterable[motile_plugin.data_model.tracks.Node], attributes: motile_plugin.data_model.tracks.Attrs)
- _update_node_segs(nodes: numpy.ndarray[Any], pixels: list[motile_plugin.data_model.tracks.SegMask], added=False) motile_plugin.data_model.actions.TracksAction
Update the segmentation and segmentation-managed attributes for a set of nodes.
Args: nodes (np.ndarray[int]):an array of node ids attributes (dict[str, np.ndarray]): dictionary containing the attributes to be updated
- add_edges(edges: numpy.ndarray[int]) None
Add edges and attributes to the graph. Also update the track ids and corresponding segmentations if applicable
- Args:
- edges (np.array[int]): An Nx2 array of N edges, each with source and target
node ids
- _add_edges(edges: numpy.ndarray[int]) motile_plugin.data_model.actions.TracksAction
Add edges and attributes to the graph. Also update the track ids and corresponding segmentations of the target node tracks and potentially sibling tracks.
- Args:
- edges (np.array[int]): An Nx2 array of N edges, each with source and target
node ids
- attributes (dict[str, np.ndarray]): dictionary mapping attribute names to
an array of values, where the index in the array matches the edge index
- Returns:
True if the edges were successfully added, False if any edge was invalid.
- is_valid(edge) tuple[bool, motile_plugin.data_model.actions.TracksAction | None]
Check if this edge is valid. Criteria: - not horizontal - not existing yet - no merges - no triple divisions - new edge should be the shortest possible connection between two nodes, given their track_ids. (no skipping/bypassing any nodes of the same track_id). Check if there are any nodes of the same source or target track_id between source and target
- Args:
edge (np.ndarray[(int, int)]: edge to be validated
- Returns:
True if the edge is valid, false if invalid
- delete_edges(edges: numpy.ndarray)
Delete edges from the graph.
- Args:
edges (np.ndarray): _description_
- _delete_edges(edges: numpy.ndarray) motile_plugin.data_model.actions.ActionGroup
- update_segmentations(to_remove: list[motile_plugin.data_model.tracks.Node], to_update_smaller: list[tuple], to_update_bigger: list[tuple], to_add: list[tuple], current_timepoint: int) None
Handle a change in the segmentation mask, checking for node addition, deletion, and attribute updates. Args:
- updated_pixels (list[(tuple(np.ndarray, np.ndarray, np.ndarray), np.ndarray, int)]):
list holding the operations that updated the segmentation (directly from the napari labels paint event). Each element in the list consists of a tuple of np.ndarrays representing indices for each dimension, an array of the previous values, and an array or integer representing the new value(s)
current_timepoint (int): the current time point in the viewer, used to set the selected node.
- undo() None
Obtain the action to undo from the history, and invert
- redo() None
Obtain the action to redo from the history
- _get_new_node_ids(n: int) list[motile_plugin.data_model.tracks.Node]
Get a list of new node ids for creating new nodes. They will be unique from all existing nodes, but have no other guarantees.
- Args:
n (int): The number of new node ids to return
- Returns:
list[Node]: A list of new node ids.