mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.67k stars 1.31k forks source link

AttributeError: 'RawEEGLAB' object has no attribute 'nave' #8093

Closed MSA8D8 closed 4 years ago

MSA8D8 commented 4 years ago

Describe the bug

I am faced with the error message as you see in the title when I tried to run the source localization script I made below.

The preprocessing to remove the noise with ICA was done by Matlab before running this script.

The EEG headset is Quick 30 made by Cognionics.

Thank you in advance.

Steps to reproduce

I attached here the script I run.

# coding:utf-8
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import mne
from mne.minimum_norm import make_inverse_operator, apply_inverse
from mne.datasets import fetch_fsaverage

fs_dir = fetch_fsaverage()
subjects_dir = os.path.dirname(fs_dir)
subject = 'fsaverage'
trans = 'fsaverage'
src = os.path.join(fs_dir, 'bem', 'fsaverage-ico-5-src.fif')
bem = os.path.join(fs_dir, 'bem', 'fsaverage-5120-5120-5120-bem-sol.fif')

script_path = os.path.abspath('./Python/EEG_analysis')
data_path = os.path.abspath('./sasakidata/output_rest')
raw = mne.io.read_raw_eeglab(data_path + '/2020-6-10/asrnc/rest1_f2t30_ave_ref_asrnc_interp_averef_ica_dipole_icbrain.set', preload=True)
raw = raw.crop(tmin = 5, tmax = 305)
raw.set_montage('standard_1020')
raw.set_eeg_reference(ref_channels = 'average', projection = 'True')
raw.info

fwd = mne.make_forward_solution(raw.info, trans=trans, src=src, bem=bem, eeg=True, mindist=5.0, n_jobs=1)
print(fwd)

noise_cov = mne.compute_raw_covariance(raw)
#mne.viz.plot_cov(noise_cov, raw.info)

inverse_operator = make_inverse_operator(raw.info, fwd, noise_cov, loose = 0.2, depth = 0.8)

stc = apply_inverse(raw, inverse_operator, verbose=True)
brain = stc.plot()

Expected results

The source localization results can be seen from another window or something like that.

Actual results

0 files missing from /Users/masarusasaki/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/mne/datasets/_fsaverage/root.txt in /Users/masarusasaki/mne_data/MNE-fsaverage-data
0 files missing from /Users/masarusasaki/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/mne/datasets/_fsaverage/bem.txt in /Users/masarusasaki/mne_data/MNE-fsaverage-data/fsaverage
Reading /Users/masarusasaki/Documents/GitHub/Script/sasakidata/output_rest/2020-6-10/asrnc/rest1_f2t30_ave_ref_asrnc_interp_averef_ica_dipole_icbrain.fdt
Reading 0 ... 154623  =      0.000 ...   309.246 secs...
Adding average EEG reference projection.
1 projection items deactivated
Average reference projection was added, but has not been applied yet. Use the apply_proj method to apply it.
Source space          : /Users/masarusasaki/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-ico-5-src.fif
MRI -> head transform : /Users/masarusasaki/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/mne/data/fsaverage/fsaverage-trans.fif
Measurement data      : instance of Info
Conductor model   : /Users/masarusasaki/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-5120-5120-5120-bem-sol.fif
Accurate field computations
Do computations in head coordinates
Free source orientations

Reading /Users/masarusasaki/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-ico-5-src.fif...
Read 2 source spaces a total of 20484 active source locations
Coordinate transformation: MRI (surface RAS) -> head
     0.999994  0.003552  0.000202      -1.76 mm
    -0.003558  0.998389  0.056626      31.09 mm
    -0.000001 -0.056626  0.998395      39.60 mm
     0.000000  0.000000  0.000000       1.00

Read  29 EEG channels from info
Head coordinate coil definitions created.
Source spaces are now in head coordinates.

Setting up the BEM model using /Users/masarusasaki/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-5120-5120-5120-bem-sol.fif...

Loading surfaces...
Three-layer model surfaces loaded.

Loading the solution matrix...

Loaded linear_collocation BEM solution from /Users/masarusasaki/mne_data/MNE-fsaverage-data/fsaverage/bem/fsaverage-5120-5120-5120-bem-sol.fif
Employing the head->MRI coordinate transform with the BEM model.
BEM model fsaverage-5120-5120-5120-bem-sol.fif is now set up

Source spaces are in head coordinates.
Checking that the sources are inside the surface and at least    5.0 mm away (will take a few...)
    Skipping interior check for 2433 sources that fit inside a sphere of radius   47.7 mm
    Skipping solid angle check for 0 points using Qhull
    Skipping interior check for 2241 sources that fit inside a sphere of radius   47.7 mm
    Skipping solid angle check for 0 points using Qhull
Setting up for EEG...
Computing EEG at 20484 source locations (free orientations)...
Finished.
<Forward | MEG channels: 0 | EEG channels: 29 | Source space: Surface with 20484 vertices | Source orientation: Free>
Using up to 1500 segments
Number of samples used : 150000
[done]
Converting forward solution to surface orientation
    No patch info available. The standard source space normals will be employed in the rotation to the local surface coordinates....
    Converting to surface-based source orientations...
    [done]
Computing inverse operator with 29 channels.
    29 out of 29 channels remain after picking
Selected 29 channels
Creating the depth weighting matrix...
    29 EEG channels
    limit = 20485/20484 = 2.709372
    scale = 54673.7 exp = 0.8
Applying loose dipole orientations. Loose value of 0.2.
Whitening the forward solution.
    Created an SSP operator (subspace dimension = 1)
Computing rank from covariance with rank=None
    Using tolerance 3.3e-14 (2.2e-16 eps * 29 dim * 5.1  max singular value)
    Estimated rank (eeg): 6
    EEG: rank 6 computed from 29 data channels with 1 projector
    Setting small EEG eigenvalues to zero (without PCA)
Creating the source covariance matrix
Adjusting source covariance matrix.
Computing SVD of whitened and weighted lead field matrix.
    largest singular value = 1.90195
    scaling factor to adjust the trace = 3.18336e+18
Traceback (most recent call last):
  File "/Users/masarusasaki/Documents/GitHub/Script/Python/EEG_analysis/sloreta.py", line 49, in <module>
    stc = apply_inverse(raw, inverse_operator, verbose=True)
  File "<decorator-gen-302>", line 20, in apply_inverse
  File "/Users/masarusasaki/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/mne/minimum_norm/inverse.py", line 877, in apply_inverse
    method_params, return_residual, use_cps)
  File "/Users/masarusasaki/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/site-packages/mne/minimum_norm/inverse.py", line 891, in _apply_inverse
    nave = evoked.nave
AttributeError: 'RawEEGLAB' object has no attribute 'nave'
[Finished in 34.809s]

Additional information

I have another problem with read_raw_eeglab because this function doesn't reflect the re-reference data in Python script. So, I need to add the set_eeg_reference before computing the inverse_operator and apply_inverse function.

MSA8D8 commented 4 years ago

I can solve the problem by myself. I need to use apply_inverse_raw instead of apply_inverse. Thank you for developing this nice library!