Skip to content

Commit 2b77c96

Browse files
committed
substantial development.. syncs EEG and ET of all Q1K tasks except NSP, FSP and VS.
1 parent 37d394b commit 2b77c96

File tree

2 files changed

+408
-86
lines changed

2 files changed

+408
-86
lines changed

q1k_eeg_et_sync.ipynb

Lines changed: 92 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 2,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -16,12 +16,12 @@
1616
},
1717
{
1818
"cell_type": "code",
19-
"execution_count": null,
19+
"execution_count": 3,
2020
"metadata": {},
2121
"outputs": [],
2222
"source": [
23-
"subject_id = '0006'\n",
24-
"task = 'ssvep'\n",
23+
"#subject_id = '0008'\n",
24+
"#task = 'ssvep'\n",
2525
"bids_root = '.'"
2626
]
2727
},
@@ -32,14 +32,35 @@
3232
"outputs": [],
3333
"source": [
3434
"#read EEG mff data\n",
35-
"eeg_raw = mne.io.read_raw_egi('sourcedata/s06/eeg/s06/s06_ssvep_20230313_113128.mff/',preload=True)\n",
35+
"eeg_raw = mne.io.read_raw_egi('sourcedata/s06/eeg/s06/s06_plr_20230313_115649.mff/',preload=True)\n",
3636
"eeg_raw_df = eeg_raw.to_data_frame()\n",
3737
"\n",
3838
"#get the EEG events from the stim stim channel\n",
39-
"eeg_events = mne.find_events(eeg_raw, stim_channel='STI 014')\n",
39+
"#eeg_events = mne.find_events(eeg_raw, stim_channel='STI 014', shortest_event = 1)\n",
40+
"eeg_events = mne.find_events(eeg_raw, shortest_event = 1)\n",
4041
"\n",
42+
"#create the event dictionary..\n",
43+
"eeg_event_dict = qst.get_event_dict(eeg_raw,eeg_events)"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
4152
"#handle task specific EEG event interpretation..\n",
42-
"eeg_events, eeg_stims, eeg_iti, eeg_event_dict = qst.eeg_event_test(eeg_events,task_name='ssvep')"
53+
"eeg_events, eeg_stims, eeg_iti, eeg_event_dict = qst.eeg_event_test(eeg_events,eeg_event_dict,task_name='plr')"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": null,
59+
"metadata": {},
60+
"outputs": [],
61+
"source": [
62+
"fig=px.scatter(x=eeg_events[:,0],y=eeg_events[:,2])\n",
63+
"fig.show()"
4364
]
4465
},
4566
{
@@ -49,11 +70,29 @@
4970
"outputs": [],
5071
"source": [
5172
"#read the asc eye tracking data and convert it to a dataframe\n",
52-
"et_raw = mne.io.read_raw_eyelink ('sourcedata/s06/eyetracking/s06ssvep.asc')\n",
73+
"et_raw = mne.io.read_raw_eyelink ('sourcedata/s06/eyetracking/s06plr.asc')\n",
5374
"et_raw_df = et_raw.to_data_frame()\n",
5475
"\n",
76+
"#get the events from the annotation structure\n",
77+
"et_annot_events, et_annot_event_dict = mne.events_from_annotations(et_raw)"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": 15,
83+
"metadata": {},
84+
"outputs": [
85+
{
86+
"name": "stdout",
87+
"output_type": "stream",
88+
"text": [
89+
"Number of eye-tracking stimulus onset DIN events: 32\n"
90+
]
91+
}
92+
],
93+
"source": [
5594
"#handle task specific ET event interpretation..\n",
56-
"et_events, et_stims, et_iti = qst.et_event_test(et_raw_df,task_name='ssvep')"
95+
"et_event_raw_df, et_events, et_stims, et_iti = qst.et_event_test(et_raw_df,task_name='plr')"
5796
]
5897
},
5998
{
@@ -62,7 +101,8 @@
62101
"metadata": {},
63102
"outputs": [],
64103
"source": [
65-
"eeg_et_raw = qst.eeg_et_combine(eeg_raw, et_raw, eeg_stims, et_stims)"
104+
"fig=px.scatter(x=et_events['index'],y=et_events['DIN_diff'])\n",
105+
"fig.show()"
66106
]
67107
},
68108
{
@@ -71,8 +111,7 @@
71111
"metadata": {},
72112
"outputs": [],
73113
"source": [
74-
"scalings=dict(eyegaze=1e1)\n",
75-
"eeg_et_raw.plot(events=eeg_events,scalings=scalings)"
114+
"qst.show_sync_offsets(eeg_stims,et_stims)"
76115
]
77116
},
78117
{
@@ -81,17 +120,16 @@
81120
"metadata": {},
82121
"outputs": [],
83122
"source": [
84-
"bids_path = mne_bids.BIDSPath(subject=subject_id, task=task, root=bids_root)\n",
85-
"mne_bids.write_raw_bids(eeg_raw, bids_path, events=eeg_events, event_id=eeg_event_dict, overwrite=True, allow_preload=True, format='EDF')"
123+
"eeg_et_raw = qst.eeg_et_combine(eeg_raw, et_raw, eeg_stims, et_stims)"
86124
]
87125
},
88126
{
89127
"cell_type": "code",
90-
"execution_count": null,
128+
"execution_count": 18,
91129
"metadata": {},
92130
"outputs": [],
93131
"source": [
94-
"qst.show_sync_offsets(eeg_stims,et_stims)"
132+
"eeg_et_raw_df = eeg_et_raw.to_data_frame()"
95133
]
96134
},
97135
{
@@ -100,8 +138,7 @@
100138
"metadata": {},
101139
"outputs": [],
102140
"source": [
103-
"#plot the event latencies\n",
104-
"fig = px.scatter(x=eeg_events[:,0],y=eeg_events[:,2])\n",
141+
"fig=px.line(x=eeg_et_raw_df['time'],y=eeg_et_raw_df['pupil_right'])\n",
105142
"fig.show()"
106143
]
107144
},
@@ -111,9 +148,9 @@
111148
"metadata": {},
112149
"outputs": [],
113150
"source": [
114-
"#show the stimulus DIN event inter-trial intervals... this should be replicated in the eye-tracking recording..\n",
115-
"fig = px.line(y=eeg_iti)\n",
116-
"fig.show()"
151+
"scalings=dict(eyegaze=1e2)\n",
152+
"eeg_et_raw.plot(events=eeg_events,duration=4,scalings=scalings)\n",
153+
"#eeg_et_raw.plot(scalings=scalings)"
117154
]
118155
},
119156
{
@@ -122,7 +159,7 @@
122159
"metadata": {},
123160
"outputs": [],
124161
"source": [
125-
"fig = px.scatter(x=et_events['index'],y=et_events['DIN'])\n",
162+
"fig=px.scatter(x=et_events['index'],y=et_events['DIN_diff'])\n",
126163
"fig.show()"
127164
]
128165
},
@@ -132,7 +169,7 @@
132169
"metadata": {},
133170
"outputs": [],
134171
"source": [
135-
"fig = px.scatter(x=et_events['index'],y=et_events['DIN_diff'])\n",
172+
"fig=px.scatter(x=et_events['time'],y=et_events['index'].diff())\n",
136173
"fig.show()"
137174
]
138175
},
@@ -142,7 +179,7 @@
142179
"metadata": {},
143180
"outputs": [],
144181
"source": [
145-
"fig = px.scatter(x=et_events['index'],y=et_events['index'].diff())\n",
182+
"fig=px.line(x=et_raw_df['time'],y=et_raw_df['DIN'])\n",
146183
"fig.show()"
147184
]
148185
},
@@ -152,7 +189,29 @@
152189
"metadata": {},
153190
"outputs": [],
154191
"source": [
155-
"fig = px.line(y=et_iti)\n",
192+
"scalings=dict(eyegaze=1e5)\n",
193+
"eeg_et_raw.plot(events=eeg_events,duration=4,scalings=scalings)\n",
194+
"#eeg_et_raw.plot(scalings=scalings)"
195+
]
196+
},
197+
{
198+
"cell_type": "code",
199+
"execution_count": null,
200+
"metadata": {},
201+
"outputs": [],
202+
"source": [
203+
"bids_path = mne_bids.BIDSPath(subject=subject_id, task=task, root=bids_root)\n",
204+
"mne_bids.write_raw_bids(eeg_raw, bids_path, events=eeg_events, event_id=eeg_event_dict, overwrite=True, allow_preload=True, format='EDF')"
205+
]
206+
},
207+
{
208+
"cell_type": "code",
209+
"execution_count": null,
210+
"metadata": {},
211+
"outputs": [],
212+
"source": [
213+
"#plot the event latencies\n",
214+
"fig = px.scatter(x=eeg_events[:,0],y=eeg_events[:,2])\n",
156215
"fig.show()"
157216
]
158217
},
@@ -162,7 +221,8 @@
162221
"metadata": {},
163222
"outputs": [],
164223
"source": [
165-
"fig = px.scatter(y=eeg_et_offset)\n",
224+
"#show the stimulus DIN event inter-trial intervals... this should be replicated in the eye-tracking recording..\n",
225+
"fig = px.line(y=eeg_iti)\n",
166226
"fig.show()"
167227
]
168228
}
@@ -185,7 +245,12 @@
185245
"pygments_lexer": "ipython3",
186246
"version": "3.8.10"
187247
},
188-
"orig_nbformat": 4
248+
"orig_nbformat": 4,
249+
"vscode": {
250+
"interpreter": {
251+
"hash": "4d51abd469969a131aa91b4c30bbe09eccdda015d2c1385281ae2bb665bb8f08"
252+
}
253+
}
189254
},
190255
"nbformat": 4,
191256
"nbformat_minor": 2

0 commit comments

Comments
 (0)