Skip to content

Error with load epochs after cropping after baseline correction #7628

Closed

Description

@SebastianSpeer

Describe the bug

I posted this on the mailing list and Alex Gramfort asked me to open this here as an issue:

I did my baseline correction on a period of 1s which is 6s prior to the onset of the event of interest (due to unfortunate experimental design), so I initially epoched my data to -7 to 3s . After epoching the data I then cropped the data to -0.3 to 3s, as I no longer needed the 7 seconds prior to the data after the baseline correction was done. When I then save the epoched data and load it again somewhere else and error occurs because the baseline parameters are outside the epoched data.
To my understanding the baseline correction is already applied during epoching so I the decided to just set the baseline parameters to (0,0) after baseline correction has been done and data has been cropped. If I do that I can load the epoched data without no problem.

Steps to reproduce

decision_epochs = mne.Epochs(eeg_data_interp_ref_ica, events, tmin=-7, tmax=3,baseline=(-7,-6),
                    #reject=reject_criteria,  flat=flat_criteria, # commented beause we're using autoreject here
                    event_id = decision_events_of_interest,
                    reject_by_annotation=False, preload=True)

decision_epochs_cropped = decision_epochs.copy().crop(tmin=-0.3, tmax=3, include_tmax=True)


# drop epochs after cropping

ar = AutoReject(verbose='tqdm_notebook', n_jobs=n_jobs, consensus=np.linspace(0, 1, 20), n_interpolate = np.array([1,4,8,16,32]) )
decision_epochs_cropped_clean_ar = ar.fit_transform(decision_epochs_cropped)

out_dir='/data/sebastian/EEG/neural_analysis/'

# This version can't be loaded after
decision_epochs_cropped_clean_ar.save(opj(out_dir,task,sub+'-TEST_'+str(cutoff_l)+'_HP_'+str(cutoff_h)+'_'+reference+'.fif'), overwrite=True)

# This version can't be loaded after
decision_epochs_cropped_clean_ar.baseline=(0,0)
decision_epochs_cropped_clean_ar.save(opj(out_dir,task,sub+'-TEST2_'+str(cutoff_l)+'_HP_'+str(cutoff_h)+'_'+reference+'.fif'), overwrite=True)

Activity

  1. algrmur commented on Apr 18, 2020

    @algrmur

    It would be really nice to get this fixed. For exactly the same reasons, I can only work with the NumPy arrays after extracting the data from the MNE.Epochs object using the get_data method and then saving the info parameter somewhere and rebuilding a new MNE.Epochs object later on if I need to do further processing, all because I can't use the save method to then re-load, because of the complaints that the (already applied) baseline correction data has been cropped away in an earlier stage of preprocessing.

    Thanks for raising this, Sebastian. I was too busy to, at the time when it was causing me headaches!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions