Locations
Locations is a catalogue of meaningful places. A catalogue is either
user-scoped, where a location ID is meaningful only for one user, or global,
where every user shares the same location IDs. This distinction makes OD and
collective analysis explicit.
Required data
Rows require location_id, center_lat, and center_lng. User-scoped catalogues
also carry a user-ID column; global catalogues must not. The scope and scheme
metadata describe identity and whether IDs came from clustering, H3, or an
external source.
locations, assigned = staypoints.generate_user_locations(epsilon_km=0.1)
labelled = locations.identify(assigned)
Global catalogues validate assignments used by models and collective measures; user catalogues can be labeled as home, work, or other.
API
fastmob.core.locations_dataframe.Locations
Bases: BaseDataFrame
One row per location in either a user or global scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame - like
|
Source data; any Narwhals-compatible eager backend. |
required |
uid_col
|
str
|
User-ID column name for user-scoped locations. Must be |
None
|
scope
|
('user', 'global')
|
Location identity scope. When omitted it is inferred from |
"user"
|
scheme
|
('cluster', 'h3', 'external')
|
Location-ID scheme. User locations default to |
"cluster"
|
location_id_col
|
str
|
Column name overrides. |
'location_id'
|
center_lat_col
|
str
|
Column name overrides. |
'location_id'
|
center_lng_col
|
str
|
Column name overrides. |
'location_id'
|
validate
|
bool
|
When True (default), check that required columns are present. |
True
|
from_tessellation(tessellation, *, tile_id_col='tile_id', lat_col=None, lng_col=None, geometry_col='geometry')
classmethod
Convert a legacy tessellation into a global location catalogue.
Numeric coordinates take precedence over geometry. When they are absent, point or polygon geometry is used solely to derive location centres; the original geometry column is retained as metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tessellation
|
DataFrame - like
|
Tile table with IDs and centres or geometries. |
required |
tile_id_col
|
str
|
Source column names. |
'tile_id'
|
lat_col
|
str
|
Source column names. |
'tile_id'
|
lng_col
|
str
|
Source column names. |
'tile_id'
|
geometry_col
|
str
|
Source column names. |
'tile_id'
|
Returns:
| Type | Description |
|---|---|
Locations
|
Global location catalogue. |
Examples:
identify(staypoints, method='freq', **kwargs)
Label each location as "home", "work", or "other".
See :func:fastmob.preprocessing.identify_locations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
staypoints
|
DataFrame - like or Staypoints
|
Location-assigned visits. |
required |
method
|
str
|
Purpose-identification method. Default is |
'freq'
|
**kwargs
|
Any
|
Forwarded to the identification function. |
{}
|
Returns:
| Type | Description |
|---|---|
Locations
|
User-scoped catalogue with purpose labels. |
Examples:
model_input()
require_global()
validate_staypoint_assignments(staypoints, *, user_id_col, location_id_col)
Validate non-null staypoint location identities against this catalogue.
The validation runs as backend-native distinct/anti joins instead of
materializing Python sets. Global catalogues match location_id;
user-scoped catalogues match (user_id, location_id).