# Open EEG binary file

**URL:** <https://discourse.julialang.org/t/open-eeg-binary-file/55972>\
**Category:** New to Julia\
**Tags:** binaryio\
**Created:** [February 25, 2021, 12:16am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972 "2021-02-25T00:16:52Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [February 25, 2021, 12:16am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/1 "2021-02-25T00:16:52Z")

</div>

Hi,

I am trying to open an EEG BrainVision binary file, but I have a problem… Please help ☹

To open the binary, I am using the solution provided [in this discussion](https://discourse.julialang.org/t/binary-reading/25207) by @stevengj (thank you).

The data is said to include 257 channels sampled at 1kHz for 10 minutes, as IEEE Float32.

Here is my code:

```julia
fs=1000 # sampling frequency
ch_numb=257 # 257 channels
record_time=10 # 10 minutes
read_bin(filename, dims) = read!(filename, Vector{Float32}(undef, dims)) # stevengji's function
data=read_bin(filename,ch_numb*record_time*60*fs) # get the data

```

So far so good, it gives the amount of data I am expecting given the data descriptor…BUT

```julia
data=read_bin(filename,ch_numb*record_time*60*fs+1000000) 

```

This code also gives me data(with no eror), I get 1 million values more than I should get.

My question is:  
_Is there a method to obtain the actual amount of Float32 values inside the binary file?_  
I mean beside increasing the ` dims` value until I get an `end of file` error.

Thanks

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [February 25, 2021, 12:45am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/2 "2021-02-25T00:45:36Z")

</div>

Are you sure the file is unstructured like that? Usually this kind of data can have all kinds of metadata embedded in the file. @jrevels works a lot with EEG data, maybe he can point you in the right direction.

---

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [February 25, 2021, 12:54am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/3 "2021-02-25T00:54:25Z")

</div>

Thank you @Keno, This file actually is composed of three files, one binary and two with metadata(sampling frequency, number of channels ,etc). My problem is that it seems to have more data than expected.

Would you think would be appropriate to contact @jrevels directly??  
(I guess using Discourse tools, I have never done it before)

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [February 25, 2021, 12:56am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/4 "2021-02-25T00:56:25Z")

</div>

Discourse will have emailed him, so he can chime in here if he knows something. Usually messaging people directly is discouraged, as it prevents other people from seeing an answer which may be useful to them (aside from any etiquette questions).

---

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [February 25, 2021, 12:58am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/5 "2021-02-25T00:58:01Z")

</div>

I understand. Thank you

---

<div class="post-metadata">

**Author:** ![Zach\_Christensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zach_christensen/32/7220_2.png) [@Zach\_Christensen](https://discourse.julialang.org/u/Zach_Christensen)\
**Post date:** [February 25, 2021, 2:45am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/6 "2021-02-25T02:45:40Z")

</div>

What is the file extension?

---

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [February 25, 2021, 3:00am UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/7 "2021-02-25T03:00:17Z")

</div>

Maybe you won’t believe this, but I was praying for you to come… Thank you.

It is BrainVision’s file, the .eeg file. I read (in a text editor) the metadata files, but I get the situation described above.

In fact, I would like to code something to read this format, and I was also thinking of contacting you to know if it could be added to you Neuro Julia projects.

I mean, if you think it is appropriate, I am just a beginner but with a couple of comments I would love to do it.

---

<div class="post-metadata">

**Author:** ![jrevels](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jrevels/32/10393_2.png) [@jrevels](https://discourse.julialang.org/u/jrevels)\
**Post date:** [February 25, 2021, 1:51pm UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/8 "2021-02-25T13:51:43Z")

</div>

I haven’t worked with BrainVision’s format directly (@Zach_Christensen would be a better bet there - IIRC BIDS adopted the BrainVision format) but these links could be helpful:

[BrainVision Core Data Format 1.0](https://www.brainproducts.com/productdetails.php?id=21&tab=5)

> **[GitHub - agricolab/brainvisionloader.jl: Loads brainvision files into Julia](https://github.com/agricolab/brainvisionloader.jl)**
>
> Loads brainvision files into Julia. Contribute to agricolab/brainvisionloader.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Zach\_Christensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zach_christensen/32/7220_2.png) [@Zach\_Christensen](https://discourse.julialang.org/u/Zach_Christensen)\
**Post date:** [February 25, 2021, 3:47pm UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/9 "2021-02-25T15:47:40Z")

</div>

It would definitely be within the scope of JuliaNeuroscience. The first thing would be to find out how they specify basic channel information in the header. For example, biosemi has this specification [Biosemi EEG ECG EMG BSPM NEURO amplifiers systems](https://www.biosemi.com/faq/file_format.htm)

---

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [February 25, 2021, 4:20pm UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/10 "2021-02-25T16:20:35Z")

</div>

Great…

BrainVision file is actually composed of three files ([here is the documentation](https://www.brainproducts.com/files/public/products/more/BrainVisionCoreDataFormat_1-0.pdf)):  
.vhdr is the header  
.vmrk the “marker” file  
.eeg contains the data

The header(.vhdr) is pretty simple actually, here is the one I am working with(I cut the last 252 channels, it is too long):

```julia
Brain Vision Data Exchange Header File Version 1.0
; Data created by FieldTrip

[Common Infos]
DataFile=sub-01_ses-RestingState_task-PicturesNaming_eeg.eeg
MarkerFile=sub-01_ses-RestingState_task-PicturesNaming_eeg.vmrk
DataFormat=BINARY
DataOrientation=MULTIPLEXED
NumberOfChannels=257
SamplingInterval=1000

[Binary Infos]
BinaryFormat=IEEE_FLOAT_32

[Channel Infos]
Ch1=E1,,1
Ch2=E2,,1
Ch3=E3,,1
Ch4=E4,,1
Ch5=E5,,1

```

What do you think? I am wondering what the “JuliaNeuro” flavor would be

---

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [February 25, 2021, 4:21pm UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/11 "2021-02-25T16:21:11Z")

</div>

Hey thanks, I am gonna give it a try today

---

<div class="post-metadata">

**Author:** ![Zach\_Christensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zach_christensen/32/7220_2.png) [@Zach\_Christensen](https://discourse.julialang.org/u/Zach_Christensen)\
**Post date:** [February 25, 2021, 6:28pm UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/12 "2021-02-25T18:28:36Z")

</div>

I’d start by importing it as a vector of 257 channels where each channel is a vector of floats. Usually that’s enough to get you to a productive work flow. Create some basic tests to ensure that your code still loads data properly as you improve on the whole IO process.

Try not to worry too much about doing things the “correct” way at first. If you ping me on GitHub I can help you out with getting basic traits working. They aren’t difficult but I’m very behind on documenting code right now (can you believe my PI wants me to publish papers instead of code documentation😉).

---

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [February 25, 2021, 6:58pm UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972/13 "2021-02-25T18:58:00Z")

</div>

Unbelievable… 🙈  
PIs, who can understand them ?

I understand what you say… In prooooogress
