Skip to content

Commit 29936ba

Browse files
committed
prevents crashing on short trials
1 parent 8f14b8d commit 29936ba

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

visual_behavior/validation/extended_trials.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,24 @@ def count_stimuli_per_trial(trials, visual_stimuli):
168168
elif all(pd.isnull(visual_stimuli.orientation)) == False:
169169
col_to_check = 'orientation'
170170

171-
# get the index of the first stimulus that started on or before the trial start
172-
start_stim = visual_stimuli[
173-
(visual_stimuli.frame <= trial.startframe + 1) &
174-
(visual_stimuli.end_frame >= trial.startframe + 1)
175-
].index[-1]
176-
177-
# get the index of the last stimulus that ended on or before the trial end
178-
end_stim = visual_stimuli[
179-
(visual_stimuli.frame <= trial.endframe)
180-
].index[-1]
181-
182-
# get all unique stimuli on this trial
183-
stimuli = np.unique(visual_stimuli.loc[start_stim:end_stim][col_to_check])
184-
# add to array
185-
stimuli_per_trial[idx] = len(stimuli)
171+
try:
172+
# get the index of the first stimulus that started on or before the trial start
173+
start_stim = visual_stimuli[
174+
(visual_stimuli.frame <= trial.startframe + 1) &
175+
(visual_stimuli.end_frame >= trial.startframe + 1)
176+
].index[-1]
177+
178+
# get the index of the last stimulus that ended on or before the trial end
179+
end_stim = visual_stimuli[
180+
(visual_stimuli.frame <= trial.endframe)
181+
].index[-1]
182+
183+
# get all unique stimuli on this trial
184+
stimuli = np.unique(visual_stimuli.loc[start_stim:end_stim][col_to_check])
185+
# add to array
186+
stimuli_per_trial[idx] = len(stimuli)
187+
except IndexError:
188+
stimuli_per_trial[idx] = 0
186189
return stimuli_per_trial
187190

188191

0 commit comments

Comments
 (0)