Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Versions follow [Semantic Versioning](https://semver.org) (`<major>.<minor>.<pat

## Unreleased

### Fixed

- `process peri-event --event response` wrongly aligned windows to `start_time + response_time`, which falls before the cue since `response_time` is measured from the cue and every trial starts with the ITI. The lever push is now taken at `cue_onset + response_time` ([#176](https://github.com/DuguidLab/mesoscopy/issues/176)).

## [0.13.2] - 2026-09-23

### Added
Expand Down
5 changes: 3 additions & 2 deletions src/mesoscopy/process/perievent.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def event_times(trials: pd.DataFrame, event: str) -> tuple[npt.NDArray[np.float6
Args:
trials (pd.DataFrame): Trials table as written by `visiomode-analysis session`, with `start_time`,
`cue_onset`, `stop_time`, `response_time` and `sdt_type` columns. Times are seconds from
behaviour start.
behaviour start, except `response_time`, which is seconds from `cue_onset`.
event (str): One of `cue_onset`, `trial_start`, `response` or `reward`.

Returns:
Expand All @@ -80,8 +80,9 @@ def event_times(trials: pd.DataFrame, event: str) -> tuple[npt.NDArray[np.float6
elif event == "response":
import pandas as pd

# `response_time` is measured from the cue.
response_time = pd.to_numeric(trials["response_time"], errors="coerce").to_numpy(dtype=np.float64)
times = trials["start_time"].to_numpy(dtype=np.float64) + response_time
times = trials["cue_onset"].to_numpy(dtype=np.float64) + response_time
keep = ~np.isnan(response_time) & (response_time >= 0) & ~np.isnan(times)
elif event == "reward":
times = trials["stop_time"].to_numpy(dtype=np.float64)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ class TestEventTimes:
[
("cue_onset", [1.0, 5.5, 10.5, 15.5, 20.5, 40.5], [0, 1, 2, 3, 4, 5]),
("trial_start", [0.5, 5.0, 10.0, 15.0, 20.0, 40.0], [0, 1, 2, 3, 4, 5]),
("response", [1.2, 6.2, 20.8, 40.5], [0, 1, 4, 5]),
("response", [1.7, 6.7, 21.3, 41.0], [0, 1, 4, 5]),
("reward", [3.0, 8.0, 23.0, 41.5], [0, 1, 4, 5]),
],
)
Expand Down
Loading