FreeSurfer: mri_vol2surf#
Sampling fMRI signal across cortical depths#
mri_vol2surf is a FreeSurfer based command that enables one to assign fMRI signal value to each surface vertex.
Authors: Fernanda L. Ribeiro
Citation:#
Open source Data from OpenNeuro:
Kelly Chang and Ione Fine and Geoffrey M. Boynton (2024). CHN Retinotopic Mapping Dataset OpenNeuro doi: doi:10.18112/openneuro.ds004698.v2.0.0
Original manuscript:
Chang, K., Fine, I., & Boynton, G. M. (2025). Improving the reliability and accuracy of population receptive field measures using a logarithmically warped stimulus. Journal of Vision, 25(1), 5. https://doi.org/10.1167/jov.25.1.5
Goal of this example notebook#
In this example notebook we demonstrate how one can assign fMRI signal values to each cortical surface vertex across cortical depths. This can be relevant, for example, to assess how topographic maps may change across cortical depths and determine the potential impact of vasculature in the topological arrangement of such maps.
Although we do not attempt to reconstruct retinotopic maps in this tutorial, here we show how to perform such procedure using retinotopic mapping data.
Install Python packages#
!pip install numpy nilearn nibabel
Requirement already satisfied: numpy in /opt/conda/lib/python3.12/site-packages (2.2.6)
Requirement already satisfied: nilearn in /opt/conda/lib/python3.12/site-packages (0.12.0)
Requirement already satisfied: nibabel in /opt/conda/lib/python3.12/site-packages (5.3.2)
Requirement already satisfied: joblib>=1.2.0 in /opt/conda/lib/python3.12/site-packages (from nilearn) (1.5.1)
Requirement already satisfied: lxml in /opt/conda/lib/python3.12/site-packages (from nilearn) (5.4.0)
Requirement already satisfied: packaging in /opt/conda/lib/python3.12/site-packages (from nilearn) (25.0)
Requirement already satisfied: pandas>=2.2.0 in /opt/conda/lib/python3.12/site-packages (from nilearn) (2.2.3)
Requirement already satisfied: requests>=2.25.0 in /opt/conda/lib/python3.12/site-packages (from nilearn) (2.32.3)
Requirement already satisfied: scikit-learn>=1.4.0 in /opt/conda/lib/python3.12/site-packages (from nilearn) (1.7.0)
Requirement already satisfied: scipy>=1.8.0 in /opt/conda/lib/python3.12/site-packages (from nilearn) (1.15.3)
Requirement already satisfied: typing-extensions>=4.6 in /opt/conda/lib/python3.12/site-packages (from nibabel) (4.13.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /opt/conda/lib/python3.12/site-packages (from pandas>=2.2.0->nilearn) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.12/site-packages (from pandas>=2.2.0->nilearn) (2024.2)
Requirement already satisfied: tzdata>=2022.7 in /opt/conda/lib/python3.12/site-packages (from pandas>=2.2.0->nilearn) (2025.2)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas>=2.2.0->nilearn) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in /opt/conda/lib/python3.12/site-packages (from requests>=2.25.0->nilearn) (3.4.2)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.12/site-packages (from requests>=2.25.0->nilearn) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.12/site-packages (from requests>=2.25.0->nilearn) (2.4.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.12/site-packages (from requests>=2.25.0->nilearn) (2025.4.26)
Requirement already satisfied: threadpoolctl>=3.1.0 in /opt/conda/lib/python3.12/site-packages (from scikit-learn>=1.4.0->nilearn) (3.6.0)
Import relevant libraries#
import numpy as np
import module
import os
Load FreeSurfer#
await module.load('freesurfer/7.3.2')
await module.list()
['freesurfer/7.3.2']
Download data from the OpenNeuro#
dataDir='/neurodesktop-storage/'
os.chdir(dataDir) # change directories
!datalad install https://github.com/OpenNeuroDatasets/ds004698.git # install NYU retinotopy dataset
os.chdir('/neurodesktop-storage/ds004698/derivatives/freesurfer') # change directories
subject='sub-01'
cmd1=f"""datalad get {subject}/*""" # download all freesurfer files from subject
cmd2=f"""datalad get /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_*""" #download all preprocessed functional volumes from subject
os.system(cmd1)
os.system(cmd2)
action summary:
get (notneeded: 7)
action summary:
get (notneeded: 7)
0
Sample fMRI data across layers#
if not os.path.exists('/neurodesktop-storage/new_data'):
os.mkdir('/neurodesktop-storage/new_data') # create a directory to save the newly sampled fMRI data
Now, we can run mri_vol2surf to sample fMRI signal values from a volume to each surface vertex.
depths = np.arange(0,1.1,0.1)
print(f"Functional data will be sample at the following depths: {depths}")
Functional data will be sample at the following depths: [0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. ]
Before assigning fMRI data to each surface vertex make sure that both the anatomical and functional data are aligned.
for depth in depths:
print(f"""Processing depth: {depth}""")
cmd = f"""mri_vol2surf --src /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz \
--regheader sub-01 \
--hemi lh \
--surf white \
--projfrac {depth} \
--sd /neurodesktop-storage/ds004698/derivatives/freesurfer \
--out /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-{depth:.1f}.func.mgh"""
os.system(cmd)
Processing depth: 0.0
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Mapping Source Volume onto Source Subject Surface
Projecting 0 0 1
1 0 0 0
using old
Done mapping volume to surface
Number of source voxels hit = 28255
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.0.func.mgh
Dim: 221709 1 1
Processing depth: 0.1
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.1
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.1 0.1 1
1 0.1 0.1 0.1
using old
Done mapping volume to surface
Number of source voxels hit = 29515
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.1.func.mgh
Dim: 221709 1 1
Processing depth: 0.2
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.2
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.2 0.2 1
1 0.2 0.2 0.2
using old
Done mapping volume to surface
Number of source voxels hit = 30311
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.2.func.mgh
Dim: 221709 1 1
Processing depth: 0.30000000000000004
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.3
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.3 0.3 1
1 0.3 0.3 0.3
using old
Done mapping volume to surface
Number of source voxels hit = 30832
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.3.func.mgh
Dim: 221709 1 1
Processing depth: 0.4
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.4
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.4 0.4 1
1 0.4 0.4 0.4
using old
Done mapping volume to surface
Number of source voxels hit = 31178
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.4.func.mgh
Dim: 221709 1 1
Processing depth: 0.5
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.5
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.5 0.5 1
1 0.5 0.5 0.5
using old
Done mapping volume to surface
Number of source voxels hit = 31350
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.5.func.mgh
Dim: 221709 1 1
Processing depth: 0.6000000000000001
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.6
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.6 0.6 1
1 0.6 0.6 0.6
using old
Done mapping volume to surface
Number of source voxels hit = 31311
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.6.func.mgh
Dim: 221709 1 1
Processing depth: 0.7000000000000001
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.7
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.7 0.7 1
1 0.7 0.7 0.7
using old
Done mapping volume to surface
Number of source voxels hit = 31118
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.7.func.mgh
Dim: 221709 1 1
Processing depth: 0.8
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.8
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.8 0.8 1
1 0.8 0.8 0.8
using old
Done mapping volume to surface
Number of source voxels hit = 30573
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.8.func.mgh
Dim: 221709 1 1
Processing depth: 0.9
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 0.9
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 0.9 0.9 1
1 0.9 0.9 0.9
using old
Done mapping volume to surface
Number of source voxels hit = 29872
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.9.func.mgh
Dim: 221709 1 1
Processing depth: 1.0
srcvol = /neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold.nii.gz
srcreg unspecified
srcregold = 0
srcwarp unspecified
surf = white
hemi = lh
ProjFrac = 1
thickness = thickness
reshape = 0
interp = nearest
float2int = round
GetProjMax = 0
INFO: float2int code = 0
Done loading volume
Computing registration from header.
Using //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/mri/orig.mgz as target reference.
-------- original matrix -----------
-1.00000 0.00000 -0.00000 0.12505;
-0.00000 -0.00000 1.00000 2.69328;
0.00000 -1.00000 0.00000 0.19273;
0.00000 0.00000 0.00000 1.00000;
-------- original matrix -----------
Reading surface //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.white
Done reading source surface
Reading thickness //neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.thickness
Done
Mapping Source Volume onto Source Subject Surface
Projecting 1 1 1
1 1 1 1
using old
Done mapping volume to surface
Number of source voxels hit = 29162
Writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-1.0.func.mgh
Dim: 221709 1 1
Finally, we can convert our data to ‘func.gii’, so we can perform population receptive field modeling using tools like SamSrf.
for depth in depths:
print(f"Processing depth: {depth}")
cmd = f"""mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-{depth:.1f}.func.mgh \
/neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-{depth:.1f}.func.gii"""
os.system(cmd)
print("Data has been converted!")
Processing depth: 0.0
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.0.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.0.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.0.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.0.func.gii...
Data has been converted!
Processing depth: 0.1
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.1.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.1.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.1.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.1.func.gii...
Data has been converted!
Processing depth: 0.2
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.2.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.2.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.2.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.2.func.gii...
Data has been converted!
Processing depth: 0.30000000000000004
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.3.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.3.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.3.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.3.func.gii...
Data has been converted!
Processing depth: 0.4
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.4.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.4.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.4.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.4.func.gii...
Data has been converted!
Processing depth: 0.5
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.5.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.5.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.5.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.5.func.gii...
Data has been converted!
Processing depth: 0.6000000000000001
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.6.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.6.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.6.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.6.func.gii...
Data has been converted!
Processing depth: 0.7000000000000001
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.7.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.7.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.7.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.7.func.gii...
Data has been converted!
Processing depth: 0.8
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.8.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.8.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.8.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.8.func.gii...
Data has been converted!
Processing depth: 0.9
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.9.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.9.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.9.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-0.9.func.gii...
Data has been converted!
Processing depth: 1.0
/opt/freesurfer-7.3.2/bin/mri_convert /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-1.0.func.mgh /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-1.0.func.gii
reading from /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-1.0.func.mgh...
TR=1200.00, TE=0.00, TI=0.00, flip angle=0.00
i_ras = (1, 0, 0)
j_ras = (0, 1, 0)
k_ras = (0, 0, 1)
writing to /neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-1.0.func.gii...
Data has been converted!
Before moving forward, make sure the newly sampled data has the same shape as previously preprocessed, sampled data.
our_newly_sampled_data = nib.load("/neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-1.0.func.gii").agg_data()
previous_sampled_data = nib.load("/neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_hemi-L_space-fsnative_bold.func.gii").agg_data()
assert our_newly_sampled_data.shape == previous_sampled_data.shape, "Sampled data is not correct!"
Visualize the data#
!mris_convert /neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.sphere /neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.sphere.gii
Saving /neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.sphere.gii as a surface
import nibabel as nib
from nilearn import plotting
from ipywidgets import Dropdown
def plot_data(depth, time_point):
if depth !='average':
data = np.array(nib.load("/neurodesktop-storage/new_data/sub-01_ses-01_task-fixedbar_run-1_space-T1w_desc-preproc_bold_depth-"
+ str(depth) + ".func.gii").agg_data())[:,time_point]
else:
data = np.array(nib.load("/neurodesktop-storage/ds004698/derivatives/fmriprep/sub-01/ses-01/func/sub-01_ses-01_task-fixedbar_run-1_hemi-L_space-fsnative_bold.func.gii").agg_data())[:,time_point]
view = plotting.view_surf(
surf_mesh="/neurodesktop-storage/ds004698/derivatives/freesurfer/sub-01/surf/lh.sphere.gii",
surf_map=np.reshape(data[:], (-1)),
cmap="Reds", black_bg=False, symmetric_cmap=False,
threshold=0, vmax=10000, darkness=None)
return view
We can generate some interactive plots with ipywidgets and nilearn.
depth = Dropdown(options = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 'average'])
time_point = Dropdown(options = [0, 50, 100, 150, 200, 250, 300])
@interact(depth = depth, time_point = time_point)
def plot1(depth, time_point):
return plot_data(depth, time_point)
/tmp/ipykernel_31854/3315881815.py:11: UserWarning: It seems you have created more than 10 nilearn views. As each view uses dozens of megabytes of RAM, you might want to delete some of them.
view = plotting.view_surf(