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

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

Open
CBroz1 opened this issue Oct 8, 2024 · 1 comment
Open

Comments

@CBroz1
Copy link
Member

CBroz1 commented Oct 8, 2024

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

@edeno
Copy link
Contributor

edeno commented Oct 8, 2024

It doesn't make sense to specify the edges without the track graph. This could be better documented (like many things in this repo). At some point I will get to the full documentation of everything here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants