Skip to content

Commit b0bf635

Browse files
anna-grimanna-grim
andauthored
Feat report summary (#159)
* doc: skeleton metrics and swc_loading * feat: fix label misalignments * doc: skeletongraph and dataloading --------- Co-authored-by: anna-grim <[email protected]>
1 parent c550662 commit b0bf635

File tree

3 files changed

+103
-7
lines changed

3 files changed

+103
-7
lines changed

src/segmentation_skeleton_metrics/data_handling/graph_loading.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727

2828
class DataLoader:
29+
"""
30+
A class that loads ground truth and fragment graphs and provides tools for
31+
labeling ground truth graphs.
32+
"""
2933

3034
def __init__(
3135
self,
@@ -34,6 +38,23 @@ def __init__(
3438
use_anisotropy=False,
3539
verbose=True
3640
):
41+
"""
42+
Instantiates a DataLoader object.
43+
44+
Parameters
45+
----------
46+
label_handler : LabelHander
47+
Handles mapping between raw segmentation labels and consolidated
48+
class IDs.
49+
anisotropy : Tuple[int], optional
50+
Image to physical coordinates scaling factors to account for the
51+
anisotropy of the microscope. Default is (1.0, 1.0, 1.0).
52+
use_anisotropy : bool, optional
53+
Indication of whether to apply the anisotropy to the coordinates
54+
from the fragment SWC files. Default is False.
55+
verbose : bool, optional
56+
Indication of whether to display a progress bar. Default is True.
57+
"""
3758
# Instance attributes
3859
self.anisotropy = anisotropy
3960
self.label_handler = label_handler
@@ -275,6 +296,21 @@ def to_graph(self, swc_dict):
275296
return {graph.name: graph}
276297

277298
def _init_graph(self, swc_dict):
299+
"""
300+
Initializes and returns a graph object from a parsed SWC dictionary.
301+
302+
Parameters
303+
----------
304+
swc_dict : dict
305+
Dictionary whose keys and values are the attribute names and
306+
values from an SWC file.
307+
308+
Returns
309+
-------
310+
SkeletonGraph
311+
An initialized LabeledGraph or FragmentGraph instance with voxel
312+
data, filename, and node count set.
313+
"""
278314
# Instantiate graph
279315
if self.is_groundtruth:
280316
graph = LabeledGraph(
@@ -304,7 +340,7 @@ def _label_graph(self, graph):
304340
305341
Parameters
306342
----------
307-
graph : SkeletonGraph
343+
graph : LabeledGraph
308344
Graph to be labeled.
309345
"""
310346
with ThreadPoolExecutor() as executor:
@@ -427,14 +463,14 @@ def check_misalignment(graph, visited_edges, nb, root):
427463
428464
Parameters
429465
----------
430-
graph : networkx.Graph
466+
graph : LabeledGraph
431467
Graph that represents a ground truth neuron.
432-
visited_edges : List[tuple]
468+
visited_edges : List[Frozenset[int]]
433469
List of edges in "graph" that have been visited.
434470
nb : int
435471
Neighbor of "root".
436472
root : int
437-
Node where possible split starts (i.e. zero-valued label).
473+
Node where possible misalignment starts (i.e. zero-valued label).
438474
"""
439475
# Search graph
440476
label_collisions = set()
@@ -542,7 +578,7 @@ def build_labels_graph(self, connections_path):
542578
543579
Returns
544580
-------
545-
networkx.Graph
581+
LabeledGraph
546582
Graph with nodes that represent labels and edges are based on the
547583
connections read from the "connections_path".
548584
"""
@@ -614,7 +650,7 @@ def get_node_labels(self, graph):
614650
615651
Parameters
616652
----------
617-
graph : SkeletonGraph
653+
graph : LabeledGraph
618654
Graph from which to retrieve the node labels.
619655
620656
Returns

src/segmentation_skeleton_metrics/data_handling/skeleton_graph.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def __init__(self, anisotropy=(1.0, 1.0, 1.0), name=None):
7575
self.voxels = None
7676

7777
def init_kdtree(self, use_voxels=True):
78+
"""
79+
Builds a KD-Tree from the node coordinates.
80+
81+
Parameters
82+
----------
83+
use_voxeles : bool, optional
84+
Indication of whether to use voxel or physical coordinates.
85+
Default is True.
86+
"""
7887
if use_voxels:
7988
self.kdtree = KDTree(self.voxels)
8089
else:
@@ -194,6 +203,9 @@ def get_radius(self):
194203
return 3
195204

196205
def prune_branches(self):
206+
"""
207+
Placeholder method to be implemented by subclasses.
208+
"""
197209
pass
198210

199211
# --- Writers ---
@@ -209,6 +221,16 @@ def to_zipped_swc(self, zip_writer):
209221
"""
210222
# Subroutines
211223
def write_entry(node, parent):
224+
"""
225+
Writes a line in an SWC file
226+
227+
Parameters
228+
----------
229+
node : int
230+
Node ID.
231+
parent : int
232+
Node ID of the parent of "node".
233+
"""
212234
x, y, z = tuple(self.voxels[i] * self.anisotropy)
213235
r = self.get_radius()
214236
node_id = cnt
@@ -239,8 +261,24 @@ def write_entry(node, parent):
239261

240262

241263
class LabeledGraph(SkeletonGraph):
264+
"""
265+
Subclass of SkeletonGraph with the provides support for node-level
266+
labeling and tracking label assignments.
267+
"""
242268

243269
def __init__(self, anisotropy=(1.0, 1.0, 1.0), name=None):
270+
"""
271+
Instantiates a LabeledGraph object.
272+
273+
Parameters
274+
----------
275+
anisotropy : ArrayLike
276+
Image to physical coordinates scaling factors to account for the
277+
anisotropy of the microscope.
278+
name : str or None
279+
Name of the graph which is derived from the SWC filename. Default
280+
is None.
281+
"""
244282
# Call parent class
245283
super().__init__(anisotropy=anisotropy, name=name)
246284

@@ -396,6 +434,9 @@ def get_radius(self):
396434

397435

398436
class FragmentGraph(SkeletonGraph):
437+
"""
438+
Subclass of SkeletonGraph for skeletons derived from the segmentation.
439+
"""
399440

400441
def __init__(
401442
self,
@@ -404,6 +445,24 @@ def __init__(
404445
label=None,
405446
segment_id=None,
406447
):
448+
"""
449+
Instantiates a FragmentGraph object.
450+
451+
Parameters
452+
----------
453+
anisotropy : ArrayLike, optional
454+
Image to physical coordinates scaling factors to account for the
455+
anisotropy of the microscope. Default is (1.0, 1.0, 1.0).
456+
name : str or None, optional
457+
Name of the graph which is derived from the SWC filename. Default
458+
is None.
459+
label : int, optional
460+
Graph-level label that corresponds to a node-level label given to
461+
a ground truth graph. Default is None.
462+
segment_id : int, optional
463+
Segment ID of the segment the given skeleton was obtained from.
464+
Default is None.
465+
"""
407466
# Call parent class
408467
super().__init__(anisotropy=anisotropy, name=name)
409468

src/segmentation_skeleton_metrics/evaluate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
@author: Anna Grim
55
66
7-
...
7+
Code that provides a wrapper for loading data and calling the SkeletMetric
8+
subclasses.
89
910
"""
1011

0 commit comments

Comments
 (0)