I do have 231 channels, but I may be calling more somehow.
Code:
import mne
import pickle
import numpy as np
from lfpykit.eegmegcalc import NYHeadModel
import os
# Import head model for EEG lead locations
nyhead = NYHeadModel(nyhead_file=os.getenv('NP_LFPYKIT_HEAD_FILE', None))
# Load pkl file
file = open('/Users/scottmcelroy/A1_scz/A1_sim_data/v34_batch53_0_0_data.pkl', 'rb')
data = pickle.load(file)
# Set dipole location
nyhead.set_dipole_pos('parietal_lobe')
nyhead.find_closest_electrode()
# Convert sim data to be in EEG format
M = nyhead.get_transformation_matrix()
timeRange = [0, 5000]
timeSteps = [int(timeRange[0] / 0.05), int(timeRange[1] / 0.05)]
# Set params to be readable by MNE
sfreq = 2500
times = np.arange(0, 5000, 0.05)
ch_types = ['eeg']*231
ch_names = []
p = data['simData']['dipoleSum']
p = np.array(p).T
p = p[:, timeSteps[0]:timeSteps[1]]
t = np.arange(timeRange[0], timeRange[1], 0.05)
# Rotate dipole to head surface and convert to appropriate units
p = nyhead.rotate_dipole_to_surface_normal(p)
eeg = M @ p * 1e3 # [mV] -> [uV] unit conversion
# Set channel names
for x in range(0, 231):
ch_names = ch_names + [str(x)]
# Create raw.info for MNE
info = mne.create_info(ch_names=ch_names, sfreq=sfreq, ch_types=ch_types)
info['description'] = 'sim_data_test'
# Create MNE Raw Array
raw = mne.io.RawArray(eeg, info)
raw.load_data()
epochs=mne.EpochsArray(raw, info)
Traceback:
runfile('/Users/scottmcelroy/GitHub/EEG_schizophrenia/sim_psd.py', wdir='/Users/scottmcelroy/GitHub/EEG_schizophrenia')
Creating RawArray with float64 data, n_channels=231, n_times=1500
Range : 0 ... 1499 = 0.000 ... 0.075 secs
Ready.
Traceback (most recent call last):
File "/Users/scottmcelroy/anaconda3/envs/dev/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-46-15f331849e66>", line 1, in <module>
runfile('/Users/scottmcelroy/GitHub/EEG_schizophrenia/sim_psd.py', wdir='/Users/scottmcelroy/GitHub/EEG_schizophrenia')
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/scottmcelroy/GitHub/EEG_schizophrenia/sim_psd.py", line 65, in <module>
epochs=mne.EpochsArray(raw, info)
File "<decorator-gen-290>", line 12, in __init__
File "/Users/scottmcelroy/anaconda3/envs/dev/lib/python3.10/site-packages/mne/epochs.py", line 3261, in __init__
dtype = np.complex128 if np.any(np.iscomplex(data)) else np.float64
File "/Users/scottmcelroy/anaconda3/envs/dev/lib/python3.10/site-packages/numpy/lib/type_check.py", line 239, in iscomplex
ax = asanyarray(x)
File "/Users/scottmcelroy/anaconda3/envs/dev/lib/python3.10/site-packages/mne/io/base.py", line 834, in __getitem__
return self._getitem(item)
File "/Users/scottmcelroy/anaconda3/envs/dev/lib/python3.10/site-packages/mne/io/base.py", line 837, in _getitem
sel, start, stop = self._parse_get_set_params(item)
File "/Users/scottmcelroy/anaconda3/envs/dev/lib/python3.10/site-packages/mne/io/base.py", line 770, in _parse_get_set_params
sel = _picks_to_idx(self.info, item[0])
File "/Users/scottmcelroy/anaconda3/envs/dev/lib/python3.10/site-packages/mne/io/pick.py", line 1350, in _picks_to_idx
raise ValueError(
ValueError: All picks must be < n_channels (231), got 231