-
Notifications
You must be signed in to change notification settings - Fork 1
Self containment metric #216
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
base: main
Are you sure you want to change the base?
Conversation
nomad/metrics/metrics.py
Outdated
| return rog.reset_index(name='rog') | ||
|
|
||
| def self_containment(stops, threshold, agg_freq='d', weighted=True, home_activity_type='Home', | ||
| activity_type_col='activity_type', traj_cols=None, time_weights=None, |
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.
Let's assume this information is in the "location_id" column. Which is passed as kwargs or in traj_cols similar to home_attribution.
home_activity_type can be "home_id", defaulting to home, but can take any location id.
nomad/metrics/metrics.py
Outdated
| non_home = g[g[activity_type_col] != home_activity_type] | ||
|
|
||
| if len(non_home) == 0: | ||
| return np.nan # No non-home activities |
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.
If there is NO activity, then np.nan is appropriate. But if there are stops at home and no non-home, then the containment should be 1.0
nomad/metrics/metrics.py
Outdated
|
|
||
| # Check if all distances are NaN (no home location found) | ||
| if non_home['dist_from_home'].isna().all(): | ||
| return np.nan |
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.
Overly-defensive and fails silently. Dist from home should never be np.nan for any of the stops and, thus, we should just let it fail.
nomad/tests/test_metrics.py
Outdated
| '2024-01-01 02:30', | ||
| '2024-01-01 03:30' | ||
| ]), | ||
| 'activity_type': ['Work', 'Shopping', 'Restaurant'], |
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.
If none of the stops correspond to home_id, maybe raise a warning when the WHOLE stop table does not contain a home.
nomad/tests/test_metrics.py
Outdated
|
|
||
| # Should return NaN when there are no non-home activities | ||
| assert len(result) == 1 | ||
| assert pd.isna(result['self_containment'].values[0]) |
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.
Self containment is expected to be 1.0 not na
No description provided.