Skip to content

Commit b3c0c54

Browse files
committed
use timing info of spacer to filter out erroneously detected spacers
1 parent f7a5a74 commit b3c0c54

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ibllib/io/extractors/ephys_passive.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,19 @@ def _get_spacer_times(spacer_template, jitter, ttl_signal, t_quiet):
125125
# adjust indices for
126126
# - `np.where` call above
127127
# - length of spacer_model
128-
idxs_spacer_middle += 2 - int((np.floor(len(spacer_model) / 2)))
128+
spacer_around = int((np.floor(len(spacer_model) / 2)))
129+
idxs_spacer_middle += 2 - spacer_around
130+
131+
# for each spacer make sure the times are monotonically increasing before
132+
# and monotonically decreasing afterwards
133+
is_valid = np.zeros((idxs_spacer_middle.size), dtype=bool)
134+
for i, t in enumerate(idxs_spacer_middle):
135+
before = all(np.diff(dttl[t - spacer_around:t]) > 0)
136+
after = all(np.diff(dttl[t + 1:t + 1 + spacer_around]) < 0)
137+
is_valid[i] = np.bitwise_and(before, after)
138+
139+
idxs_spacer_middle = idxs_spacer_middle[is_valid]
140+
129141
# pull out spacer times (middle)
130142
ts_spacer_middle = ttl_signal[idxs_spacer_middle]
131143
# put beginning/end of spacer times into an array

0 commit comments

Comments
 (0)