1
2
3
4
5
6
7
8
9 """Common functions and options definitions for command line
10
11 __docformat__ = 'restructuredtext'
12
13 Conventions:
14 Every option (instance of optparse.Option) has prefix "opt". Lists of options
15 has prefix opts (e.g. `optsCommon`).
16
17 Option name should be camelbacked version of .dest for the option.
18 """
19
20
21 from optparse import OptionParser, Option, OptionGroup
22
23
24 from mvpa.misc import verbose
25
26
27
28
29
30
31
32
33
34
35
36 parser = OptionParser(add_help_option=False,
37 conflict_handler="resolve")
38
39
40
41
48
49 optHelp = \
50 Option("-h", "--help", "--sos",
51 action="help",
52 help="Show this help message and exit")
53
54 optVerbose = \
55 Option("-v", "--verbose", "--verbosity",
56 action="callback", callback=verboseCallback, nargs=1,
57 type="int", dest="verbose", default=0,
58 help="Verbosity level of output")
59 """Pre-cooked `optparse`'s option to specify verbose level"""
60
61 optsCommon = OptionGroup(parser, title="Generic"
62
63 )
64
65 optsCommon.add_options([optVerbose, optHelp])
66
67
68 if __debug__:
69 from mvpa.misc import debug
70
72 """Callback for -d|--debug cmdline option
73 """
74 if value == "list":
75 print "Registered debug IDs:"
76 keys = debug.registered.keys()
77 keys.sort()
78 for k in keys:
79 print "%-7s: %s" % (k, debug.registered[k])
80 print "Use ALL: to enable all of the debug IDs listed above."
81 print "Use python regular expressions to select group. CLF.* will" \
82 " enable all debug entries starting with CLF (e.g. CLFBIN, CLFMC)"
83 raise SystemExit, 0
84
85 optstr = optstr
86 debug.setActiveFromString(value)
87
88
89 setattr(parser.values, option.dest, value)
90
91
92 optDebug = Option("-d", "--debug",
93 action="callback", callback=debugCallback,
94 nargs=1,
95 type="string", dest="debug", default="",
96 help="Debug entries to report. " +
97 "Run with '-d list' to get a list of " +
98 "registered entries")
99
100 optsCommon.add_option(optDebug)
101
102
103
104
105
106 optClf = \
107 Option("--clf",
108 type="choice", dest="clf",
109 choices=['knn', 'svm', 'ridge'], default='svm',
110 help="Type of classifier to be used. Default: svm")
111
112 optRadius = \
113 Option("-r", "--radius",
114 action="store", type="float", dest="radius",
115 default=5.0,
116 help="Radius to be used (eg for the searchlight). Default: 5.0")
117
118
119 optKNearestDegree = \
120 Option("-k", "--k-nearest",
121 action="store", type="int", dest="knearestdegree", default=3,
122 help="Degree of k-nearest classifier. Default: 3")
123
124 optsKNN = OptionGroup(parser, "Specification of kNN")
125 optsKNN.add_option(optKNearestDegree)
126
127 optSVMC = \
128 Option("-C", "--svm-C",
129 action="store", type="float", dest="svm_C", default=1.0,
130 help="C parameter for soft-margin C-SVM classification. " \
131 "Default: 1.0")
132
133 optSVMNu = \
134 Option("--nu", "--svm-nu",
135 action="store", type="float", dest="svm_nu", default=0.1,
136 help="nu parameter for soft-margin nu-SVM classification. " \
137 "Default: 0.1")
138
139 optSVMGamma = \
140 Option("--gamma", "--svm-gamma",
141 action="store", type="float", dest="svm_gamma", default=1.0,
142 help="gamma parameter for Gaussian kernel of RBF SVM. " \
143 "Default: 1.0")
144
145
146 optsSVM = OptionGroup(parser, "SVM specification")
147 optsSVM.add_options([optSVMNu, optSVMC, optSVMGamma])
148
149
150
151
152 optCrossfoldDegree = \
153 Option("-c", "--crossfold",
154 action="store", type="int", dest="crossfolddegree", default=1,
155 help="Degree of N-fold crossfold. Default: 1")
156
157 optsGener = OptionGroup(parser, "Generalization estimates")
158 optsGener.add_options([optCrossfoldDegree])
159
160
161
162 optZScore = \
163 Option("--zscore",
164 action="store_true", dest="zscore", default=0,
165 help="Enable zscoring of dataset samples. Default: Off")
166
167 optTr = \
168 Option("--tr",
169 action="store", dest="tr", default=2.0, type='float',
170 help="fMRI volume repetition time. Default: 2.0")
171
172 optDetrend = \
173 Option("--detrend",
174 action="store_true", dest="detrend", default=0,
175 help="Do linear detrending. Default: Off")
176
177 optsPreproc = OptionGroup(parser, "Preprocessing options")
178 optsPreproc.add_options([optZScore, optTr, optDetrend])
179
180
181
182 optBoxLength = \
183 Option("--boxlength",
184 action="store", dest="boxlength", default=1, type='int',
185 help="Length of the box in volumes (integer). Default: 1")
186
187 optBoxOffset = \
188 Option("--boxoffset",
189 action="store", dest="boxoffset", default=0, type='int',
190 help="Offset of the box from the event onset in volumes. Default: 0")
191
192 optsBox = OptionGroup(parser, "Box options")
193 optsBox.add_options([optBoxLength, optBoxOffset])
194
195
196
197
198 optChunk = \
199 Option("--chunk",
200 action="store", dest="chunk", default='0',
201 help="Id of the data chunk. Default: 0")
202
203 optChunkLimits = \
204 Option("--chunklimits",
205 action="store", dest="chunklimits", default=None,
206 help="Limit processing to a certain chunk of data given by start " \
207 "and end volume number (including lower, excluding upper " \
208 "limit). Numbering starts with zero.")
209
210 optsChunk = OptionGroup(parser, "Chunk options AKA Sample attributes XXX")
211 optsChunk.add_options([optChunk, optChunkLimits])
212