Realtime fMRI Cloud Framework
The Realtime fMRI Cloud Framework is an open-source software package that makes it easier to build and deploy real-time fMRI experiments. RT-Cloud streams scanner data (DICOM images) over to the cloud (or any machine) for real-time analysis, which then can be forwarded to the machine presenting stimuli to the participant, allowing for real-time control over experiment presentation (e.g., depicting trial-by-trial neurofeedback to the subject via PsychoPy, jsPsych, MATLAB PsychToolbox, etc.). RT-Cloud supports neuroimaging standards such as BIDS and OpenNeuro.org.
RT-Cloud supports any sort of machine configuration. You could run RT-Cloud entirely on a local computer or you can have separate machines handling each of the below three components.
For more information on RT-Cloud, see our paper in NeuroImage 2022. If you publish work that utilized RT-Cloud, please include a citation to this paper.
After you have installed RT-Cloud, please check out our rtcloud-projects repository: https://github.com/brainiak/rtcloud-projects.
There you can find full example projects, demos of Psychopy integration, and empty project templates for starting your own RT-Cloud project.
Overview of RT-Cloud Components

- data_streamer (runs on machine that receives/sends DICOMs)
- Watches for new DICOM brain images and sends them to whatever machine is analysing the data
- Can simulate the transfer of DICOMs from the MRI scanner using a precollected folder of DICOMs or via an OpenNeuro dataset (OpenNeuroService)
- data_analyser (runs on machine that analyses data in real-time)
- Runs experimenter’s script to process DICOMs
- Provides a web-based user interface for experimenter control
- analysis_listener (runs on machine that runs presentation software)
- Listens for results from data_analyser to inform experiment presentation (e.g., PsychoPy, jsPsych, MATLAB PsychToolbox)
As an example for how you could setup the RT-Cloud components across machines, you could have the MRI workstation running data_streamer, a cloud-based virtual machine running data_analyser, and the experimenter’s laptop presenting stimuli based on the results from analysis_listener.
Development of RT-Cloud was initially funded by Intel Labs; the framework is under active development with funding from NIMH to further extend its capabilities.
Quickstart Demo: sample project via Docker
Assuming that Docker is installed (if not, see instructions below) you can follow these instructions to automatically run a sample project that demonstrates some of RT-Cloud's functionality. The three aforementioned components will be run on a single machine without SSL encryption. Ten DICOM files will be analyzed in real-time and the average brain activation for each TR will be plotted in the RT-Cloud web browser's "Data Plots" tab.
Docker
docker run -it --rm -p 8888:8888 brainiak/rtcloud:latest scripts/data_analyser.sh -p sample --test
Wait for the terminal to output "Listening on: http://localhost:8888" and then open your web browser and go to the url "localhost:8888" (if using a cloud machine, replace "localhost" to the cloud server's ip address). The login username/password for the web browser are both "test". Click the "Run" button to run through the simulated real-time scanning example.
Tutorial: RTCloud Installation & Usage
1. Install Docker, Singularity, or Miniconda
You can use either Docker, Singularity, or a local Conda environment to run RTCloud.
Docker Installation
Windows: https://docs.docker.com/desktop/windows/install/
- Note that Windows has a quirk when it comes to volume mounting with Docker. Docker commands along the lines of "-v $PROJ_DIR" require a backslash "/" before the directory (e.g., "-v /$PROJ_DIR"). Volume mounting also requires full paths: e.g., "-v ~/certs" would need to be replaced with the full path "-v /c/Users/paul/certs".
- If using Git Bash, you will need to add "winpty" before all Docker commands.
Mac: https://docs.docker.com/desktop/mac/install/
- M1 Macs are not supported! All RTCloud functionality will work but scripts will run very slowly. You should follow the local installation instructions instead.
Linux: https://docs.docker.com/engine/install/
Pull RTCloud Docker image
Either pull rtcloud (9Gb, recommended), rtcloudxl (30Gb), or rtcloudlite (3.6Gb)
docker pull brainiak/rtcloud:latest
- "rtcloud": RTCloud, FSL analysis functions (no fsleyes), most of ANTs, c3d_affine_tool, brainiak, VNC Viewer
- "rtcloudxl": RTCloud, FSL, fsleyes, ANTs, Convert3D, brainiak, VNC Viewer
- "rtcloudlite": RTCloud, brainiak, VNC Viewer
Docker images operate in Linux CentOS and use a miniconda environment called "rtcloud" that contains many preinstalled packages (see environment.yml, environment-synthetic-data.yml, websockify.yml, docker/Dockerfile.rttools).
Singularity Installation
Singularity can be used if you lack root permissions to install RT-Cloud via Docker.
Linux install: https://sylabs.io/guides/3.9/admin-guide/installation.html
Example of terminal commands for Linux (CentOS 7) installation:
sudo yum update -y && \
sudo yum install -y epel-release && \
sudo yum update -y && \
sudo yum install -y singularity-runtime singularity
Clone this GitHub repository, cd into it, and build the Singularity image corresponding to the Docker container you wish to run: rtcloud (9Gb, recommended), rtcloudxl (30Gb), or rtcloudlite (3.6Gb).
git clone https://github.com/brainiak/rt-cloud.git
cd rt-cloud/docker/
sudo singularity build rtcloud.sif rtcloud.def
If you lack root permissions, you will need to build the .sif file on a machine that has root permissions and then transfer the .sif file.
Singularity usage instructions. Enter your Singularity image running RT-Cloud. Then execute a few commands to setup your environment:
singularity exec docker/rtcloud.sif bash
source /opt/run-singularity.sh
You will need to perform the above steps 1 & 2 every time you want to use RT-Cloud with Singularity.
Now you can follow the same steps as the local installation to run RT-Cloud via Singularity! Note that source /opt/run-singularity.sh activates a pre-made "rtcloud" conda environment and changes your directory to /tmp/rt-cloud/ (/tmp allows write permissions).
Local Installation
(Note: Windows not supported.)
- Install miniconda
- Clone rt-cloud code from github and cd into it
- Prepare rtcloud conda environment
conda create --name rtcloud
- Note: you must use the name "rtcloud" for your conda environment!
conda activate rtcloud
- Install necessary packages
conda install -y -c defaults -c conda-forge awscli bcrypt boto3 dcm2niix flake8 indexed_gzip jupyter mypy nibabel nilearn nodejs pip pydicom python=3.8 requests rpyc scipy toml tornado websocket-client
pip install inotify pybids watchdog wsaccel
- Install node module dependencies
cd web; npm install; cd ..
- Install FSL, ANTs, or any other software that you plan to use for real-time analysis
2. Making RTCloud secure with SSL encryption
If you do not care about SSL encryption and simply want to test out RTCloud without security, you can skip this step (you will need to add the "--test" flag to all commands in step 4). The RT-Cloud web interface will use "https" with SSL encryption and "http" without SSL encryption.
2a. Create SSL certificate and username/password
The following instructions will create a "certs" folder on your machine. Do this step only once on one machine. To allow for encrypted communication across RTCloud components, the path to this certs folder needs to be provided every time you run RTCloud components. Replace "username" in the below code with the username you want to use to login to the RTCloud web interface.
Docker
The below code will create a certs folder located in your home directory.
docker run -it --name ssl brainiak/rtcloud:latest bash
You will now be within the RTCloud docker image in terminal. Replace "username" below with the username you want to use to login to the RTCloud web browser.
IP=`curl https://ifconfig.co/`
conda deactivate; conda activate rtcloud
openssl genrsa -out certs/rtcloud_private.key 2048
bash scripts/make-sslcert.sh -ip $IP
bash scripts/add-user.sh -u username
You will be prompted to enter a password.
exit
docker cp ssl:/rt-cloud/certs ~/certs
docker rm -f ssl
Local
The below code will create a certs folder in your current working directory. Make sure you keep note of the path where this certs folder lives for later.
IP=`curl https://ifconfig.co/`
mkdir certs; openssl genrsa -out certs/rtcloud_private.key 2048
bash scripts/make-sslcert.sh -ip $IP
bash scripts/add-user.sh -u username
# You will be prompted to enter a password.
2b. Copy your certs folder to all other machines
If you are using RTCloud across multiple machines, you should only create a certs folder once. Then, you should copy this certs folder to the other machines. All RTCloud machines must contain identical certs/rtcloud_private.key and certs/passwd files.
2c. Install SSL certificate
Perform this step on the machine that will be used to open the RTCloud web interface via a web browser (e.g., Chrome, Safari).
On Mac:
- Open application 'Keychain Access'.
- On left sidebar, click 'Login' under Default Keychain.
- Drag and drop your ssl certificate ("~/certs/rtcloud.crt" or "rt-cloud/certs/rtcloud.crt") into the window
- Your certificate should now show up in the 'Keychain Access' certifications list
- Double-click the certification > Trust > 'When using this certificate' choose 'Always Trust'
On Linux:
When you eventually go to use the web interface, a security warning about untrusted certificate will show up. When this happens, click "Add Exception" > "Confirm Security Exception".
On Windows:
Follow the instructions outlined on this webpage: https://learn.microsoft.com/en-us/skype-sdk/sdn/articles/installing-the-trusted-root-certificate
3. Prepare your experiment's script
You will need to prepare a folder containing whatever analysis steps you want to be performed in real-time. We supply a pre-made projects folder that contains several examples for you to try out (https://github.com/brainiak/rtcloud-projects). We highly recommend that you first try running the template project ("rtcloud-projects/template"), which is an example analysis that runs through a complete RT-fMRI pipeline based on Mennen et al. (2021) and is heavily commented such that you can understand what the script is doing and edit it to suit your particular experiment's needs. If you are not using the template project, then replace any instances of "template" in the code blocks below with the name of your project.
Note that the template project uses FSL and ANTs commands, which are preinstalled in the "rtcloud" and "rtcloudxl" Docker/Singularity images, but which would need to be installed if using RTCloud locally or with the "rtcloudlite" Docker image.
git clone https://github.com/brainiak/rtcloud-projects.git
4. Run RTCloud experiment: template project
The following starts up the three RTCloud components and runs through the template project mentioned in step 3. These three components can all be run on the same machine or can be separately started up on different machines.
If you are running all three components on the same machine within a single terminal for testing purposes then you can skip steps 4b and 4c, remove the --dataRemote and --subjectRemote arguments, and if using Docker add -v OUT_DIR:/rt-cloud/outDir to the data_analyser command (where OUT_DIR refers to where you want your realtime outputs stored).