Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/changes/dev/13967.newfeature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include label and description fields when reading EGI mff files, by `Martin Oberg`_.
8 changes: 6 additions & 2 deletions mne/io/egi/egimff.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def __init__(
first_samps = [0]
last_samps = [egi_info["last_samps"][-1] - 1]

annot = dict(onset=list(), duration=list(), description=list())
annot = dict(onset=list(), duration=list(), description=list(), extras=list())

if len(idx["pns"]):
# PNS Data is present and should be read:
Expand Down Expand Up @@ -566,15 +566,19 @@ def __init__(
annot["onset"].append((prev_last - 0.5) / egi_info["sfreq"])
annot["duration"].append(gap / egi_info["sfreq"])
annot["description"].append("BAD_ACQ_SKIP")
annot["extras"].append({})

# create events from annotations
if events_as_annotations:
for code, samples in mff_events.items():
for code, dicts in mff_events.items():
if code not in include:
continue
samples = [d["start_sample"] for d in dicts]
extras = [d["extras"] for d in dicts]
annot["onset"].extend(np.array(samples) / egi_info["sfreq"])
annot["duration"].extend([0.0] * len(samples))
annot["description"].extend([code] * len(samples))
annot["extras"].extend(extras)

if len(annot["onset"]):
self.set_annotations(Annotations(**annot))
Expand Down
11 changes: 9 additions & 2 deletions mne/io/egi/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def _read_events(input_fname, info):
info["event_codes"] = event_codes
events = np.zeros([info["n_events"], info["n_segments"] * n_samples])
for n, event in enumerate(event_codes):
for i in mff_events[event]:
for dct in mff_events[event]:
i = dct["start_sample"]
if (i < 0) or (i >= events.shape[1]):
continue
events[n][i] = n + 1
Expand Down Expand Up @@ -74,6 +75,7 @@ def _read_mff_events(filename, sfreq, start_time):
event_start = event["beginTime"]
start_sec = (event_start - start_time).total_seconds()
duration = event["duration"] / 1e9
extras = dict(label=event["label"], desc=event["description"])

markers.append(
{
Expand All @@ -82,11 +84,16 @@ def _read_mff_events(filename, sfreq, start_time):
"start_sample": int(np.trunc(start_sec * sfreq)),
"end": start_sec + duration,
"chan": None,
"extras": extras,
}
)

events_tims = {
ev: [marker["start_sample"] for marker in markers if marker["name"] == ev]
ev: [
dict(start_sample=marker["start_sample"], extras=marker["extras"])
for marker in markers
if marker["name"] == ev
]
for ev in code
}
return events_tims, code
Expand Down
Loading