Changeset 13439
- Timestamp:
- 04/24/12 16:52:43 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/pyscripts/sandbox/dneise/gain/gain.py
r13421 r13439 6 6 from drs_spikes import DRSSpikes 7 7 from fir_filter import CFD 8 from extractor import ZeroXing9 8 from fir_filter import SlidingAverage 10 9 … … 16 15 import numpy as np 17 16 18 data_filename = 'data/20111017_0 10.fits.gz'19 calib_filename = 'data/20111017_00 7.drs.fits.gz'17 data_filename = 'data/20111017_009.fits.gz' 18 calib_filename = 'data/20111017_006.drs.fits.gz' 20 19 out_filename = 'test.pkl' 21 20 22 21 run = RawData(data_filename, calib_filename, return_dict = True, do_calibration=True) 23 22 despike = DRSSpikes() 24 smooth = SlidingAverage( 8)23 smooth = SlidingAverage(7) 25 24 cfd = CFD() 26 find = ZeroXing()27 25 28 #plt.ion() 26 thr = 3 27 filter_delay = 3 29 28 30 p eak_list = []31 32 p = Plotter('data[0]')29 plt.ion() 30 fig = plt.figure() 31 fig.hold(True) 33 32 34 35 #fig = plt.figure()36 #plt.grid(True)37 38 stupid_list = []39 33 40 34 for event in run: … … 42 36 data = event['acal_data'] 43 37 data = despike(data) 38 data_orig = data.copy() 44 39 data = smooth(data) 45 40 filtered = cfd(data) 46 41 filtered = smooth(filtered) 47 peak_positions = find(data) 42 43 for dat, fil, orig in zip(data, filtered, data_orig): 44 plt.cla() 45 prod = fil[:-1] * fil[1:] 46 cand = np.where( prod <= 0)[0] 47 # zero crossing with rising edge 48 cross = cand[np.where(fil[cand] < 0)[0]] 49 50 over_thr = cross[np.where(dat[cross-4] > thr)[0]] 51 52 # Now we have these values, we will throw away all those, 53 # which are probably on a falling edge of its predecessor 54 55 56 over = [] 57 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 # these positions, we just found, do not exactly point to the maximum 65 # of a peak, but the peak will be on the left side of it. 66 # we use the smoothed data to find the position of the local maximum 67 # and then stopre this position and the value of both 68 # the smoothed data and the original data. 69 70 max_pos = np.zeros( over_thr.shape ) 71 max_smoothed = np.zeros( over_thr.shape ) 72 max_orig = np.zeros( over_thr.shape ) 48 73 49 # find peak heights 50 # and get rid of too small peaks 51 # good_peaks = [] 52 # for idx,pixel in enumerate(peak_positions): 53 # good_peaks.append([]) 54 # for peak_pos in pixel: 55 # peak_height = data[idx][int(peak_pos)] 56 # stupid_list.append(peak_height) 57 # if peak_height > 4.0: 58 # good_peaks[-1].append((peak_pos,peak_height)) 59 # 60 # plt.hist(np.array(stupid_list)) 74 for i in range(len(over_thr)): 75 # We search for a local maximum in a window of size 12 76 if len(dat[over_thr[i]-12:over_thr[i]]) > 0: 77 78 max_pos[i] = over_thr[i]-12 + np.argmax(dat[over_thr[i]-12:over_thr[i]]) 79 max_smoothed[i] = dat[max_pos[i]] 80 max_orig[i] = orig[max_pos[i]-filter_delay] 61 81 62 p((data[0],filtered[0])) 63 print 'peak_positions:', map(int, peak_positions[0]) 64 65 peak_pussies = map(int, peak_positions[0]) 66 peak_h = [] 67 for i in peak_pussies: 68 peak_h.append(data[0][i-8]) 69 70 71 pp = Plotter('peaks', x=peak_pussies) 72 pp(peak_h) 73 74 75 ret = raw_input('quit?') 76 if ret=='q': 77 break 78 79 # peak_list.append( good_peaks ) 82 plt.plot(max_pos, max_smoothed, 'ro') 83 plt.plot(max_pos, max_orig, 'bo') 84 plt.plot(np.arange(len(dat)), dat, 'k:') 85 86 raw_input('bla') 80 87 81 88
Note:
See TracChangeset
for help on using the changeset viewer.