source: fact/tools/pyscripts/tools/cleaning/area_vs_size.py@ 13102

Last change on this file since 13102 was 13102, checked in by neise, 13 years ago
UNTESTED: example script using the AmplitudeCleaner, for calculating area vs log(size), compare to begin.py
  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#!/usr/bin/python -i
2#
3# Dominik Neise
4#
5# cleaning a small step towards the truth
6from pyfact_rename import *
7import os.path
8import matplotlib.pyplot as plt
9import numpy as np
10from fir_filter import *
11from extractor import *
12from drs_spikes import *
13from plotters import *
14import time as t
15from cleaners import AmplitudeCleaner
16confirm_next_step = False# this is for user interaction
17
18data_file_name = '/media/daten_platte/FACT/data/20120229_144.fits.gz'
19calib_file_name = '/media/daten_platte/FACT/data/20120229_132.drs.fits.gz'
20if not os.path.isfile(data_file_name):
21 print 'not able to find file:', data_file_name
22 sys.exit(-1)
23if not os.path.isfile(calib_file_name ):
24 print 'not able to find file:', calib_file_name
25 sys.exit(-1)
26
27run = RawData(data_file_name, calib_file_name)
28despike = DRSSpikes()
29smooth = SlidingAverage(8)
30extract = GlobalMaxFinder(40,200)
31cleaner = 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
41areas = []
42sizes = []
43for 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
82plt.ion()
83myfig = plt.figure()
84myn = myfig.number
85logsize = np.log10(np.array(sizes))
86areas = np.array(areas)
87
88plt.figure(myn)
89plt.title('area vs. log10(size) of '+ str(run.event_id.value) + 'events')
90plt.xlabel('log10(size/1mV)')
91plt.ylabel('area [#pixel]')
92plt.plot( logsize,areas, '.')
Note: See TracBrowser for help on using the repository browser.