Reading brainstorm exported raw data in mne

Hi Francois,

I am new to MNE. I wanted to ask you how can we read raw data exported after applying filters from brainstorm ( in either of .bst, .mat, .edf, .raw format) into MNE? I tried loading the .edf file exported from brainstorm to MNE but it gave me an error saying :


ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_10800/1370881937.py in
----> 1 raw= mne.io.read_raw_edf(fname)

~\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py in read_raw_edf(input_fname, eog, misc, stim_channel, exclude, preload, verbose)
1325 if ext != 'edf':
1326 raise NotImplementedError(f'Only EDF files are supported, got {ext}.')
-> 1327 return RawEDF(input_fname=input_fname, eog=eog, misc=misc,
1328 stim_channel=stim_channel, exclude=exclude, preload=preload,
1329 verbose=verbose)

in init(self, input_fname, eog, misc, stim_channel, exclude, preload, verbose)

~\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py in init(self, input_fname, eog, misc, stim_channel, exclude, preload, verbose)
112 logger.info('Extracting EDF parameters from {}...'.format(input_fname))
113 input_fname = os.path.abspath(input_fname)
--> 114 info, edf_info, orig_units = _get_info(input_fname, stim_channel, eog,
115 misc, exclude, preload)
116 logger.info('Creating raw.info structure...')

~\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py in _get_info(fname, stim_channel, eog, misc, exclude, preload)
355 misc = misc if misc is not None else []
356
--> 357 edf_info, orig_units = _read_header(fname, exclude)
358
359 # XXX: tal_ch_names to pass to _check_stim_channel should be computed

~\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py in _read_header(fname, exclude)
342 logger.info('%s file detected' % ext.upper())
343 if ext in ('bdf', 'edf'):
--> 344 return _read_edf_header(fname, exclude)
345 elif ext == 'gdf':
346 return _read_gdf_header(fname, exclude), None

~\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py in _read_edf_header(fname, exclude)
707
708 physical_min = np.array(
--> 709 [float(_edf_str(fid.read(8))) for ch in channels])[sel]
710 physical_max = np.array(
711 [float(_edf_str(fid.read(8))) for ch in channels])[sel]

~\Anaconda3\envs\mne\lib\site-packages\mne\io\edf\edf.py in (.0)
707
708 physical_min = np.array(
--> 709 [float(_edf_str(fid.read(8))) for ch in channels])[sel]
710 physical_max = np.array(
711 [float(_edf_str(fid.read(8))) for ch in channels])[sel]

ValueError: could not convert string to float: '-7.8072e'

I was wondering if you could help me with this

I'm not sure why MNE-Python can't read the EDF+ files exported from Brainstorm.
I don't know if there are better solutions for importing data processed by Brainstorm in MNE.
@Alexandre?

Note that you can use Brainstorm functions to create directly MNE-Python objects:

hi,

if it's the file you shared with me loading the file in eeglab with biosig already raised
many warnings.

try with https://www.teuniz.net/edfbrowser/ if the file can be read. For be it's a good reference for EDF files.

Alex

Fixing the EDF export

I tested the export of the EEG/Epilepsy tutorial dataset to EDF+ with Brainstorm.
It's very slow, but the .edf file generated is read by EDFBrowser and Cartool without any problem, including all the event markers.

@SubratBastola
Please share a short example file generated with Brainstorm that you can't read with MNE-Python: upload the file somewhere and post the download link here.
Before posting it at least with EDFBrowser before submitting it, and let us know what you obtain.
Note that the EDF+ format is adapted for exchanging EEG signals only (no MEG or NIRS).

Use the BrainVision format instead

In general, floating point data (type double in Matlab - 8 bytes per value), such as signals pre-processed with Brainstorm or MNE-Python, should never be exported back to EDF files. This converts the values back to integer values (type int16 in Matlab - 2 bytes per value) , causing various rounding issues.

You can use instead the BrainVision BrainAmp .eeg/.vhdr/.vmrk format, another exchange format we recommend in the BIDS-EEG specification, which includes a support for floating point data:
https://bids-specification.readthedocs.io/en/stable/04-modality-specific-files/03-electroencephalography.html#eeg-recording-data