txusser / simpet

SimPET is a framework intended to setup and launch PET imaging Monte Carlo simulations on a simple way. It uses popular tools such as SimSET and STIR
8 stars 8 forks source link
medical monte-carlo-simulation positron-emission-tomography

Logo


Project

The SIMPET project is intended to allow to setup and launch MC simulation on a simple way. It provides functionalities to:

Installtion

  1. Install Git LFS.
  2. Clone the repository by adding the --recurse-submodules flag:
    git clone --recurse-submodules --branch develop https://github.com/txusser/simpet.git
  3. Install python 3.9. If you use apt (most Debian based distros use it):
    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt install python3.9
  4. Create a python virtual environment from python 3.9, there are several options for this (we recommend Conda):

You can isntall miniconda in Linux with the following code:

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh

Then restart your shell:

~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
  1. Activate the virtual environment and install the requirements with:

    pip install -r requirements.txt

    Sometimes, even activating the virtual environemnt, the shell will use the wide system pip, you can check it with which pip (in Linux). In that case, you may want to locate the python interpreter of your virtual environment or an alias (most of the times python3.9) then run:

    /path/to/your/virtual-environtment/bin/python3.9 -m pip install -r requirements.txt
  2. Install the project with (we recommend to be an user with root privileges):

    make install
  3. Decompress dummy data with:

    make dummy-data
  4. Activate your virtual environment and run a test with the simulation launcher:

    python3.9 scripts/experiment.py

Usage

To make the most of this version of the project is strongly recommended to be familiar with facebook-hydra. The configuration of a given simulation (and reconstruction) is split into 3 groups: global configuration, params, configuration and scanner configuration (examples given below). The scanner group is a subgroup of params group and params is a subgroup of the global configuration.

This approach allows the user to have several configuration groups and switch between them at no cost. For example, given the following tree of configurations (each subgroup has a "production" configuration and a "test" configuration):

.
└── configs/
    ├── config_prod.yaml  # global configuration group
    ├── config_test.yaml  # global configuration group
    └── params/
        ├── params_prod.yaml
        ├── params_test.yaml
        └── scanner/
            ├── siemens.yaml
            └── discovery.yaml

Using facebook-hydra override syntax and the experiment.py launcher, switching between configurations is trivial:

# Running test configuration with Siemens scanner
python scripts/experiment.py --config-name config_test params/scanner=siemens
# Running prod configuration with test `params` and Discovery scanner
python scripts/experiment.py --config-name config_prod params=params_test params/scanner=discovery
# Running prod configuration with test `params` and Discovery scanner but doing only reconstruction
python scripts/experiment.py --config-name config_prod params=params_test params/scanner=discovery params.do_simulation=0
# Running prod configuration with test `params` and Discovery scanner, doing only reconstruction and overriding the scanner radius
python scripts/experiment.py --config-name config_prod params=params_test params/scanner=discovery params.do_simulation=0 params.scanner.scanner_radius=35

Whole Body Simulation

You can perform whole body simulations following the same logic described in the last section. You may want to add z_min and z_max parameters to the params configuration group. Here you can find the configuration templates:

Then you can launch an experiment with the experiment_wholebody.py launcher:

python3.9 scripts/experiment_wholebody.py --config-name <your_config_name>

Even add z_min and z_max on the fly:

python3.9 scripts/experiment_wholebody.py --config-name <your_config_name> +params.z_min=29 +params.z_max=89

Or override them:

python3.9 scripts/experiment_wholebody.py --config-name <your_config_name> params.z_min=29 params.z_max=89

BrainVISET

BrainVISET is an iterative algorithm that allows the generation of activity and attenuation maps from high-resolution CT and MRI images. To run BrainVISET you will need SPM12 and MATLAB MCR. Ensure that the configuration keys matlab_mcr_path (path to MATLAB MCR) and spm_path (path to SPM12) are well set in your configs file. In addition, you must also specify the names (with extension) of the CT, MRI and PET images in your configs/params file (keys ct_image, mri_image and pet_image). Then, you can run BrainVISET using the experiment_brainviset.py launcher:

python3.9 scripts/experiment_brainviset.py --config-name <your_config_name>

Even change image names on the fly (or other parameters):

python3.9 scripts/experiment_brainviset.py --config-name <your_config_name> params.ct_image="my_ct.nii" params.mri_image="my_mri.nii" params.pet_image="my_pet.nii"

GENERAL NOTES ON USAGE:

Parameters documentation

File under configs directory

Directories

Interactive mode

SimSET base configuration

See SimSET documentation for further information.

File under configs/params directory

Simulation time and environment

Run parameters

PET system

Input and output directories

Single simulation variables

Whole body simulation variables

BrainVISET variables

SimSET Parameters (not used by STIR sim)

File under configs/params/scanner directory

Scanner Description

Crystal description

Energy characteristics

Sinogram creation

Binning

Coincidence window (ns)

Sinogram pre-processing

Corrections

Attenuation correction

Scatter Correction

Randoms Correction

Reconstruction

Configuration of reconstruction output

Filter

Contributors

References

You may find more information about STIR and SimSET parameters in their official documentation.

[1] SimSET.

[2] STIR.