@@ -301,6 +301,7 @@ def run(self):
301301 path = f"{ self .output_dir } /{ prefix } results.csv"
302302 if self .fragment_graphs is None :
303303 self .metrics = self .metrics .drop ("# Merges" , axis = 1 )
304+ self .metrics = self .metrics .drop ("Merge Rate" , axis = 1 )
304305 self .metrics .to_csv (path , index = False )
305306
306307 # Report results
@@ -337,28 +338,39 @@ def detect_splits(self):
337338
338339 # Store results
339340 for process in as_completed (pending .keys ()):
341+ # Update graph
340342 key = pending .pop (process )
341- self .graphs [key ], n_split_edges = process .result ()
342- n_before = self .graphs [key ].graph ["n_initial_edges" ]
343- n_after = self .graphs [key ].number_of_edges ()
344-
345- n_missing_edges = n_before - n_after
346- n_splits = gutil .count_splits (self .graphs [key ])
347- p_omit = 100 * (n_missing_edges + n_split_edges ) / n_before
348- p_split = 100 * n_split_edges / n_before
349- rl = np .sum (self .graphs [key ].run_lengths ())
350- gt_rl = self .graphs [key ].run_length
351- split_rate = rl / n_splits if n_splits > 0 else np .nan
352-
353- self .metrics .at [key , "# Splits" ] = n_splits
354- self .metrics .at [key , "Split Rate" ] = split_rate
355- self .metrics .loc [key , "% Split Edges" ] = round (p_split , 2 )
356- self .metrics .at [key , "% Omit Edges" ] = round (p_omit , 2 )
357- self .metrics .loc [key , "SWC Run Length" ] = round (gt_rl , 2 )
343+ graph , n_split_edges = process .result ()
344+ self .graphs [key ] = graph
358345
346+ # Compute metrics
347+ self .compute_split_metrics (key , n_split_edges )
359348 if self .verbose :
360349 pbar .update (1 )
361350
351+ def compute_split_metrics (self , key , n_split_edges ):
352+ # Edge counts
353+ n_edges_before = self .graphs [key ].graph ["n_initial_edges" ]
354+ n_edges_after = self .graphs [key ].number_of_edges ()
355+ n_edge_missing = n_edges_before - n_edges_after
356+
357+ # Split statistics
358+ n_splits = gutil .count_splits (self .graphs [key ])
359+ p_omit = 100 * (n_edge_missing + n_split_edges ) / n_edges_before
360+ p_split = 100 * n_split_edges / n_edges_before
361+
362+ # Run lengths
363+ rl = np .sum (self .graphs [key ].run_lengths ())
364+ gt_rl = self .graphs [key ].run_length
365+ split_rate = rl / n_splits if n_splits > 0 else np .nan
366+
367+ # Update metrics
368+ self .metrics .at [key , "# Splits" ] = n_splits
369+ self .metrics .at [key , "Split Rate" ] = split_rate
370+ self .metrics .at [key , "% Split Edges" ] = round (p_split , 2 )
371+ self .metrics .at [key , "% Omit Edges" ] = round (p_omit , 2 )
372+ self .metrics .at [key , "SWC Run Length" ] = round (gt_rl , 2 )
373+
362374 # -- Merge Detection --
363375 def detect_merges (self ):
364376 """
@@ -724,4 +736,3 @@ def to_local_voxels(self, key, i, offset):
724736 voxel = np .array (self .graphs [key ].voxels [i ])
725737 offset = np .array (offset )
726738 return tuple (voxel - offset )
727-
0 commit comments