Example #1
0

# visualize the raw data
# plot a subset of single-trials
plotTrials(X, range(3))
# plot the grand average's per condition
plotERP(X, Y)

#-------------------------------------------------------------------
#  Run the standard pre-processing and analysis pipeline
# 1: detrend
X = preproc.detrend(X)
updatePlots()

# 2: bad-channel removal, channels in dim=0
goodch, badch = preproc.outlierdetection(X)
X = X[goodch, :, :]
Cnames = Cnames[goodch]
Cpos = Cpos[:, goodch]
updatePlots()

# 3: apply spatial filter
X = preproc.spatialfilter(X, type='car')
updatePlots()

# 4 & 5: map to frequencies and select frequencies of interest
X = preproc.fftfilter(X, 1, [8, 10, 28, 30], fs)
updatePlots()

# 6 : bad-trial removal, trials in dim=2
goodtr, badtr = preproc.outlierdetection(X, dim=2)
Example #2
0
    data = np.array(p['data'])
    events = p['events']
    hdr = p['hdr']
# Map events to numbers
y = np.array([1 if e.value == 'target' else -1 for e in events])

#-------------------------------------------------------------------
#  Run the standard pre-processing and analysis pipeline
# 0: Remove extra channels
print('number of channels:', NUM_OF_CHANNELS)
print('data shaped as:', data.shape)
data = data[:, :, :NUM_OF_CHANNELS]
# 1: detrend
data = preproc.detrend(data)
# 2: bad-channel removal; channels are last
goodch, badch = preproc.outlierdetection(data, dim=2)
#data = data[:,:,goodch]
data[:, :, badch] *= 0
print('data shape after bad channesls', badch)
print('data shaped as:', data.shape)
# 3: apply spatial filter
data = preproc.spatialfilter(data, type='car')
# 4: frequency filtering
data = preproc.fftfilter(data, 1, [0, 0.1, 30, 32], hdr.fSample)
# 5 : bad-trial removal
goodtr, badtr = preproc.outlierdetection(data, dim=0)
data = data[goodtr]
print('data after good trails:', data.shape)
y = y[goodtr]
print('good trails:', y, y.shape)
# Squash data into 2 dimensions
Example #3
0
    for element in original:
        if hasattr(element,"deepcopy"):
            clone.append(element.deepcopy())
        elif hasattr(element,"copy"):
            clone.append(element.copy())
        else:
            clone.append(element)
    
    return clone


if __name__=="main":
    #%pdb
    import preproc
    import numpy
    fs   = 40
    data = numpy.random.randn(3,fs,5)  # 1s of data    
    ppdata=preproc.detrend(data,0)
    ppdata=preproc.spatialfilter(data,'car')
    ppdata=preproc.spatialfilter(data,'whiten')
    ppdata,goodch=preproc.badchannelremoval(data)
    ppdata,goodtr=preproc.badtrialremoval(data)
    goodtr,badtr=preproc.outlierdetection(data,-1)
    Fdata,freqs=preproc.fouriertransform(data, 2, fSamples=1, posFreq=True)
    Fdata,freqs=preproc.powerspectrum(data, 1, dim=2)
    filt=preproc.mkFilter(10,[0,4,6,7],1)
    filt=preproc.mkFilter(numpy.abs(numpy.arange(-10,10,1)),[0,4,6,7])
    ppdata=preproc.fftfilter(data,1,[0,3,4,6],fs)
    ppdata,keep=preproc.selectbands(data,[4,5,10,15],1); ppdata.shape
# convert to numeric labels
valuedict={} # dict to convert from event.values to numbers    
#y = np.array(y) # N.B. Only works with *NUMERIC* event values...
# get the unique values in y
valuedict = set(y)
# convert to dictionary
valuedict = { val:i for i,val in enumerate(valuedict) }
# use the dict to map from values to numbers
y    = np.array([ valuedict[val] for val in y ])


# 1: detrend
data        = preproc.detrend(data)

# 2: bad-channel removal
goodch, badch = preproc.outlierdetection(data);
data = data[goodch,:,:];

# 3: apply spatial filter
spatialfilter='car'
data        = preproc.spatialfilter(data,type=spatialfilter)

# 4: map to frequencies 
data,freqs = preproc.powerspectrum(data,dim=1,fSample=fs)

# 5 : select the frequency bins we want
freqbands   =[8,10,28,30]
data,freqIdx=preproc.selectbands(data,dim=1,band=freqbands,bins=freqs)

# 6 : bad-trial removal
goodtr, badtr = preproc.outlierdetection(data,dim=2)
Example #5
0
plotTrials(X,range(3));


# plot the grand average's per condition
plotERP(X,Y);


#-------------------------------------------------------------------
#  Run the standard pre-processing and analysis pipeline
# 1: detrend
X        = preproc.detrend(X)
updatePlots();


# 2: bad-channel removal
goodch, badch = preproc.outlierdetection(X);
X = X[goodch,:,:];
Cnames=Cnames[goodch];
Cpos=Cpos[:,goodch];
updatePlots()


# 3: apply spatial filter
X        = preproc.spatialfilter(X,type='car')
updatePlots();


# Map to frequency domain, only keep the positive frequencies
X,freqs = preproc.powerspectrum(X,dim=1,fSample=fs)
yvals = freqs; # ensure the plots use the right x-ticks
ylabel='freq (Hz)'