-
Notifications
You must be signed in to change notification settings - Fork 0
/
8_time_series.py
executable file
·143 lines (104 loc) · 5.6 KB
/
8_time_series.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'''...................... Launch IPython with eelbrain ......................'''
import numpy as np
import pandas as pd
import mne, pickle, eelbrain
from os import chdir
import os.path as op
# from surfer import Brain
'''..................... directory, date, output folder .....................'''
# set up current directory
root = '/Volumes/bin_battuta/biphon'
subjects_dir = op.join(root,'mri')
chdir(root)
# date of analysis
date = '24March2020'
# output folder path
output = op.join(root, 'grp/%s/time_series_left' %date)
'''.................... lists of subjects and conditions ....................'''
subjects = ['A0280','A0318','A0392','A0396','A0416','A0417']
conditions = ['nonnative']
# vowels = [['i1_A','i2_A'],['u1_A','u2_A'],['ah1_A','ah2_A'],['ae1_A','ae2_A'],
# ['i1_B','i2_B'],['u1_B','u2_B'],['ah1_B','ah2_B'],['ae1_B','ae2_B'],
# ['i1_X','i2_X'],['u1_X','u2_X'],['ah1_X','ah2_X'],['ae1_X','ae2_X'],
# ['yih1_A','yih2_A'],['yih1_B','yih2_B'],['yih1_X','yih2_X'],
# ['y1_A','y2_A'],['y1_B','y2_B'],['y1_X','y2_X'],
# ['uu1_A','uu2_A'],['uu1_B','uu2_B'],['uu1_X','uu2_X'],
# ['ob1_A','ob2_A'],['ob1_B','ob2_B'],['ob1_X','ob2_X']]
#
# vowels = ['i1_A_i2_A', 'u1_A_u2_A', 'ah1_A_ah2_A', 'ae1_A_ae2_A',
# 'i1_B_i2_B', 'u1_B_u2_B', 'ah1_B_ah2_B', 'ae1_B_ae2_B',
# 'i1_X_i2_X', 'u1_X_u2_X', 'ah1_X_ah2_X', 'ae1_X_ae2_X']
# vowels = ['i1_A_i2_A', 'u1_A_u2_A', 'ah1_A_ah2_A', 'ae1_A_ae2_A',
# 'i1_B_i2_B', 'u1_B_u2_B', 'ah1_B_ah2_B', 'ae1_B_ae2_B',
# 'i1_X_i2_X', 'u1_X_u2_X', 'ah1_X_ah2_X', 'ae1_X_ae2_X','i1_A_i2_A','u1_A_u2_A','ah1_A_ah2_A','ae1_A_ae2_A','y1_A_y2_A','yih1_A_yih2_A','ob1_A_ob2_A','uu1_A_uu2_A',
# 'i1_B_i2_B','u1_B_u2_B','ah1_B_ah2_B','ae1_B_ae2_B','y1_B_y2_B','yih1_B_yih2_B','ob1_B_ob2_B','uu1_B_uu2_B',
# 'i1_X_i2_X','u1_X_u2_X','ah1_X_ah2_X','ae1_X_ae2_X','y1_X_y2_X','yih1_X_yih2_X','ob1_X_ob2_X','uu1_X_uu2_X']
# vowels = ['i1_A_i2_A', 'u1_A_u2_A', 'ah1_A_ah2_A', 'ae1_A_ae2_A',
# 'y1_A_y2_A','yih1_A_yih2_A','ob1_A_ob2_A','uu1_A_uu2_A']
#
# vowels = ['i1_B_i2_B', 'u1_B_u2_B', 'ah1_B_ah2_B', 'ae1_B_ae2_B',
# 'y1_B_y2_B','yih1_B_yih2_B','ob1_B_ob2_B','uu1_B_uu2_B']
vowels = ['i1_X_i2_X', 'u1_X_u2_X', 'ah1_X_ah2_X', 'ae1_X_ae2_X',
'y1_X_y2_X','yih1_X_yih2_X','ob1_X_ob2_X','uu1_X_uu2_X']
'''.................. get fsaverage vertices for morphing ...................'''
print('Reading in source space...')
subject_to = 'fsaverage'
fs = mne.read_source_spaces('mri/fsaverage/bem/fsaverage-ico-4-src.fif')
vertices_to = [fs[0]['vertno'], fs[1]['vertno']]
'''......................... read in morphed stcs ...........................'''
stcs,subjectlist,conditionlist,vowellist = [],[],[],[]
for subject in subjects:
print('Reading in source estimates from Subject %s...' %subject)
for condition in conditions:
for vowel in vowels:
tmp = mne.read_source_estimate('evoked/%s/%s_%s_%s_morphed-lh.stc' %(subject,subject,condition,vowel),subject='fsaverage')
stcs.append(tmp)
subjectlist.append(subject)
conditionlist.append(condition)
vowellist.append(vowel)
del tmp
'''................ create dataset with stcs, subjs, conds ..................'''
print ('Creating dataset...')
ds = Dataset()
# asso = [str.split(i,'_')[0] for i in conditionlist]
# comp = [str.split(i,'_')[1] for i in conditionlist]
vowel = vowellist
print ('Reading in stcs...')
ds['stcs'] = load.fiff.stc_ndvar(stcs, subject='fsaverage', src='ico-4', subjects_dir=subjects_dir, parc='aparc') # parcellating source space
ds['Subject'] = Factor(subjectlist,random=True)
ds['Condition'] = Factor(conditionlist)
# ds['Association'] = Factor(asso)
# ds['Composition'] = Factor(comp)
ds['Vowel'] = Factor(vowel)
src_reset = ds['stcs']
'''...................... plot time courses by region .......................'''
# language network regions of interest
# regions = ['IFG-lh', 'vmPFC-lh', 'ATL+MTL-lh', 'PTL-lh', 'TPJ-lh','V1-lh']
regions = ['superiortemporal-lh']
xticks=np.arange(-0.2,0.6,0.1)
plot_by = 'Vowel' # Condition, Association, Composition
for region in regions:
print('Plotting time series at %s...' %region)
ds['srcm'] = src_reset
src_region = src_reset.sub(source=region) # subset language network region data
ds['srcm'] = src_region # assign this back to the ds
timecourse = src_region.mean('source')
activation = eelbrain.plot.UTSStat(timecourse, plot_by, ds=ds, match='Subject', legend=None, error=None,
xlabel='Time (ms)', ylabel='Activation (dSPM)', tight=True, xlim=(0,0.6), frame=None, title='Time Series at %s' %region)
activation._axes[0].set_xticks(xticks)
activation._axes[0].lines[0].set_lw(w=2)
# activation._axes[0].lines[1].set_ls(ls='--')
# activation._axes[0].lines[1].set_lw(w=2)
activation._axes[0].legend(labels=ds['Vowel'], loc='upper right')
activation._axes[0].legend()
activation.set_ylim(-1,1)
activation._axes[0].set_xticks(xticks)
activation._axes[0].axvline(linewidth = '2', x=0, color='k', linestyle='--')
activation.save(op.join(output, 'ts_%s_max3.jpg' %region), dpi=1200, quality=95, optimize=True, format='jpg', transparent=True)
activation.close()
# @ colour scheme
# position (5,6,7): '#DDAA33','#AA3377','#004488'
# association (high, low): '#CCBB44','#AA4499'
# composition (sent, list): '#332288','#117733'
# composition*position: '#EE7733','#CC3311','#EE3377','#0077BB', '#33BBEE','#009988'
# condition (high_sent, high_list, low_sent, low_list): 'royalblue', 'orange', 'lightseagreen', 'tomato'