Hi,
A follow up question to my previous one. I want to compute the covariance using mne.compute_covariance using the code snippets below
import numpy as np
import mne
import os.path as op
from mne.datasets import eegbci, fetch_fsaverage
from mne.minimum_norm import apply_inverse, make_inverse_operator
data = np.random.rand(24,251) #Toy-data
# Download fsaverage files
fs_dir = fetch_fsaverage(verbose=True)
subjects_dir = op.dirname(fs_dir)
# The files live in:
subject = "fsaverage"
trans = "fsaverage" # MNE has a built-in fsaverage transformation
src = op.join(fs_dir, "bem", "fsaverage-ico-5-src.fif")
bem = op.join(fs_dir, "bem", "fsaverage-5120-5120-5120-bem-sol.fif")
ch_names = ["Fp1", "Fp2", "F3", "F4", "C3", "C4", "P3", "P4", "O1", "O2", "F7", "F8", "T7", "T8", "P7", "P8", "Fz", "Cz", "Pz", "M1", "M2", "AFz", "CPz", "POz"]
montage = mne.channels.make_standard_montage('standard_1020')
info = mne.create_info(ch_names=ch_names, sfreq=1000, ch_types='eeg').set_montage(montage, match_case=False)
raw = mne.io.RawArray(data,info)
raw.set_eeg_reference(projection=True)
# Setting up source space and compute forward
fwd = mne.make_forward_solution(raw.info, trans=trans, src=src, bem=bem, eeg=True, mindist=5.0, n_jobs=None)
eventEEG = np.array([[ 0., 0., 0.], [251., 0., 1.]], dtype=int)
baseline = (0, 0)
reject = dict(eeg=150e-6)
epochs = mne.Epochs(raw, eventEEG,event_id=None,
tmin=0,tmax=251,proj=True,picks=("eeg"),
baseline=baseline,reject=reject)
noise_cov = mne.compute_covariance(epochs, tmin=0, tmax=251,
method=["shrunk", "empirical"], rank=None, verbose=True)
# Compute the evoked response
evoked = epochs.average().pick("eeg")
evoked.plot(time_unit="s")
evoked.plot_topomap(times=np.linspace(0.05, 0.25, 5), ch_type="eeg")
The error I get says
ValueError Traceback (most recent call last) Cell In[18], line 1 ----> 1 noise_cov = mne.compute_covariance(epochs, tmin=0, tmax=251, 2 method=[“shrunk”, “empirical”], rank=None, verbose=True) File :10, in compute_covariance(epochs, keep_sample_mean, tmin, tmax, projs, method, method_params, cv, scalings, n_jobs, return_estimators, on_mismatch, rank, verbose) File [c:\Users\Starboy\AppData\Local\Programs\Python\Python312\Lib\site-packages\mne\cov.py:1157](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/mne/cov.py:1157), in compute_covariance(failed resolving arguments) [1154](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/mne/cov.py:1154) else: [1155](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/mne/cov.py:1155) epochs = epochs[0] → [1157](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/mne/cov.py:1157) epochs = np.hstack(epochs) [1158](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/mne/cov.py:1158) n_samples_tot = epochs.shape[-1] [1159](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/mne/cov.py:1159) _check_n_samples(n_samples_tot, len(picks_meeg)) File [c:\Users\Starboy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\core\shape_base.py:359](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/numpy/core/shape_base.py:359), in hstack(tup, dtype, casting) [357](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/numpy/core/shape_base.py:357) return _nx.concatenate(arrs, 0, dtype=dtype, casting=casting) [358](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/numpy/core/shape_base.py:358) else: → [359](file:///C:/Users/Starboy/AppData/Local/Programs/Python/Python312/Lib/site-packages/numpy/core/shape_base.py:359) return _nx.concatenate(arrs, 1, dtype=dtype, casting=casting)
ValueError: need at least one array to concatenate
If you comment out the noise_cov, there is also an error in the evoked response.
An explanation and solution will be appreciated. Thanks