source: fact/tools/pyscripts/sandbox/dneise/gain/test_gain.py@ 13442

Last change on this file since 13442 was 13440, checked in by neise, 13 years ago
init
  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/usr/bin/python -tti
2#
3#
4
5from pyfact import RawData
6from drs_spikes import DRSSpikes
7from fir_filter import CFD
8from extractor import ZeroXing
9from fir_filter import SlidingAverage
10
11from plotters import Plotter
12
13import sys
14import cPickle
15import matplotlib.pyplot as plt
16import numpy as np
17
18data_filename = 'data/20111017_009.fits.gz
19calib_filename = 'data/20111017_006.drs.fits.gz'
20out_filename = 'test.pkl'
21
22run = RawData(data_filename, calib_filename, return_dict = True, do_calibration=True)
23despike = DRSSpikes()
24smooth = SlidingAverage(7)
25cfd = CFD()
26find = ZeroXing()
27
28plt.ion()
29
30peak_list = []
31
32#p = Plotter('data[0]')
33
34
35#fig = plt.figure()
36#plt.grid(True)
37
38stupid_list = []
39thr = 3
40
41fig = plt.figure()
42fig.hold(True)
43
44for event in run:
45 print event['event_id'].value
46 data = event['acal_data']
47 origorig = data.copy()
48 data = despike(data)
49 data_orig = data.copy()
50 data = smooth(data)
51 filtered = cfd(data)
52 filtered = smooth(filtered)
53
54 for dat, fil, orig, zzz in zip(data, filtered, data_orig, origorig):
55 plt.cla()
56 prod = fil[:-1] * fil[1:]
57 cand = np.where( prod <= 0)[0]
58 # zero crossing with rising edge
59 cross = cand[np.where(fil[cand] < 0)[0]]
60
61 over_thr = cross[np.where(dat[cross-4] > thr)[0]]
62
63 maxima = np.zeros( over_thr.shape )
64 maxima_pos =np.zeros( over_thr.shape )
65 omaxima = np.zeros( over_thr.shape )
66 omaxima_pos =np.zeros( over_thr.shape )
67
68 for i in range(len(over_thr)):
69 if len(dat[over_thr[i]-12:over_thr[i]]) > 0:
70 maxima_pos[i] = over_thr[i]-12 + np.argmax(dat[over_thr[i]-12:over_thr[i]])
71 maxima[i] = dat[maxima_pos[i]]
72 omaxima_pos[i] = over_thr[i]-12 + np.argmax(orig[over_thr[i]-12:over_thr[i]])
73 omaxima[i] = orig[maxima_pos[i]-3]
74
75 x_values = np.array(range(len(dat)))
76
77 plt.plot( x_values-3, dat , 'k:')
78 plt.plot( x_values, orig , 'y:')
79 plt.plot( x_values, zzz , 'r.')
80
81 plt.plot( maxima_pos-3, maxima, 'bo')
82 plt.plot( maxima_pos-3, omaxima, 'yo')
83 plt.plot( over_thr-3, dat[over_thr], 'ro')
84
85
86
87 ret = raw_input('quit?')
88 if ret=='q':
89 break
90
91# peak_list.append( good_peaks )
92
93
94#output = open(out_filename, 'wb')
95#cPickle.dump(data_filename, output, -1)
96#cPickle.dump(calib_filename, output, -1)
97#cPickle.dump(peak_list, output, -1)
Note: See TracBrowser for help on using the repository browser.