FastPtx: a python pTx pulse design tool for freely optimizing RF and gradient pulses with autodifferentiation
Dario Bosch <[email protected]>
- Qi Wang <[email protected]>
- helped with porting the bloch simulation code from C++ to Python
- helped with pytorch support
- Alexander Loktyushin <[email protected]>
- gave valueable input on optimization with pytorch
- helped working out bugs
The following steps describe using Python Virtual Environments. If you prefer using Anaconda you can try adapting those steps. I don't see why it shouldn't work
- Open a terminal in the projects' main directory
- Create a python virtual environment:
python -m venv ./env
- Activate the environment:
source ./env/bin/activate
- Install the necessary python packages
pip install -r ./requirements.txt
- Get the example data and put it into the directory ./data/ by running the downloadFiles.sh script
./downloadFiles.sh
- open either
spyder
orjupyter lab
from the active shell - modify and run
calc_smallFA_paper.py
- the line
dev = torch.device('cuda')
sets the calculation to happen on a GPU. If you don't have a CUDA-enabled GPU, set it tocpu
instead. do_UP = False
switches between tailored and universal pulses- Flip angle, pulse duration, etc can also be controlled by changing the settings in the beginning of the file.
- Run by either executing the
calc_smallFA_paper.ipynb
notebook in jupyter or by running thecalc_smallFA_paper.py
script directly
- the line
- You can create an animation (gif) for an optimized pulse using the
animatePulse.ipynb
notebook
If you use this code, please cite the corresponding paper:
Bosch, D.; Scheffler, K.: FastPtx: A Versatile Toolbox for Rapid, Joint Design of pTx RF and Gradient Pulses Using Pytorch's Autodifferentiation. Magnetic Resonance Materials in Physics, Biology and Medicine