Changeset 13012


Ignore:
Timestamp:
03/08/12 10:04:39 (13 years ago)
Author:
lusterma
Message:
improved algorithm, now only loops previously defined candidates, now uses all function and sign of the pattern
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fact/tools/pyscripts/pyfact/drs_spikes.py

    r12950 r13012  
    1717    """
    1818   
    19     def __init__(self, threshold,
    20                  single_pattern=np.array( [0.5, 1.0, 0.5]) ,
    21                  double_pattern=np.array([1., 1., 1., 1.]),
     19    def __init__(self, threshold=10.,
     20                 single_pattern=np.array( [-0.5, 1.0, -0.5]) ,
     21                 double_pattern=np.array([-1., 1., 1., -1.]),
    2222                 debug = False):
    2323        """ initialize spike filter
     
    2828
    2929        self.threshold = threshold
    30         self.single_pattern = list(single_pattern * threshold)
    31         self.double_pattern = list(double_pattern * threshold)
     30        self.single_pattern = single_pattern * threshold
     31        self.double_pattern = double_pattern * threshold
    3232       
    3333        self.remove_signal = fir.RemoveSignal()
    34        
     34        self.debug = debug
     35
    3536    def __call__(self, data):
    3637
     
    4041        singles = []
    4142        doubles = []
    42        
     43
     44        cc = candidates = np.where(a > self.threshold)
     45        print 'candidates: ', candidates[0]-1
    4346        #: find single spikes
    44         p = self.single_pattern
    45         for i, x in enumerate(zip(-a[:-2], a[1:-1], -a[2:])):
    46             if ( (x[0]>p[0]) & (x[1] > p[1]) & (x[2] > p[2]) ):
    47                 singles.append(i)
     47        p = self.single_pattern * np.sign( self.single_pattern )
     48        for i, can in enumerate( zip(a[cc[0]-1], a[cc[0]], a[cc[0]+1]) ):
     49            print 'can : p', can, p
     50            can = can * np.sign(self.single_pattern)
     51            if all(can > p):
     52                singles.append(candidates[0][i] - 1)
    4853
    49         #: find double spike
    50         p = self.double_pattern
    51         for i, x in enumerate(zip(-a[:-3], a[1:-2], a[2:-1], -a[3:])):
    52             if (x[0] > p[0]) & (x[1] > p[1]) & (x[2] > p[2]) & (x[3] > p[3]):
    53                 doubles.append(i)
     54        #: find double spikes
     55        p = self.double_pattern * np.sign( self.double_pattern )
     56        for i, can in enumerate( zip(a[cc[0]-1], a[cc[0]],
     57                                     a[cc[0]+1], a[cc[0]+2]) ):
     58            print 'can : p', can, p
     59            can = can * np.sign(self.double_pattern)
     60            if all(can > p):
     61                doubles.append(candidates[0][i] - 1)
    5462
    55         print 'singles: ', singles
    56         print 'doubles: ', doubles
     63        if self.debug:
     64            print 'singles: ', singles
     65            print 'doubles: ', doubles
    5766
    5867        data = self.remove_single_spikes(singles, data)
     
    8594    print a
    8695
    87     SpikeRemover = DRSSpikes(3.)
     96    SpikeRemover = DRSSpikes(3., debug=True)
    8897    print 'single spike pattern ', SpikeRemover.single_pattern
    8998    print 'double spike pattern ', SpikeRemover.double_pattern
Note: See TracChangeset for help on using the changeset viewer.