1- from contextlib import contextmanager
2- from typing import Annotated , Literal
3- import tempfile
4- import itertools
51import functools
2+ import itertools
3+ import tempfile
4+ from contextlib import contextmanager
65from pathlib import Path
7- import time
8- from pprint import pprint
6+ from typing import Annotated , Literal
97
108import daisy
119import mwatershed as mws
12- import numpy as np
1310import networkx as nx
11+ import numpy as np
1412from funlib .geometry import Coordinate , Roi
1513from pydantic import Field
1614
2018from ..dbs import PostgreSQL , SQLite
2119from ..utils import PydanticCoordinate
2220from .blockwise import BlockwiseTask
23- from ..datasets import Labels
2421
2522DB = Annotated [
2623 PostgreSQL | SQLite ,
@@ -313,7 +310,6 @@ def process_block(block: daisy.Block):
313310 both_sides = True ,
314311 )
315312
316- t1 = time .time ()
317313 edges = []
318314 inputs = set (
319315 node
@@ -391,15 +387,13 @@ def process_block(block: daisy.Block):
391387 in_group = new_seg_to_frag_mapping .setdefault (int (out_frag ), set ())
392388 in_group .add (int (in_frag ))
393389
394- t1 = time .time ()
395390 # save the lut to a temporary file for this block
396391 block_lut = LUT (
397392 path = f"{ tmp_path } /{ '-' .join ([str (o ) for o in block .write_roi .offset ])} -lut"
398393 )
399394 lut = np .array ([inputs , outputs ])
400395 block_lut .save (lut , edges = edges )
401396
402- t1 = time .time ()
403397 # read luts and existing super fragments in neighboring blocks
404398 existing_luts = [
405399 LUT (
@@ -420,7 +414,6 @@ def process_block(block: daisy.Block):
420414 + [self .lut ],
421415 ).load ()
422416
423- t1 = time .time ()
424417 frag_seg_mapping : dict [int , int ] = {
425418 int (k ): int (v ) for k , v in total_lut .T
426419 }
@@ -429,10 +422,8 @@ def process_block(block: daisy.Block):
429422 in_group = seg_frag_mapping .setdefault (out_frag , set ())
430423 in_group .add (in_frag )
431424
432- t1 = time .time ()
433425 out_graph = out_rag_provider .read_graph (block .read_roi )
434426
435- t1 = time .time ()
436427 for out_seg , in_frags in new_seg_to_frag_mapping .items ():
437428 agglomerated_attrs = {
438429 "size" : sum (
@@ -454,7 +445,6 @@ def process_block(block: daisy.Block):
454445
455446 out_graph .add_node (int (out_seg ), ** agglomerated_attrs )
456447
457- t1 = time .time ()
458448 edges_to_agglomerate = {}
459449 for u , v in graph .edges ():
460450 if (
@@ -601,7 +591,6 @@ def process_block(block: daisy.Block):
601591 edge_attrs = list (self .weights .keys ()),
602592 )
603593
604- t1 = time .time ()
605594 edges = []
606595 for u , v , edge_attrs in graph .edges (data = True ):
607596 if (
@@ -630,15 +619,13 @@ def process_block(block: daisy.Block):
630619 else :
631620 inputs , outputs = [], []
632621
633- t1 = time .time ()
634622 # save the lut to a temporary file for this block
635623 block_lut = LUT (
636624 path = f"{ tmp_path } /{ '-' .join ([str (o ) for o in block .write_roi .offset ])} -lut"
637625 )
638626 lut = np .array ([inputs , outputs ])
639627 block_lut .save (lut , edges = edges )
640628
641- t1 = time .time ()
642629 # read luts and existing super fragments in neighboring blocks
643630 existing_luts = [
644631 LUT (
@@ -659,7 +646,6 @@ def process_block(block: daisy.Block):
659646 + [self .lut ],
660647 ).load ()
661648
662- t1 = time .time ()
663649 frag_seg_mapping : dict [int , int ] = {
664650 int (k ): int (v ) for k , v in total_lut .T
665651 }
@@ -668,11 +654,9 @@ def process_block(block: daisy.Block):
668654 in_group = seg_frag_mapping .setdefault (out_frag , set ())
669655 in_group .add (in_frag )
670656
671- t1 = time .time ()
672657 out_graph = out_rag_provider .read_graph (block .read_roi )
673658 assert out_graph .number_of_nodes () == 0 , out_graph .number_of_nodes
674659
675- t1 = time .time ()
676660 for out_frag in np .unique (outputs ):
677661 if out_frag is not None and out_frag not in out_graph .nodes :
678662 in_group = seg_frag_mapping [out_frag ]
@@ -699,7 +683,6 @@ def process_block(block: daisy.Block):
699683
700684 out_graph .add_node (int (out_frag ), ** agglomerated_attrs )
701685
702- t1 = time .time ()
703686 edges_to_agglomerate = {}
704687 for u , v in graph .edges ():
705688 if u in frag_seg_mapping and v in frag_seg_mapping :
0 commit comments