Skip to content

Commit 9ded82d

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5b9e385 commit 9ded82d

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

mne/io/eyelink/_utils.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,21 @@ def _create_dataframes(raw_extras, apply_offsets):
325325
df_dict["recording_blocks"] = pd.DataFrame(blocks, columns=cols)
326326

327327
# make dataframes for other button events
328-
if raw_extras["event_lines"]["BUTTON"]:
328+
if raw_extras["event_lines"]["BUTTON"]:
329329
button_events = raw_extras["event_lines"]["BUTTON"]
330330
parsed = []
331331
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-
})
332+
parsed.append(
333+
{
334+
"onset": float(entry[0]),
335+
"button_id": int(entry[1]),
336+
"button_pressed": int(entry[2]), # 1 = press, 0 = release
337+
}
338+
)
337339
df_dict["buttons"] = pd.DataFrame(parsed)
338340
else:
339341
logger.info("No button events found in this file.")
340-
342+
341343
return df_dict
342344

343345

@@ -429,7 +431,7 @@ def _assign_col_names(col_names, df_dict):
429431
elif key == "messages":
430432
cols = ["time", "offset", "event_msg"]
431433
df.columns = cols
432-
#added for buttons
434+
# added for buttons
433435
elif key == "buttons":
434436
cols = ["time", "button_id", "button_pressed"]
435437
df.columns = cols
@@ -694,7 +696,7 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
694696
"pupil_right",
695697
),
696698
}
697-
valid_descs = ["blinks", "saccades", "fixations", "buttons", "messages" ]
699+
valid_descs = ["blinks", "saccades", "fixations", "buttons", "messages"]
698700
msg = (
699701
"create_annotations must be True or a list containing one or"
700702
f" more of {valid_descs}."
@@ -737,17 +739,19 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
737739
descriptions = df["event_msg"]
738740
this_annot = Annotations(
739741
onset=onsets, duration=durations, description=descriptions
740-
)
741-
elif (key in ["buttons"]) and (key in descs):
742+
)
743+
elif (key in ["buttons"]) and (key in descs):
742744
onsets = df["time"]
743745
durations = np.zeros_like(onsets)
744746
descriptions = df.apply(
745-
lambda row: f"button_{int(row['button_id'])}_{'press' if row['button_pressed'] == 1 else 'release'}", axis=1)
747+
lambda row: f"button_{int(row['button_id'])}_{'press' if row['button_pressed'] == 1 else 'release'}",
748+
axis=1,
749+
)
746750
this_annot = Annotations(
747-
onset=onsets, duration= durations, description=descriptions
748-
)
751+
onset=onsets, duration=durations, description=descriptions
752+
)
749753
else:
750-
continue
754+
continue
751755
if not annots:
752756
annots = this_annot
753757
elif annots:

mne/io/eyelink/tests/test_eyelink.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _simulate_eye_tracking_data(in_file, out_file):
201201
"SAMPLES\tPUPIL\tLEFT\tVEL\tRES\tHTARGET\tRATE\t1000.00"
202202
"\tTRACKING\tCR\tFILTER\t2\tINPUT"
203203
)
204-
204+
205205
# Define your known BUTTON events
206206
button_events = [
207207
(5488529, 1, 0),
@@ -213,7 +213,7 @@ def _simulate_eye_tracking_data(in_file, out_file):
213213
(5488571, 1, 0),
214214
]
215215
button_idx = 0
216-
216+
217217
with out_file.open("w") as fp:
218218
in_recording_block = False
219219
events = []
@@ -244,7 +244,7 @@ def _simulate_eye_tracking_data(in_file, out_file):
244244
tokens[3] = "1" # simulate button pressed
245245
tokens[4:4] = ["100", "20", "45", "45", "127.0"]
246246
tokens.extend(["1497.0", "5189.0", "512.5", "............."])
247-
247+
248248
continue
249249
elif event_type == "END":
250250
pass
@@ -267,15 +267,18 @@ def _simulate_eye_tracking_data(in_file, out_file):
267267
f"{timestamp}\t-2434.0\t-1760.0\t840.0\t100\t20\t45\t45\t127.0\t"
268268
"...\t1497\t5189\t512.5\t.............\n"
269269
)
270-
270+
271271
for timestamp in np.arange(5488500, 5488600): # 100 samples
272272
# Write sample line
273273
fp.write(
274274
f"{timestamp}\t-2434.0\t-1760.0\t840.0\t100\t20\t45\t45\t127.0\t"
275275
"...\t1497\t5189\t512.5\t.............\n"
276276
)
277277
# Check and insert button events at this timestamp
278-
while button_idx < len(button_events) and button_events[button_idx][0] == timestamp:
278+
while (
279+
button_idx < len(button_events)
280+
and button_events[button_idx][0] == timestamp
281+
):
279282
t, btn_id, state = button_events[button_idx]
280283
fp.write(f"BUTTON\t{t}\t{btn_id}\t{state}\n")
281284
button_idx += 1

0 commit comments

Comments
 (0)