Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions nomad/stop_detection/density_algs.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def ta_dbscan(
passthrough_cols=None,
keep_col_names=True,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -227,6 +228,8 @@ def ta_dbscan(
Include extra stats if True (default: False).
passthrough_cols : list, optional
Columns to retain per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
traj_cols : dict, optional
Mapping for column names.
**kwargs
Expand Down Expand Up @@ -279,6 +282,7 @@ def ta_dbscan(
complete_output=complete_output,
dur_min=dur_min,
passthrough_cols=passthrough_cols,
passthrough_agg=passthrough_agg,
keep_col_names=keep_col_names,
traj_cols=traj_cols,
**kwargs,
Expand All @@ -295,6 +299,7 @@ def ta_dbscan_per_user(
traj_cols=None,
n_jobs=1,
print_progress=False,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -320,6 +325,7 @@ def ta_dbscan_per_user(
"dur_min": dur_min,
"complete_output": complete_output,
"passthrough_cols": pt_cols,
"passthrough_agg": passthrough_agg,
"traj_cols": traj_cols,
**kwargs,
},
Expand Down Expand Up @@ -536,6 +542,7 @@ def dbstop(
passthrough_cols=None,
keep_col_names=True,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -557,6 +564,8 @@ def dbstop(
Include extra stats if True (default: False).
passthrough_cols : list, optional
Columns to retain per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
traj_cols : dict, optional
Mapping for column names.
**kwargs
Expand Down Expand Up @@ -609,6 +618,7 @@ def dbstop(
complete_output=complete_output,
dur_min=dur_min,
passthrough_cols=passthrough_cols,
passthrough_agg=passthrough_agg,
keep_col_names=keep_col_names,
traj_cols=traj_cols,
**kwargs,
Expand All @@ -626,6 +636,7 @@ def dbstop_per_user(
traj_cols=None,
n_jobs=1,
print_progress=False,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -651,6 +662,7 @@ def dbstop_per_user(
"dur_min": dur_min,
"complete_output": complete_output,
"passthrough_cols": pt_cols,
"passthrough_agg": passthrough_agg,
"keep_col_names": keep_col_names,
"traj_cols": traj_cols,
**kwargs,
Expand Down Expand Up @@ -967,6 +979,7 @@ def seqscan(
passthrough_cols=None,
keep_col_names=True,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -988,6 +1001,8 @@ def seqscan(
Include extra stats if True (default: False).
passthrough_cols : list, optional
Columns to retain per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
traj_cols : dict, optional
Mapping for column names.
**kwargs
Expand Down Expand Up @@ -1039,6 +1054,7 @@ def seqscan(
labels,
complete_output=complete_output,
passthrough_cols=passthrough_cols,
passthrough_agg=passthrough_agg,
keep_col_names=keep_col_names,
traj_cols=traj_cols,
**kwargs,
Expand All @@ -1057,6 +1073,7 @@ def seqscan_per_user(
traj_cols=None,
n_jobs=1,
print_progress=False,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -1082,6 +1099,7 @@ def seqscan_per_user(
"dur_min": dur_min,
"complete_output": complete_output,
"passthrough_cols": pt_cols,
"passthrough_agg": passthrough_agg,
"keep_col_names": keep_col_names,
"traj_cols": traj_cols,
**kwargs,
Expand Down Expand Up @@ -1932,6 +1950,7 @@ def st_hdbscan(
complete_output=False,
passthrough_cols=None,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -1953,6 +1972,8 @@ def st_hdbscan(
If True, include extra stats.
passthrough_cols : list, optional
Columns to passthrough to final stop table
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
traj_cols : dict, optional
Mapping for key columns.
**kwargs
Expand Down Expand Up @@ -1989,6 +2010,7 @@ def st_hdbscan(
labels,
complete_output=complete_output,
passthrough_cols=passthrough_cols,
passthrough_agg=passthrough_agg,
keep_col_names=True,
traj_cols=traj_cols,
**kwargs,
Expand All @@ -2005,6 +2027,7 @@ def st_hdbscan_per_user(
traj_cols=None,
n_jobs=1,
print_progress=False,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -2031,6 +2054,7 @@ def st_hdbscan_per_user(
"dur_min": dur_min,
"complete_output": complete_output,
"passthrough_cols": pt_cols,
"passthrough_agg": passthrough_agg,
"traj_cols": traj_cols,
**kwargs,
},
Expand Down
24 changes: 24 additions & 0 deletions nomad/stop_detection/sequential_algs.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def detect_stops(
passthrough_cols=None,
keep_col_names=True,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -152,6 +153,8 @@ def detect_stops(
If True, include additional summary statistics in output.
passthrough_cols : list, optional
Columns to retain (and summarize/propagate) per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
keep_col_names : bool, default True
Whether to keep original column names in output.
traj_cols : dict, optional
Expand Down Expand Up @@ -193,6 +196,7 @@ def detect_stops(
labels,
complete_output=complete_output,
passthrough_cols=passthrough_cols,
passthrough_agg=passthrough_agg,
keep_col_names=keep_col_names,
traj_cols=traj_cols,
**kwargs,
Expand All @@ -211,6 +215,7 @@ def detect_stops_per_user(
traj_cols=None,
n_jobs=1,
print_progress=False,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -232,6 +237,8 @@ def detect_stops_per_user(
If True, include additional summary statistics in output.
passthrough_cols : list, optional
Columns to retain (and summarize/propagate) per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
keep_col_names : bool, default True
Whether to keep original column names in output.
traj_cols : dict, optional
Expand Down Expand Up @@ -271,6 +278,7 @@ def detect_stops_per_user(
"method": method,
"complete_output": complete_output,
"passthrough_cols": pt_cols,
"passthrough_agg": passthrough_agg,
"keep_col_names": keep_col_names,
"traj_cols": traj_cols,
**kwargs,
Expand Down Expand Up @@ -497,6 +505,7 @@ def lachesis(
postprocessing=None,
eps=None,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -518,6 +527,8 @@ def lachesis(
Passed along to the column‐detection helper.
passthrough_cols : list, optional
Columns to retain (and summarize/propagate) per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
postprocessing : {None, 'dbscan'}, optional
Optional stop postprocessing method.
eps : float, optional
Expand Down Expand Up @@ -559,6 +570,7 @@ def lachesis(
labels,
complete_output=complete_output,
passthrough_cols=passthrough_cols,
passthrough_agg=passthrough_agg,
keep_col_names=keep_col_names,
traj_cols=traj_cols,
**kwargs,
Expand All @@ -577,6 +589,7 @@ def lachesis_per_user(
traj_cols=None,
n_jobs=1,
print_progress=False,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -596,6 +609,8 @@ def lachesis_per_user(
If True, include additional summary statistics in output.
passthrough_cols : list, optional
Columns to retain (and summarize/propagate) per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
postprocessing : {None, 'dbscan'}, optional
Optional stop postprocessing method applied separately to each user.
eps : float, optional
Expand Down Expand Up @@ -639,6 +654,7 @@ def lachesis_per_user(
"dur_min": dur_min,
"complete_output": complete_output,
"passthrough_cols": pt_cols,
"passthrough_agg": passthrough_agg,
"postprocessing": postprocessing,
"eps": eps,
"traj_cols": traj_cols,
Expand Down Expand Up @@ -784,6 +800,7 @@ def grid_based(
complete_output=False,
passthrough_cols=None,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -801,6 +818,10 @@ def grid_based(
Minimum duration in minutes for a valid stop. Default is 5.
complete_output : bool, optional
If True, include additional stop statistics in the output.
passthrough_cols : list, optional
Columns to retain per stop.
passthrough_agg : dict, optional
Aggregation functions for selected passthrough columns.
traj_cols : dict, optional
Mapping for 'timestamp', 'datetime', or 'location_id' column names.
**kwargs
Expand Down Expand Up @@ -844,6 +865,7 @@ def grid_based(
traj_cols=traj_cols,
keep_col_names=True,
passthrough_cols=passthrough_cols,
passthrough_agg=passthrough_agg,
**kwargs
),
include_groups=False
Expand All @@ -864,6 +886,7 @@ def grid_based_per_user(
traj_cols=None,
n_jobs=1,
print_progress=False,
passthrough_agg=None,
**kwargs
):
"""
Expand Down Expand Up @@ -892,6 +915,7 @@ def grid_based_per_user(
"dur_min": dur_min,
"complete_output": complete_output,
"passthrough_cols": pt_cols,
"passthrough_agg": passthrough_agg,
"traj_cols": traj_cols,
**kwargs,
},
Expand Down
12 changes: 11 additions & 1 deletion nomad/stop_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def summarize_stop_grid(
keep_col_names=True,
passthrough_cols=None,
traj_cols=None,
passthrough_agg=None,
**kwargs
):
"""
Expand All @@ -418,6 +419,9 @@ def summarize_stop_grid(
if True, they use the user's time‐column name.
passthrough_cols : list[str], optional
Additional columns (e.g. 'user_id') to carry through.
passthrough_agg : dict, optional
Pandas-compatible aggregation function for each passthrough column that
should not use its first value.
traj_cols : dict, optional
Column‐name overrides.

Expand All @@ -432,6 +436,8 @@ def summarize_stop_grid(
"""
if passthrough_cols is None:
passthrough_cols = []
if passthrough_agg is None:
passthrough_agg = {}

# 1) pick time key
t_key, use_datetime = loader._fallback_time_cols_dt(grouped_data.columns, traj_cols, kwargs)
Expand Down Expand Up @@ -486,7 +492,11 @@ def summarize_stop_grid(

for c in to_pass:
if c in grouped_data.columns:
out[c] = grouped_data[c].iloc[0]
out[c] = (
grouped_data[c].agg(passthrough_agg[c])
if c in passthrough_agg
else grouped_data[c].iloc[0]
)

return pd.Series(out, dtype='object')

Expand Down
Loading