# Epochs.compute\_psd doesn't working

**URL:** <https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990>\
**Category:** Support & Discussions\
**Tags:** eeg, epochs\
**Created:** [November 24, 2022, 6:14pm UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990 "2022-11-24T18:14:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rookiecookie](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rookiecookie](https://mne.discourse.group/u/rookiecookie)\
**Post date:** [November 24, 2022, 6:14pm UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990/1 "2022-11-24T18:14:03Z")

</div>

Hello,  
Now I’m using compute\_psd method according to this tutorial [Sleep stage classification from polysomnography (PSG) data — MNE 1.6.0 documentation](https://mne.tools/stable/auto_tutorials/clinical/60_sleep.html#sphx-glr-auto-tutorials-clinical-60-sleep-py)

And when I’m using compute\_psd, an error will occur like this

> AttributeError: ‘Epochs’ object has no attribute ‘compute\_psd’

However, I have tested ‘plot\_psd’ method, and it works fine for me.

Can you please advice how to fix this thing? Thank you so much 😃

```python
folder = mne.datasets.sample.data_path()
file = os.path.join(folder, 'MEG', 'sample', 'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(file, preload=True)
samf = raw.info['sfreq']

para = dict(order=3, ftype='butter', output='sos')
h_para = mne.filter.construct_iir_filter(para, f_pass=0.3, sfreq=samf, btype='high', return_copy=False)
l_para = mne.filter.construct_iir_filter(para, f_pass=35.0, sfreq=samf, btype='low', return_copy=False)
high = raw.filter(l_freq=0.3, h_freq=None, picks=None, method='iir', iir_params=h_para)
low = high.filter(l_freq=None, h_freq=35.0, picks=None, method='iir', iir_params=l_para)

n_para = mne.filter.construct_iir_filter(para, f_stop=50.0, sfreq=samf, btype='bandstop', return_copy=False)
fil = low.notch_filter(freqs=50.0, method='iir')
epochs = mne.make_fixed_length_epochs(fil, duration=30.0, overlap=1)

def eeg_power_band(epochs):
    # specific frequency bands
    FREQ_BANDS = {"delta": [0.5, 4.5],
                  "theta": [4.5, 8.5],
                  "alpha": [8.5, 11.5],
                  "sigma": [11.5, 15.5],
                  "beta": [15.5, 30]}

    spectrum = epochs.compute_psd(picks='eeg', fmin=0.5, fmax=30.)
    psds, freqs = spectrum.get_data(return_freqs=True)
    # Normalize the PSDs
    psds /= np.sum(psds, axis=-1, keepdims=True)

    X = []
    for fmin, fmax in FREQ_BANDS.values():
        psds_band = psds[:, :, (freqs >= fmin) & (freqs < fmax)].mean(axis=-1)
        X.append(psds_band.reshape(len(psds), -1))

    return np.concatenate(X, axis=1)

power = eeg_power_band(epochs)
plt.plot(power)
plt.show()

```

Platform: Windows 10 Home 64-bit  
Python: 3.9.10  
MNE: 1.2.2

---

<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:** [November 24, 2022, 7:58pm UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990/2 "2022-11-24T19:58:54Z")

</div>

Hi,

> [@rookiecookie](#):
>
> AttributeError: ‘Epochs’ object has no attribute ‘compute\_psd’

This indicates that you’re not actually running MNE 1.2 (which is the version that introduced this functionality). You can check the output of

```python
import mne 
mne.sys_info()

```

to get version information,

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![rookiecookie](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rookiecookie](https://mne.discourse.group/u/rookiecookie)\
**Post date:** [November 24, 2022, 8:34pm UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990/3 "2022-11-24T20:34:45Z")

</div>

Hi,  
Thank you for the answer.  
I have already updated MNE by using `pip install -U mne` but when I’m check the version by using `mne.sys_info` it shows 1.1.0.  
And when I’m using pip list to check the version, it shows mne version 1.2.2

How could I fix this?  
Thank you

---

<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:** [November 24, 2022, 8:39pm UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990/4 "2022-11-24T20:39:42Z")

</div>

I don’t know, sounds like some confusion between virtual environments … you should check you’re updating & running MNE from the same virtual environment.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [January 11, 2023, 11:34am UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990/5 "2023-01-11T11:34:25Z")

</div>

Hi @richard

I’ve the same problem (“AttributeError: ‘Epochs’ object has no attribute ‘compute\_psd’”) even if my version is the 1.3.0

here the log:

```python
mne: 1.3.0
numpy: 1.19.3 {OpenBLAS 0.3.12 with 8 threads}
scipy: 1.6.1
matplotlib: 3.4.2 {backend=Qt5Agg}

sklearn: 0.24.1
numba: Not found
nibabel: Not found
nilearn: Not found
dipy: Not found

cupy: Not found
pandas: 1.2.3
pyvista: Not found
pyvistaqt: Not found
ipyvtklink: Not found
vtk: Not found
qtpy: Not found
ipympl: Not found
pyqtgraph: Not found
pooch: v1.6.0

mne_bids: Not found
mne_nirs: Not found
mne_features: Not found
mne_qt_browser: Not found
mne_connectivity: Not found
mne_icalabel: Not found

```

Some idea to fix the issue? thanks in advance

---

<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:** [January 11, 2023, 12:19pm UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990/6 "2023-01-11T12:19:03Z")

</div>

Hello @BaggioMarco, are you absolutely sure the MNE you’re using to run your script is actually the same that produces the output you shared? How do you run your script? Could you add to your script:

```python
import mne
print(mne. __version__ )

```

and see which version number is being printed?

---

<div class="post-metadata">

**Author:** ![BaggioMarco](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/baggiomarco/32/190_2.png) [@BaggioMarco](https://mne.discourse.group/u/BaggioMarco)\
**Post date:** [January 11, 2023, 12:24pm UTC](https://mne.discourse.group/t/epochs-compute-psd-doesnt-working/5990/7 "2023-01-11T12:24:32Z")

</div>

@richard after unistalling and reinstalling 3 times finally I have the method 😉 I don’t know what was happening
