lina-usc / pylossless

🧠 EEG Processing pipeline that annotates continuous data
https://pylossless.readthedocs.io/en/latest/
MIT License
18 stars 8 forks source link

Find Breaks Workflow Requires Annotation Structure in Raw #99

Open Andesha opened 1 year ago

Andesha commented 1 year ago

When passing find_breaks to the pipeline like the following:

config['find_breaks'] = {}
config['find_breaks']['min_break_duration'] = 10
config['find_breaks']['t_start_after_previous'] = 3
config['find_breaks']['t_stop_before_next'] = 0
config['find_breaks']['ignore'] = ['boundary', 'e-255']

The pipeline crashes if there is not an annotation structure already created in the data. Error here:

  File "/scratch/tk11br/TRI-pipeline/env/lib/python3.10/site-packages/mne/preprocessing/artifact_detection.py", line 471, in annotate_break
    raise ValueError('Could not find (or generate) any annotations in '
ValueError: Could not find (or generate) any annotations in your data.

I fixed this personally by doing this:

annos = mne.annotations_from_events(events=mne.find_events(raw, initial_event=True),
                                    sfreq=raw.info['sfreq'],
                                    orig_time=raw.info['meas_date'])
raw.set_annotations(annos)

Likely needs to be fixed before the initial release.

scott-huberty commented 1 year ago

I see.

You should also be able to pass config['find_breaks'] = False to skip this step.

I made the find_breaks behavior True by default because when I used MATLAB Lossless, finding breaks was not done by default, and this is something I always needed to do (but often forgot) which resulted in having to re-run the pipeline.

The default for annotate_break is to look for annotations, alternatively, you can pass in an event array (or set your annotations from your stim channel as you did).

But I agree that we might want to handle a situation like yours more gracefully.