You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to calculate the mean of of a task map and the principal gradient map (i.e. from Daniel Marguilies) within each parcel of Schaefer 400 parcellations, and then zscored these parcels for each of the task activation and gradient maps. Next, we calculated the zscore difference between these two maps. We have got the difference scores for each parcel, the thing we would like to try is to project the difference value to the voxel within each corresponding parcel in the Schaefer 400 parcellations, and then visualise that map. Would that be possible to replace the parcel number (i.e, voxel value) with the calculated difference score and save that as a new nifti file?
Any help would be appreciated!
Best wishes,
Meichao.
The code we tried is shown as below:
importnumpyasnpimportnibabelasnibimportosfromscipy.statsimportzscore# Load the fMRI data and the parcellation atlaspath_input='/groups/labs/semwandering_scratch/Meichao/P1336_NBack_task_Project/Gradient_Analysis/Sept_2023_State_space_Triangle'file_task_activation=os.path.join(path_input,'1back_over_0back','1back_over_0back.nii.gz')
file_gradient_1=os.path.join(path_input,'Gradient','Gradient1.nii.gz')
file_parcellation=os.path.join(path_input,'Schaefer2018_400Parcels_7Networks_order_FSLMNI152_2mm.nii.gz')
defparcellate_image(file_map_voxel,file_parcellation):
""" parcellate a voxel-based map based on the specific parcellaltion :param file_map_voxel: the voxel-based brain map :param file_parcellation: the parcellation file :return: the parcel-based value """fmri_img=nib.load(file_map_voxel)
parcellation_img=nib.load(file_parcellation)
fmri_data=fmri_img.get_fdata()
parcellation_data=parcellation_img.get_fdata()
# Get the unique parcels/labels in the parcellation data excluding the background (usually 0)unique_parcels=np.unique(parcellation_data)[1:] # Excludes backgroundprint(unique_parcels)
# Initialize an empty array to store the mean values of each parcelparcel_means=np.zeros_like(unique_parcels)
# Parcellate the fMRI datafori, parcelinenumerate(unique_parcels):
# Get the mask of the current parcelmask=parcellation_data==parcel# Extract the fMRI values of this parcel and compute their meanparcel_means[i] =fmri_data[mask].mean()
returnparcel_meansparcel_means_activation=parcellate_image(file_task_activation,file_parcellation)
print(parcel_means_activation)
parcel_means_gradient_1=parcellate_image(file_gradient_1,file_parcellation)
print(parcel_means_gradient_1)
# Compute z-scoresparcel_means_activation_z=zscore(parcel_means_activation)
parcel_means_gradient_1_z=zscore(parcel_means_gradient_1)
# Compute the z-scores diffdiff_z=parcel_means_activation_z-parcel_means_gradient_1_zprint(diff_z)
parcellation_file='/groups/labs/semwandering_scratch/Meichao/P1336_NBack_task_Project/Gradient_Analysis/Sept_2023_State_space_Triangle/Schaefer2018_400Parcels_7Networks_order_FSLMNI152_2mm.nii.gz'parcellation_image=nib.load(parcellation_file)
diff_img=nib.Nifti1Image(diff_z, parcellation_image.affine, parcellation_image.header)
nib.save(diff_img, os.path.join(path_input,'1back_over_0back','1back_over_G1.nii.gz'))
This discussion was converted from issue #1259 on December 03, 2023 21:23.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello there,
I would like to calculate the mean of of a task map and the principal gradient map (i.e. from Daniel Marguilies) within each parcel of Schaefer 400 parcellations, and then zscored these parcels for each of the task activation and gradient maps. Next, we calculated the zscore difference between these two maps. We have got the difference scores for each parcel, the thing we would like to try is to project the difference value to the voxel within each corresponding parcel in the Schaefer 400 parcellations, and then visualise that map. Would that be possible to replace the parcel number (i.e, voxel value) with the calculated difference score and save that as a new nifti file?
Any help would be appreciated!
Best wishes,
Meichao.
The code we tried is shown as below:
Beta Was this translation helpful? Give feedback.
All reactions