mobilipy.privacy

Functions

add_noise(point[, radius, offset])

Adds random uniform noise to the given point, in a radius = radius - offset

aggregate(waypoints_df[, cell_size, delta])

Aggregates users in timedeltas and cells on the map.

assign_cell_center(latitude, longitude, ...)

Returns the closest cell center for the given coordinates, when the map is divided into a lattice with the supplied cell_size

dt_floor(dt, delta)

Performs the floor operation on datetime values, with given timedelta as the base, e.g.

get_obfuscation_utility(w_prepared, ...)

Calculates the ratio of legs affected by obfuscation to total legs

km_to_lat(km_north)

Expresses latitude given in kilometers to the east in degrees

km_to_lon(km_east, latitude)

Expresses given kilometers to the east in longitude degrees.

lat_to_km(latitude)

Expresses given latitude in kilometers to the north

lon_to_km(latitude, longitude)

Expresses given longitude in kilometers to the east

obfuscate(df, locations[, radius, offset, mode])

Obfuscates the regions of points given in 'locations' parameter by either removing all the points in their proximity, or changing the location of these points to one, noisy location in the proximity circle.

shift_point(point, latitude_shift_km, ...)

Shifts the coordinates of a given point.

mobilipy.privacy.add_noise(point, radius=100, offset=30)

Adds random uniform noise to the given point, in a radius = radius - offset

Parameters
  • point (tuple) – Points as a tuple (latitude, longitude) in degrees.

  • radius (int, optional) – Radius of the point neighbourhood. Defaults to 100.

  • offset (int, optional) – Offset from the perimeter of the neighbourhood circle, where the shifted point can’t be located. Defaults to 30.

Returns

tuple – Shifted point expressed as (latitude, longitude)

mobilipy.privacy.aggregate(waypoints_df, cell_size=0.2, delta=datetime.timedelta(seconds=900)) pandas.core.frame.DataFrame

Aggregates users in timedeltas and cells on the map. Returns a DataFrame with the count of users in a given timedelta and cell.

Parameters
  • waypoints_df (pandas.DataFrame) – DataFrame with ‘latitude’, ‘longitude’, ‘user_id’ and ‘tracked_at’ columns.

  • cell_size (float) – Size of the square cells on the map, in kilometers.

  • delta (datetime.timedelta) – Frequency for the time aggregation, e.g. 15 minutes.

Returns

pandas.DataFrame – DataFrame with ‘tracked_at’, ‘cell_latitude’, ‘cell_longitude’ and ‘count’ columns. The ‘cell_latitude’ and ‘cell_longitude’ columns give coordinates of the centers of cells on the map.

mobilipy.privacy.assign_cell_center(latitude, longitude, cell_size)

Returns the closest cell center for the given coordinates, when the map is divided into a lattice with the supplied cell_size

Parameters
  • latitude (float) – Latitude as degrees

  • longitude (float) – Longitude as degrees

  • cell_size (float) – Cell size in kilometers

Returns

tuple(float, float) – Coordinates of the closest cell center on the map

mobilipy.privacy.dt_floor(dt, delta) datetime.datetime

Performs the floor operation on datetime values, with given timedelta as the base, e.g. 2021-01-01 12:21:47 with timedelta of 15s returns 2021-01-01 12:21:45.

Parameters
  • dt (datetime.datetime) – Datetime value to be floored.

  • delta (datetime.timedelta) – Timedelta used for the floor operation.

Returns

datetime.datetime – Floored datetime.

mobilipy.privacy.get_obfuscation_utility(w_prepared, w_obfuscated, legs) float

Calculates the ratio of legs affected by obfuscation to total legs

Parameters
  • w_prepared (pandas.DataFrame) – Smoothed and cleaned waypoints DataFrame

  • w_obfuscated (pandas.DataFrame) – Smoothed, cleaned, and obfuscated waypoints DataFrame

  • legs (pandas.DataFrame) – DataFrame that contains assembled legs

Returns

[float] – Ratio of legs affected by obfuscation to total legs

mobilipy.privacy.km_to_lat(km_north) float

Expresses latitude given in kilometers to the east in degrees

Parameters

km_north (float) – Latitude expressed in kilometers to the north

Returns

float – Latitude in degrees

mobilipy.privacy.km_to_lon(km_east, latitude) float

Expresses given kilometers to the east in longitude degrees.

Parameters
  • km_east (float) – Longitude expressed in km going east from longitude 0, at the given latitude

  • latitude (float) – Latitude in degrees

Returns

float – Longitude in degrees

mobilipy.privacy.lat_to_km(latitude) float

Expresses given latitude in kilometers to the north

Parameters

latitude (float) – Latitude in degrees.

Returns

float – Latitude expressed in kilometers to the north

mobilipy.privacy.lon_to_km(latitude, longitude) float

Expresses given longitude in kilometers to the east

Parameters
  • latitude (float) – Latitude expressed in degrees

  • longitude (float) – Longitude expressed in degrees

Returns

float – Longitude as kilometers to the east

mobilipy.privacy.obfuscate(df, locations, radius=100, offset=30, mode='remove') pandas.core.frame.DataFrame

Obfuscates the regions of points given in ‘locations’ parameter by either removing all the points in their proximity, or changing the location of these points to one, noisy location in the proximity circle.

Parameters
  • df (pandas.DataFrame) – DataFrame with ‘latitude’ and ‘longitude’ columns.

  • locations (list) – List of locations given as (latitude, longitude) tuples

  • radius (int, optional) – Radius of the obfuscation circle. Defaults to 100.

  • offset (int, optional) – Smallest distance from the perimeter of the obfuscation circle at which the location of interest must be located. Defaults to 30.

  • mode (str, optional) – Obfuscation mode, can be either ‘remove’ or ‘assign’. Defaults to ‘remove’.

Returns

pandas.DataFrame – DataFrame with obfuscated regions

mobilipy.privacy.shift_point(point, latitude_shift_km, longitude_shift_km)

Shifts the coordinates of a given point.

Parameters
  • point (tuple) – Starting point as (latitude, longitude), in degrees

  • latitude_shift_km (float) – Latitude offset in kilometers

  • longitude_shift_km (float) – Longitude offset in kilometers

Returns

tuple – Shifted point expressed as (latitude, longitude)