very basic - raw EEG from MUSE csv

I’m using a MUSE 1 device along with a SATo paradigm.
To avoid GUI issues I’ve hacked the device and obtained raw volts data and place them in a csv file.

How can I convert voltage values from 4 channels in a csv file to fif format to begin measurements?

The file looks like this

baseLine_0
3,"[44.921875,1.953125,21.484375,39.55078125,30.2734375,41.50390625,22.4609375,36.62109375,41.9921875,25.390625,28.3203125,40.0390625]",1681226151368
2,"[53.22265625,52.24609375,50.29296875,46.875,50.29296875,51.26953125,43.45703125,45.8984375,53.7109375,49.8046875,42.96875,45.41015625]",1681226151368
0,"[24.4140625,27.34375,9.27734375,26.3671875,20.01953125,35.64453125,70.80078125,20.99609375,-1.46484375,29.78515625,11.23046875,-27.83203125]",1681226151368
1,"[66.89453125,69.3359375,67.87109375,55.6640625,62.01171875,70.80078125,71.77734375,72.265625,54.6875,55.17578125,68.359375,62.98828125]",1681226151368
3,"[26.85546875,-26.3671875,-12.20703125,17.578125,-3.90625,-9.27734375,14.6484375,10.7421875,5.37109375,1.953125,6.34765625,32.71484375]",1681226151414.875
2,"[54.6875,55.6640625,53.7109375,43.45703125,29.296875,41.015625,48.33984375,44.921875,46.875,40.52734375,41.9921875,45.41015625]",1681226151414.875
0,"[1.953125,39.55078125,7.32421875,10.7421875,35.64453125,17.08984375,0.48828125,6.34765625,3.90625,-0.9765625,8.30078125,26.85546875]",1681226151414.875

‘baseLine_0’ is a marker. The library I use buffers 12 volt values per chunk in each channel.

Hey @Patricio - I can’t advise on your specific situation but generally when starting with data from csv I would look into:

  1. Loading that data into a Numpy Array
  2. Create a MNE Raw object from the Numpy array
  3. use the save method to save the MNE Raw object to fif format.

Best of luck!

Scott

1 Like

Great, thank you.

And how can I reference the electrodes to each array?

Patricio

so your file has:

  • one column with values 0,1,2,3 (channel numbers?)
  • one column with a string-formatted list of 12 voltage values from that channel
  • one column with what looks like time info (total seconds since the unix epoch perhaps?)

I don’t think there are any out-of-the-box solutions, you’ll need to write a small script to parse the file and put the data where it belongs. Something like this (not tested):

import ast
from collections import default_dict

accumulator = default_dict(list)
times = list()

with open(filename, 'r') as fid:
    for line in fid:
        ch_num, *_, time = line.split(',')
        ch_num = int(ch_num)
        time = float(time)
        data = ast.literal_eval(line.split('"')[1])
        accumulator[ch_num].append(data)
        if times[-1] != time:
            times.append(time)

Then you can combine the channels in accumulator into a numpy array, and use mne.io.RawArray as suggested by @scott-huberty

I’m not sure what you mean, can you elaborate?

Wow, thank you.

On the question about the reference, I forgot that in EEG this word is delicate. I was wondering how can I build a multidimensional numpy array with the electrode names, as when you plot a fif data file. But you answered that above.

I’ll test and report for others with the same problem.

Thanks again
Patricio

The numpy array won’t have channel names. When you combine data from accumulator entries you’ll need to be careful to make sure you put them in the correct order. Then when you use RawArray you pass in the channel names there.

I forgot to say before that you’ll also want to make sure you end up with the same number of samples in each channel (if not then your data CSV file is corrupted/truncated).

The last thing you said kept me awake, and I checked it.
The library I use, perhaps because of javascript or who knows, drop buffers.

[ 335, 260, 376, 260 ]

In a very short time I had almost 100 losses on the 3rd electrode. Multiplied by 12!

Thanks again, I’ll change the framework.

2 Likes

if it’s any consolation: you probably would have caught it eventually when trying to put the data into a NumPy array (because the channels would have different numbers of samples). Heads up that my quick untested script had a bug which I’ve just edited (the ch_num and time variables were wrong).

1 Like