Scripts for data processing for “Enhancing Transcranial Ultrasound Stimulation Planning with MRI-Derived Skull Masks: A Comparative Analysis with CT-based processing”
This collection includes the scripts and steps required to reproduce the analyses presented in the publication Zadeh et al. 2024, Enhancing Transcranial Ultrasound Stimulation Planning with MRI-Derived Skull Masks: A Comparative Analysis with CT-based processing, DOI:10.1088/1741-2552/adab22. Below is a detailed description of each file and the procedure to execute the analyses.
- The repository contains the following scripts to reproduce the results.
0_eeg_normals.py
: Generates EEG normal trajectories for each location.1_BabelBrain_All_Conditions.ipynb
: Runs ultrasound simulations for MRI-based and CT-based processing.2_TemplateCalcStats.ipynb
: Calculates pressure metrics and area statistics.3_Dice_Coeff.ipynb
: Computes Dice coefficients for simulations.SELECTED_EEG.csv
: Contains selected EEG locations for analysis. Note: Specific locations (e.g., Fp1, Fp2, Fpz) were excluded due to complications such as passage through air-filled structures, proximity to the ear, or defacing issues, leaving 54 locations for analysis.- MRI and CT data: Defaced data can be downloaded from https://doi.org/10.5281/zenodo.7894431, please take note of the paths.
- The directory MRI_Custom_Settings contains the improved atlas and settings for a better skull segmentation with CHARM.
Verify you have the minimum hardware requirements to run BabelBrain
Use installer for v4.1.0 version. Take note of SimNIBS path; for example,/Users/john/Applications//SimNIBS-4.1
Clone source code from https://github.com/ProteusMRIgHIFU/BabelBrain. While the latest version should be compatible with the scripts, we recommend using version 0.3.5 to ensure the reproducibility of the results in the manuscript. You can do a checkout of the tag 0.3.5
to select the version.
Create a conda environment using the most appropriate YAML file for your computer type; for example, use environment_mac_arm64-39.yml
for macOS with an Apple Silicon processor.
After downloading the MRI and CT data, delete the included directories of previous calculations with the CHARM tool as they were produced with version 4.0.0 of the tool. The directories to delete have the prefix m2m
, for example m2m_SDR0p55
. Process the T1- and T2-weighted scans using the CHARM tool in SimNIBS 4.1 to generate the m2m folder for each participant. Follow these steps:
Run the following command:
charm <id> T1.nii.gz T2.nii.gz –forceqform
The custom CHARM FAT atlas files are in the directory MRI_Custom_Settings
<path_to_simnibs>/simnibs/segmentation/atlases/
Download settings_fat.ini
and shared_gmm_fat.txt
and place them together in a directory.
charm <subid> T1.nii.gz T2.nii.gz --usesettings <path_to_settings_fat.ini> --noneck –forceqform
Run 0_eeg_normals.py
script with a conda environment based on SimNIBS specifying the paths to the SimNIBS output for the dataset. For example
conda activate <path_to_simnibs>/simnibs_env/
python 0_eeg_normals.py ~/Documents/TempForSim/SDR_0p42/m2m_SDR_0p42/SDR_0p42.msh ~/Documents/TempForSim/SDR_0p42/m2m_SDR_0p42/eeg_positions/EEG10-10_Neuroelectrics.csv SDR_0p42_eeg_normals.csv
This generates normal trajectories for each EEG location and participant. Run this for each of the 5 datasets.
Open 1_BabelBrain_All_Conditions.ipynb
:
- Update the “Additions to path” section with the path to the BabelBrain v0.3.5 folder.
- Run the notebook to perform simulations for MRI-based and CT-based processing at frequencies of 250, 500, and 750 kHz.
In 2_TemplateCalcStats.ipynb
:
- Update the following parameters:
inputcsv
: Path to the trajectory file (e.g., SDR_0p55_eeg_normals.csv).BasePath
: Path to the m2m folder generated using CHARM.T1W
: Path to the T1-weighted image.Frequency
andPPW
(e.g., 500 kHz, PPW=6).
- Run the notebook to calculate:
- Maximum Pressure
- Area Size
- Centroid coordinates (0, 1, 2)
- Outputs are saved in an Excel file
In 3_Dice_Coeff.ipynb
:
- Specify the paths to the BabelBrain folder and the BasePath for the participant.
- Adjust the frequency and PPW settings (e.g., 500 kHz, PPW=6).
- Run the notebook to compute Dice coefficients between MRI-based and CT-based simulations.