Skip to content

Commit ae815f9

Browse files
committed
feat: add phase offset times to trial phases for convenience
1 parent 16de70f commit ae815f9

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ data/
143143

144144
### scan_log CSV
145145

146-
One row per trial phase: `trial_n`, `phase`, `tr_n`, `phase_global_time`, `phase_trial_time`, `pulse_ct`.
146+
One row per trial phase: `trial_n`, `phase`, `tr_n`, `phase_onset_global_time`, `phase_offset_global_time`, `phase_onset_trial_time`, `phase_offset_trial_time`, `pulse_ct`. The `*_offset_*` (phase end) columns are tiled: a phase's end equals the next phase's onset, and the final phase of a trial ends at the trial end.
147147

148148
## Quitting Early
149149

src/mid_det/recorder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class ScanPhase:
128128
phase_onset_global_time: float
129129
phase_onset_trial_time: float
130130
pulse_ct: int
131+
phase_offset_global_time: float = 0.0
132+
phase_offset_trial_time: float = 0.0
131133

132134

133135
BEHAVIORAL_COLUMNS: list[str] = [
@@ -148,7 +150,10 @@ class ScanPhase:
148150
]
149151

150152
SCAN_LOG_COLUMNS: list[str] = [
151-
"trial_n", "phase", "tr_n", "phase_onset_global_time", "phase_onset_trial_time", "pulse_ct",
153+
"trial_n", "phase", "tr_n",
154+
"phase_onset_global_time", "phase_offset_global_time",
155+
"phase_onset_trial_time", "phase_offset_trial_time",
156+
"pulse_ct",
152157
]
153158

154159

src/mid_det/trial.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,17 @@ def _update_overlay(phase: str) -> None:
466466
time_trial_end = global_clock.getTime()
467467
time_sched_end = nominal_time
468468

469+
# Backfill each phase's end = onset of the next phase (tiled timeline);
470+
# the final phase ends at the trial end.
471+
for i, sp in enumerate(scan_phases):
472+
end_global = (
473+
scan_phases[i + 1].phase_onset_global_time
474+
if i + 1 < len(scan_phases)
475+
else time_trial_end
476+
)
477+
sp.phase_offset_global_time = end_global
478+
sp.phase_offset_trial_time = end_global - time_onset
479+
469480
record = TrialRecord(
470481
trial_n=trial_n,
471482
trial_type=trial_type,

0 commit comments

Comments
 (0)