A short instruction of how to do Neuroimaging using Google cloud (based on FSL)
To start with, there are some handy commands you should keep in mind, such as:
-
gsutil (what you do to call/edit your bucket)
gsutil -m -cp YOUR_CURRENTFILES gs://YOUR_BUCKETNAME
-
gcloud auth login (what you do to get access to other proj/bucket)
gcloud auth login
-
Create a Google cloud account
-
Go to google cloud console, pick Vertex AI on the menu and create a workbench
-
Choose machine and storage (there are some limitations here, should check on your quotas)
-
Start the VM and open up terminal
-
curl -Ls https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/releases/getfsl.sh | sh -s -
Open up another terminal
You are all set!
-
If you are running 1st level analysis for multiple subjects, I would suggest you to use parallel to boost up the speed
sudo apt-get install parallel # Ubuntu/DebianExample code to add on your script so it can run with parallel:
cat "${DATA_PATH}/subject_list.txt" | parallel -j "$PARALELJOBSCOUNT" YOURMAINCODE {}
-
gsfuse may not be a good idea as there might be some restrictions when running fsl and leads to error
-
Better way to do is to mount your storage and read files from storage, work on your VM and upload back to storage
- This is an alternative way to run fsl on google cloud, but you might need to adjust your script so the route to fsl can be set correctly
-
Establish your VM by choosing Compute Engine >> VM instance
-
Choose the machine and storage
-
Mount Disk (the root storage does not have enough space for instaling FSL)
-
curl -Ls https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/releases/getfsl.sh | sh -s(if this doesn't work, go and download getfsl.sh and edit the file)
Complete!
- Debugging:
- fsl:command not found
Edit bashrc
- fsl:command not found
FSLDIR=/MOUNT_DIR/fsl
. ${FSLDIR}/etc/fslconf/fsl.sh
PATH=${FSLDIR}/bin:${PATH}
export FSLDIR PATH
- Add disk to VM
- Click on the VM and edit
- Add disk and choose the volume
- Check if disk exist
lsblk - Check if mounted(usually not properly mounted in the first time)
df -h - You have to format the disk:
sudo mkfs.FILE_SYSTEM_TYPE -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/DEVICE_NAME
- Create directory
- Mount
sudo mount -o discard,defaults /dev/DEVICE_NAME /MOUNT_DIR
- Fusing cloud storage
- Make sure your google cloud permits access from google VM
Stop your vm--> Edit VM --> see Access rights scope --> Set access rights for each API seperately - Install gcsfuse
sudo apt-get update sudo apt-get install gcsfuse
- Make a folder for fusing point and grant access
mkdir FOLDERchmod 777 FOLDER - Start fusing
gcsfuse BUCKET_NAME FOLDER
- if you have several subfolders you can do this:
gcsfuse--implicit-dirs BUCKET_NAME FOLDER
- Check if you have access
cd FOLDERls -l