Skip to content

Commit e1465ff

Browse files
author
anna-grim
committed
doc: util
1 parent c6c683b commit e1465ff

File tree

4 files changed

+123
-129
lines changed

4 files changed

+123
-129
lines changed

src/segmentation_skeleton_metrics/skeleton_metric.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(
7777
Pointer to ground truth SWC files, see "swc_util.Reader" for
7878
documentation. These SWC files are assumed to be stored in voxel
7979
coordinates.
80-
label_mask : ArrayLike
80+
label_mask : ImageReader
8181
Predicted segmentation mask.
8282
anisotropy : Tuple[float], optional
8383
Image to physical coordinate scaling factors applied to SWC files
@@ -100,8 +100,8 @@ def __init__(
100100
default is None.
101101
valid_labels : set[int], optional
102102
Segment IDs that can be assigned to nodes. This argument accounts
103-
for segments that were removed during thresholding based on path
104-
length. The default is None.
103+
for segments that were been removed due to some type of filtering.
104+
The default is None.
105105
106106
Returns
107107
-------

src/segmentation_skeleton_metrics/utils/graph_util.py

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class GraphBuilder:
2222
"""
23-
A class that builds and processes graphs constructed from SWC files.
23+
A class that builds graphs constructed from SWC files.
2424
2525
"""
2626

@@ -31,6 +31,28 @@ def __init__(
3131
selected_ids=None,
3232
use_anisotropy=True,
3333
):
34+
"""
35+
Instantiates a GraphBuilder object.
36+
37+
Parameters
38+
----------
39+
anisotropy : Tuple[int], optional
40+
Image to physical coordinates scaling factors to account for the
41+
anisotropy of the microscope. The default is [1.0, 1.0, 1.0].
42+
label_mask : ImageReader, optional
43+
Predicted segmentation mask.
44+
selected_ids : Set[int], optional
45+
Only SWC files with an swc_id contained in this set are read. The
46+
default is None.
47+
use_anisotropy : bool, optional
48+
Indication of whether to apply anisotropy to coordinates in SWC
49+
files. The default is True.
50+
51+
Returns
52+
-------
53+
None
54+
55+
"""
3456
# Instance attributes
3557
self.anisotropy = anisotropy
3658
self.label_mask = label_mask
@@ -42,12 +64,45 @@ def __init__(
4264
)
4365

4466
def run(self, swc_pointer):
67+
"""
68+
Builds graphs by reading SWC files to extract content which is then
69+
loaded into a custom SkeletonGraph object. Optionally, the nodes are
70+
labeled if a "label_mask" is provided.
71+
72+
Parameters
73+
----------
74+
swc_pointer : Any
75+
Object that points to SWC files to be read.
76+
77+
Returns
78+
-------
79+
dict
80+
A dictionary where the keys are unique identifiers (i.e. filenames
81+
of SWC files) and values are the correspondign SkeletonGraph.
82+
83+
"""
4584
graphs = self._build_graphs_from_swcs(swc_pointer)
4685
graphs = self._label_graphs_with_segmentation(graphs)
4786
return graphs
4887

4988
# --- Build Graphs ---
5089
def _build_graphs_from_swcs(self, swc_pointer):
90+
"""
91+
Builds graphs by reading SWC files to extract content which is then
92+
loaded into a custom SkeletonGraph object.
93+
94+
Parameters
95+
----------
96+
swc_pointer : Any
97+
Object that points to SWC files to be read.
98+
99+
Returns
100+
-------
101+
dict
102+
A dictionary where the keys are unique identifiers (i.e. filenames
103+
of SWC files) and values are the correspondign SkeletonGraph.
104+
105+
"""
51106
# Initializations
52107
swc_dicts = self.swc_reader.read(swc_pointer)
53108
pbar = tqdm(total=len(swc_dicts), desc="Build Graphs")
@@ -81,11 +136,12 @@ def to_graph(self, swc_dict):
81136
Parameters
82137
----------
83138
swc_dict : dict
84-
...
139+
Dictionary whose keys and values are the attribute names and
140+
values from an SWC file.
85141
86142
Returns
87143
-------
88-
networkx.Graph
144+
SkeletonGraph
89145
Graph built from an SWC file.
90146
91147
"""
@@ -119,15 +175,18 @@ def _label_graph(self, key):
119175
class LabelHandler:
120176
def __init__(self, connections_path=None, valid_labels=None):
121177
"""
122-
Initializes the label handler and builds the label mappings
123-
if a connections path is provided.
178+
Initializes the label handler and builds the label mappings if a
179+
connections path is provided.
124180
125181
Parameters
126182
----------
127183
connections_path : str, optional
128184
Path to a file containing pairs of segment ids that were merged.
185+
The default is None.
129186
valid_labels : Set[int], optional
130-
Set of valid segment ids to be considered during processing.
187+
Segment IDs that can be assigned to nodes. This argument accounts
188+
for segments that were been removed due to some type of filtering.
189+
The default is None.
131190
132191
Returns
133192
-------
@@ -194,8 +253,8 @@ def build_labels_graph(self, connections_path):
194253
# Main
195254
for line in util.read_txt(connections_path):
196255
ids = line.split(",")
197-
id_1 = get_segment_id(ids[0])
198-
id_2 = get_segment_id(ids[1])
256+
id_1 = util.get_segment_id(ids[0])
257+
id_2 = util.get_segment_id(ids[1])
199258
labels_graph.add_edge(id_1, id_2)
200259
return labels_graph
201260

@@ -231,7 +290,3 @@ def count_splits(graph):
231290
232291
"""
233292
return max(nx.number_connected_components(graph) - 1, 0)
234-
235-
236-
def get_segment_id(swc_id):
237-
return int(swc_id.split(".")[0])

src/segmentation_skeleton_metrics/utils/swc_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def __init__(self, anisotropy=(1.0, 1.0, 1.0), selected_ids=None):
5151
Parameters
5252
----------
5353
anisotropy : Tuple[float], optional
54-
Image to world scaling factors applied to xyz coordinates to
55-
account for anisotropy of the microscope. The default is
56-
(1.0, 1.0, 1.0).
54+
Image to physical coordinates scaling factors to account for the
55+
anisotropy of the microscope. The default is [1.0, 1.0, 1.0].
5756
selected_ids : Set[int], optional
58-
Only SWC files with an swc_id contained in this set are read.
57+
Only SWC files with an swc_id contained in this set are read. The
58+
default is None.
5959
6060
Returns
6161
-------

0 commit comments

Comments
 (0)