# OpenBci EEG bdf format convert to mne array

**URL:** <https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093>\
**Category:** Support & Discussions\
**Tags:** preprocessing, eeg\
**Created:** [June 15, 2023, 8:15pm UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093 "2023-06-15T20:15:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SoroushZrZ](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/soroushzrz/32/3429_2.png) [@SoroushZrZ](https://mne.discourse.group/u/SoroushZrZ)\
**Post date:** [June 15, 2023, 8:15pm UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/1 "2023-06-15T20:15:26Z")

</div>

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

```python
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

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [June 15, 2023, 8:39pm UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/2 "2023-06-15T20:39:56Z")

</div>

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](https://mne.tools/stable/generated/mne.io.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:

```python
# 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:

- [raw.rename\_channels](https://mne.tools/stable/generated/mne.io.Raw.html#mne.io.Raw.rename_channels), to rename any channels
- [raw.set\_channel\_types](https://mne.tools/stable/generated/mne.io.Raw.html#mne.io.Raw.set_channel_types) to set the channel types to `'eeg'` if you need to.

---

<div class="post-metadata">

**Author:** ![SoroushZrZ](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/soroushzrz/32/3429_2.png) [@SoroushZrZ](https://mne.discourse.group/u/SoroushZrZ)\
**Post date:** [June 15, 2023, 9:19pm UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/3 "2023-06-15T21:19:36Z")

</div>

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.

 ![Capture](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/b/befba79d8cf3b5926098be5adb763768a76a4f9b.png)

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [June 16, 2023, 5:05am UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/4 "2023-06-16T05:05:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scott-huberty](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/scott-huberty/32/2715_2.png) [@scott-huberty](https://mne.discourse.group/u/scott-huberty)\
**Post date:** [June 16, 2023, 1:39pm UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/5 "2023-06-16T13:39:31Z")

</div>

@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](https://mne.tools/dev/generated/mne.io.read_raw_bdf.html) has a `units` keyword argument, @SoroushZrZ_if the units are missing in your files_, maybe this argument can be of help to you.

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [June 16, 2023, 2:56pm UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/6 "2023-06-16T14:56:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SoroushZrZ](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/soroushzrz/32/3429_2.png) [@SoroushZrZ](https://mne.discourse.group/u/SoroushZrZ)\
**Post date:** [June 16, 2023, 3:29pm UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/7 "2023-06-16T15:29:32Z")

</div>

Hi @cbrnr and @scott-huberty,  
The info of all 14 channels is as follows, which shows the data have 14 EEG signals.  
 ![Capture3](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/c/c2cbafbea7bff58c1a9d60bc38209f6bd8fed4cb.png)

The data which I collected from OpenBci is like below:

 ![Capture1](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/0/0a13667636c246b74c73bd81b2c88cb9de2411b7.png)

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

 ![Capture2](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/a/a51c0328c1f1aa72e21fbeda4d32c731f3f4fd1c.png)

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [June 20, 2023, 5:29am UTC](https://mne.discourse.group/t/openbci-eeg-bdf-format-convert-to-mne-array/7093/8 "2023-06-20T05:29:12Z")

</div>

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](https://www.teuniz.net/edfbrowser/EDFbrowser%20manual.html#File_Info)).
