|
38 | 38 | "sacc_visual_angle", |
39 | 39 | "peak_velocity", |
40 | 40 | ), |
| 41 | + "messages": ("time", "offset", "event_msg"), |
41 | 42 | } |
42 | 43 |
|
43 | 44 |
|
@@ -356,6 +357,7 @@ def _infer_col_names(raw_extras): |
356 | 357 | col_names = {} |
357 | 358 | # initiate the column names for the sample lines |
358 | 359 | col_names["samples"] = list(EYELINK_COLS["timestamp"]) |
| 360 | + col_names["messages"] = list(EYELINK_COLS["messages"]) |
359 | 361 |
|
360 | 362 | # and for the eye message lines |
361 | 363 | col_names["blinks"] = list(EYELINK_COLS["eye_event"]) |
@@ -410,12 +412,33 @@ def _assign_col_names(col_names, df_dict): |
410 | 412 | col_names : dict |
411 | 413 | Dictionary of column names for each dataframe. |
412 | 414 | """ |
| 415 | + skipped_types = [] |
413 | 416 | for key, df in df_dict.items(): |
414 | | - if key in ("samples", "blinks", "fixations", "saccades"): |
415 | | - df.columns = col_names[key] |
416 | | - elif key == "messages": |
417 | | - cols = ["time", "offset", "event_msg"] |
418 | | - df.columns = cols |
| 417 | + if key in ("samples", "blinks", "fixations", "saccades", "messages"): |
| 418 | + cols = col_names[key] |
| 419 | + else: |
| 420 | + skipped_types.append(key) |
| 421 | + continue |
| 422 | + max_cols = len(cols) |
| 423 | + if len(df.columns) != len(cols): |
| 424 | + if key in ("saccades", "fixations") and len(df.columns) >= 4: |
| 425 | + # see https://github.com/mne-tools/mne-python/pull/13357 |
| 426 | + logger.debug( |
| 427 | + f"{key} events have more columns ({len(df.columns)}) than " |
| 428 | + f"expected ({len(cols)}). Using first 4 (eye, time, end_time, " |
| 429 | + "duration)." |
| 430 | + ) |
| 431 | + max_cols = 4 |
| 432 | + else: |
| 433 | + raise ValueError( |
| 434 | + f"Expected the {key} data in this file to have {len(cols)} columns " |
| 435 | + f"of data, but got {len(df.columns)}. Expected columns: {cols}." |
| 436 | + ) |
| 437 | + new_col_names = { |
| 438 | + old: new for old, new in zip(df.columns[:max_cols], cols[:max_cols]) |
| 439 | + } |
| 440 | + df.rename(columns=new_col_names, inplace=True) |
| 441 | + logger.debug(f"Skipped assigning column names to {skipped_types} dataframes.") |
419 | 442 | return df_dict |
420 | 443 |
|
421 | 444 |
|
@@ -474,10 +497,10 @@ def _convert_times(df, first_samp, col="time"): |
474 | 497 | """ |
475 | 498 | _sort_by_time(df, col) |
476 | 499 | for col in df.columns: |
477 | | - if col.endswith("time"): # 'time' and 'end_time' cols |
| 500 | + if str(col).endswith("time"): # 'time' and 'end_time' cols |
478 | 501 | df[col] -= first_samp |
479 | 502 | df[col] /= 1000 |
480 | | - if col in ["duration", "offset"]: |
| 503 | + if str(col) in ["duration", "offset"]: |
481 | 504 | df[col] /= 1000 |
482 | 505 | return df |
483 | 506 |
|
|
0 commit comments