Skip to content

Commit afbb822

Browse files
authored
Merge pull request #113 from napakalas/issue-#112
Issue #112
2 parents 495de45 + e9a9a0c commit afbb822

File tree

6 files changed

+174
-112
lines changed

6 files changed

+174
-112
lines changed

mapmaker/flatmap/__init__.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ def save_feature_for_node_lookup(self, feature: Feature):
247247
def features_for_anatomical_node(self, anatomical_node: AnatomicalNode, warn: bool=True) -> Optional[tuple[AnatomicalNode, set[Feature]]]:
248248
#=========================================================================================================================================
249249
if self.__feature_node_map is not None:
250-
return self.__feature_node_map.features_for_anatomical_node(anatomical_node, warn=warn)
250+
if len((features:=self.__feature_node_map.features_for_anatomical_node(anatomical_node, warn=warn))[1]) > 0:
251+
return features
252+
if len(fts:=set(feature for feature in self.__features_with_id.values()
253+
if feature.models in [features[0][0]]+list(features[0][1])
254+
and feature.get_property('kind')=='proxy')) > 0:
255+
return (anatomical_node, fts)
256+
return features
251257

252258
def duplicate_feature_id(self, feature_ids: str) -> bool:
253259
#========================================================
@@ -299,6 +305,7 @@ def __add_proxied_features(self):
299305
if self.__bottom_exported_layer is None:
300306
log.warning('No exported layer on which to add proxy features', type='proxy')
301307
return
308+
proxy_seqs = {}
302309
for proxy_definition in self.__properties_store.proxies:
303310
feature_model = proxy_definition['feature']
304311
if self.__feature_node_map.has_model(feature_model):
@@ -308,16 +315,17 @@ def __add_proxied_features(self):
308315
if not self.__feature_node_map.has_model(proxy_model):
309316
log.warning('Proxy missing from map', type='proxy', models=feature_model, proxy=proxy_model)
310317
for feature in self.__feature_node_map.get_features(proxy_model):
311-
self.__add_proxy_feature(feature, feature_model)
318+
proxy_seqs[feature.id] = proxy_seqs.get(feature.id, -1) + 1
319+
self.__add_proxy_feature(feature, feature_model, proxy_seqs[feature.id])
312320

313-
def __add_proxy_feature(self, feature: Feature, feature_model: str):
314-
#===================================================================
321+
def __add_proxy_feature(self, feature: Feature, feature_model: str, proxy_seq: int):
322+
#================================================================================
315323
if 'Polygon' not in feature.geometry.geom_type:
316324
log.warning('Proxy feature must have a polygon shape', type='proxy', models=feature_model, feature=feature)
317325
elif self.__bottom_exported_layer is not None:
318326
self.__bottom_exported_layer.add_feature(
319-
self.new_feature(self.__bottom_exported_layer.id, proxy_dot(feature.geometry), { # type: ignore
320-
'id': f'proxy_on_{feature.id}',
327+
self.new_feature(self.__bottom_exported_layer.id, proxy_dot(feature.geometry, proxy_seq), { # type: ignore
328+
'id': f'proxy_{proxy_seq}_on_{feature.id}',
321329
'tile-layer': FEATURES_TILE_LAYER,
322330
'models': feature_model,
323331
'kind': 'proxy'

mapmaker/flatmap/feature.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def __init__(self, terms_alias_file: Optional[str]=None):
130130
for alias in equivalence.get('aliases', []):
131131
alias = (alias[0], tuple(alias[1])) if isinstance(alias, list) else alias
132132
if alias in self.__anatomical_aliases:
133-
self.__log.error('Alias cannot map to both terms, alias=alias, terms=[self.__anatomical_aliases[alias], term]')
133+
self.__log.error(f'Alias cannot map to both terms, alias=alias, terms={[self.__anatomical_aliases[alias], term]}')
134134
else:
135135
self.__anatomical_aliases[alias] = term
136136
self.__model_to_features: dict[str|tuple, set[Feature]] = defaultdict(set)

mapmaker/geometry/proxy_dot.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#===============================================================================
2525

26-
def proxy_dot(poly: MultiPolygon|Polygon) -> Polygon:
26+
def proxy_dot(poly: MultiPolygon|Polygon, proxy_seq: int) -> Polygon:
2727
envelope_coords = shapely.oriented_envelope(poly).boundary.coords
2828
edge_coords = list(zip(envelope_coords, envelope_coords[1:]))
2929
edges = [LineString(coords) for coords in edge_coords]
@@ -35,8 +35,9 @@ def proxy_dot(poly: MultiPolygon|Polygon) -> Polygon:
3535
median_line = LineString([p0, p1])
3636
else:
3737
median_line = LineString([p1, p0])
38-
proxy_point = shapely.line_interpolate_point(median_line, 0.8, normalized=True)
39-
40-
return proxy_point.buffer(median_line.length/16)
38+
distance = 0.8 - proxy_seq * 0.15
39+
proxy_point = shapely.line_interpolate_point(median_line, distance, normalized=True)
40+
median_distance = median_line.length/16 if median_line.length/16 < 1000 else 1000
41+
return proxy_point.buffer(median_distance)
4142

4243
#===============================================================================

mapmaker/properties/pathways.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,18 @@ def __route_network_connectivity(self, network: Network):
673673
path = paths_by_id[path_id]
674674
path_geojson_ids = []
675675
path_taxons = None
676+
added_properties = {
677+
key: value for key, value in [
678+
('missing-nodes', path.connectivity.graph.get('missing_nodes')),
679+
('alert', path.connectivity.graph.get('alert')),
680+
('biological-sex', path.connectivity.graph.get('biological-sex')),
681+
('completeness', path.connectivity.graph.get('completeness')),
682+
] if value is not None
683+
}
684+
676685
for geometric_shape in geometric_shapes:
677686
if geometric_shape.properties.get('type') not in ['arrow', 'junction']:
678-
properties = DEFAULT_PATH_PROPERTIES.copy()
687+
properties = DEFAULT_PATH_PROPERTIES.copy() | added_properties
679688
if routed_path.centrelines is not None:
680689
# The list of nerve models that the path is associated with
681690
properties['nerves'] = routed_path.centrelines_model
@@ -700,7 +709,7 @@ def __route_network_connectivity(self, network: Network):
700709
path_taxons = feature.get_property('taxons')
701710

702711
for geometric_shape in geometric_shapes:
703-
properties = DEFAULT_PATH_PROPERTIES.copy()
712+
properties = DEFAULT_PATH_PROPERTIES.copy() | added_properties
704713
properties.update(geometric_shape.properties)
705714
if properties.get('type') in ['arrow', 'junction']:
706715
properties['kind'] = path.path_type.viewer_kind

0 commit comments

Comments
 (0)