Skip to content

Commit 4e896b9

Browse files
committed
fix(edits/split): filter out inactive cross edges
1 parent e013b3a commit 4e896b9

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

pychunkedgraph/graph/chunkedgraph.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,11 @@ def copy_fake_edges(self, chunk_id: np.uint64) -> None:
657657
self.client.write(mutations)
658658

659659
def get_l2_agglomerations(
660-
self, level2_ids: np.ndarray, edges_only: bool = False
660+
self,
661+
level2_ids: np.ndarray,
662+
edges_only: bool = False,
663+
active: bool = False,
664+
time_stamp: typing.Optional[datetime.datetime] = None,
661665
) -> typing.Tuple[typing.Dict[int, types.Agglomeration], typing.Tuple[Edges]]:
662666
"""
663667
Children of Level 2 Node IDs and edges.
@@ -703,6 +707,15 @@ def get_l2_agglomerations(
703707
raise ValueError("Found conflicting parents.")
704708
sv_parent_d.update(dict(zip(svs.tolist(), [l2id] * len(svs))))
705709

710+
if active:
711+
n1, n2 = all_chunk_edges.node_ids1, all_chunk_edges.node_ids2
712+
layers = self.get_cross_chunk_edges_layer(all_chunk_edges.get_pairs())
713+
max_layer = np.max(layers) + 1
714+
parents1 = self.get_roots(n1, stop_layer=max_layer, time_stamp=time_stamp)
715+
parents2 = self.get_roots(n2, stop_layer=max_layer, time_stamp=time_stamp)
716+
mask = parents1 == parents2
717+
all_chunk_edges = all_chunk_edges[mask]
718+
706719
in_edges, out_edges, cross_edges = edge_utils.categorize_edges_v2(
707720
self.meta, all_chunk_edges, sv_parent_d
708721
)

pychunkedgraph/graph/edits.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ def remove_edges(
313313
cg,
314314
*,
315315
atomic_edges: Iterable[np.ndarray],
316-
l2id_agglomeration_d: Dict,
317316
operation_id: basetypes.OPERATION_ID = None,
318317
time_stamp: datetime.datetime = None,
319318
parent_ts: datetime.datetime = None,
@@ -323,6 +322,9 @@ def remove_edges(
323322
roots = cg.get_roots(l2ids, assert_roots=True, time_stamp=parent_ts)
324323
assert np.unique(roots).size == 1, "L2 IDs must belong to same root."
325324

325+
l2id_agglomeration_d, _ = cg.get_l2_agglomerations(
326+
l2ids, active=True, time_stamp=parent_ts
327+
)
326328
new_old_id_d = defaultdict(set)
327329
old_new_id_d = defaultdict(set)
328330
old_hierarchy_d = _init_old_hierarchy(cg, l2ids, parent_ts=parent_ts)
@@ -409,7 +411,6 @@ def _get_descendants(cg, new_id):
409411
return result
410412

411413

412-
413414
def _update_neighbor_cross_edges_single(
414415
cg, new_id: int, cx_edges_d: dict, node_map: dict, *, parent_ts
415416
) -> dict:
@@ -498,7 +499,7 @@ def _update_neighbor_cross_edges(
498499

499500
def _get_supervoxels(cg, node_ids):
500501
"""Returns the first supervoxel found for each node_id."""
501-
result = {}
502+
result = {}
502503
node_ids_copy = np.copy(node_ids)
503504
children = np.copy(node_ids)
504505
children_d = cg.get_children(node_ids)

pychunkedgraph/graph/operation.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def _apply(
640640
operation_id=operation_id,
641641
time_stamp=timestamp,
642642
parent_ts=self.parent_ts,
643-
allow_same_segment_merge=self.allow_same_segment_merge
643+
allow_same_segment_merge=self.allow_same_segment_merge,
644644
)
645645
return new_roots, new_l2_ids, fake_edge_rows + new_entries
646646

@@ -751,18 +751,11 @@ def _apply(
751751
):
752752
raise PreconditionError("Supervoxels must belong to the same object.")
753753

754-
with TimeIt("subgraph", self.cg.graph_id, operation_id):
755-
l2id_agglomeration_d, _ = self.cg.get_l2_agglomerations(
756-
self.cg.get_parents(
757-
self.removed_edges.ravel(), time_stamp=self.parent_ts
758-
),
759-
)
760754
with TimeIt("remove_edges", self.cg.graph_id, operation_id):
761755
return edits.remove_edges(
762756
self.cg,
763757
operation_id=operation_id,
764758
atomic_edges=self.removed_edges,
765-
l2id_agglomeration_d=l2id_agglomeration_d,
766759
time_stamp=timestamp,
767760
parent_ts=self.parent_ts,
768761
)
@@ -929,7 +922,6 @@ def _apply(
929922
self.cg,
930923
operation_id=operation_id,
931924
atomic_edges=self.removed_edges,
932-
l2id_agglomeration_d=l2id_agglomeration_d,
933925
time_stamp=timestamp,
934926
parent_ts=self.parent_ts,
935927
)

pychunkedgraph/repair/edits.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
from pychunkedgraph.graph.operation import GraphEditOperation
88

99

10+
def _get_previous_log_ts(cg, operation):
11+
log, previous_ts = cg.client.read_log_entry(operation - 1)
12+
if log:
13+
return previous_ts
14+
return _get_previous_log_ts(cg, operation-1)
15+
16+
1017
def repair_operation(
1118
cg: ChunkedGraph,
1219
operation_id: int,
@@ -20,8 +27,8 @@ def repair_operation(
2027
_, current_ts = cg.client.read_log_entry(operation_id)
2128
parent_ts = current_ts - timedelta(milliseconds=10)
2229
if operation_id > 1 and use_preceding_edit_ts:
23-
_, previous_ts = cg.client.read_log_entry(operation_id - 1)
24-
parent_ts = previous_ts + timedelta(milliseconds=200)
30+
previous_ts = _get_previous_log_ts(cg, operation_id)
31+
parent_ts = previous_ts + timedelta(milliseconds=100)
2532

2633
result = operation.execute(
2734
operation_id=operation_id,

0 commit comments

Comments
 (0)