-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Compute neighbor distance #392
Conversation
2082fe9
to
5dfdd1a
Compare
5dfdd1a
to
de0963a
Compare
pedpy/methods/method_utils.py
Outdated
as_list (bool): Return the neighbors as a list per pedestrian and frame, | ||
if true, otherwise each neighbor is in a single row. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
6f86a73
to
3c8bbaa
Compare
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.
3c8bbaa
to
43c290b
Compare
There was a problem hiding this 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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
☔ View full report in Codecov by Sentry. |
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 " |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 " |
There was a problem hiding this comment.
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 " |
There was a problem hiding this comment.
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"], |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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:
Closes #246