Skip to content

Commit 868606c

Browse files
anna-grimanna-grim
andauthored
refactor: minor update (#172)
Co-authored-by: anna-grim <anna.grim@alleninstitute.org>
1 parent 418e37a commit 868606c

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

src/segmentation_skeleton_metrics/data_handling/swc_loading.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ def read_from_zips(self, zip_dir):
201201
with ProcessPoolExecutor() as executor:
202202
# Assign threads
203203
processes = list()
204-
for f in zip_names:
205-
zip_path = os.path.join(zip_dir, f)
204+
for name in zip_names:
205+
zip_path = os.path.join(zip_dir, name)
206206
processes.append(executor.submit(self.read_from_zip, zip_path))
207207

208208
# Store results
@@ -323,10 +323,6 @@ def read_from_gcs_swcs(self, bucket_name, swc_paths):
323323
# Assign threads
324324
threads = list()
325325
for path in swc_paths:
326-
327-
if "003" not in path: # TEMP
328-
continue # TEMP
329-
330326
threads.append(
331327
executor.submit(self.read_from_gcs_swc, bucket_name, path)
332328
)

src/segmentation_skeleton_metrics/evaluate.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535

3636

3737
def evaluate(
38-
gt_pointer,
38+
gt_path,
3939
segmentation,
4040
output_dir,
4141
anisotropy=(1.0, 1.0, 1.0),
4242
connections_path=None,
43-
fragments_pointer=None,
43+
fragments_path=None,
4444
results_filename="results",
4545
save_merges=False,
4646
save_fragments=False,
@@ -54,10 +54,9 @@ def evaluate(
5454
5555
Parameters
5656
----------
57-
gt_pointer : str
58-
Pointer to ground truth SWC files, see "swc_util.Reader" for
59-
documentation. These SWC files are assumed to be stored in voxel
60-
coordinates.
57+
gt_path : str
58+
Path to ground truth SWC files, see swc_util.Reader for documentation
59+
These SWC files are assumed to be stored in voxel coordinates.
6160
segmentation : ImageReader
6261
Predicted segmentation.
6362
anisotropy : Tuple[float], optional
@@ -66,11 +65,11 @@ def evaluate(
6665
connections_path : str, optional
6766
Path to a txt file containing pairs of segment IDs that represents
6867
fragments that were merged. Default is None.
69-
fragments_pointer : str, optional
70-
Pointer to SWC files corresponding to "segmentation", see
71-
"swc_util.Reader" for documentation. Notes: (1) "anisotropy" is
72-
applied to these SWC files and (2) these SWC files are required
73-
for counting merges. Default is None.
68+
fragments_path : str, optional
69+
Path to SWC files corresponding to "segmentation", see swc_util.Reader
70+
for documentation. Notes: (1) "anisotropy" is applied to these SWC
71+
files and (2) these SWC files are required for counting merges.
72+
Default is None.
7473
results_filename : str, optional
7574
Name of file that skeleton metric results are written to. Default is
7675
"results".
@@ -97,10 +96,11 @@ def evaluate(
9796
use_anisotropy=use_anisotropy,
9897
verbose=verbose
9998
)
100-
gt_graphs = dataloader.load_groundtruth(gt_pointer, segmentation)
101-
fragment_graphs = dataloader.load_fragments(fragments_pointer, gt_graphs)
99+
gt_graphs = dataloader.load_groundtruth(gt_path, segmentation)
100+
fragment_graphs = dataloader.load_fragments(fragments_path, gt_graphs)
102101

103102
# Run evaluation
103+
util.mkdir(output_dir)
104104
evaluator = Evaluator(output_dir, results_filename, verbose)
105105
evaluator(gt_graphs, fragment_graphs)
106106

src/segmentation_skeleton_metrics/skeleton_metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def add_merge_site_names(self):
570570
for i, _ in enumerate(self.merge_sites.index, 1):
571571
row_names.append(f"merge-{i}.swc")
572572
self.merge_sites.index = row_names
573+
self.merge_sites.index.name = "Merge_ID"
573574

574575
def remove_repeat_merge_sites(self):
575576
"""

src/segmentation_skeleton_metrics/utils/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def mkdir(path, delete=False):
3838
"""
3939
if delete:
4040
rmdir(path)
41-
if not os.path.exists(path):
42-
os.mkdir(path)
41+
42+
os.makedirs(path, exist_ok=True)
4343

4444

4545
def rmdir(path):
@@ -268,7 +268,7 @@ def is_gcs_path(path):
268268
return path.startswith("gs://")
269269

270270

271-
def list_gcs_filenames(bucket_name, prefix, extension):
271+
def list_gcs_filenames(bucket_name, prefix, extension=""):
272272
"""
273273
Lists all files in a GCS bucket with the given extension.
274274
@@ -278,8 +278,8 @@ def list_gcs_filenames(bucket_name, prefix, extension):
278278
Name of bucket to be searched.
279279
prefix : str
280280
Path to location within bucket to be searched.
281-
extension : str
282-
File extension of filenames to be listed.
281+
extension : str, optional
282+
File extension of filenames to be listed. Default is an empty string.
283283
284284
Returns
285285
-------

0 commit comments

Comments
 (0)