mne.HEDAnnotations#
- class mne.HEDAnnotations(onset, duration, description, hed_string, hed_version='8.3.0', orig_time=None, ch_names=None, *, extras=None)[source]#
Annotations object for annotating segments of raw data with HED tags.
- Parameters:
- onset
arrayoffloat, shape (n_annotations,) The starting time of annotations in seconds after
orig_time.- duration
arrayoffloat, shape (n_annotations,) |float Durations of the annotations in seconds. If a float, all the annotations are given the same duration.
- description
arrayofstr, shape (n_annotations,) |str Array of strings containing description for each annotation. If a string, all the annotations are given the same description. To reject epochs, use description starting with keyword ‘bad’. See example above.
- hed_string
arrayofstr, shape (n_annotations,) |str Sequence of strings containing a HED tag (or comma-separated list of HED tags) for each annotation. If a single string is provided, all annotations are assigned the same HED string.
- hed_version
str The HED schema version against which to validate the HED strings.
- orig_time
float|str|datetime|tupleofint|None A POSIX Timestamp, datetime or a tuple containing the timestamp as the first element and microseconds as the second element. Determines the starting time of annotation acquisition. If None (default), starting time is determined from beginning of raw data acquisition. In general,
raw.info['meas_date'](or None) can be used for syncing the annotations with raw data if their acquisition is started at the same time. If it is a string, it should conform to the ISO8601 format. More precisely to this ‘%Y-%m-%d %H:%M:%S.%f’ particular case of the ISO8601 format where the delimiter between date and time is ‘ ‘.- ch_names
list|None List of lists of channel names associated with the annotations. Empty entries are assumed to be associated with no specific channel, i.e., with all channels or with the time slice itself. None (default) is the same as passing all empty lists. For example, this creates three annotations, associating the first with the time interval itself, the second with two channels, and the third with a single channel:
Annotations(onset=[0, 3, 10], duration=[1, 0.25, 0.5], description=['Start', 'BAD_flux', 'BAD_noise'], ch_names=[[], ['MEG0111', 'MEG2563'], ['MEG1443']])
- extras
list[dict[str,int|float|str|None] |None] |None Optional list of dicts containing extra fields for each annotation. The number of items must match the number of annotations.
- onset
- Attributes:
Methods
__add__(other)Add (concatencate) two Annotation objects.
__getitem__(key, *[, with_ch_names, with_extras])Propagate indexing and slicing to the underlying structure.
__iter__()Iterate over the annotations.
__len__()Return the number of annotations.
append(*, onset, duration, description, ...)Add an annotated segment.
copy()Return a copy of the Annotations.
count()Count annotations.
crop([tmin, tmax, emit_warning, ...])Remove all annotations that are outside of [tmin, tmax].
delete(idx)Remove an annotation.
rename(mapping[, verbose])Rename annotation description(s).
save(fname, *[, overwrite, verbose])Save annotations to FIF, CSV or TXT.
set_durations(mapping[, verbose])Set annotation duration(s).
to_data_frame([time_format])Export annotations in tabular structure as a pandas DataFrame.
See also
Notes
New in v1.12.
- __getitem__(key, *, with_ch_names=None, with_extras=True)[source]#
Propagate indexing and slicing to the underlying structure.
- append(*, onset, duration, description, hed_string, ch_names=None, extras=None)[source]#
Add an annotated segment. Operates inplace.
- Parameters:
- onset
float| array_like Annotation time onset from the beginning of the recording in seconds.
- duration
float| array_like Duration of the annotation in seconds.
- description
str| array_like Description for the annotation. To reject epochs, use description starting with keyword ‘bad’.
- hed_string
arrayofstr, shape (n_annotations,) |str Sequence of strings containing a HED tag (or comma-separated list of HED tags) for each annotation. If a single string is provided, all annotations are assigned the same HED string.
- ch_names
list|None List of lists of channel names associated with the annotations. Empty entries are assumed to be associated with no specific channel, i.e., with all channels or with the time slice itself. None (default) is the same as passing all empty lists. For example, this creates three annotations, associating the first with the time interval itself, the second with two channels, and the third with a single channel:
Annotations(onset=[0, 3, 10], duration=[1, 0.25, 0.5], description=['Start', 'BAD_flux', 'BAD_noise'], ch_names=[[], ['MEG0111', 'MEG2563'], ['MEG1443']])
- extras
list[dict[str,int|float|str|None] |None] |None Optional list of dicts containing extras fields for each annotation.
- onset
- Returns:
- self
mne.HEDAnnotations The modified HEDAnnotations object.
- self
- copy()[source]#
Return a copy of the Annotations.
- Returns:
- instinstance of
Annotations A copy of the object.
- instinstance of
- count()[source]#
Count annotations.
- Returns:
- counts
dict A dictionary containing unique annotation descriptions as keys with their counts as values.
- counts
- crop(tmin=None, tmax=None, emit_warning=False, use_orig_time=True, verbose=None)[source]#
Remove all annotations that are outside of [tmin, tmax].
The method operates inplace.
- Parameters:
- tmin
float|datetime|None Start time of selection in seconds.
- tmax
float|datetime|None End time of selection in seconds.
- emit_warningbool
Whether to emit warnings when limiting or omitting annotations. Defaults to False.
- use_orig_timebool
Whether to use orig_time as an offset. Defaults to True.
- verbosebool |
str|int|None Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
- tmin
- Returns:
- selfinstance of
HEDAnnotations The cropped HEDAnnotations object.
- selfinstance of
- delete(idx)[source]#
Remove an annotation. Operates inplace.
- Parameters:
- idx
int| array_like ofint Index of the annotation to remove. Can be array-like to remove multiple indices.
- idx
- property extras#
The extras of the Annotations.
The
extrasattribute is a list of dictionaries. It can easily be converted to a pandas DataFrame using:pd.DataFrame(extras).
- property orig_time#
The time base of the Annotations.
- rename(mapping, verbose=None)[source]#
Rename annotation description(s). Operates inplace.
- Parameters:
- mapping
dict A dictionary mapping the old description to a new description, e.g. {‘1.0’ : ‘Control’, ‘2.0’ : ‘Stimulus’}.
- verbosebool |
str|int|None Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
- mapping
- Returns:
- self
mne.Annotations The modified Annotations object.
- self
Notes
New in v0.24.0.
- save(fname, *, overwrite=False, verbose=None)[source]#
Save annotations to FIF, CSV or TXT.
Typically annotations get saved in the FIF file for raw data (e.g., as
raw.annotations), but this offers the possibility to also save them to disk separately in different file formats which are easier to share between packages.- Parameters:
- fnamepath-like
The filename to use.
- overwritebool
If True (default False), overwrite the destination file if it exists.
New in v0.23.
- verbosebool |
str|int|None Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
Notes
The format of the information stored in the saved annotation objects depends on the chosen file format.
.csvfiles store the onset as timestamps (e.g.,2002-12-03 19:01:56.676071), whereas.txtfiles store onset as seconds since start of the recording (e.g.,45.95597082905339).
- set_durations(mapping, verbose=None)[source]#
Set annotation duration(s). Operates inplace.
- Parameters:
- mapping
dict|float A dictionary mapping the annotation description to a duration in seconds e.g.
{'ShortStimulus' : 3, 'LongStimulus' : 12}. Alternatively, if a number is provided, then all annotations durations are set to the single provided value.- verbosebool |
str|int|None Control verbosity of the logging output. If
None, use the default verbosity level. See the logging documentation andmne.verbose()for details. Should only be passed as a keyword argument.
- mapping
- Returns:
- self
mne.Annotations The modified Annotations object.
- self
Notes
New in v0.24.0.
- to_data_frame(time_format='datetime')[source]#
Export annotations in tabular structure as a pandas DataFrame.
- Parameters:
- time_format
str|None Desired time format. If
None, no conversion is applied, and time values remain as float values in seconds. If'ms', time values will be rounded to the nearest millisecond and converted to integers. If'timedelta', time values will be converted topandas.Timedeltavalues. If'datetime', time values will be converted topandas.Timestampvalues, relative toraw.info['meas_date']and offset byraw.first_samp. Default isNoneunless specified otherwise.
- time_format
- Returns:
- result
pandas.DataFrame Returns a pandas DataFrame with onset, duration, description, and hed_string columns. A column named ch_names is added if any annotations are channel-specific.
- result