|
def get_2D_distance( |
|
position1: np.ndarray, |
|
position2: np.ndarray, |
|
track_graph: nx.Graph = None, |
|
edges: list = None, |
|
precomputed_distance: bool = True, |
|
) -> np.ndarray: |
|
"""Distance of two points along the graph of the track. |
|
|
|
Parameters |
|
---------- |
|
position1 : np.ndarray, shape (n_time, 2) |
|
position2 : np.ndarray, shape (n_time, 2) |
|
track_graph : nx.Graph or None |
|
edges : list or None |
|
precomputed_distance : bool, optional |
|
|
|
Returns |
|
------- |
|
distance : np.ndarray, shape (n_time,) |
|
|
|
""" |
|
position1 = np.asarray(position1) |
|
position2 = np.asarray(position2) |
|
|
|
if position1.ndim < 2: |
|
position1 = position1[np.newaxis] |
|
if position2.ndim < 2: |
|
position2 = position2[np.newaxis] |
|
|
|
if track_graph is None: |
|
distance = np.linalg.norm(position1 - position2, axis=1) |
|
else: |
|
node_positions = nx.get_node_attributes(track_graph, "pos") |
|
node_ids = np.asarray(list(node_positions.keys())) |
|
node_positions = np.asarray(list(node_positions.values())) |
|
|
|
# remove outer boundary edge |
|
bin_edges = [e[1:-1] for e in edges] |
track_graph and edges args are both optional. If provided the former and not the latter, this results in a TypeError: 'NoneType' is not iterable'. Can edges be inferred from track_graph? Should this instead raise an error about 'if a, must include b'?
non_local_detector/src/non_local_detector/analysis/distance2D.py
Lines 197 to 235 in eb86ba0
track_graphandedgesargs are both optional. If provided the former and not the latter, this results in aTypeError: 'NoneType' is not iterable'. Can edges be inferred fromtrack_graph? Should this instead raise an error about 'if a, must include b'?