Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #112 #113

Merged
merged 9 commits into from
Feb 11, 2025
20 changes: 14 additions & 6 deletions mapmaker/flatmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ def save_feature_for_node_lookup(self, feature: Feature):
def features_for_anatomical_node(self, anatomical_node: AnatomicalNode, warn: bool=True) -> Optional[tuple[AnatomicalNode, set[Feature]]]:
#=========================================================================================================================================
if self.__feature_node_map is not None:
return self.__feature_node_map.features_for_anatomical_node(anatomical_node, warn=warn)
if len((features:=self.__feature_node_map.features_for_anatomical_node(anatomical_node, warn=warn))[1]) > 0:
return features
if len(fts:=set(feature for feature in self.__features_with_id.values()
if feature.models in [features[0][0]]+list(features[0][1])
and feature.get_property('kind')=='proxy')) > 0:
return (anatomical_node, fts)
return features

def duplicate_feature_id(self, feature_ids: str) -> bool:
#========================================================
Expand Down Expand Up @@ -299,6 +305,7 @@ def __add_proxied_features(self):
if self.__bottom_exported_layer is None:
log.warning('No exported layer on which to add proxy features', type='proxy')
return
proxy_seqs = {}
for proxy_definition in self.__properties_store.proxies:
feature_model = proxy_definition['feature']
if self.__feature_node_map.has_model(feature_model):
Expand All @@ -308,16 +315,17 @@ def __add_proxied_features(self):
if not self.__feature_node_map.has_model(proxy_model):
log.warning('Proxy missing from map', type='proxy', models=feature_model, proxy=proxy_model)
for feature in self.__feature_node_map.get_features(proxy_model):
self.__add_proxy_feature(feature, feature_model)
proxy_seqs[feature.id] = proxy_seqs.get(feature.id, -1) + 1
self.__add_proxy_feature(feature, feature_model, proxy_seqs[feature.id])

def __add_proxy_feature(self, feature: Feature, feature_model: str):
#===================================================================
def __add_proxy_feature(self, feature: Feature, feature_model: str, proxy_seq: int):
#================================================================================
if 'Polygon' not in feature.geometry.geom_type:
log.warning('Proxy feature must have a polygon shape', type='proxy', models=feature_model, feature=feature)
elif self.__bottom_exported_layer is not None:
self.__bottom_exported_layer.add_feature(
self.new_feature(self.__bottom_exported_layer.id, proxy_dot(feature.geometry), { # type: ignore
'id': f'proxy_on_{feature.id}',
self.new_feature(self.__bottom_exported_layer.id, proxy_dot(feature.geometry, proxy_seq), { # type: ignore
'id': f'proxy_{proxy_seq}_on_{feature.id}',
'tile-layer': FEATURES_TILE_LAYER,
'models': feature_model,
'kind': 'proxy'
Expand Down
2 changes: 1 addition & 1 deletion mapmaker/flatmap/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, terms_alias_file: Optional[str]=None):
for alias in equivalence.get('aliases', []):
alias = (alias[0], tuple(alias[1])) if isinstance(alias, list) else alias
if alias in self.__anatomical_aliases:
self.__log.error('Alias cannot map to both terms, alias=alias, terms=[self.__anatomical_aliases[alias], term]')
self.__log.error(f'Alias cannot map to both terms, alias=alias, terms={[self.__anatomical_aliases[alias], term]}')
else:
self.__anatomical_aliases[alias] = term
self.__model_to_features: dict[str|tuple, set[Feature]] = defaultdict(set)
Expand Down
9 changes: 5 additions & 4 deletions mapmaker/geometry/proxy_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#===============================================================================

def proxy_dot(poly: MultiPolygon|Polygon) -> Polygon:
def proxy_dot(poly: MultiPolygon|Polygon, proxy_seq: int) -> Polygon:
envelope_coords = shapely.oriented_envelope(poly).boundary.coords
edge_coords = list(zip(envelope_coords, envelope_coords[1:]))
edges = [LineString(coords) for coords in edge_coords]
Expand All @@ -35,8 +35,9 @@ def proxy_dot(poly: MultiPolygon|Polygon) -> Polygon:
median_line = LineString([p0, p1])
else:
median_line = LineString([p1, p0])
proxy_point = shapely.line_interpolate_point(median_line, 0.8, normalized=True)

return proxy_point.buffer(median_line.length/16)
distance = 0.8 - proxy_seq * 0.15
proxy_point = shapely.line_interpolate_point(median_line, distance, normalized=True)
median_distance = median_line.length/16 if median_line.length/16 < 1000 else 1000
return proxy_point.buffer(median_distance)

#===============================================================================
13 changes: 11 additions & 2 deletions mapmaker/properties/pathways.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,18 @@ def __route_network_connectivity(self, network: Network):
path = paths_by_id[path_id]
path_geojson_ids = []
path_taxons = None
added_properties = {
key: value for key, value in [
('missing-nodes', path.connectivity.graph.get('missing_nodes')),
('alert', path.connectivity.graph.get('alert')),
('biological-sex', path.connectivity.graph.get('biological-sex')),
('completeness', path.connectivity.graph.get('completeness')),
] if value is not None
}

for geometric_shape in geometric_shapes:
if geometric_shape.properties.get('type') not in ['arrow', 'junction']:
properties = DEFAULT_PATH_PROPERTIES.copy()
properties = DEFAULT_PATH_PROPERTIES.copy() | added_properties
if routed_path.centrelines is not None:
# The list of nerve models that the path is associated with
properties['nerves'] = routed_path.centrelines_model
Expand All @@ -700,7 +709,7 @@ def __route_network_connectivity(self, network: Network):
path_taxons = feature.get_property('taxons')

for geometric_shape in geometric_shapes:
properties = DEFAULT_PATH_PROPERTIES.copy()
properties = DEFAULT_PATH_PROPERTIES.copy() | added_properties
properties.update(geometric_shape.properties)
if properties.get('type') in ['arrow', 'junction']:
properties['kind'] = path.path_type.viewer_kind
Expand Down
Loading
Loading