ValueError with write_raw_bids() function after CSD run

Hello MNE community!

I have a question concerning mne.bids.write_raw_bids() function.
I’m trying to save the preprocessed data from the eegbci dataset after running mne.preprocessing.compute_current_source_density() on it, but I get the following error:

ValueError: The specified datatype eeg was not found in the raw object. Please 
specify the correct datatype using `bids_path.update(datatype="<datatype>")` or 
use raw.set_channel_types to set the correct channel types in the raw object.

If I run the mne.bids.write_raw_bids() function before running mne.preprocessing.compute_current_source_density(), everything works fine. Here is my code after applying mne.preprocessing.compute_current_source_density():

bids_root = 'C:/Users/M/Desktop/data/BIDS_preprocessed'
# csd
raw_csd = mne.preprocessing.compute_current_source_density(ica_raw)
    
#saving as BIDS
bids_path = BIDSPath(subject='001', session='01', task= 'EyesOpen',
                     datatype='eeg', root= bids_root)
write_raw_bids(raw_csd, bids_path=bids_path, allow_preload=True, format = 'BrainVision')

I guess, the problem is with the format of the data after running the mne.preprocessing.compute_current_source_density() function, but I don’t know how to solve it.
WIll be grateful for your help!

  • MNE version: 1.6.1
  • operating system: Windows 11

Hello, BIDS doesn’t support storing this kind of data; this is so-called derivative data that hasn’t been fully specified in BIDS yet. You can save it in a derivatives folder inside of your BIDS dataset (the one that contains the unprocessed raw data) using pure MNE-Python functions (i.e. not using write_raw_bids().

(When you calculate CSP, MNE changes all channel types to csp, which doesn’t exist in BIDS)

Best wishes,
Richard

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.