From 438cc4c27024aba5b2d1a99971fcd36156ac8a34 Mon Sep 17 00:00:00 2001 From: vivekjax Date: Fri, 13 Feb 2026 20:07:03 -0500 Subject: [PATCH] Fix misleading _time_secs column name to _time_min The aggregated behavior time column was named `_time_secs` but the formula computes `proportion_of_behavior * bin_size * 5`, which yields a value in minutes (e.g. bin_size=4 produces a 20-minute window scaled by the proportion of time spent in the behavior). Rename to `_time_min` in both the Python and R implementations to accurately reflect the unit. Breaking change: downstream consumers of the output CSV that reference columns like `bin_sum_20.grooming_time_secs` must update to `bin_sum_20.grooming_time_min`. Co-authored-by: Cursor --- support_code/behavior_summaries.R | 2 +- support_code/behavior_summaries.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/support_code/behavior_summaries.R b/support_code/behavior_summaries.R index b33a450..6891d7f 100644 --- a/support_code/behavior_summaries.R +++ b/support_code/behavior_summaries.R @@ -29,7 +29,7 @@ data_agg <- lapply(seq_along(row_num), function(x) { tmp <- data |> group_by(MouseID) |> filter(row_number() <= row_num[x]) tmpsum <- rowsum(tmp[,sapply(tmp, is.numeric)], tmp$MouseID) - tmpsum <- tmpsum |> mutate(!!paste0("bin_avg_", row_num[x]*5, ".", behavior, "_time_secs") := get(paste0(behavior, "_time_behavior"))/(get(paste0(behavior, "_time_behavior")) + get(paste0(behavior, "_time_not_behavior")))*row_num[x]*5, !!paste0("bin_avg_", row_num[x]*5, ".", behavior, "_distance_cm") := get(paste0(behavior, "_behavior_dist"))/(row_num[x]*5)) + tmpsum <- tmpsum |> mutate(!!paste0("bin_avg_", row_num[x]*5, ".", behavior, "_time_min") := get(paste0(behavior, "_time_behavior"))/(get(paste0(behavior, "_time_behavior")) + get(paste0(behavior, "_time_not_behavior")))*row_num[x]*5, !!paste0("bin_avg_", row_num[x]*5, ".", behavior, "_distance_cm") := get(paste0(behavior, "_behavior_dist"))/(row_num[x]*5)) tmpsum$MouseID <- rownames(tmpsum) tmpsum <- tmpsum |> select(!all_of(cols_to_exclude)) diff --git a/support_code/behavior_summaries.py b/support_code/behavior_summaries.py index a24a26f..a178ddd 100644 --- a/support_code/behavior_summaries.py +++ b/support_code/behavior_summaries.py @@ -141,9 +141,9 @@ def aggregate_data_by_bin_size( behavior_dist_col = f"{behavior}_behavior_dist" behavior_bout_col = f"{behavior}_bout_behavior" - # Calculate time spent in behavior + # Calculate time spent in behavior (in minutes) # TODO: Do we need to make `5` a configurable parameter? - aggregated[f"bin_sum_{bin_size * 5}.{behavior}_time_secs"] = ( + aggregated[f"bin_sum_{bin_size * 5}.{behavior}_time_min"] = ( aggregated[time_behavior_col] / (aggregated[time_behavior_col] + aggregated[time_not_behavior_col]) * bin_size