Skip to content

Commit 4551f5e

Browse files
author
anna-grim
committed
upds
1 parent cdf85c9 commit 4551f5e

File tree

2 files changed

+17
-78
lines changed

2 files changed

+17
-78
lines changed

src/segmentation_skeleton_metrics/skeleton_metric.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,23 @@ def __init__(
6464
6565
Parameters
6666
----------
67-
gt_pointer : dict/str/list[str]
67+
gt_pointer : Any
6868
Pointer to ground truth swcs, see "swc_util.Reader" for further
69-
documentation. Note these swc files are assumed to be stored in
69+
documentation. Note these SWC files are assumed to be stored in
7070
image coordinates.
71-
pred_labels : numpy.ndarray or tensorstore.TensorStore
71+
pred_labels : ArrayLike
7272
Predicted segmentation mask.
73-
anisotropy : list[float], optional
74-
Image to real-world coordinates scaling factors applied to swc
75-
stored at "fragments_pointer". The default is [1.0, 1.0, 1.0].
73+
anisotropy : Tuple[float], optional
74+
Image to physical coordinate scaling factors applied to SWC files
75+
stored at "fragments_pointer". The default is (1.0, 1.0, 1.0).
7676
connections_path : str, optional
7777
Path to a txt file containing pairs of segment ids of segments
7878
that were merged into a single segment. The default is None.
79-
fragments_pointer : dict/str/list[str], optional
80-
Pointer to fragments (i.e. swcs) corresponding to "pred_labels",
81-
see "swc_util.Reader" for further documentation. Note these swc
82-
files may be stored in either world or image coordinates. If the
83-
swcs are stored in world coordinates, then provide the world to
84-
image coordinates anisotropy factor. Note the filename of each swc
85-
is assumed to "segment_id.swc" where segment_id cooresponds to the
86-
segment id from "pred_labels". The default is None.
79+
fragments_pointer : Any, optional
80+
Pointer to SWC files corresponding to "pred_labels", see
81+
"swc_util.Reader" for further documentation. Note that these SWC
82+
file may be stored in physical coordiantes, but the anisotropy
83+
scaling factors must be provided. The default is None.
8784
output_dir : str, optional
8885
Path to directory that mistake sites are written to. The default
8986
is None.
@@ -168,7 +165,7 @@ def init_graphs(self, paths):
168165
None
169166
170167
"""
171-
# Read graphs
168+
# Build graphs
172169
self.graphs = swc_util.Reader().load(paths)
173170
self.fragment_graphs = None
174171

@@ -204,11 +201,9 @@ def set_node_labels(self, key):
204201
threads.append(executor.submit(self.get_label, i, voxel))
205202

206203
# Store label
207-
pbar = tqdm(total=len(threads), desc="threads finished")
208204
for thread in as_completed(threads):
209205
i, label = thread.result()
210206
self.graphs[key].nodes[i].update({"label": label})
211-
pbar.update(1)
212207

213208
def get_label(self, i, voxel):
214209
"""

src/segmentation_skeleton_metrics/utils/swc_util.py

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def load_from_local_paths(self, swc_paths):
155155

156156
# Store results
157157
graph_dict = dict()
158-
pbar = tqdm(total=len(filenames), desc="Label Graph")
158+
pbar = tqdm(total=len(threads), desc="Load SWCs")
159159
for thread in as_completed(threads):
160160
graph_dict.update(thread.result())
161161
pbar.update(1)
@@ -200,7 +200,7 @@ def load_from_local_zips(self, zip_dir):
200200
pbar.update(1)
201201
return graph_dict
202202

203-
def load_from_local_zip(self, zip_path, verbose=True):
203+
def load_from_local_zip(self, zip_path):
204204
"""
205205
Reads SWC files from zip on the local machine.
206206
@@ -376,9 +376,12 @@ def get_graph(self, content):
376376
graph = nx.Graph()
377377
offset = [0, 0, 0]
378378
for line in content:
379+
# Check for offset
379380
if line.startswith("# OFFSET"):
380381
parts = line.split()
381382
offset = self.read_voxel(parts[2:5])
383+
384+
# Check for entry
382385
if not line.startswith("#"):
383386
parts = line.split()
384387
child = int(parts[0])
@@ -398,65 +401,6 @@ def get_graph(self, content):
398401

399402

400403
# --- Write ---
401-
def save(path, xyz_1, xyz_2, color=None):
402-
"""
403-
Writes an swc file.
404-
405-
Parameters
406-
----------
407-
path : str
408-
Path on local machine that swc file will be written to.
409-
xyz_1 : ...
410-
...
411-
xyz_2 : ...
412-
...
413-
color : str, optional
414-
Color of nodes. The default is None.
415-
416-
Returns
417-
-------
418-
None.
419-
420-
"""
421-
with open(path, "w") as f:
422-
# Preamble
423-
if color is not None:
424-
f.write("# COLOR " + color)
425-
else:
426-
f.write("# id, type, z, y, x, r, pid")
427-
f.write("\n")
428-
429-
# Entries
430-
f.write(make_entry(1, -1, xyz_1))
431-
f.write("\n")
432-
f.write(make_entry(2, 1, xyz_2))
433-
434-
435-
def make_entry(node, parent, xyz):
436-
"""
437-
Makes an entry to be written in an SWC file.
438-
439-
Parameters
440-
----------
441-
graph : networkx.Graph
442-
Graph that "node_id" and "parent_id" belong to.
443-
node : int
444-
Node ID that entry corresponds to.
445-
parent_id : int
446-
Parent ID of the given node.
447-
voxel : ...
448-
Voxel coordinate of the given node.
449-
450-
Returns
451-
-------
452-
entry : str
453-
Entry to be written in an swc file.
454-
455-
"""
456-
x, y, z = tuple(util.to_physical(voxel, (0.748, 0.748, 1.0)))
457-
return f"{node} 2 {x} {y} {z} 3 {parent}"
458-
459-
460404
def to_zipped_swc(zip_writer, graph, color=None):
461405
"""
462406
Writes a graph to an swc file that is to be stored in a zip.

0 commit comments

Comments
 (0)