Skip to content
Merged
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/14084.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When concatenating :class:`~mne.io.Raw` objects containing annotations, also merge the ``extras`` fields, by `Marijn van Vliet`_
5 changes: 4 additions & 1 deletion mne/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,10 @@ def _combine_annotations(
duration = np.concatenate([one.duration, two.duration])
description = np.concatenate([one.description, two.description])
ch_names = np.concatenate([one.ch_names, two.ch_names])
return Annotations(onset, duration, description, one.orig_time, ch_names)
extras = one.extras + two.extras
return Annotations(
onset, duration, description, one.orig_time, ch_names, extras=extras
)


def _handle_meas_date(meas_date):
Expand Down
4 changes: 3 additions & 1 deletion mne/tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_basics():
onset = np.array(range(10))
duration = np.ones(10)
description = np.repeat("test", 10)
extras = [dict(foo=i) for i in range(10)]
dt = raw.info["meas_date"]
assert isinstance(dt, datetime)
stamp = _dt_to_stamp(dt)
Expand All @@ -110,7 +111,7 @@ def test_basics():
offset = offset[0] + offset[1] * 1e-6
offset = orig_time - offset
assert_allclose(offset, raw._first_time)
annot = Annotations(onset, duration, description, orig_time)
annot = Annotations(onset, duration, description, orig_time, extras=extras)
assert annot.orig_time is not None
assert " segments" in repr(annot)
raw2.set_annotations(annot)
Expand All @@ -122,6 +123,7 @@ def test_basics():
assert_allclose(onset + offset + delta, raw.annotations.onset, rtol=1e-5)
assert_array_equal(annot.duration, raw.annotations.duration)
assert_array_equal(raw.annotations.description, np.repeat("test", 10))
assert raw.annotations.extras == extras


def test_annot_sanitizing(tmp_path):
Expand Down
Loading