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

Last change on this file since 13440 was 13439, checked in by neise, 12 years ago
further steps
  • Property svn:executable set to *
File size: 2.6 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 fir_filter import SlidingAverage
9
10from plotters import Plotter
11
12import sys
13import cPickle
14import matplotlib.pyplot as plt
15import numpy as np
16
17data_filename = 'data/20111017_009.fits.gz'
18calib_filename = 'data/20111017_006.drs.fits.gz'
19out_filename = 'test.pkl'
20
21run = RawData(data_filename, calib_filename, return_dict = True, do_calibration=True)
22despike = DRSSpikes()
23smooth = SlidingAverage(7)
24cfd = CFD()
25
26thr = 3
27filter_delay = 3
28
29plt.ion()
30fig = plt.figure()
31fig.hold(True)
32
33
34for event in run:
35 print event['event_id'].value
36 data = event['acal_data']
37 data = despike(data)
38 data_orig = data.copy()
39 data = smooth(data)
40 filtered = cfd(data)
41 filtered = smooth(filtered)
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 )
73
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]
81
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')
87
88
89#output = open(out_filename, 'wb')
90#cPickle.dump(data_filename, output, -1)
91#cPickle.dump(calib_filename, output, -1)
92#cPickle.dump(peak_list, output, -1)
Note: See TracBrowser for help on using the repository browser.