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

Compute neighbor distance #392

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

schroedtert
Copy link
Collaborator

Closes #246

@schroedtert schroedtert force-pushed the neighbors-distance branch 2 times, most recently from 2082fe9 to 5dfdd1a Compare December 8, 2024 12:05
schroedtert

This comment was marked as outdated.

@schroedtert schroedtert marked this pull request as ready for review February 22, 2025 16:50
Comment on lines 293 to 294
as_list (bool): Return the neighbors as a list per pedestrian and frame,
if true, otherwise each neighbor is in a single row.
Copy link
Collaborator Author

@schroedtert schroedtert Feb 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a warning in the API description and the user guide notebook that discourages usage of the function with the default value. Do we additionally want to emit a deprecation warning if it is set to True?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about: I also added a deprecation warning, this way everybody gets informed when using the function, without any need to read a up-to-date documentation. This way more user will update their scripts (hopefully).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this explicit solution better.

@schroedtert schroedtert requested a review from chraibi February 22, 2025 16:55
@schroedtert schroedtert force-pushed the neighbors-distance branch 3 times, most recently from 6f86a73 to 3c8bbaa Compare February 23, 2025 09:12
Also add the (preferable) option to give the neighbors not as a list,
but as rows. This way they can later better be used in other
computations.
Copy link
Collaborator

@chraibi chraibi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. Need to check functionality.

Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.69%. Comparing base (0e5e402) to head (43c290b).
Report is 1 commits behind head on main.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

if as_list:
warnings.warn(
"The parameter 'as_list=True' is deprecated and may change in a "
"future version. It is kept for backwards compatability. We "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compatibility

stacklevel=2, # Makes the warning appear at the caller level
)

if as_list:
Copy link
Collaborator

@chraibi chraibi Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use if as_list: once instead of twice?

warnings.warn(
"The parameter 'as_list=True' is deprecated and may change in a "
"future version. It is kept for backwards compatability. We "
"highly discourage in using this, as its result is harder to be "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highly discourage in using this.

"""
if NEIGHBORS_COL in neighborhood.columns:
raise ValueError(
"For compute the distance between neighbors compute the "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise ValueError(
    "Cannot compute distance between neighbors with list-format data. "
    "Please use the result of compute_neighbors with parameter as_list=False."
)


neighbors_with_position[DISTANCE_COL] = shapely.distance(
neighbors_with_position[POINT_COL],
neighbors_with_position["point_neighbor"],
Copy link
Collaborator

@chraibi chraibi Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can "point_neighbor" depend on POINT_COL instead of being hard-coded?

What about

NEIGHBOR_POINT_COL = POINT_COL + "_neighbor"

and then use

neighbors_with_position[DISTANCE_COL] = shapely.distance(
    neighbors_with_position[POINT_COL],
    neighbors_with_position[NEIGHBOR_POINT_COL],
)

traj_data.data[[ID_COL, FRAME_COL, POINT_COL]],
left_on=[NEIGHBOR_ID_COL, FRAME_COL],
right_on=[ID_COL, FRAME_COL],
suffixes=("", "_neighbor"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct I assume, but does the result have a duplicate column ID_COL?
If so, maybe you can drop it:

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

Successfully merging this pull request may close these issues.

Compute distance to neighbors
2 participants