Skip to content

ENH: Added button parsing in eyelink _utils.py #13253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions mne/io/eyelink/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,22 @@ def _create_dataframes(raw_extras, apply_offsets):
cols = ["time", "end_time", "block"]
df_dict["recording_blocks"] = pd.DataFrame(blocks, columns=cols)

# TODO: Make dataframes for other eyelink events (Buttons)
# make dataframes for other button events
if raw_extras["event_lines"]["BUTTON"]:
button_events = raw_extras["event_lines"]["BUTTON"]
parsed = []
for entry in button_events:
parsed.append(
{
"onset": float(entry[0]),
"button_id": int(entry[1]),
"button_pressed": int(entry[2]), # 1 = press, 0 = release
}
)
df_dict["buttons"] = pd.DataFrame(parsed)
else:
logger.info("No button events found in this file.")

return df_dict


Expand Down Expand Up @@ -416,6 +431,10 @@ def _assign_col_names(col_names, df_dict):
elif key == "messages":
cols = ["time", "offset", "event_msg"]
df.columns = cols
# added for buttons
elif key == "buttons":
cols = ["time", "button_id", "button_pressed"]
df.columns = cols
return df_dict


Expand Down Expand Up @@ -677,7 +696,7 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
"pupil_right",
),
}
valid_descs = ["blinks", "saccades", "fixations", "messages"]
valid_descs = ["blinks", "saccades", "fixations", "buttons", "messages"]
msg = (
"create_annotations must be True or a list containing one or"
f" more of {valid_descs}."
Expand Down Expand Up @@ -721,8 +740,18 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
this_annot = Annotations(
onset=onsets, duration=durations, description=descriptions
)
elif (key in ["buttons"]) and (key in descs):
onsets = df["time"]
durations = np.zeros_like(onsets)
descriptions = df.apply(
lambda row: f"button_{int(row['button_id'])}_{'press' if row['button_pressed'] == 1 else 'release'}",
axis=1,
)
this_annot = Annotations(
onset=onsets, duration=durations, description=descriptions
)
else:
continue # TODO make df and annotations for Buttons
continue
if not annots:
annots = this_annot
elif annots:
Expand Down
Loading