In [ ]:
%matplotlib inline
projecttitle = 'Analogy'
import sys, os
if sys.platform == 'darwin':
sys.path.append(os.path.join("/Users", "njchiang", "GitHub", "task-fmri-utils"))
else:
sys.path.append(os.path.join("D:\\", "GitHub", "task-fmri-utils"))
In [2]:
import fmri_core as pa
In [3]:
projectSettings = pa.utils.loadConfig(os.path.join('analogy', 'config', 'project.json'))
analysisSettings = pa.utils.loadConfig(os.path.join('analogy', 'config', 'analyses.json'))
In [4]:
# paths = projectSettings['filepaths']['osxPaths']
paths = projectSettings['filepaths']['winPaths']
ROI Analysis
In [5]:
# for each subject
# mask = lIFGoperc_bin-mask
def runsubject(sub, mask):
# set image data
imgFile = os.path.join(paths['root'], 'derivatives', sub, 'betas', pa.utils.formatBIDSName(sub, 'task-analogy', 'betas-pymvpa.nii.gz'))
mask = pa.utils.loadImg(paths['root'],
'derivatives', sub, 'masks',
mask + '.nii.gz')
labels = pa.utils.loadLabels(paths['root'],
'derivatives', sub, 'betas',
pa.utils.formatBIDSName(sub, 'task-analogy', 'events-pymvpa.tsv'),
sep='\t', index_col=0)
# load image
maskedImg = pa.utils.maskImg(imgFile, mask)
# clean out timepoints of interest
conditionSelector = labels['ab'] == 1
# preprocessing
from sklearn.preprocessing import StandardScaler
op = StandardScaler()
scaledData = pa.utils.opByLabel(maskedImg, labels['chunks'], op)
# analysis
from sklearn.svm import SVC
clf = SVC()
from sklearn.model_selection import LeaveOneGroupOut
cv = LeaveOneGroupOut().split(scaledData[conditionSelector], labels['trialtype'][conditionSelector], labels['chunks'][conditionSelector])
result = pa.analysis.roi(scaledData[conditionSelector], labels['abmainrel'][conditionSelector], clf, cv=cv) #, groups=labels['chunks'][conditionSelector])
# result = pa.unmaskImg(scaledData, mask)
return result
In [6]:
test = runsubject('sub-01', 'lIFGoperc-bin_mask')
In [7]:
test
Out[7]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: