Changeset 13012 for fact/tools/pyscripts/pyfact
- Timestamp:
- 03/08/12 10:04:39 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/pyfact/drs_spikes.py
r12950 r13012 17 17 """ 18 18 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.]), 22 22 debug = False): 23 23 """ initialize spike filter … … 28 28 29 29 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 32 32 33 33 self.remove_signal = fir.RemoveSignal() 34 34 self.debug = debug 35 35 36 def __call__(self, data): 36 37 … … 40 41 singles = [] 41 42 doubles = [] 42 43 44 cc = candidates = np.where(a > self.threshold) 45 print 'candidates: ', candidates[0]-1 43 46 #: 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) 48 53 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) 54 62 55 print 'singles: ', singles 56 print 'doubles: ', doubles 63 if self.debug: 64 print 'singles: ', singles 65 print 'doubles: ', doubles 57 66 58 67 data = self.remove_single_spikes(singles, data) … … 85 94 print a 86 95 87 SpikeRemover = DRSSpikes(3. )96 SpikeRemover = DRSSpikes(3., debug=True) 88 97 print 'single spike pattern ', SpikeRemover.single_pattern 89 98 print 'double spike pattern ', SpikeRemover.double_pattern
Note:
See TracChangeset
for help on using the changeset viewer.