MCPcopy
hub / github.com/mne-tools/mne-python / events_from_annotations

Function events_from_annotations

mne/annotations.py:2270–2389  ·  view source on GitHub ↗

Get :term:`events` and ``event_id`` from an Annotations object. Parameters ---------- raw : instance of Raw The raw data for which Annotations are defined. event_id : dict | callable | None | ``'auto'`` Can be: - **dict**: map descriptions (keys) to integer

(
    raw,
    event_id="auto",
    regexp=r"^(?![Bb][Aa][Dd]|[Ee][Dd][Gg][Ee]).*$",
    use_rounding=True,
    chunk_duration=None,
    tol=1e-8,
    verbose=None,
)

Source from the content-addressed store, hash-verified

2268
2269@verbose
2270def events_from_annotations(
2271 raw,
2272 event_id="auto",
2273 regexp=r"^(?![Bb][Aa][Dd]|[Ee][Dd][Gg][Ee]).*$",
2274 use_rounding=True,
2275 chunk_duration=None,
2276 tol=1e-8,
2277 verbose=None,
2278):
2279 """Get :term:`events` and ``event_id`` from an Annotations object.
2280
2281 Parameters
2282 ----------
2283 raw : instance of Raw
2284 The raw data for which Annotations are defined.
2285 event_id : dict | callable | None | ``'auto'``
2286 Can be:
2287
2288 - **dict**: map descriptions (keys) to integer event codes (values).
2289 Only the descriptions present will be mapped, others will be ignored.
2290 - **callable**: must take a string input and return an integer event
2291 code, or return ``None`` to ignore the event.
2292 - **None**: Map descriptions to unique integer values based on their
2293 ``sorted`` order.
2294 - **'auto' (default)**: prefer a raw-format-specific parser:
2295
2296 - Brainvision: map stimulus events to their integer part; response
2297 events to integer part + 1000; optic events to integer part + 2000;
2298 'SyncStatus/Sync On' to 99998; 'New Segment/' to 99999;
2299 all others like ``None`` with an offset of 10000.
2300 - Other raw formats: Behaves like None.
2301
2302 .. versionadded:: 0.18
2303 regexp : str | None
2304 Regular expression used to filter the annotations whose
2305 descriptions is a match. The default ignores descriptions beginning
2306 ``'bad'`` or ``'edge'`` (case-insensitive).
2307
2308 .. versionchanged:: 0.18
2309 Default ignores bad and edge descriptions.
2310 use_rounding : bool
2311 If True, use rounding (instead of truncation) when converting
2312 times to indices. This can help avoid non-unique indices.
2313 chunk_duration : float | None
2314 Chunk duration in seconds. If ``chunk_duration`` is set to None
2315 (default), generated events correspond to the annotation onsets.
2316 If not, :func:`mne.events_from_annotations` returns as many events as
2317 they fit within the annotation duration spaced according to
2318 ``chunk_duration``. As a consequence annotations with duration shorter
2319 than ``chunk_duration`` will not contribute events.
2320 tol : float
2321 The tolerance used to check if a chunk fits within an annotation when
2322 ``chunk_duration`` is not ``None``. If the duration from a computed
2323 chunk onset to the end of the annotation is smaller than
2324 ``chunk_duration`` minus ``tol``, the onset will be discarded.
2325 %(verbose)s
2326
2327 Returns

Calls 5

infoMethod · 0.80
_check_event_idFunction · 0.70
time_as_indexMethod · 0.45
appendMethod · 0.45