6677
88"""
9- from concurrent .futures import ProcessPoolExecutor , ThreadPoolExecutor , as_completed
9+ from concurrent .futures import as_completed , ProcessPoolExecutor
1010from random import sample
1111from scipy .spatial import distance
1212from tqdm import tqdm
1313
1414import networkx as nx
1515import numpy as np
16- import sys
1716
18- from segmentation_skeleton_metrics .utils import img_util , swc_util , util
19-
20- ANISOTROPY = np .array ([0.748 , 0.748 , 1.0 ])
17+ from segmentation_skeleton_metrics .utils import swc_util , util
2118
2219
2320class GraphBuilder :
@@ -42,7 +39,9 @@ def __init__(
4239
4340 # Reader
4441 anisotropy = anisotropy if use_anisotropy else (1.0 , 1.0 , 1.0 )
45- self .swc_reader = swc_util .Reader (anisotropy , selected_ids = selected_ids )
42+ self .swc_reader = swc_util .Reader (
43+ anisotropy , selected_ids = selected_ids
44+ )
4645
4746 def run (self , swc_pointer ):
4847 graphs = self ._build_graphs_from_swcs (swc_pointer )
@@ -51,13 +50,12 @@ def run(self, swc_pointer):
5150
5251 # --- Build Graphs ---
5352 def _build_graphs_from_swcs (self , swc_pointer ):
54- with ThreadPoolExecutor () as executor :
53+ with ProcessPoolExecutor () as executor :
5554 # Assign processes
5655 processes = list ()
5756 swc_dicts = self .swc_reader .load (swc_pointer )
5857 while len (swc_dicts ) > 0 :
5958 swc_dict = swc_dicts .pop ()
60- #if self._process_swc_dict(swc_dict["swc_id"]):
6159 processes .append (executor .submit (self .to_graph , swc_dict ))
6260
6361 # Store results
@@ -97,9 +95,8 @@ def to_graph(self, swc_dict):
9795
9896 # Build graph
9997 if not self .coords_only :
100- # graph.set_nodes()
98+ graph .set_nodes ()
10199 id_lookup = dict ()
102- run_length = 0
103100 for i , id_i in enumerate (swc_dict ["id" ]):
104101 id_lookup [id_i ] = i
105102 if swc_dict ["pid" ][i ] != - 1 :
0 commit comments