Problem with outputting EEG data after annotations

I need to output the EEG data after annotations. However, the output files I get are only with annotations and not containing EEG + annotations data. With save containing EEG + annotations data ?

Raw objects have a raw.save() method that saves the data and annotations. Annotations can be saved in a separate file via raw.annotations.save(). To reconstruct later, there is mne.read_annotations() followed by raw.set_annotations().

Is there some reason that this won’t work for you, and you must store the annotations in the same file as the data?

The annotations on data I can output. However the data containing both the EEG Sign + Annotations I can’t get.

I need to cut out the EEG data in the interval of the crisis, and mark points of interest with Annotations.
And output that data to use another moment.

Do you have an example? It is better to understand!

I cannot reproduce the problem. Here is an example where I add an annotation, save the raw file, and when I reload the raw file the annotation is there.

import os
import mne

# load sample data
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
                                    'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file)
raw.crop(0, 10).load_data()

# annotate
ann = mne.Annotations(onset=4, duration=3, description='TestingTesting')
raw.set_annotations(ann)

# save-load roundtrip
filename = 'foo-raw.fif'
raw.save(filename, overwrite=True)
del raw
loaded_raw = mne.io.read_raw(filename)
print(loaded_raw.annotations)
1 Like

That’s how it should work. raw.save saves everything contained in the raw object, which includes annotations.

1 Like

But there is no way to cut the data, save it in a new .EEG file?containing only data winth annotations!

I’m not certain that I understand what you want to do. Raw objects have a .crop() method for “cutting” the data. Are you trying to remove the part that has the annotation, or to keep the annotated part and remove the rest of the data?

Other things that might be helpful:

  1. The .save() method saves in the .fif format, not in the .EEG format (which is BrainVision I think?). We don’t currently support export to BrainVision, but MNE-BIDS can write BrainVision format I think.

  2. if you are trying to exclude the annotated part, you can make your annotation start with the letters BAD and then various MNE-Python functions can automatically ignore it (using a reject_by_annotation=True parameter). That way there is no need to actually remove the bad data segment from the file; you can leave it in and it will be ignored.

1 Like

Small correction: pybv can export to BrainVision.

1 Like