1 | #!/usr/bin/python -i
|
---|
2 | #
|
---|
3 | # Dominik Neise
|
---|
4 | #
|
---|
5 | # cleaning a small step towards the truth
|
---|
6 | from pyfact_rename import *
|
---|
7 | import os.path
|
---|
8 | import matplotlib.pyplot as plt
|
---|
9 | import numpy as np
|
---|
10 | from fir_filter import *
|
---|
11 | from extractor import *
|
---|
12 | from drs_spikes import *
|
---|
13 | from plotters import *
|
---|
14 | import time as t
|
---|
15 | from cleaners import AmplitudeCleaner
|
---|
16 | confirm_next_step = False# this is for user interaction
|
---|
17 |
|
---|
18 | data_file_name = '/media/daten_platte/FACT/data/20120229_144.fits.gz'
|
---|
19 | calib_file_name = '/media/daten_platte/FACT/data/20120229_132.drs.fits.gz'
|
---|
20 | if not os.path.isfile(data_file_name):
|
---|
21 | print 'not able to find file:', data_file_name
|
---|
22 | sys.exit(-1)
|
---|
23 | if not os.path.isfile(calib_file_name ):
|
---|
24 | print 'not able to find file:', calib_file_name
|
---|
25 | sys.exit(-1)
|
---|
26 |
|
---|
27 | run = RawData(data_file_name, calib_file_name)
|
---|
28 | despike = DRSSpikes()
|
---|
29 | smooth = SlidingAverage(8)
|
---|
30 | extract = GlobalMaxFinder(40,200)
|
---|
31 | cleaner = AmplitudeCleaner(45,18)
|
---|
32 |
|
---|
33 | #plotA = CamPlotter('amplitudes')
|
---|
34 | #plotT = CamPlotter('times')
|
---|
35 | #plotCA = CamPlotter('cleaned amplitudes')
|
---|
36 |
|
---|
37 | #plotArea = HistPlotter('area', 1440, (0,1440) )
|
---|
38 | #plotSize = HistPlotter('size', 1000, (0,10000) )
|
---|
39 |
|
---|
40 |
|
---|
41 | areas = []
|
---|
42 | sizes = []
|
---|
43 | for data,startcell,tt in run:
|
---|
44 | if tt==4:
|
---|
45 | data = despike(data)
|
---|
46 | data = smooth(data)
|
---|
47 | amplitude, time_of_max = extract(data)
|
---|
48 | clean_mask = cleaner(amplitude)
|
---|
49 | #plotA.name='amplitudes EvtID:' + str(run.event_id.value) + ' TT:' + str(tt)
|
---|
50 | #plotA(amplitude)
|
---|
51 | #plotT(time_of_max)
|
---|
52 | #plotCA(data=amplitude, mask=clean_mask)
|
---|
53 |
|
---|
54 | survivors = np.where( clean_mask)[0]
|
---|
55 | size = 0
|
---|
56 | for pixel in survivors:
|
---|
57 | size += amplitude[pixel]
|
---|
58 |
|
---|
59 | if len(survivors) > 0:
|
---|
60 | areas.append( len(survivors) )
|
---|
61 | sizes.append( size )
|
---|
62 |
|
---|
63 |
|
---|
64 | #plotArea(areas, 'areas of ' + str(run.event_id.value) + 'events')
|
---|
65 | #plotSize(sizes, 'sizes of ' + str(run.event_id.value) + 'events')
|
---|
66 |
|
---|
67 | if confirm_next_step:
|
---|
68 | user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
|
---|
69 | number=None
|
---|
70 | try:
|
---|
71 | number=int(user_input)
|
---|
72 | except:
|
---|
73 | number=None
|
---|
74 | if user_input.find('q') != -1:
|
---|
75 | sys.exit(0)
|
---|
76 | elif user_input.find('r') != -1:
|
---|
77 | confirm_next_step = False
|
---|
78 | elif number!=None:
|
---|
79 | run += number
|
---|
80 |
|
---|
81 |
|
---|
82 | plt.ion()
|
---|
83 | myfig = plt.figure()
|
---|
84 | myn = myfig.number
|
---|
85 | logsize = np.log10(np.array(sizes))
|
---|
86 | areas = np.array(areas)
|
---|
87 |
|
---|
88 | plt.figure(myn)
|
---|
89 | plt.title('area vs. log10(size) of '+ str(run.event_id.value) + 'events')
|
---|
90 | plt.xlabel('log10(size/1mV)')
|
---|
91 | plt.ylabel('area [#pixel]')
|
---|
92 | plt.plot( logsize,areas, '.')
|
---|