Esempio n. 1
0
    def peakfind_2D(self, subpixel=False, peak_width=10, medfilt_radius=5,
                        maxpeakn=30000):
            """Find peaks in a 2D array (peaks in an image).

            Function to locate the positive peaks in a noisy x-y data set.
    
            Returns an array containing pixel position of each peak.
            
            Parameters
            ---------
            subpixel : bool (optional)
                    default is set to True

            peak_width : int (optional)
                    expected peak width.  Affects subpixel precision fitting window,
                    which takes the center of gravity of a box that has sides equal
                    to this parameter.  Too big, and you'll include other peaks.
                    default is set to 10

            medfilt_radius : int (optional)
                     median filter window to apply to smooth the data
                     (see scipy.signal.medfilt)
                     if 0, no filter will be applied.
                     default is set to 5

            maxpeakn : int (optional)
                    number of maximum detectable peaks
                    default is set to 30000             
            """
            from peak_char import two_dim_findpeaks
            if len(self.data.shape)==2:
                self.peaks=two_dim_findpeaks(self.data, subpixel=subpixel,
                                             peak_width=peak_width, 
                                             medfilt_radius=medfilt_radius)
                
            elif len(self.data.shape)==3:
                # preallocate a large array for the results
                self.peaks=np.zeros((maxpeakn,2,self.data.shape[2]))
                for i in xrange(self.data.shape[2]):
                    tmp=two_dim_findpeaks(self.data[:,:,i], 
                                             subpixel=subpixel,
                                             peak_width=peak_width, 
                                             medfilt_radius=medfilt_radius)
                    self.peaks[:tmp.shape[0],:,i]=tmp
                trim_id=np.min(np.nonzero(np.sum(np.sum(self.peaks,axis=2),axis=1)==0))
                self.peaks=self.peaks[:trim_id,:,:]
            elif len(self.data.shape)==4:
                # preallocate a large array for the results
                self.peaks=np.zeros((maxpeakn,2,self.data.shape[0],self.data.shape[1]))
                for i in xrange(self.data.shape[0]):
                    for j in xrange(self.data.shape[1]):
                        tmp=two_dim_findpeaks(self.data[i,j,:,:], 
                                             subpixel=subpixel,
                                             peak_width=peak_width, 
                                             medfilt_radius=medfilt_radius)
                        self.peaks[:tmp.shape[0],:,i,j]=tmp
                trim_id=np.min(np.nonzero(np.sum(np.sum(np.sum(self.peaks,axis=3),axis=2),axis=1)==0))
                self.peaks=self.peaks[:trim_id,:,:,:]
Esempio n. 2
0
 def locate_peaks(self):
     peaks=[]
     progress = ProgressDialog(title="Peak finder progress", message="Finding peaks on %s images"%self.numfiles, max=self.numfiles, show_time=True, can_cancel=False)
     progress.open()
     for idx in xrange(self.numfiles):
         self.controller.set_active_index(idx)
         self.data = self.controller.get_active_image()[:]
         self.CC = cv_funcs.xcorr(self.template, self.data)
         # peak finder needs peaks greater than 1.  Multiply by 255 to scale them.
         pks=pc.two_dim_findpeaks(self.CC*255, peak_width=self.peak_width, medfilt_radius=None)
         pks[:,2]=pks[:,2]/255.
         peaks.append(pks)
         progress.update(idx+1)
     #ipdb.set_trace()
     self.peaks=peaks
     self.redraw_plots()
Esempio n. 3
0
    def peakfind_2D(self,
                    subpixel=False,
                    peak_width=10,
                    medfilt_radius=5,
                    maxpeakn=30000):
        """Find peaks in a 2D array (peaks in an image).

            Function to locate the positive peaks in a noisy x-y data set.
    
            Returns an array containing pixel position of each peak.
            
            Parameters
            ---------
            subpixel : bool (optional)
                    default is set to True

            peak_width : int (optional)
                    expected peak width.  Affects subpixel precision fitting window,
                    which takes the center of gravity of a box that has sides equal
                    to this parameter.  Too big, and you'll include other peaks.
                    default is set to 10

            medfilt_radius : int (optional)
                     median filter window to apply to smooth the data
                     (see scipy.signal.medfilt)
                     if 0, no filter will be applied.
                     default is set to 5

            maxpeakn : int (optional)
                    number of maximum detectable peaks
                    default is set to 30000             
            """
        from peak_char import two_dim_findpeaks
        if len(self.data.shape) == 2:
            self.peaks = two_dim_findpeaks(self.data,
                                           subpixel=subpixel,
                                           peak_width=peak_width,
                                           medfilt_radius=medfilt_radius)

        elif len(self.data.shape) == 3:
            # preallocate a large array for the results
            self.peaks = np.zeros((maxpeakn, 2, self.data.shape[2]))
            for i in xrange(self.data.shape[2]):
                tmp = two_dim_findpeaks(self.data[:, :, i],
                                        subpixel=subpixel,
                                        peak_width=peak_width,
                                        medfilt_radius=medfilt_radius)
                self.peaks[:tmp.shape[0], :, i] = tmp
            trim_id = np.min(
                np.nonzero(np.sum(np.sum(self.peaks, axis=2), axis=1) == 0))
            self.peaks = self.peaks[:trim_id, :, :]
        elif len(self.data.shape) == 4:
            # preallocate a large array for the results
            self.peaks = np.zeros(
                (maxpeakn, 2, self.data.shape[0], self.data.shape[1]))
            for i in xrange(self.data.shape[0]):
                for j in xrange(self.data.shape[1]):
                    tmp = two_dim_findpeaks(self.data[i, j, :, :],
                                            subpixel=subpixel,
                                            peak_width=peak_width,
                                            medfilt_radius=medfilt_radius)
                    self.peaks[:tmp.shape[0], :, i, j] = tmp
            trim_id = np.min(
                np.nonzero(
                    np.sum(np.sum(np.sum(self.peaks, axis=3), axis=2), axis=1)
                    == 0))
            self.peaks = self.peaks[:trim_id, :, :, :]