Skip to content

Commit 108ba54

Browse files
authored
Merge pull request #115 from napakalas/issue-#114
Issue #114: Update mechanism to handle `unrouted` features.
2 parents afbb822 + ead156c commit 108ba54

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

mapmaker/routing/__init__.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ def pairwise(iterable):
8686
from mapmaker.properties import PropertiesStore
8787
from mapmaker.properties.pathways import Path
8888

89-
#===============================================================================
90-
91-
NOT_LATERAL_NODES = [
92-
'UBERON:0001896',
93-
'UBERON:0000988',
94-
'UBERON:0001891'
95-
]
9689

9790
#=============================================================
9891

@@ -758,7 +751,7 @@ def __feature_properties_from_node(self, connectivity_node: AnatomicalNode) -> d
758751

759752
elif matched is not None:
760753
properties['name'] = matched[0].name
761-
features = set(f for f in matched[1] if f.id is not None)
754+
features = set(f for f in matched[1] if f.id is not None and not f.get_property('unrouted', False))
762755
if len(features):
763756
properties['type'] = 'feature'
764757
properties['features'] = features
@@ -967,7 +960,7 @@ def add_route_edges_from_graph(G, used_nodes):
967960
# else connect to one closest no_segment point and neighbour feature.
968961
features = (
969962
neighbour_dict['features']
970-
if len(neighbour_dict['features']) <= 2 and all(item not in {neighbour_dict['node'][0], *neighbour_dict['node'][1]} for item in NOT_LATERAL_NODES)
963+
if len(neighbour_dict['features']) <= 2
971964
else sorted(neighbour_dict['features'], key=lambda f: f.id)[:1]
972965
)
973966
for feature in features:
@@ -1204,14 +1197,18 @@ def get_node_feature(node_dict, neighbour_features, used_features) -> Feature:
12041197
one_feature_terminals = {
12051198
n: min([
12061199
features[0].geometry.centroid.distance(nf.geometry.centroid)
1207-
for neighbour in connectivity_graph.neighbors(n)
1208-
for nf in (
1209-
connectivity_graph.nodes[neighbour].get("features", set()) |
1210-
{self.__flatmap.get_feature(f_id) for f_id in connectivity_graph.nodes[neighbour].get("used", set())}
1211-
)
1200+
for nf in nfs
12121201
])
12131202
for n, n_dict in connectivity_graph.nodes(data=True)
1214-
if connectivity_graph.degree(n) == 1 and len(features := list(n_dict.get("features", []))) == 1
1203+
if connectivity_graph.degree(n) == 1
1204+
and len(features := list(n_dict.get("features", []))) == 1
1205+
and len(nfs:= [
1206+
nf for neighbour in connectivity_graph.neighbors(n)
1207+
for nf in (
1208+
connectivity_graph.nodes[neighbour].get("features", set()) |
1209+
{self.__flatmap.get_feature(f_id) for f_id in connectivity_graph.nodes[neighbour].get("used", set())}
1210+
)
1211+
]) > 0
12151212
}
12161213
one_feature_terminals = dict(sorted(one_feature_terminals.items(), key=lambda item: item[1]))
12171214
two_feature_terminals = [
@@ -1274,7 +1271,7 @@ def add_paths_to_neighbours(node, node_dict):
12741271
else used_features.get(node, set())
12751272
if connectivity_graph.degree(node) > 1 and len(used_features.get(node, set())) in [1, 2]
12761273
else set(node_dict['features'])
1277-
if connectivity_graph.degree(node) == 1 and all(item not in {node_dict['node'][0], *node_dict['node'][1]} for item in NOT_LATERAL_NODES)
1274+
if connectivity_graph.degree(node) == 1
12781275
else [get_node_feature(node_dict, neighbour_features, used_features)]
12791276
)
12801277
for node_feature in node_features:
@@ -1302,7 +1299,6 @@ def add_paths_to_neighbours(node, node_dict):
13021299
neighbour_features = (
13031300
neighbour_dict.get('features', [])
13041301
if len(neighbour_dict.get('features', [])) <= 2 and degree == 1 and len(node_features) == 1
1305-
and all(item not in {neighbour_dict['node'][0], *neighbour_dict['node'][1]} for item in NOT_LATERAL_NODES)
13061302
else [get_node_feature(neighbour_dict, [node_feature], used_features)]
13071303
if len(neighbour_terminal_laterals) > 0 and len(used_features.get(neighbour, set())) == 0
13081304
else [get_node_feature(neighbour_dict, [node_feature], used_features)]

0 commit comments

Comments
 (0)