mobilkit.displacement module

Tools and functions to analyze the displacement based on pings rather than their localized tile IDs.

mobilkit.displacement.calc_displacement(df_usr_day, df_usr_home)

Given all the events of a (user,date) it computes the average and min distance from home, the closest point to home plus the original home location of the user on that day.

Parameters:

df_usr_day (dask.DataFrame) – A dataframe containing all the events as returned by mobilkit.temporal.filter_daynight_time.

df_usr_homepd.DataFrame or dask.DataFrame

A uid,homelat,homelon df containing the lat and lon of the user’s home to be joined with df_usr_day. Note that only events belonging to uid contained in this df will be considered.

Returns:

df – A df containing, for each uid,date couple observed:

  • mindist,avgdist the minimum and average distance from home recorded on that date

  • lat,lng coordinates of the closest point to home recorded on date

  • homelat,homelon the user’s home coordinates

  • rg,ttd the radius of gyration and the total traveled distance for a

    user on date.

Return type:

dask.DataFrame

mobilkit.displacement.process_user_day_displacement_pings(g)

Given all the events of a (user,date) it computes the average and min distance from home, the closest point to home plus the original home location of the user.

Parameters:

g (grouped df or pd.DataFrame) – A group of all the events of a user uid recorded in a day date or dataframe as returned by mobilkit.temporal.filter_daynight_time and joined with a uid,homelat,homelon df with at least the uid,date,homelat,homelon,lat,lng

Returns:

df – A one-row df containing the original uid,date,homelat,homelon columns plus the minimum and average distance from home mindist,avgdist recorded on that date plus the lat,lng coordinates of the closest point to home.

Return type:

pd.DataFrame

mobilkit.displacement.process_user_displacement_pings(g)

Given all the events of a user uid it computes the average and min distance from home, the closest point to home plus the original home location of the user for each date observed.

Parameters:

g (grouped df or pd.DataFrame) – A group of all the events of a user uid recorded in all the dates or dataframe as returned by mobilkit.temporal.filter_daynight_time and joined with a uid,homelat,homelon df with at least the uid,date,homelat,homelon,lat,lng

Returns:

df – A df containing the original uid,homelat,homelon columns plus the minimum and average distance from home mindist,avgdist recorded on that date plus the lat,lng coordinates of the closest point to home for each observed day.

Return type:

pd.DataFrame