In [1]:
%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]:
from fmri_core import analysis as pa
from fmri_core import utils as pu
import numpy as np
import matplotlib.pyplot as plt
In [3]:
os.chdir("D:\\CloudStation\\Grad\\Research\\montilab-ucla")
In [4]:
projectSettings = pu.loadConfig(os.path.join('analogy', 'config', 'project.json'))
analysisSettings = pu.loadConfig(os.path.join('analogy', 'config', 'analyses.json'))
# paths = projectSettings['filepaths']['osxPaths']
paths = projectSettings['filepaths']['winPaths']
analysisSettings['searchlight']
Out[4]:
In [5]:
paths
Out[5]:
In [6]:
sub = "sub-01"
run = "run-01"
In [7]:
funcFile = ("%s_task-analogy_%s_bold.nii.gz" % (sub, run))
eventFile = ("%s_task-analogy_%s_events.tsv" % (sub, run))
maskFile = "aal-LOFC-bin_mask.nii.gz"
In [8]:
img = pu.maskImg(os.path.join(paths['root'],
'derivatives',
sub, 'func',
funcFile),
os.path.join(paths['root'],
'derivatives',
sub, 'masks',
maskFile))
labels = pu.loadLabels(os.path.join(paths['root'],
'derivatives',
sub, 'func',
eventFile), sep="\t")
In [9]:
labels.keys()
Out[9]:
In [10]:
label = [("%s_%s" % (labels.iloc[i]['TrialTag'],
labels.iloc[i]['TrialType']))
for i in range(len(labels))]
In [11]:
tr = 1.0
frametimes = np.arange(img.shape[0]) * tr
In [12]:
des = pa.make_designmat(frametimes, label,
labels['Onset'].values,
labels['Duration'].values)
In [13]:
des.show()
Out[13]:
In [14]:
sgf = pa.sgfilter(window_length=121, polyorder=3, **analysisSettings['SGF'])
In [15]:
from sklearn.linear_model import Ridge, LinearRegression
ols = LinearRegression()
ridge = Ridge()
In [16]:
ols.fit(des.matrix, sgf.fit_transform(img))
Out[16]:
In [17]:
ridge.fit(des.matrix, sgf.fit_transform(img))
Out[17]:
In [ ]:
ols.coef_.shap
In [ ]:
a = des.names
a.remove("constant")
In [ ]:
a
In [ ]:
plt.imshow(pa.rdm(arr.T, square=True))
In [ ]:
arr.shape
In [ ]:
trialtype, trialtag = [], []
for t in des.names:
curr = t.split('_')
trialtype += curr[0]
trialtag += curr[1]
In [ ]:
des.names.index('constant')
In [ ]:
ols.coef_[:, des.names.index("constant")].sum()
In [ ]:
for i in des.names:
print(i.split('_')[0], i.split('_')[1])
In [ ]: