@@ -37,6 +37,13 @@ def assign_tracklet_ids(graph: nx.DiGraph) -> nx.DiGraph:
37
37
return graph , intertrack_edges
38
38
39
39
40
+ def _get_location (graph , node , location_key ):
41
+ if isinstance (location_key , list ) or isinstance (location_key , tuple ):
42
+ return [graph .nodes [node ][dim ] for dim in location_key ]
43
+ else :
44
+ return graph .nodes [node ][location_key ]
45
+
46
+
40
47
def to_napari_tracks_layer (
41
48
graph , frame_key = NodeAttr .TIME .value , location_key = NodeAttr .POS .value , properties = ()
42
49
):
@@ -67,16 +74,14 @@ def to_napari_tracks_layer(
67
74
case of track splitting, or more than one (the track has multiple
68
75
parents, but only one child) in the case of track merging.
69
76
"""
70
- for _ , loc in graph .nodes (data = location_key ):
71
- ndim = len (loc )
72
- break
77
+ ndim = len (_get_location (graph , next (iter (graph .nodes )), location_key ))
73
78
napari_data = np .zeros ((graph .number_of_nodes (), ndim + 2 ))
74
79
napari_properties = {prop : np .zeros (graph .number_of_nodes ()) for prop in properties }
75
80
napari_edges = {}
76
81
graph , intertrack_edges = assign_tracklet_ids (graph )
77
82
for index , node in enumerate (graph .nodes (data = True )):
78
83
node_id , data = node
79
- location = data [ location_key ]
84
+ location = _get_location ( graph , node_id , location_key )
80
85
napari_data [index ] = [data ["tracklet_id" ], data [frame_key ], * location ]
81
86
for prop in properties :
82
87
if prop in data :
0 commit comments