Skip to content

Conversation

@carolineychen8
Copy link
Contributor

No description provided.

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,
Copy link
Collaborator

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.

non_home = g[g[activity_type_col] != home_activity_type]

if len(non_home) == 0:
return np.nan # No non-home activities
Copy link
Collaborator

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


# Check if all distances are NaN (no home location found)
if non_home['dist_from_home'].isna().all():
return np.nan
Copy link
Collaborator

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.

'2024-01-01 02:30',
'2024-01-01 03:30'
]),
'activity_type': ['Work', 'Shopping', 'Restaurant'],
Copy link
Collaborator

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.


# Should return NaN when there are no non-home activities
assert len(result) == 1
assert pd.isna(result['self_containment'].values[0])
Copy link
Collaborator

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

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.

3 participants