motile_tracker.data_model.tracks_controller
Classes
A set of high level functions to change the data model. |
Module Contents
- class motile_tracker.data_model.tracks_controller.TracksController(tracks: motile_tracker.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_tracker.data_model.tracks.Attrs, pixels: list[motile_tracker.data_model.tracks.SegMask] | None = None) None
Calls the _add_nodes function to add nodes. Calls the refresh signal when finished.
- Args:
attributes (Attrs): dictionary containing at least time and position attributes pixels (list[SegMask] | None, optional): The pixels associated with each node,
if a segmentation is present. Defaults to None.
- _get_pred_and_succ(track_id: int, time: int) tuple[motile_tracker.data_model.tracks.Node | None, motile_tracker.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.
- _confirm_remove_division_edges() bool
Spawn a dialog box to ask the user if they want to break an upstream division event or not.
- Returns:
- bool: True if the upstream division edges should be removed to make room for
the new node in the track, False if the user wants to cancel the operation.
- _add_nodes(attributes: motile_tracker.data_model.tracks.Attrs, pixels: list[motile_tracker.data_model.tracks.SegMask] | None = None) tuple[motile_tracker.data_model.actions.TracksAction, list[motile_tracker.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 - node_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:
- attributes (Attrs): dictionary containing at least time and track id,
and either node_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 new node id
- delete_nodes(nodes: collections.abc.Iterable[motile_tracker.data_model.tracks.Node]) None
Calls the _delete_nodes function and then emits the refresh signal
- Args:
nodes (Iterable[Node]): array of node_ids to be deleted
- _delete_nodes(nodes: collections.abc.Iterable[motile_tracker.data_model.tracks.Node], pixels: list[motile_tracker.data_model.tracks.SegMask] | None = None) motile_tracker.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_tracker.data_model.tracks.Node], pixels: list[motile_tracker.data_model.tracks.SegMask], added=False) motile_tracker.data_model.actions.TracksAction
Update the segmentation and segmentation-managed attributes for a set of nodes.
- Args:
nodes (Iterable[Node]): The nodes to update pixels (list[SegMask]): The pixels for each node that were edited added (bool, optional): If the pixels were added to the nodes (True)
or deleted (False). Defaults to False. Cannot mix adding and removing pixels in one call.
- Returns:
TracksAction: _description_
- add_edges(edges: numpy.ndarray[int]) None
Add edges 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
- update_node_attrs(nodes: collections.abc.Iterable[motile_tracker.data_model.tracks.Node], attributes: motile_tracker.data_model.tracks.Attrs)
Update the user provided node attributes (not the managed attributes). Also adds the action to the history and emits the refresh signal.
- Args:
nodes (Iterable[Node]): The nodes to update the attributes for attributes (Attrs): A mapping from user-provided attributes to values for
each node.
- _update_node_attrs(nodes: collections.abc.Iterable[motile_tracker.data_model.tracks.Node], attributes: motile_tracker.data_model.tracks.Attrs) motile_tracker.data_model.actions.TracksAction
Update the user provided node attributes (not the managed attributes).
- Args:
nodes (Iterable[Node]): The nodes to update the attributes for attributes (Attrs): A mapping from user-provided attributes to values for
each node.
Returns: A TracksAction object that performed the update
- _add_edges(edges: numpy.ndarray[int]) motile_tracker.data_model.actions.TracksAction
Add edges and attributes to the graph. Also update the track ids 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
- Returns:
A TracksAction containing all edits performed in this call
- is_valid(edge) tuple[bool, motile_tracker.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): The Nx2 array of edges to be deleted
- _delete_edges(edges: numpy.ndarray) motile_tracker.data_model.actions.ActionGroup
- update_segmentations(to_remove: list[motile_tracker.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_tracker.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.