Developed by Liberty Hamilton, David Chang, Morgan Lee at the Laboratory of Dr. Edward Chang, UC San Francisco http://changlab.ucsf.edu
This contains the imaging pipeline as one importable python class for running a patient's brain surface reconstruction and electrode localization/labeling.
The full capabilities of the pipeline are described in the paper: Hamilton LS, Chang DL, Lee MB, Chang EF (2017). Semi-automated anatomical labeling and inter-subject warping of high-density intracranial recording electrodes in electrocorticography. Frontiers in Neuroinformatics 11(62).
Sample data is available on Zenodo, including an AC-PC aligned T1 scan, CT scan, and all intermediate and final files from the img_pipe processing pipeline.
img_pipe is an open source python package for preprocessing of imaging data for use in intracranial electrocorticography (ECoG) and intracranial stereo-EEG analyses. This python package aims to provide a standardized interface for electrode localization, labeling, and warping to an atlas, as well as code to plot and display results on 3D cortical surface meshes. It gives the user an easy interface to create anatomically labeled electrodes that can also be warped to an atlas brain, starting with only a preoperative T1 MRI scan and a postoperative CT scan.
Example results are shown below in the native subject space (left) and in the cvs_avg35_inMNI152 atlas space (right):
Setup and Installation
To download this package, you will need:
- a MacOS or Linux machine (if you are using Windows, download a Linux Virtual Machine to use this package)
- anaconda for Python version 2.7 or 3 (https://www.continuum.io/downloads)
- Freesurfer (https://surfer.nmr.mgh.harvard.edu/fswiki/DownloadAndInstall) version 5.3.0 or higher
After you download and install those dependencies, run the following commands in your terminal if using Python 2.7:
$ git clone https://github.com/changlabucsf/img_pipe $ conda env create -f img_pipe/environment_py27.yml $ source activate img_pipe_py2 $ ipython $ import img_pipe
The following instructions should be used if you wish to work in Python 3:
$ git clone https://github.com/changlabucsf/img_pipe $ conda env create -f img_pipe/environment_py35.yml $ source activate img_pipe_py3 $ ipython $ from img_pipe import img_pipe
After that, edit your ~/.bash_profile or ~/.bashrc and set the following environment variables with these lines:
export SUBJECTS_DIR=/path/to/freesurfer/subjects export FREESURFER_HOME=/path/to/freesurfer/ source $FREESURFER_HOME/SetUpFreeSurfer.sh
Note that you can set
SUBJECTS_DIR to wherever you want to place your subjects' imaging data - for example,
Then in terminal, run
source ~/.bash_profile or
source ~/.bashrc to activate these environment variables.
img_pipe, you will need a high quality non-contrast T1 scan and a non-contrast CT scan. The T1 scan should ideally be
AC-PC aligned before you start. Name the T1 scan T1.nii and place in
$SUBJECTS_DIR/your_subj/acpc. Name the CT scan CT.nii
and place in
You should now be able to import img_pipe from python.
>>> import img_pipe # Or in python 3, from img_pipe import img_pipe >>> patient = img_pipe.freeCoG(subj='subject_name', hem='lh') >>> patient.prep_recon() >>> patient.get_recon()
If you have completed all of the steps, you can plot the brain with anatomically-labeled electrodes as follows:
>>> import img_pipe >>> patient = img_pipe.freeCoG(subj='subject_name', hem='lh') >>> patient.plot_recon_anatomy()
Or just the brain with
The full workflow is shown as a flowchart below:
In addition to localization, labeling, and warping of electrodes,
img_pipe includes some nice plotting functions for visualizing your data. You can plot cortical and subcortical ROIs with different surface properties (opacity, color, specularity, etc) and you can plot electrodes either as spheres or as gaussian blobs on the cortical surface. Electrodes can be colored individually or all the same color. If you prefer to work in 2D (using matplotlib), there is a function
patient.auto_2D_brain() that will create a brain image and corresponding projected 2D coordinates for even more flexibility (and some added speed since it avoids 3D rendering).
All of these images should be created after initializing the patient (as below).
>>> import img_pipe >>> patient = img_pipe.freeCoG(subj='subj_ID', hem='lh')
If you find any bugs, please post in the Issues tab.