OpenBci EEG bdf format convert to mne array

I want to convert bdf file exported from Open Bci GUI to mne.

data=mne.io.read_raw_bdf('OpenBCI-BDF-2023-06-15_15-15-45.bdf')
data.drop_channels(['Accel X','Accel Y','Accel Z'])
montage = mne.channels.make_standard_montage('standard_1020')
ch_names = ['FP1', 'Fp2', 'F7', 'F3', 'F4', 'F8', 'T7', 'C3', 'C4', 'T8', 'P7', 'P3', 'P4', 'P8', 'O1', 'O2']
ch_types = ['eeg'] * 16
info = mne.create_info(ch_names=ch_names,sfreq=125,ch_types=ch_types)
info.set_montage('standard_1020', match_case=False)
data_converted=mne.io.RawArray(data,info)

But I got the following error:
ValueError: All picks must be < n_channels (16), got 16

Could you please help me with this or suggest any other way to do that.

Thanks

Hi @SoroushZrZ

your issue is here:

data_converted=mne.io.RawArray(data,info)

mne.io.RawArray expects a numpy array, but you passed a Raw instance.

You need to do

mne.io.RawArray(data.get_data(), info).

Although if you are just doing this because you need to set the channel names and channel types of your raw object, maybe you can try:

# the usual convention is to name  this variable "raw"
raw = mne.io.read_raw_bdf('OpenBCI-BDF-2023-06-15_15-15-45.bdf')
raw.drop_channels(['Accel X','Accel Y','Accel Z'])

And then use:

Hi @scott-huberty,

Thank you so much. It works very well. And since my plot of the signals are not well, as you can see below, should I multiply it by 1e6 because the output of OpenBci is microvolt and mne plot Volts? If so, how can multiply all the signals without raw.get_data(), bc I do not want to convert the data to np.array at this stage.

If you don’t want to instantiate the NumPy array (which is how data is stored inside a Raw object), then you can do it at a later stage, just before you work with the data.

@cbrnr I’ve never worked with read_raw_bdf nor OpenBCI, but do you think it’s a bit weird that read_raw_bdf didn’t convert and store the data in Volts?

I see that read_raw_bdf has a units keyword argument, @SoroushZrZ if the units are missing in your files, maybe this argument can be of help to you.

Units are stored in the BDF header, it would be worthwile to check what they are. I’d also be interested in the channel types, i.e. print(raw.info). It’s hard to say from the screenshot if the signals will look more like EEG if they are multiplied by 1e6, so if possible I’d also like to see the transformed signals.

1 Like

Hi @cbrnr and @scott-huberty,
The info of all 14 channels is as follows, which shows the data have 14 EEG signals.
Capture3

The data which I collected from OpenBci is like below:

But, after I want to plot it with mne, then the plot doesn’t make sense. The plot is as following:

Channels are correctly recognized as EEG, so that’s not the problem. I’d be interested in the BDF header, you could use EDFbrowser to view the header and see which units are specified for each channel (EDFbrowser manual).