def showFilter(self): if self.compCh != None: if self.fTypeW["PCA"].get_active(): self.y = pcafilt.mix(self.x2,self.compCh.choose_mask) elif self.fTypeW["ICA"].get_active(): self.y = icafilt.mix(self.x2,self.compCh.choose_mask) self.a.cla() self.a.plotChannels(self.x,"k") self.a.plotChannels(self.y,"r") #for i in range(17): # self.a.plot(self.x[:,i]) self.canvas.draw()
def showFilter(self): if self.compCh != None: if self.fTypeW["PCA"].get_active(): self.y = pcafilt.mix(self.x2, self.compCh.choose_mask) elif self.fTypeW["ICA"].get_active(): self.y = icafilt.mix(self.x2, self.compCh.choose_mask) self.a.cla() self.a.plotChannels(self.x, "k") self.a.plotChannels(self.y, "r") #for i in range(17): # self.a.plot(self.x[:,i]) self.canvas.draw()
def remove_slice_components(self, width=None): assert self._t_slices != None, "Before removing slice components, first find the slice-positions!" if width == None: width = self._slice_width print "Removing slice components" if show_progressbar: pbar = ProgressBar(self._data.shape[1]) for cn in range(self._data.shape[1]): if show_progressbar: pbar.update(cn) if debug: print "Channel %i", cn try: for i in self._ts: one_c_slices = n.zeros((width, len(self._t_slices)), "d") for k, j in enumerate(self._t_slices): if debug: print k, i, j one_c_slices[:, k] = self._data[i + j - width / 2:i + j + width / 2, cn] components = pcafilt.unmix(one_c_slices) for k in range(components.shape[1]): if debug: print "Channel %i, Component %i, std %f, mean(abs) %f" % ( cn, k, components[:, k].std(), abs(components[:, k]).mean()), if components[:, k].std() > 100.0 or k < 2: #acc > 0.03: if debug: print " removed" components[:, k] = n.zeros(components[:, k].shape, "d") else: if debug: print " not removed" #pylab.ioff() #pylab.hist(accs,20) #pylab.show() one_c_slices = pcafilt.mix(components) k = 0 for k, j in enumerate(self._t_slices): self._data[i + j - width / 2:i + j + width / 2, cn] = one_c_slices[:, k] except Exception, e: if debug: print "Error in remove_slice_components,", e
def remove_common_components(self): assert self._mean_data != None, "Before removing components, first calulate the mean!" print "Removing common components" if show_progressbar: pbar = ProgressBar(self._data.shape[1]) for cn in range(self._data.shape[1]): #pbar.progress(cn) if show_progressbar: pbar.update(cn) one_c_data = n.zeros((self._len, len(self._ts)), "d") for i, t in enumerate(self._ts): one_c_data[:, i] = self._data[t:t + self._len, cn] components = pcafilt.unmix(one_c_data) accs = [] for i in range(components.shape[1]): acc = abs( n.corrcoef(self._mean_data[:, cn], components[:, i])[0, 1]) accs.append(acc) if debug: print "Channel %i, Component %i, corrcoef %f, std %f, mean(abs) %f" % ( cn, i, acc, components[:, i].std(), abs(components[:, i]).mean()), if (components[:, i].std() > 100.0 and i < 10) or i < 2: #acc > 0.03: if debug: print " removed" components[:, i] = n.zeros(components[:, i].shape, "d") else: if debug: print " not removed" #pylab.ioff() #pylab.hist(accs,20) #pylab.show() one_c_data = pcafilt.mix(components) for i, t in enumerate(self._ts): try: self._data[t:t + self._len, cn] = one_c_data[:, i] except ValueError, e: print "Error at t=%i, cannot write data back after PCA, shapes are %s and %s" % ( t, self._data[t:t + self._len, cn].shape, one_c_data[:, i].shape), e
def remove_slice_components(self,width=None): assert self._t_slices != None, "Before removing slice components, first find the slice-positions!" if width==None: width=self._slice_width print "Removing slice components" if show_progressbar: pbar = ProgressBar(self._data.shape[1]) for cn in range(self._data.shape[1]): if show_progressbar: pbar.update(cn) if debug: print "Channel %i", cn try: for i in self._ts: one_c_slices = n.zeros((width,len(self._t_slices)),"d") for k,j in enumerate(self._t_slices): if debug: print k,i,j one_c_slices[:,k] = self._data[i+j-width/2:i+j+width/2,cn] components = pcafilt.unmix(one_c_slices) for k in range(components.shape[1]): if debug: print "Channel %i, Component %i, std %f, mean(abs) %f" % (cn,k,components[:,k].std(), abs(components[:,k]).mean()), if components[:,k].std()>100.0 or k<2:#acc > 0.03: if debug: print " removed" components[:,k] = n.zeros(components[:,k].shape,"d") else: if debug: print " not removed" #pylab.ioff() #pylab.hist(accs,20) #pylab.show() one_c_slices = pcafilt.mix(components) k=0 for k,j in enumerate(self._t_slices): self._data[i+j-width/2:i+j+width/2,cn] = one_c_slices[:,k] except Exception,e: if debug: print "Error in remove_slice_components,", e
def remove_common_components(self): assert self._mean_data != None, "Before removing components, first calulate the mean!" print "Removing common components" if show_progressbar: pbar = ProgressBar(self._data.shape[1]) for cn in range(self._data.shape[1]): #pbar.progress(cn) if show_progressbar: pbar.update(cn) one_c_data = n.zeros((self._len,len(self._ts)),"d") for i,t in enumerate(self._ts): one_c_data[:,i] = self._data[t:t+self._len,cn] components = pcafilt.unmix(one_c_data) accs = [] for i in range(components.shape[1]): acc = abs(n.corrcoef(self._mean_data[:,cn],components[:,i])[0,1]) accs.append(acc) if debug: print "Channel %i, Component %i, corrcoef %f, std %f, mean(abs) %f" % (cn,i,acc, components[:,i].std(), abs(components[:,i]).mean()), if (components[:,i].std()>100.0 and i<10) or i<2:#acc > 0.03: if debug: print " removed" components[:,i] = n.zeros(components[:,i].shape,"d") else: if debug: print " not removed" #pylab.ioff() #pylab.hist(accs,20) #pylab.show() one_c_data = pcafilt.mix(components) for i,t in enumerate(self._ts): try: self._data[t:t+self._len,cn] = one_c_data[:,i] except ValueError, e: print "Error at t=%i, cannot write data back after PCA, shapes are %s and %s"%(t,self._data[t:t+self._len,cn].shape,one_c_data[:,i].shape), e