@@ -324,7 +324,20 @@ def _create_dataframes(raw_extras, apply_offsets):
324
324
cols = ["time" , "end_time" , "block" ]
325
325
df_dict ["recording_blocks" ] = pd .DataFrame (blocks , columns = cols )
326
326
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
+
328
341
return df_dict
329
342
330
343
@@ -416,6 +429,10 @@ def _assign_col_names(col_names, df_dict):
416
429
elif key == "messages" :
417
430
cols = ["time" , "offset" , "event_msg" ]
418
431
df .columns = cols
432
+ #added for buttons
433
+ elif key == "buttons" :
434
+ cols = ["time" , "button_id" , "button_pressed" ]
435
+ df .columns = cols
419
436
return df_dict
420
437
421
438
@@ -677,7 +694,7 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
677
694
"pupil_right" ,
678
695
),
679
696
}
680
- valid_descs = ["blinks" , "saccades" , "fixations" , "messages" ]
697
+ valid_descs = ["blinks" , "saccades" , "fixations" , "buttons" , " messages" ]
681
698
msg = (
682
699
"create_annotations must be True or a list containing one or"
683
700
f" more of { valid_descs } ."
@@ -720,9 +737,17 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
720
737
descriptions = df ["event_msg" ]
721
738
this_annot = Annotations (
722
739
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
+ )
724
749
else :
725
- continue # TODO make df and annotations for Buttons
750
+ continue
726
751
if not annots :
727
752
annots = this_annot
728
753
elif annots :
0 commit comments