-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
178 lines (144 loc) · 5.7 KB
/
config.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
========================
Study configuration file
========================
Configuration parameters and global variable values for the study.
Authors: José C. García Alanis <[email protected]>
License: BSD (3-clause)
"""
import os
from os import path as op
import platform
import argparse
import multiprocessing
from utils import FileNames
from mne.channels import make_standard_montage
###############################################################################
class LoggingFormat:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
###############################################################################
# User parser to handle command line arguments
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('subject',
metavar='sub###',
help='The subject to process',
type=int)
# Determine which user is running the scripts on which machine. Set the path to
# where the data is stored and determine how many CPUs to use for analysis.
node = platform.node() # machine
system = platform.system() # OS
# You want to add your machine to this list
if 'Jose' in node and 'n' in system:
# iMac at work
data_dir = '../data'
n_jobs = 2 # This station has 4 cores (we'll use 2).
elif 'jose' in node and 'x' in system:
# pc at home
data_dir = '../data'
n_jobs = 'cuda' # Use NVIDIA CUDA GPU processing
elif 'ma04' in node:
data_dir = '../data'
n_jobs = 2
else:
# Defaults
data_dir = '../data'
n_jobs = 1
# For BLAS to use the right amount of cores
use_cores = multiprocessing.cpu_count()//2
if use_cores < 2:
use_cores = 1
os.environ['OMP_NUM_THREADS'] = str(use_cores)
###############################################################################
# Relevant parameters for the analysis.
sample_rate = 256. # Hz
task_name = 'ernsoc'
task_description = 'effects of social interaction on neural correlates of ' \
'error processing in the flanker task'
# eeg channel names and locations
montage = make_standard_montage(kind='standard_1020')
# channels to be exclude from import
exclude = ['EXG4', 'EXG5', 'EXG6', 'EXG7', 'EXG8']
# subjects to use for analysis
subjects = [2, 35, 36]
# relevant events in the paradigm
event_ids = {'flanker_onset': 71,
# first digit in 11 tells whether target stimulus was
# congruent (1) of incongruent (2) to the flanker stimuli.
# the second digit tells whether target stimulus was a left (1) or
# right (2) pointing arrow
'target_congruent_left': 11,
'target_congruent_right': 12,
'target_incongruent_left': 21,
'target_incongruent_right': 22,
# button presses
'correct_left': 101,
'correct_right': 102,
'incorrect_left': 201,
'incorrect_right': 202,
'end_of_block': 245}
ev_ids = {'245': 1, # end of block
'71': 2, # onset of flanker stimuli
'11': 3, # target_C_L
'12': 4, # target_C_R
'21': 5, # target_I_L
'22': 6, # target_I_R
'101': 7, # left button pressed correctly
'102': 8, # right button pressed correctly
'201': 9, # left button pressed incorrectly
'202': 10 # right button pressed incorrectly
}
###############################################################################
# Templates for file names
#
# This part of the config file uses the FileNames class. It provides a small
# wrapper around string.format() to keep track of a list of file names.
# See fnames.py for details on how this class works.
fname = FileNames()
# Directories to use for input and output:
# bids directory
fname.add('data_dir', data_dir)
# path to sourcedata
fname.add('sourcedata_dir', '{data_dir}/sourcedata')
# target path for data in bids format
fname.add('bids_data', '{data_dir}/sub-{subject:03d}')
# path to derivatives
fname.add('derivatives_dir', '{data_dir}/derivatives')
# path for reports on processing steps
fname.add('reports_dir', '{derivatives_dir}/reports')
# path for results and figures
fname.add('results', '{derivatives_dir}/results')
fname.add('figures', '{results}/figures')
fname.add('dataframes', '{results}/dataframes')
def source_file(files, source_type, subject):
if source_type == 'eeg':
return files.sourcedata_dir + '/sub-%02d/%s/10%02d_ern_soc.bdf' % (subject, source_type, subject) # noqa: E501
elif source_type == 'demographics':
return files.sourcedata_dir + '/sub-%02d/%s/10%02d_demographics.tsv' % (subject, source_type, subject) # noqa: E501
# create full path for data file input
fname.add('source',
source_file) # noqa: E501
# create path for files that are produced in each analysis step
def output_path(path, processing_step, subject, file_type):
path = op.join(path.derivatives_dir, processing_step, 'sub-%03d' % subject)
os.makedirs(path, exist_ok=True)
return op.join(path, 'sub-%03d-%s-%s' % (subject, processing_step, file_type)) # noqa: E501
# the full path for data file output
fname.add('output', output_path)
# create path for files that are produced by mne.report()
def report_path(path, subject):
h5_path = op.join(path.reports_dir, 'sub-%03d.h5' % subject)
html_path = op.join(path.reports_dir, 'sub-%03d-report.html' % subject)
return h5_path, html_path
# the full path for the report file output
fname.add('report', report_path)
# path for file produced by check_system.py
fname.add('system_check', './system_check.txt')