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.
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.
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.
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.
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.
Self containment is expected to be 1.0 not na
No description provided.