source: fact/tools/pyscripts/examples/hillas_test.py@ 13227

Last change on this file since 13227 was 13227, checked in by neise, 13 years ago
evolving to the next level
  • Property svn:executable set to *
File size: 3.3 KB
Line 
1#!/usr/bin/python -tt
2#
3# Example
4# * looping over RawData class object
5#
6import matplotlib.pyplot as plt
7import numpy as np
8import matplotlib.patches as patches
9
10from pyfact import RawData
11from plotters import Plotter
12from plotters import CamPlotter
13
14
15
16from drs_spikes import DRSSpikes
17from fir_filter import SlidingAverage
18from extractor import GlobalMaxFinder
19from cleaners import AmplitudeCleaner
20from image_extractors import HillasParameter
21from image_extractors import SimpleArea
22from image_extractors import SimpleSize
23import sys
24
25data_filename = 'data/20120223_210.fits.gz'
26calib_filename = 'data/20120223_206.drs.fits.gz'
27
28run = RawData(data_filename, calib_filename, return_dict = True)
29despike = DRSSpikes()
30sa = SlidingAverage(8)
31gmf = GlobalMaxFinder(30,230)
32clean = AmplitudeCleaner(45,18)
33clean.return_bool_mask = False
34hillas = HillasParameter()
35
36#p = CamPlotter('cleaned')
37#p2 = CamPlotter('not')
38
39
40for event in run:
41 if event['trigger_type'].value == 4:
42 #if True:
43 print event['event_id']
44 data = event['acal_data']
45 unspiked_data = despike(data)
46 data = sa(data)
47 amp, time = gmf(data)
48 survivors= clean(amp)
49
50 # if nothing survived the cleaning, just go on
51 if len(clean.islands) == 0:
52 continue
53
54 # play with the if statements here, to look at only those events you would like to analyse
55 #if num_islands >= 2 and len(survivors) > 30:
56 #if num_islands == 1 and len(survivors) > 20:
57 if True:
58
59 print 'calling HillasParameter'
60 hillaspar = hillas(survivors, amp)
61 for k in hillaspar.keys():
62 if k[0] != '_':
63 print k, hillaspar[k]
64
65 #print
66 #print 'delta:', hillaspar['delta']/np.pi * 180
67 #print 'COG:', hillaspar['cog_euc']
68 #print 'Mxx/size:', hillaspar['Mxx']/hillaspar['size']
69 #print 'Mxy/size:', hillaspar['Mxy']/hillaspar['size']
70 #print 'Myy/size:', hillaspar['Myy']/hillaspar['size']
71
72
73 #p ( amp, survivors )
74 #plt.figure( p.fig_id )
75
76 # paint arroy to COG
77 #plt.gca().add_patch(
78 # patches.Polygon(
79 # [
80 # (hillaspar['source_pos'][0], hillaspar['source_pos'][1]),
81 # (hillaspar['cog_euc'][0], hillaspar['cog_euc'][1])
82 # ] ) )
83 # paint copy of x-axis through COG
84 #plt.axhline( hillaspar['cog_euc'][1] )
85
86 #plt.gca().add_patch(
87 # patches.Ellipse(
88 # ( hillaspar['cog_euc'][0], hillaspar['cog_euc'][1] ),
89 # 2*hillaspar['length'],
90 # 2*hillaspar['width'],
91 # hillaspar['delta'] /np.pi * 180,
92 # facecolor='none' ) )
93
94 #plt.gca().add_patch(
95 # patches.Circle(
96 # (hillaspar['source_pos'][0], hillaspar['source_pos'][1] ),
97 # 0.5 ) )
98
99
100
101
102 #p2 (amp)
103
104 #sys.exit(0)
105
106 answer = raw_input('hit <Enter> to go on .... hit "q" to quit')
107 if 'q' in answer:
108 break
109print 'good bye'
Note: See TracBrowser for help on using the repository browser.