Skip to content

Commit 076c2e1

Browse files
committed
add notebook on how to use 2 logfiles
1 parent 8bb1a43 commit 076c2e1

File tree

1 file changed

+222
-0
lines changed

1 file changed

+222
-0
lines changed

notebooks/using_2_logfiles.ipynb

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# saving two `_events.tsv` for the same run"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 32,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"% add the relevant functions from the src folder\n",
17+
"addpath(genpath(fullfile(pwd, '..', 'src')));\n",
18+
"\n",
19+
"cfg.dir.output = fullfile(pwd, 'output');\n",
20+
"\n",
21+
"cfg.task.name = 'test task';\n",
22+
"\n",
23+
"cfg.subject.subjectNb = 1;\n",
24+
"cfg.subject.runNb = 1;\n",
25+
"\n",
26+
"cfg.testingDevice = 'mri';\n",
27+
"\n",
28+
"cfg.verbose = true;"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"## create a first logfile"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 33,
41+
"metadata": {
42+
"scrolled": true
43+
},
44+
"outputs": [
45+
{
46+
"name": "stdout",
47+
"output_type": "stream",
48+
"text": [
49+
"\r\n",
50+
"Data will be saved in this directory:\r\n",
51+
"\t/home/remi/github/CPP_BIDS/notebooks/output/source/sub-001/ses-001/func\r\n",
52+
"\r\n",
53+
"Data will be saved in this file:\r\n",
54+
"\tsub-001_ses-001_task-testTask_run-001_events_date-202010191333.tsv\r\n"
55+
]
56+
}
57+
],
58+
"source": [
59+
"[cfg] = createFilename(cfg);\n",
60+
"logFile.extraColumns = {'target_position', 'target_type'};"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 34,
66+
"metadata": {},
67+
"outputs": [
68+
{
69+
"name": "stdout",
70+
"output_type": "stream",
71+
"text": [
72+
"onset\tduration\ttrial_type\ttarget_position\ttarget_type\r\n"
73+
]
74+
}
75+
],
76+
"source": [
77+
"logFile = saveEventsFile('open', cfg, logFile);"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {},
83+
"source": [
84+
"## create a second logfile"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": 35,
90+
"metadata": {},
91+
"outputs": [
92+
{
93+
"name": "stdout",
94+
"output_type": "stream",
95+
"text": [
96+
"\r\n",
97+
"Data will be saved in this directory:\r\n",
98+
"\t/home/remi/github/CPP_BIDS/notebooks/output/source/sub-001/ses-001/func\r\n",
99+
"\r\n",
100+
"Data will be saved in this file:\r\n",
101+
"\tsub-001_ses-001_task-testTask_acq-extraInfo_run-001_events_date-202010191333.tsv\r\n"
102+
]
103+
}
104+
],
105+
"source": [
106+
"% we use a copy of the configuration and we modify the 'acq' field in the BIDS naming convention\n",
107+
"cfg_2 = cfg;\n",
108+
"cfg_2.suffix.acquisition = 'extraInfo';\n",
109+
"\n",
110+
"[cfg_2] = createFilename(cfg_2);\n",
111+
"logFile_2.extraColumns = {'target_color'};"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 36,
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"onset\tduration\ttrial_type\ttarget_color\r\n"
124+
]
125+
}
126+
],
127+
"source": [
128+
"logFile_2 = saveEventsFile('open', cfg_2, logFile_2);\n",
129+
"clear cfg2 % we don't need it anymore as this was only need to create the new filename"
130+
]
131+
},
132+
{
133+
"cell_type": "markdown",
134+
"metadata": {},
135+
"source": [
136+
"## log file into the 2 different files"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"execution_count": 37,
142+
"metadata": {},
143+
"outputs": [
144+
{
145+
"name": "stdout",
146+
"output_type": "stream",
147+
"text": [
148+
"2.000000\t0.500000\tmotion_up\t2.000000\tvisual\t\n",
149+
"3.000000\t1.000000\tmotion_down\t1.000000\tvisual\t\n",
150+
"\n",
151+
"\n",
152+
"2.000000\t0.500000\tmotion_up\tred\t\n",
153+
"3.000000\t1.000000\tmotion_down\tblue\t\n"
154+
]
155+
}
156+
],
157+
"source": [
158+
"% Trial one\n",
159+
"logFile(1,1).onset = 2;\n",
160+
"logFile(1,1).trial_type = 'motion_up';\n",
161+
"logFile(1,1).duration = 0.5;\n",
162+
"logFile(1,1).target_position = 2;\n",
163+
"logFile(1,1).target_type = 'visual';\n",
164+
"\n",
165+
"% we do have to repeat some information here for onset, duration, trial type\n",
166+
"logFile_2(1,1).onset = 2;\n",
167+
"logFile_2(1,1).trial_type = 'motion_up';\n",
168+
"logFile_2(1,1).duration = 0.5;\n",
169+
"logFile_2(1,1).target_color = 'red';\n",
170+
"\n",
171+
"% Trial two\n",
172+
"logFile(2,1).onset = 3;\n",
173+
"logFile(2,1).trial_type = 'motion_down';\n",
174+
"logFile(2,1).duration = 1;\n",
175+
"logFile(2,1).target_position = 1;\n",
176+
"logFile(2,1).target_type = 'visual';\n",
177+
"\n",
178+
"logFile_2(2,1).onset = 3;\n",
179+
"logFile_2(2,1).trial_type = 'motion_down';\n",
180+
"logFile_2(2,1).duration = 1;\n",
181+
"logFile_2(2,1).target_color = 'blue';\n",
182+
"\n",
183+
"% save to the tsv file\n",
184+
"logFile = saveEventsFile('save', cfg, logFile);\n",
185+
"\n",
186+
"% skip lines for display\n",
187+
"fprintf(1, '\\n\\n')\n",
188+
"\n",
189+
"logFile_2 = saveEventsFile('save', cfg, logFile_2);"
190+
]
191+
}
192+
],
193+
"metadata": {
194+
"kernelspec": {
195+
"display_name": "Octave",
196+
"language": "octave",
197+
"name": "octave"
198+
},
199+
"language_info": {
200+
"file_extension": ".m",
201+
"help_links": [
202+
{
203+
"text": "GNU Octave",
204+
"url": "https://www.gnu.org/software/octave/support.html"
205+
},
206+
{
207+
"text": "Octave Kernel",
208+
"url": "https://github.com/Calysto/octave_kernel"
209+
},
210+
{
211+
"text": "MetaKernel Magics",
212+
"url": "https://metakernel.readthedocs.io/en/latest/source/README.html"
213+
}
214+
],
215+
"mimetype": "text/x-octave",
216+
"name": "octave",
217+
"version": "4.2.2"
218+
}
219+
},
220+
"nbformat": 4,
221+
"nbformat_minor": 4
222+
}

0 commit comments

Comments
 (0)