-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from ai4er-cdt/feature/graph-analysis-identifi…
…cation Feature/graph analysis identification
- Loading branch information
Showing
28 changed files
with
6,465 additions
and
103 deletions.
There are no files selected for viewing
1,409 changes: 1,409 additions & 0 deletions
1,409
notebooks/exploratory/svm-10-optimise-identify-node.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
1,976 changes: 1,976 additions & 0 deletions
1,976
notebooks/exploratory/svm-7-getting-to-know-graph.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
2,488 changes: 2,488 additions & 0 deletions
2,488
notebooks/exploratory/svm-8-generate-test-cases.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Contains tools for binary operations between GeoGraph objects.""" | ||
from numpy import ndarray | ||
from src.models.polygon_utils import ( | ||
connect_with_interior_bulk, | ||
connect_with_interior_or_edge_bulk, | ||
connect_with_interior_or_edge_or_corner_bulk, | ||
) | ||
|
||
# For switching identifiction mode in `identify_node` | ||
_BULK_SPATIAL_IDENTIFICATION_FUNCTION = { | ||
"corner": connect_with_interior_or_edge_or_corner_bulk, | ||
"edge": connect_with_interior_or_edge_bulk, | ||
"interior": connect_with_interior_bulk, | ||
} | ||
|
||
|
||
def identify_node(node: dict, other_graph: "GeoGraph", mode: str = "corner") -> ndarray: | ||
""" | ||
Return list of all node ids in `other_graph` which identify with the given `node`. | ||
Args: | ||
node (dict): The node for which to find nodes in `other_graphs` that can be | ||
identified with `node`. | ||
other_graph (GeoGraph): The GeoGraph object in which to search for | ||
identifications | ||
mode (str, optional): Must be one of `corner`, `edge` or `interior`. Defaults | ||
to "corner". | ||
The different modes correspond to different rules for identification: | ||
- corner: Polygons of the same `class_label` which overlap, touch in their | ||
edges or corners will be identified with each other. (fastest) | ||
- edge: Polygons of the same `class_label` which overlap or touch in their | ||
edges will be identified with each other. | ||
- interior: Polygons of the same `class_label` which overlap will be | ||
identified with each other. Touching corners or edges are not counted. | ||
Returns: | ||
np.ndarray: List of node ids in `other_graph` which identify with `node`. | ||
""" | ||
# Mode switch | ||
assert mode in ["corner", "edge", "interior"] | ||
have_valid_overlap = _BULK_SPATIAL_IDENTIFICATION_FUNCTION[mode] | ||
|
||
# Get potential candidates for overlap | ||
candidate_ids = other_graph.rtree.query(node["geometry"], sort=True) | ||
# Filter candidates according to the same class label | ||
candidate_ids = candidate_ids[ | ||
other_graph.class_label[candidate_ids] == node["class_label"] | ||
] | ||
# Filter candidates accroding to correct spatial overlap | ||
candidate_ids = candidate_ids[ | ||
have_valid_overlap(node["geometry"], other_graph.geometry[candidate_ids]) | ||
] | ||
|
||
return candidate_ids |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.