Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tuple location key #18

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/motile_toolbox/visualization/napari_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def assign_tracklet_ids(graph: nx.DiGraph) -> nx.DiGraph:
return graph, intertrack_edges


def _get_location(graph, node, location_key):
if isinstance(location_key, list) or isinstance(location_key, tuple):
return [graph.nodes[node][dim] for dim in location_key]
else:
return graph.nodes[node][location_key]


def to_napari_tracks_layer(
graph, frame_key=NodeAttr.TIME.value, location_key=NodeAttr.POS.value, properties=()
):
Expand Down Expand Up @@ -67,16 +74,14 @@ def to_napari_tracks_layer(
case of track splitting, or more than one (the track has multiple
parents, but only one child) in the case of track merging.
"""
for _, loc in graph.nodes(data=location_key):
ndim = len(loc)
break
ndim = len(_get_location(graph, next(iter(graph.nodes)), location_key))
napari_data = np.zeros((graph.number_of_nodes(), ndim + 2))
napari_properties = {prop: np.zeros(graph.number_of_nodes()) for prop in properties}
napari_edges = {}
graph, intertrack_edges = assign_tracklet_ids(graph)
for index, node in enumerate(graph.nodes(data=True)):
node_id, data = node
location = data[location_key]
location = _get_location(graph, node_id, location_key)
napari_data[index] = [data["tracklet_id"], data[frame_key], *location]
for prop in properties:
if prop in data:
Expand Down
Loading