@@ -275,8 +275,52 @@ def report_summary(self, results):
275275
276276 # --- Writers ---
277277 def save_fragments (self , gt_graphs , fragment_graphs ):
278- assert fragment_graphs is not None
279- pass
278+ """
279+ Saves ground-truth graphs and their intersecting fragment graphs to
280+ zipped SWC files.
281+
282+ Parameters
283+ ----------
284+ gt_graphs : Dict[str, LabeledGraph]
285+ Graphs built from ground truth SWC files.
286+ fragment_graphs : Dict[str, FragmentsGraph]
287+ Graphs built from skeletons obtained from a segmentation.
288+ """
289+ # Initializations
290+ fragments_dir = os .path .join (self .output_dir , "fragments" )
291+ util .mkdir (fragments_dir , delete = True )
292+
293+ # Main
294+ for key , graph in gt_graphs .items ():
295+ # Create zip writer
296+ zip_path = os .path .join (fragments_dir , f"{ graph .name } .zip" )
297+ zip_writer = ZipFile (zip_path , "a" )
298+
299+ # Save skeletons
300+ graph .to_zipped_swc (zip_writer )
301+ self .save_intersecting_fragments (
302+ graph , fragment_graphs , zip_writer
303+ )
304+
305+ @staticmethod
306+ def save_intersecting_fragments (gt_graph , fragment_graphs , zip_writer ):
307+ """
308+ Saves SWC files for all fragment graphs whose label intersects with
309+ the given ground-truth graph.
310+
311+ Parameters
312+ ----------
313+ gt_graph : LabeledGraph
314+ Graphs built from ground truth SWC files.
315+ fragment_graphs : Dict[str, FragmentGraph]
316+ Graphs built from skeletons obtained from a segmentation.
317+ zip_writer : zipfile.ZipFile
318+ Open ZIP file handle used to write fragments.
319+ """
320+ intersecting_labels = gt_graph .get_node_labels ()
321+ for key , graph in fragment_graphs .items ():
322+ if graph .label in intersecting_labels :
323+ graph .to_zipped_swc (zip_writer )
280324
281325 def save_merge_results (self , gt_graphs , fragment_graphs , output_dir ):
282326 """
@@ -313,7 +357,7 @@ def save_merge_sites(self, zip_writer):
313357 Parameters
314358 ----------
315359 zip_writer : zipfile.ZipFile
316- Open ZIP file handle used to store merge site data.
360+ Open ZIP file handle used to write merge site data.
317361 """
318362 merge_sites = self .metrics ["# Merges" ].merge_sites
319363 for i in range (len (merge_sites )):
0 commit comments