Changeset 13442 for fact/tools/pyscripts/sandbox
- Timestamp:
- 04/25/12 07:51:48 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/sandbox/dneise/gain/gain.py
r13439 r13442 26 26 thr = 3 27 27 filter_delay = 3 28 search_window_size = 12 29 # shortcut 30 sws = search_window_size 28 31 29 32 plt.ion() 30 33 fig = plt.figure() 31 34 fig.hold(True) 35 32 36 33 37 … … 41 45 filtered = smooth(filtered) 42 46 47 # this is a loop over all pixel of this event 48 43 49 for dat, fil, orig in zip(data, filtered, data_orig): 44 50 plt.cla() 45 51 prod = fil[:-1] * fil[1:] 46 52 cand = np.where( prod <= 0)[0] 53 if len(cand) == 0: 54 continue 47 55 # zero crossing with rising edge 48 56 cross = cand[np.where(fil[cand] < 0)[0]] 49 57 if len(cross) == 0: 58 continue 50 59 over_thr = cross[np.where(dat[cross-4] > thr)[0]] 51 60 52 # Now we have these values, we will throw away all those,61 # Now since we have these values, we will throw away all those, 53 62 # which are probably on a falling edge of its predecessor 54 55 56 over = []57 63 dover = np.diff(over_thr) 58 59 for i in range(len(over_thr)): 60 if dover[i] > 100: 61 62 63 over_thr = np.array(over) 64 if len(dover) == 0: 65 good = over_thr 66 else: 67 good = [] 68 good.append(over_thr[0]) 69 for i in range(len(dover)): 70 if dover[-i-1] > 100: 71 good.append(over_thr[-i-1]) 72 73 good = np.array(sorted(good)) 64 74 # these positions, we just found, do not exactly point to the maximum 65 75 # of a peak, but the peak will be on the left side of it. … … 68 78 # the smoothed data and the original data. 69 79 70 max_pos = np.zeros( over_thr.shape )71 max_smoothed = np.zeros( over_thr.shape )72 max_orig = np.zeros( over_thr.shape )80 max_pos = np.zeros( good.shape ) 81 max_smoothed = np.zeros( good.shape ) 82 max_orig = np.zeros( good.shape ) 73 83 74 for i in range(len( over_thr)):84 for i in range(len(good)): 75 85 # We search for a local maximum in a window of size 12 76 if len(dat[ over_thr[i]-12:over_thr[i]]) > 0:86 if len(dat[good[i]-sws:good[i]]) > 0: 77 87 78 max_pos[i] = over_thr[i]-12 + np.argmax(dat[over_thr[i]-12:over_thr[i]])88 max_pos[i] = good[i]-sws + np.argmax(dat[good[i]-sws:good[i]]) 79 89 max_smoothed[i] = dat[max_pos[i]] 80 max_orig[i] 90 max_orig[i] = orig[max_pos[i]-filter_delay] 81 91 82 92 plt.plot(max_pos, max_smoothed, 'ro')
Note:
See TracChangeset
for help on using the changeset viewer.