Data
| API | Description | Example |
|---|---|---|
list_datasets |
List datasets. | Which datasets does the library list? |
load_dataset |
Load dataset. | |
get_dataset_info |
Get dataset info. | Which datasets does the library list? |
load_geolife |
Load GPS trajectories of selected GeoLife users, downloading only what is needed. | Load the data |
load_brightkite |
Load Brightkite location check-ins, downloading only the rows requested. | Load and clean |
DatasetBuilder |
Base class for dataset-specific builders. | |
DatasetBuilder.prepare |
Turn the downloaded files (a list of paths) into the dataset object; implemented by each dataset builder. |
Datasets
| Name | Type | Description |
|---|---|---|
foursquare_nyc |
trajectory | Foursquare checkins of individuals in New York City. |
flow_foursquare_nyc |
flow | Movements between 4 km tiles in NYC derived from Foursquare data. |
taxi_san_francisco |
trajectory | GPS traces of ~500 taxis over 30 days in the San Francisco Bay Area. Requires auth. |
parking_san_francisco |
auxiliar | Parking meters in San Francisco. |
nyc_boundaries |
shape | NYC Borough Boundaries shapefile (water areas included). |
API Reference
list_datasets(details=False, data_types=None)
List datasets.
List all the names of the datasets available in the data module of scikit-mobility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
details
|
bool
|
Whether to return full metadata for each dataset instead of the name only.
The default is |
False
|
data_types
|
str or list of str
|
Specify which dataset types to show. Accepted values: |
None
|
Returns:
| Type | Description |
|---|---|
list of str or dict
|
A list of dataset names, or a dict mapping name to metadata when |
Examples:
Worked example: Which datasets does the library list?
load_dataset(name, drop_columns=False, auth=None, show_progress=False)
Load dataset.
Load one of the datasets that are present in the repository of scikit-mobility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the dataset to load (e.g., |
required |
drop_columns
|
bool
|
Whether to keep additional columns when returning a TrajDataFrame. The default is |
False
|
auth
|
tuple of str
|
Pair of strings |
None
|
show_progress
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
TrajDataFrame or FlowDataFrame or GeoDataFrame or DataFrame
|
An object containing the downloaded dataset. |
Examples:
>>> from fastmob.data import load_dataset, list_datasets
>>> tdf_nyc = load_dataset("foursquare_nyc", drop_columns=True)
>>> print(tdf_nyc.head())
uid lat lng datetime
0 470 40.719810 -74.002581 2012-04-03 18:00:09+00:00
1 979 40.606800 -74.044170 2012-04-03 18:00:25+00:00
2 69 40.716162 -73.883070 2012-04-03 18:02:24+00:00
3 395 40.745164 -73.982519 2012-04-03 18:02:41+00:00
4 87 40.740104 -73.989658 2012-04-03 18:03:00+00:00
get_dataset_info(name)
Get dataset info.
Return the metadata stored in the JSON file associated with the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the dataset to query (e.g., |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the dataset metadata. |
Examples:
>>> from fastmob.data import get_dataset_info
>>> get_dataset_info("foursquare_nyc")
{'name': 'Foursquare_NYC',
'description': 'Dataset containing the Foursquare checkins of individuals moving in New York City',
'url': 'http://www-public.it-sudparis.eu/~zhang_da/pub/dataset_tsmc2014.zip',
'hash': 'cbe3fdab373d24b09b5fc53509c8958c77ff72b6c1a68589ce337d4f9a80235b',
'auth': 'no',
'data_type': 'trajectory',
'download_format': 'zip',
'sep': '\t',
'encoding': 'ISO-8859-1'}
Worked example: Which datasets does the library list?
load_geolife(users=('000', '001', '002'), max_trips_per_user=25, cache=None)
Load GPS trajectories of selected GeoLife users, downloading only what is needed.
GeoLife is a public GPS dataset collected by Microsoft Research Asia (182 users,
about 25 million fixes, mostly in Beijing, sampled every 1 to 5 seconds). The full
archive is about 313 MB; this loader reads the requested users' .plt files straight
from the archive with HTTP range requests, so a few users cost a few megabytes.
Files are cached per combination of arguments, so repeated calls with the same arguments do not download again and a call never returns files cached for a different selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
users
|
iterable of str or int
|
GeoLife user ids (three-digit codes such as |
('000', '001', '002')
|
max_trips_per_user
|
int
|
Keep only each user's first N trip files, in file-name order. |
25
|
cache
|
str or path
|
Directory to cache downloads in. The default is a |
None
|
Returns:
| Type | Description |
|---|---|
TrajDataFrame
|
Columns |
Raises:
| Type | Description |
|---|---|
OSError
|
If the archive cannot be downloaded or does not support partial downloads. No substitute data is generated. |
Examples:
Worked example: Load the data
load_brightkite(max_rows=300000, cache=None)
Load Brightkite location check-ins, downloading only the rows requested.
Brightkite (Stanford SNAP) holds about 4.7 million check-ins by 58 thousand users of
a location-based social network, 2008 to 2010, worldwide. The compressed file is about
60 MB; the file is streamed and the download stops after max_rows rows, so the
default 300,000 rows cost about 4 MB. Rows without coordinates are dropped. The first
rows are not a random sample of users: they hold the earliest user ids' complete
histories only up to the cut-off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_rows
|
int
|
Number of raw rows to read before dropping rows without coordinates. |
300000
|
cache
|
str or path
|
Directory to cache the rows in. The default is a |
None
|
Returns:
| Type | Description |
|---|---|
TrajDataFrame
|
Columns |
Raises:
| Type | Description |
|---|---|
OSError
|
If the file cannot be downloaded. No substitute data is generated. |
Examples:
Worked example: Load and clean
DatasetBuilder
Bases: ABC
Base class for dataset-specific builders.
prepare(full_path_files)
abstractmethod
Turn the downloaded files (a list of paths) into the dataset object; implemented by each dataset builder.