Skip to content

Commit bf5b980

Browse files
author
Wouter Kroot
committed
Added button event parsing in _utils.py
1 parent dda454d commit bf5b980

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

mne/io/eyelink/_utils.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,20 @@ def _create_dataframes(raw_extras, apply_offsets):
324324
cols = ["time", "end_time", "block"]
325325
df_dict["recording_blocks"] = pd.DataFrame(blocks, columns=cols)
326326

327-
# TODO: Make dataframes for other eyelink events (Buttons)
327+
# make dataframes for other button events
328+
if raw_extras["event_lines"]["BUTTON"]:
329+
button_events = raw_extras["event_lines"]["BUTTON"]
330+
parsed = []
331+
for entry in button_events:
332+
parsed.append({
333+
"onset": float(entry[0]),
334+
"button_id": int(entry[1]),
335+
"button_pressed": int(entry[2]) # 1 = press, 0 = release
336+
})
337+
df_dict["buttons"] = pd.DataFrame(parsed)
338+
else:
339+
logger.info("No button events found in this file.")
340+
328341
return df_dict
329342

330343

@@ -416,6 +429,10 @@ def _assign_col_names(col_names, df_dict):
416429
elif key == "messages":
417430
cols = ["time", "offset", "event_msg"]
418431
df.columns = cols
432+
#added for buttons
433+
elif key == "buttons":
434+
cols = ["time", "button_id", "button_pressed"]
435+
df.columns = cols
419436
return df_dict
420437

421438

@@ -677,7 +694,7 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
677694
"pupil_right",
678695
),
679696
}
680-
valid_descs = ["blinks", "saccades", "fixations", "messages"]
697+
valid_descs = ["blinks", "saccades", "fixations", "buttons", "messages" ]
681698
msg = (
682699
"create_annotations must be True or a list containing one or"
683700
f" more of {valid_descs}."
@@ -720,9 +737,17 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
720737
descriptions = df["event_msg"]
721738
this_annot = Annotations(
722739
onset=onsets, duration=durations, description=descriptions
723-
)
740+
)
741+
elif (key in ["buttons"]) and (key in descs):
742+
onsets = df["time"]
743+
durations = np.zeros_like(onsets)
744+
descriptions = df.apply(
745+
lambda row: f"button_{int(row['button_id'])}_{'press' if row['button_pressed'] == 1 else 'release'}", axis=1)
746+
this_annot = Annotations(
747+
onset=onsets, duration= durations, description=descriptions
748+
)
724749
else:
725-
continue # TODO make df and annotations for Buttons
750+
continue
726751
if not annots:
727752
annots = this_annot
728753
elif annots:

0 commit comments

Comments
 (0)