# Raw object interprets data incorrectly

**URL:** <https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415>\
**Category:** Support & Discussions\
**Tags:** visualization, data-import, raw\
**Created:** [March 3, 2024, 9:00am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415 "2024-03-03T09:00:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![averinkit](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/averinkit/32/2562_2.png) [@averinkit](https://mne.discourse.group/u/averinkit)\
**Post date:** [March 3, 2024, 9:00am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/1 "2024-03-03T09:00:51Z")

</div>

Hello,  
I have some text files with the EEG signal, let’s take two of them to start with. Inside of them signals stored as 2 columns with many rows. I want to create a raw object from them and when plotting them I want to get 2 EEG channels with the first signal in the first channel and the second signal in the second channel. However, I have encountered a problem that mne takes this data from two files and puts it into the second channel. I read them separately with np.loadtxt, which is supposed to create numpy arrays from them. Then I transposed them, because initially they were received with the form (32000, 2), and I understand that these two values should be put in reverse for mne to make the raw object correctly. So I concatenated them and wrote data.reshape(2, 32000).  
To create the raw itself, I write sfreq = 250 based on the experiment data. I initialize ch\_names with two values and the same with ch\_types.  
This method didn’t work, so I resorted to the second method, where I used a loop to read the two files and write them to the dictionary. I would then turn it into a numpy array, use np.stack and again transpose them. This too produced the same result.  
I would be very grateful if anyone has any other ideas.

 ![загрузка](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/0/01d858719cb037e8ef742a209c72a84a890555a5.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:** [March 3, 2024, 2:54pm UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/2 "2024-03-03T14:54:09Z")

</div>

Can you show your code?

---

<div class="post-metadata">

**Author:** ![averinkit](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/averinkit/32/2562_2.png) [@averinkit](https://mne.discourse.group/u/averinkit)\
**Post date:** [March 3, 2024, 3:52pm UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/3 "2024-03-03T15:52:53Z")

</div>

Of course, the first piece of code is:  
data1 = np.loadtxt(“1\_class\_new\_2.dat”)  
data2 = np.loadtxt(“2\_class\_new\_2.dat”)

data11 = data1.T  
data22 = data2.T

datacomb = np.concatenate((data11, data22), axis=1)  
datacomb1 = datacomb.reshape(2, 649984)

sfreq = 250  
ch\_names = [‘eeg1’, ‘eeg2’]

info = mne.create\_info(ch\_names, sfreq=sfreq, ch\_types=[‘eeg’] \* 2)  
raw = mne.io.RawArray(datacomb1, info=info)  
raw.plot(scalings={‘eeg’: 20e2}, duration = 2600)

The second one is:  
data\_list =   
for i in range(2):  
data\_list.append(np.loadtxt(‘{0}\_class\_new\_2.dat’.format(i+1)))

data\_list = np.array(data\_list)  
datamain = np.stack(data\_list, axis = 0)  
datamain = np.transpose(datamain)  
datamain = datamain.reshape(2, 649984)

sfreq = 250

ch\_names = [‘eeg1’, ‘eeg2’]  
ch\_types=[‘eeg’] \* 2  
n\_channels = 2

info = mne.create\_info(n\_channels, ch\_types=ch\_types, sfreq=sfreq)  
raw = mne.io.RawArray(datamain, info=info)

raw.plot(scalings={‘eeg’: 20e2}, duration = 2600)

---

<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:** [March 4, 2024, 5:48am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/4 "2024-03-04T05:48:11Z")

</div>

This looks alright, but why are you doing `datacomb1 = datacomb.reshape(2, 649984)`? The concatenated data should already have the correct shape, because you transposed in the previous lines.

Also, why do you think the data is put into the second channel? There is some signal in the first one, although this doesn’t look like EEG.

Can you try creating two separate raw objects just to see if they look correct?

---

<div class="post-metadata">

**Author:** ![averinkit](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/averinkit/32/2562_2.png) [@averinkit](https://mne.discourse.group/u/averinkit)\
**Post date:** [March 4, 2024, 7:14am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/5 "2024-03-04T07:14:05Z")

</div>

I tried to create separate raws, first file worked, but with the second I got strange error  
“TypeError: **init** () got an unexpected keyword argument ‘data1’”  
The code I used:  
data = np.loadtxt(“1\_class\_new\_2.dat”)  
data = data.T

times = data[0]  
values = data[1]  
sfreq = 250  
info = mne.create\_info([‘channel 1’], sfreq=sfreq, ch\_types=[‘eeg’])  
raw = mne.io.RawArray(data=np.atleast\_2d(values), info=info)

raw.plot(scalings={‘eeg’: 20e2}, duration = 2120)

 ![загрузка](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/4/410323b1a589f1b8f6f23c1e386efd95b5f24bb9.png)  
Code for the second one:  
data1 = np.loadtxt(“2\_class\_new\_2.dat”)  
data1 = data.T

times1 = data1[0]  
values1 = data1[1]  
sfreq1 = 250

info1 = mne.create\_info([‘channel 2’], sfreq=sfreq1, ch\_types=[‘eeg’])  
raw1 = mne.io.RawArray(data1=np.atleast\_2d(values1), info=info1)  
raw1.plot(scalings={‘eeg’: 20e2}, duration = 2120)

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [March 4, 2024, 7:19am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/6 "2024-03-04T07:19:31Z")

</div>

> [@averinkit](#):
>
> raw1 = mne.io.RawArray(data1=np.atleast\_2d(values1), info=info1)

This must be `data=`, not `data1=`.

---

<div class="post-metadata">

**Author:** ![averinkit](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/averinkit/32/2562_2.png) [@averinkit](https://mne.discourse.group/u/averinkit)\
**Post date:** [March 4, 2024, 7:33am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/7 "2024-03-04T07:33:56Z")

</div>

Hello,  
It really worked. Can you tell me why data= should be substituted in raw1? I thought we are working with data1.  
And also, I would like to know how to combine these two signals into a single raw, so that they are in different channels. I have other files that need to be used as well

 ![загрузка](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/b/b258753d3ff80b4c14cc4a4bc44a6c8bbb552a3f.png)

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [March 4, 2024, 8:11am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/8 "2024-03-04T08:11:36Z")

</div>

> [@averinkit](#):
>
> Can you tell me why data= should be substituted in raw1?

The **parameter** name is `data`. Your **variable** name is `data1`. To pass your **variable** to the function, you need to write `data=data1`. The function doesn’t know any **parameter** with the name `data1`.

---

<div class="post-metadata">

**Author:** ![averinkit](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/averinkit/32/2562_2.png) [@averinkit](https://mne.discourse.group/u/averinkit)\
**Post date:** [March 4, 2024, 9:57am UTC](https://mne.discourse.group/t/raw-object-interprets-data-incorrectly/8415/9 "2024-03-04T09:57:06Z")

</div>

Thanks, but the last question remains the same: is there any way to somehow merge multiple raws into one, so that the first signal is in the first channel, etc. So that we can then place events and further process the whole data, rather than working with only one of the channels in the end.  
The mne.io.concatenate\_raws doesn’t work in the same sense I have in mind either.

 ![загрузка (1)](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/2/22813780be2a0c7f207641c286a0934c87becef2.png)
