|
9 | 9 | from typing import Iterable |
10 | 10 | from typing import Optional |
11 | 11 | from collections import defaultdict |
| 12 | +from functools import reduce |
12 | 13 |
|
13 | 14 | import fastremap |
14 | 15 | import numpy as np |
@@ -46,7 +47,9 @@ def concatenate_chunk_edges(chunk_edge_dicts: Iterable) -> Dict: |
46 | 47 | return edges_dict |
47 | 48 |
|
48 | 49 |
|
49 | | -def concatenate_cross_edge_dicts(edges_ds: Iterable[Dict], unique: bool = False) -> Dict: |
| 50 | +def concatenate_cross_edge_dicts( |
| 51 | + edges_ds: Iterable[Dict], unique: bool = False |
| 52 | +) -> Dict: |
50 | 53 | """Combines cross chunk edge dicts of form {layer id : edge list}.""" |
51 | 54 | result_d = defaultdict(list) |
52 | 55 | for edges_d in edges_ds: |
@@ -182,3 +185,20 @@ def get_edges_status(cg, edges: Iterable, time_stamp: Optional[float] = None): |
182 | 185 | active_status.extend(mask) |
183 | 186 | active_status = np.array(active_status, dtype=bool) |
184 | 187 | return existence_status, active_status |
| 188 | + |
| 189 | + |
| 190 | +def filter_inactive_cross_edges( |
| 191 | + cg, all_chunk_edges: Edges, time_stamp: Optional[float] = None |
| 192 | +): |
| 193 | + result = [] |
| 194 | + layers = cg.get_cross_chunk_edges_layer(all_chunk_edges.get_pairs()) |
| 195 | + for layer in np.unique(layers): |
| 196 | + layer_mask = layers == layer |
| 197 | + parent_layer = layer + 1 |
| 198 | + layer_edges = all_chunk_edges[layer_mask] |
| 199 | + n1, n2 = layer_edges.node_ids1, layer_edges.node_ids2 |
| 200 | + parents1 = cg.get_roots(n1, stop_layer=parent_layer, time_stamp=time_stamp) |
| 201 | + parents2 = cg.get_roots(n2, stop_layer=parent_layer, time_stamp=time_stamp) |
| 202 | + mask = parents1 == parents2 |
| 203 | + result.append(layer_edges[mask]) |
| 204 | + return reduce(lambda x, y: x + y, result, Edges([], [])) |
0 commit comments