|
38 | 38 | "sacc_visual_angle",
|
39 | 39 | "peak_velocity",
|
40 | 40 | ),
|
| 41 | + "messages": ("time", "offset", "event_msg"), |
41 | 42 | }
|
42 | 43 |
|
43 | 44 |
|
@@ -373,6 +374,7 @@ def _infer_col_names(raw_extras):
|
373 | 374 | col_names = {}
|
374 | 375 | # initiate the column names for the sample lines
|
375 | 376 | col_names["samples"] = list(EYELINK_COLS["timestamp"])
|
| 377 | + col_names["messages"] = list(EYELINK_COLS["messages"]) |
376 | 378 |
|
377 | 379 | # and for the eye message lines
|
378 | 380 | col_names["blinks"] = list(EYELINK_COLS["eye_event"])
|
@@ -427,16 +429,33 @@ def _assign_col_names(col_names, df_dict):
|
427 | 429 | col_names : dict
|
428 | 430 | Dictionary of column names for each dataframe.
|
429 | 431 | """
|
| 432 | + skipped_types = [] |
430 | 433 | for key, df in df_dict.items():
|
431 |
| - if key in ("samples", "blinks", "fixations", "saccades"): |
432 |
| - df.columns = col_names[key] |
433 |
| - elif key == "messages": |
434 |
| - cols = ["time", "offset", "event_msg"] |
435 |
| - df.columns = cols |
436 |
| - # added for buttons |
437 |
| - elif key == "buttons": |
438 |
| - cols = ["time", "button_id", "button_pressed"] |
439 |
| - df.columns = cols |
| 434 | + if key in ("samples", "blinks", "fixations", "saccades", "messages"): |
| 435 | + cols = col_names[key] |
| 436 | + else: |
| 437 | + skipped_types.append(key) |
| 438 | + continue |
| 439 | + max_cols = len(cols) |
| 440 | + if len(df.columns) != len(cols): |
| 441 | + if key in ("saccades", "fixations") and len(df.columns) >= 4: |
| 442 | + # see https://github.com/mne-tools/mne-python/pull/13357 |
| 443 | + logger.debug( |
| 444 | + f"{key} events have more columns ({len(df.columns)}) than " |
| 445 | + f"expected ({len(cols)}). Using first 4 (eye, time, end_time, " |
| 446 | + "duration)." |
| 447 | + ) |
| 448 | + max_cols = 4 |
| 449 | + else: |
| 450 | + raise ValueError( |
| 451 | + f"Expected the {key} data in this file to have {len(cols)} columns " |
| 452 | + f"of data, but got {len(df.columns)}. Expected columns: {cols}." |
| 453 | + ) |
| 454 | + new_col_names = { |
| 455 | + old: new for old, new in zip(df.columns[:max_cols], cols[:max_cols]) |
| 456 | + } |
| 457 | + df.rename(columns=new_col_names, inplace=True) |
| 458 | + logger.debug(f"Skipped assigning column names to {skipped_types} dataframes.") |
440 | 459 | return df_dict
|
441 | 460 |
|
442 | 461 |
|
@@ -495,10 +514,10 @@ def _convert_times(df, first_samp, col="time"):
|
495 | 514 | """
|
496 | 515 | _sort_by_time(df, col)
|
497 | 516 | for col in df.columns:
|
498 |
| - if col.endswith("time"): # 'time' and 'end_time' cols |
| 517 | + if str(col).endswith("time"): # 'time' and 'end_time' cols |
499 | 518 | df[col] -= first_samp
|
500 | 519 | df[col] /= 1000
|
501 |
| - if col in ["duration", "offset"]: |
| 520 | + if str(col) in ["duration", "offset"]: |
502 | 521 | df[col] /= 1000
|
503 | 522 | return df
|
504 | 523 |
|
|
0 commit comments