Skip to content

Implement SIP - #321

Merged
paco-barreras merged 29 commits into
mainfrom
darren-contact-sip
Aug 13, 2026
Merged

Implement SIP#321
paco-barreras merged 29 commits into
mainfrom
darren-contact-sip

Conversation

@DPnimo11

@DPnimo11 DPnimo11 commented Jun 16, 2026

Copy link
Copy Markdown
Member

Implements contact-based social interaction potential from stop tables. Contacts can be estimated either from a shared location_id or 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_cols or keyword mappings, datetime and timestamp inputs retain their representation and timezone, and outputs use the canonical start/end, duration, location_id, and distance names. complete_output controls 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.

@DPnimo11 DPnimo11 added this to the SICC 2026 Codebase milestone Jun 16, 2026
@DPnimo11
DPnimo11 requested a review from paco-barreras June 16, 2026 17:01
@DPnimo11 DPnimo11 linked an issue Jun 16, 2026 that may be closed by this pull request
@DPnimo11 DPnimo11 self-assigned this Jun 16, 2026
Comment thread nomad/contact_estimation.py Outdated
+ 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread nomad/contact_estimation.py Outdated
from sklearn.neighbors import BallTree, KDTree


_EARTH_RADIUS_M = 6_371_000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@paco-barreras
paco-barreras merged commit 0c7fc21 into main Aug 13, 2026
@paco-barreras
paco-barreras deleted the darren-contact-sip branch August 13, 2026 04:58
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.

Implementation and testing of Social Interaction Potential

3 participants