Skip to content

get_2D_distance errors if provided a track graph but not edge list #5

@CBroz1

Description

@CBroz1

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'?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions