# HOW USE MNE RAW WITH YASA TO GENERATE SPECTOGRAMS. Just in case it can help anyone.

**URL:** https://mne.discourse.group/t/how-use-mne-raw-with-yasa-to-generate-spectograms-just-in-case-it-can-help-anyone/3999
**Category:** Support & Discussions
**Tags:** time-frequency
**Created:** [November 21, 2021, 7:08pm UTC](https://mne.discourse.group/t/how-use-mne-raw-with-yasa-to-generate-spectograms-just-in-case-it-can-help-anyone/3999 "2021-11-21T19:08:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![PauloKanda](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/paulokanda/32/642_2.png) [@PauloKanda](https://mne.discourse.group/u/PauloKanda)
#### Post date: [November 21, 2021, 7:08pm UTC](https://mne.discourse.group/t/how-use-mne-raw-with-yasa-to-generate-spectograms-just-in-case-it-can-help-anyone/3999/1 "2021-11-21T19:08:32Z")

</div>

I was having a dificult time in:

[Bandpower of an EEG signal](https://raphaelvallat.com/bandpower.html).

I was trying to use an mne EDf to get power spectrum, as in the tutorial but it returns an error

```python
data = raw.get_data()
Define sampling frequency and time vector
sf = 100.
time = np.arange(data.size) / sf
Plot the signal

fig, ax = plt.subplots(1, 1, figsize=(12, 4))
plt.plot(time, data, lw=1.5, color='k')
plt.xlabel('Time (seconds)')
plt.ylabel('Voltage')
plt.xlim([time.min(), time.max()])
plt.title('N3 sleep EEG data (F3)')
sns.despine()

```

AttributeError: ‘RawEDF’ object has no attribute ‘get’  
my mne raw file is a edf file and data = raw.get\_data() doesnot work:  
ValueError: x and y must have same first dimension, but have shapes (1616000,) and (20, 80800)

```python
---------------------

> data = raw.get_data()

doesnot work because :

(1) Yasa works with 1 EEG channel in numpy array format not mne forma. As it is said in:

https://raphaelvallat.com/yasa/build/html/_modules/yasa/plotting.html

```

quote:

def plot\_spectrogram(data, sf, hypno=None, …

```
 data : :py:class:`numpy.ndarray`
    Single-channel EEG data. Must be a 1D NumPy array.

```

(2) my mne raw EEG is a 20 channels signal and as is said in the tutorial  
(3) data must be Single-channel EEG data and Must be a 1D NumPy array.

How to solve this problem?

Lets use mne raw EEG from edf to build spectogram:

sample\_data\_raw\_file = ‘C:\000\_tmp\00000034\_s001\_t002.edf’  
raw = mne.io.read\_raw\_edf(sample\_data\_raw\_file, preload=True, verbose=False)

raw\_temp = raw.copy()  
raw\_temp.pick\_channels([‘O1’]) #getting 1 channel (mne raw format)

data3d = raw\_temp.get\_data() #transform to 3D np array (we need 1d)(np format)

data1d = data3d.flatten() #transform to 1D np array:

now it will work:

sf = 100.  
time = np.arange(data1d.size) / sf

Plot the signal:

fig, ax = plt.subplots(1, 1, figsize=(12, 4))  
plt.plot(time, data1d, lw=1.5, color=‘k’)  
plt.xlabel(‘Time (seconds)’)  
plt.ylabel(‘Voltage’)  
plt.xlim([time.min(), time.max()])  
plt.title(‘N3 sleep EEG data (F3)’)  
sns.despine()  
print(data1d)

The “catch” is to get just 1 raw channel convert to np3D and finally np1D before trying to plot.

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/2e694d4fbdefd9b0fd96b3277708bcd8caf4d747.png)
