Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions kftools/nifti/fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from nilearn.plotting import plot_surf_stat_map
import nibabel as nib

from nilearn.connectome import ConnectivityMeasure
from nilearn.input_data import NiftiLabelsMasker





### seed coords from (Eggebrecht et al., 2014) ###
seed_coord_dict = {'vis':(-19.5, -102, -3),
Expand Down Expand Up @@ -102,6 +108,42 @@ def fc_for_seeds(nifti_f,dothese=None,clip_vols=[],radius=10):




def run_vol_parcbasedfc(nifti_obj, n_rois):
'''
get 4d nifti object and calculate functional connectivity based on Shaefer parcellations

nifti_obj: 4D nifti object
n_rois: number of parcellations to be used {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}

output: functional connectivity matrix (n_rois x n_rois np array)
'''
# importing parcellations map

parcellation = datasets.fetch_atlas_schaefer_2018(n_rois=n_rois)

atlas_fname = parcellation.maps
labels = parcellation.labels

# Defining mask and extracting info based on parcellation map

masker = NiftiLabelsMasker(labels_img = atlas_fname, standardize=True, memory='nilean_cache', verbose=5 ) # might be able to tweak this to get better signal

# Getting time series

time_series = masker.fit_transform(nifti_obj)

# Getting correlation matrices

corr_measure = ConnectivityMeasure(kind='correlation')
corr_matrix = corr_measure.fit_transform([time_series])[0]
np.fill_diagonal(corr_matrix, 0)

return corr_matrix




"""
Surface-based FC functions
=============================================================
Expand Down