Beauchamp:Reconstruction and Electrode Labeling (UPenn)

From OpenWetWare
Jump to navigationJump to search
Brain picture
Beauchamp Lab

Reconstruction and Electrode Labeling (UPenn)

Once you've received confirmation (usually from Everett) that data (T1, electrode sheets) are available in the shared BOX folder ("CNT Implant Reconstructions"), you can download data the necessary data for subject brain reconstruction, and for creating an electrode labeling file with coordinates that RAVE can use.

Files needed to download from the BOX folder

Connect to BOX folder "CNT Implant Reconstructions" (a folder shared by UPenn clinicians for patient scans), you may need your UPenn Key + pwd for login.

You will need to download:




electrodelabels.csv (optional, for double checking)

After downloading, move these files to the rave directory: /Volumes/data/rave_data

T1 Reconstruction

Open a terminal, and navigate to the subject folder in rave directory. Each subject has a RID code that was assigned by UPenn, for example, subject HUP213 was assigned as RID649:

 cd /Volumes/data/rave_data/${subj}/localization
 set subj = XX
 setenv SUBJECTS_DIR `pwd`

Unzip the T1_MPRAGE file by double clicking the file "T00_RID${subj}_mprage.nii.gz"

Reconstruction in freesurfer:

 recon-all -all -parallel -subject fs -i ./T00_RIDXXX_mprage.nii 

Freesurfer will complete the reconstruction

Creating Electrode Labeling File

The electrode labeling file (electrodes.csv) is required for RAVE to localize the electrodes (channels). Make sure the coordinates are in T1 space (NOT MNI, or other spaces):

This is how you make electrodes.csv:

 copy the first THREE columns from "electrode_coordinates_T1.csv" (they are the coordinates in T1 space: Coord_x;Coord_y;Coord_z);
 copy the first TWO columns from "electrodenames_coordinates_native_and_T1.csv" (they are the Label; FreeSurferLabel for each channel);
 Copy the numbering label from "electrodenames_coordinates_native_and_T1.csv"--Column G or H (this is the 'Electrode' numbers);

This will create an electrodes.csv file with the following columns: Electrode; Coord_x; Coord_y; Coord_z; Label; FreeSurferLabel

To finish up this file, fill all the blank rows in the 'FreeSurferLabel' column with 'OOB' (standing for 'out of brain').

Save this electrodes.csv in /Volumes/data/rave_data/${subj}/localization.

This file will need to be copied into the pre-processed subject folder (usually it's under a project folder), for example, it should be in:


This shows that electrodes.csv is in subject HUP211 pre-processed RAVE folder, and this subject belongs to the 'MaskedSpeech' project.

Converting coordinates from T1 space to fs space usind RAVE

In R, type in the following commands:

 b <- rave::rave_brain2('EMU_NoisyWords/$subj')

'EMU_NoisyWords' is the project name, insert the subject name here as needed

 els <- as.matrix(b$electrodes$raw_table[,2:4])
 b$Torig %*% solve(b$Norig) %*% rbind(t(els), 1) %>% t %>% write.csv(file='~/Desktop/els.csv')