Hi everyone,
I have scanned the positions of my electrodes using a 3D scan like the one use in fieldtrip (Localizing electrodes using a 3D-scanner - FieldTrip toolbox). As it is described in that tutorial, the coordinate system in which my electrode positions are after is the CTF system. Now, what I have done, is import the locations into mne and using the code you see below, to add the positions to my raw data. After that, I have used the fig = mne.viz.plot_alignment(ā¦) to align it to the fsaverage, since I have the individual EEG positions but not the individual MRI. However, what I donāt understand or I donāt know how to do, is how can I now save the āalignedā positions to my raw dataset. Are these already saved but not applied? I want to do this, before I continue with my preprocessing (next step is ICA), since afterwards, we will perform source reconstruction.
Load the json file
with open(pathOut + fā{partID}/ā + fāsub-{participant}_positionElectrodes_NEW_fiducials.jsonā) as f:
mat_file = json.load(f)
factorUnits = 1000 # Convert mm to m
elecpos_data = np.array(mat_file[āelecposā]).reshape(67,3) / factorUnits
Ensure channel names match those in the raw data
ch_names = mat_file[ālabelā]
Create a dictionary with channel names as keys and 3D coordinates as values
channel_positions = {ch_names[i]: elecpos_data[i] for i in range(len(ch_names))}
#Find indices for the fiducial points
nas = channel_positions[ānasā]
lpa = channel_positions[ālpaā]
rpa = channel_positions[ārpaā]
#%% Montage creation and alignment
Create a new montage with the rotated positions
montage = mne.channels.make_dig_montage(ch_pos=channel_positions, nasion=nas, lpa=lpa, rpa=rpa)
raw.set_montage(montage)
raw.set_eeg_reference(projection=True) # needed for inverse modeling
#SECOND PART CODE
Step 1: Download and set the fsaverage template MRI
subject = āfsaverageā
subjects_dir = rāC:\Users\HuertasPenenS\mne_data\MNE-fsaverage-dataā
src = rāC:\Users\HuertasPenenS\mne_data\MNE-fsaverage-data\fsaverage\bem\fsaverage-ico-5-src.fifā
Load transformation matrix
trans = rāC:\Users\HuertasPenenS\mne_data\MNE-fsaverage-data\fsaverage\bem\fsaverage-trans.fifā
Step 4: Plot the alignment (head surface and EEG electrodes)
fig = mne.viz.plot_alignment(
raw.info,
subject=subject,
subjects_dir=subjects_dir,
src = src,
surfaces=[āheadā], # Plot the head surface
coord_frame=āmriā, # Use MRI coordinate frame
eeg=[āoriginalā,āprojectedā], # Plot EEG electrodes
trans=trans, # Use the identity transformation matrix
show_axes=True,
mri_fiducials=True,
dig=āfiducialsā,
)
MNE VERSION: 1.7.1
WINDOWS: 11