@@ -59,7 +59,7 @@ def labels2binlabels(ds, mode):
59
59
ds .labels [:]= N .array ([i in filt for i in ds .labels ], dtype = 'int' )
60
60
61
61
62
- def loadData (subj ):
62
+ def loadData (subj , sr = None ):
63
63
"""Load data for one subject and return dataset.
64
64
65
65
:Parameter:
@@ -89,7 +89,8 @@ def loadData(subj):
89
89
90
90
#snippet_start resample
91
91
# inplace resampling
92
- d .resample (sr = target_samplingrate )
92
+ if sr is not None :
93
+ d .resample (sr = sr )
93
94
verbose (2 , 'Downsampled data to %.1f Hz' % d .samplingrate )
94
95
#snippet_end resample
95
96
@@ -228,7 +229,7 @@ def topoFigure(ds, senses):
228
229
229
230
ax = fig .add_subplot (1 , nsens + 1 , nsens + 1 , frame_on = False )
230
231
cb = P .colorbar (shrink = 0.95 , fraction = 0.05 , drawedges = False ,
231
- ticks = [0 , 0.1 , 0.2 , 0.3 , 0.4 ])
232
+ ticks = [0 , 0.2 , 0.4 ])
232
233
ax .axison = False
233
234
# Expand things a bit
234
235
fig .subplots_adjust (left = 0.06 , right = 1.05 , bottom = 0.01 , wspace = - 0.2 )
@@ -237,7 +238,8 @@ def topoFigure(ds, senses):
237
238
#snippet_end figures
238
239
239
240
240
- def topoFigures (ds , senses , timepoints = ['all' , 'allabs' ], dt = 1 ):
241
+ def topoFigures (ds , senses , timepoints = ['all' , 'allabs' ], dt = 1 ,
242
+ globaly_normed = False ):
241
243
"""Plot topographies of given sensitivities at specified timepoints
242
244
243
245
:Parameters:
@@ -246,6 +248,9 @@ def topoFigures(ds, senses, timepoints=['all', 'allabs'], dt=1):
246
248
to plot sensitivities
247
249
dt : float
248
250
Duration (in seconds) to take for averaging the sensitivity
251
+ globaly_normed : bool
252
+ Either to norm sensitivities through all time points or just
253
+ for a given time point separately
249
254
250
255
XXX: This function shares a lot of code with topoFigure, refactor
251
256
"""
@@ -271,28 +276,42 @@ def topoFigures(ds, senses, timepoints=['all', 'allabs'], dt=1):
271
276
# we can do that only after we avg across splits
272
277
avgbackproj = backproj .mean (axis = 0 )
273
278
279
+ if globaly_normed :
280
+ # strip EOG scores (which are zero anyway,
281
+ # as they had been stripped of before cross-validation)
282
+ avgbackproj = avgbackproj [:- 3 ]
283
+
284
+ # and normalize so that all scores squared sum up to 1
285
+ avgbackproj = L2Normed (avgbackproj )
286
+
287
+ clim = 0.05
288
+
274
289
if timepoint == 'TotalAbs' :
275
290
# compute per channel scores and average across folds
276
291
# (yields (nchannels, )
277
- scores = N .sum (Absolute (avgbackproj ), axis = 1 )
292
+ scores = N .mean (Absolute (avgbackproj ), axis = 1 )
278
293
elif timepoint == 'Total' :
279
294
# compute per channel scores and average across folds
280
295
# (yields (nchannels, )
281
- scores = N .sum (avgbackproj , axis = 1 )
296
+ scores = N .mean (avgbackproj , axis = 1 )
282
297
elif N .isreal (timepoint ):
283
298
timesample = N .round ((timepoint - ds .t0 ) / ds .dt )
284
299
dsample = dt / ds .dt
285
- scores = N .sum (avgbackproj [:, timesample - dsample :timesample + dsample ],
286
- axis = 1 )
300
+ scores = N .mean (avgbackproj [:, timesample - dsample :timesample + dsample ],
301
+ axis = 1 )
287
302
else :
288
303
raise ValueError , "Don't know how to treat timepoint '%s'" % timepoint
289
304
290
- # strip EOG scores (which are zero anyway,
291
- # as they had been stripped of before cross-validation)
292
- scores = scores [:- 3 ]
293
305
294
- # and normalize so that all scores squared sum up to 1
295
- scores = L2Normed (scores )
306
+ if not globaly_normed :
307
+ # strip EOG scores (which are zero anyway,
308
+ # as they had been stripped of before cross-validation)
309
+ scores = scores [:- 3 ]
310
+
311
+ # and normalize so that all scores squared sum up to 1
312
+ scores = L2Normed (scores )
313
+
314
+ clim = 0.4
296
315
297
316
# plot all EEG sensor scores
298
317
plotHeadTopography (
@@ -301,7 +320,7 @@ def topoFigures(ds, senses, timepoints=['all', 'allabs'], dt=1):
301
320
plotsensors = True , resolution = 50 ,
302
321
interpolation = 'nearest' )
303
322
# ensure uniform scaling
304
- P .clim (vmin = - 0.4 , vmax = 0.4 )
323
+ P .clim (vmin = - clim , vmax = clim )
305
324
306
325
if it == 0 :
307
326
# Mention sensitivity in the 0th column
@@ -328,8 +347,8 @@ def topoFigures(ds, senses, timepoints=['all', 'allabs'], dt=1):
328
347
329
348
ax = fig .add_subplot (1 , nsens + 1 , nsens + 1 , frame_on = False )
330
349
cb = P .colorbar (shrink = 0.95 , fraction = 0.05 , drawedges = False ,
331
- pad = 0.9 ,
332
- ticks = [ - 0.4 , - 0.3 , - 0.2 , - 0.1 , 0 , 0.1 , 0.2 , 0.3 , 0.4 ])
350
+ pad = 0.9 , ticks = [ - clim , 0 , clim ])
351
+
333
352
334
353
ax .axison = False
335
354
# Expand things a bit
@@ -339,7 +358,7 @@ def topoFigures(ds, senses, timepoints=['all', 'allabs'], dt=1):
339
358
340
359
if __name__ == '__main__' :
341
360
# load dataset for some subject
342
- ds = loadData (subj )
361
+ ds = loadData (subj , sr = target_samplingrate )
343
362
344
363
# artificially group into chunks
345
364
nchunks = 6
@@ -398,7 +417,7 @@ def topoFigures(ds, senses, timepoints=['all', 'allabs'], dt=1):
398
417
s *= - 1.0
399
418
400
419
# (re)get pristine dataset for plotting of ERPs
401
- ds_pristine = loadData (subj )
420
+ ds_pristine = loadData (subj , sr = target_samplingrate )
402
421
403
422
P .ioff ()
404
423
0 commit comments