So, I’ve calculated the leadfield matrix for 24 electrodes, by using the mne documentation for forward model computation. I first got the montage for 24 electrodes and then, followed the forward model method and obtained the leadfield matrix.
I’m not sure if the method is correct as I’ve used the sample directory in the MNE library to generate it. How do I check if its correct?
from mne.datasets import sample
data_path = sample.data_path()
# Set the SUBJECTS_DIR to the MNE sample data directory
os.environ['SUBJECTS_DIR'] = os.path.join(data_path, 'subjects')
# Load a standard montage (e.g., standard_1020)
montage = mne.channels.make_standard_montage('standard_1020')
# Check the names of the electrodes in the montage
print(montage.ch_names)
# Select the electrodes (this case: first 24 electrodes)
# Adjust as needed !!!
selected_electrodes = montage.ch_names[:24]
# Create a new info object with only the selected electrodes
info = mne.create_info(ch_names=selected_electrodes, sfreq=256, ch_types='eeg')
# Set the montage to the info object
info.set_montage(montage)
# Create a source space
# Here, we use a standard source space for the sample subject
src = mne.setup_source_space('sample', spacing='oct6', add_dist=False)
# Define the conductivity for the BEM model
# For EEG we use 3 layers (inner skull, outer skull, and skin)
conductivity = (0.3, 0.006, 0.3) # 3 layers for EEG (Ref: https://mne.tools/1.8/auto_tutorials/forward/30_forward.html)
# Create the BEM model
model = mne.make_bem_model(subject='sample', ico=4, conductivity=conductivity)
# Create the BEM solution
bem = mne.make_bem_solution(model)
# the raw file containing the channel location + types
sample_dir = data_path / "MEG" / "sample"
# The transformation file obtained by coregistration
trans = sample_dir / "sample_audvis_raw-trans.fif"
# Create the forward solution
fwd = mne.make_forward_solution(info, trans, src=src, bem=bem, eeg=True)
# The leadfield matrix is contained in fwd['sol']['data']
leadfield_matrix = fwd['sol']['data']