Implement SIP - #321
Conversation
| + np.cos(lat_1) * np.cos(lat_2) * np.sin(dlon / 2) ** 2 | ||
| ) | ||
| return 2 * _EARTH_RADIUS_M * np.arcsin(np.sqrt(a)) | ||
| return np.linalg.norm(query_coords[stop_1] - query_coords[stop_2], axis=1) |
There was a problem hiding this comment.
A function like this already exists in nomad/stop_detection/utils.py#L154 , something like temporal_blocking also exists, but I'm not super convinced it is necessary here.
Please integrate and avoid redundancy.
There was a problem hiding this comment.
I replaced _pair_distances with _haversine_distance. For temporal blocking, it's not strictly necessary, but I feel like it is still worth including as a performance upgrade; I saw speedup on the order of 10x when I tested on 500 users.
…darren-contact-sip
…darren-contact-sip
| from sklearn.neighbors import BallTree, KDTree | ||
|
|
||
|
|
||
| _EARTH_RADIUS_M = 6_371_000 |
There was a problem hiding this comment.
I suppose once PR #403 is merged this should just be constants.EARTH_RADIUS_METERS
| stop_2 = pairs["stop_2"].to_numpy() | ||
| keep = ( | ||
| (stop_1 < stop_2) | ||
| & (users[stop_1] != users[stop_2]) |
There was a problem hiding this comment.
what if both user ids are missing, would this evaluate to true? Then we would get a false contact? Not sure if/where we check for missing user_ids
Implements contact-based social interaction potential from stop tables. Contacts can be estimated either from a shared
location_idor spatial proximity, using temporal blocking to avoid comparing stops that cannot overlap. Contact events can then be weighted by duration or linear distance decay and aggregated into user-level SIP.Review also aligned the new API with NOMAD conventions: column names resolve through
traj_colsor keyword mappings, datetime and timestamp inputs retain their representation and timezone, and outputs use the canonical start/end,duration,location_id, anddistancenames.complete_outputcontrols whether end time and location/distance are retained. Earth-radius calculations now use the shared package constant, and redundant pandas/NumPy conversions were simplified.Adds focused tests for exact and radius contacts, temporal overlap and block boundaries, custom column mappings, datetime preservation, SIP aggregation, and the latitude/longitude BallTree path. Removes the redundant demo notebook and updates the SICSS tutorial for the reviewed API.