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

Last change on this file since 13449 was 13298, checked in by neise, 13 years ago
made a real example out of it ... should be comprehendable and working now
  • Property svn:executable set to *
File size: 3.7 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
11#from 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( source_pos=(1,-1) )
35
36p = CamPlotter('cleaned')
37
38
39print 'Source Position for HillasParameter class is:'
40print hillas.source_pos
41print 'change it in line 34 if you like'
42
43for event in run:
44 # trigger_type 4 means 'physical data'
45 if event['trigger_type'].value == 4:
46
47 print 'event number:', int(event['event_id'].value)
48
49 #remark:
50 # currently one needs a quite long expression for getting the event id
51 # out of the event-dictionary:
52 # it looks like this: int(event['event_id'].value
53 #
54 # I will change it, such that it looks like this:
55 # event['event_id']
56 # or maybe:
57 # event['id']
58 #
59 # what do you think, dear reader?? :-)
60
61 data = event['acal_data']
62 unspiked_data = despike(data)
63 data = sa(data)
64 amp, time = gmf(data)
65 survivors= clean(amp)
66
67 # the cleaner also sorts all pixels into groups of islands
68 # clean.islands is a list of lists of pixel_ids
69 # the number of lists is simply the number of islands...
70 num_islands = len(clean.islands)
71
72 # if nothing survived the cleaning, just go on
73 if num_islands == 0:
74 continue
75
76
77 if num_islands == 1:
78
79 hillaspar = hillas(survivors, amp)
80
81 print 'size', hillaspar['size']
82 print 'alpha', hillaspar['alpha']
83 print 'delta', hillaspar['delta']
84 print 'width', hillaspar['width']
85 print 'length', hillaspar['length']
86 print 'COG in euclidic coordinates:'
87 print hillaspar['cog_euc']
88
89
90 p ( amp, survivors )
91 plt.figure( p.fig_id )
92
93 # paint arrow to COG
94 plt.gca().add_patch(
95 patches.Polygon(
96 [
97 (hillaspar['source_pos'][0], hillaspar['source_pos'][1]),
98 (hillaspar['cog_euc'][0], hillaspar['cog_euc'][1])
99 ] ) )
100 # paint copy of x-axis through COG
101 plt.axhline( hillaspar['cog_euc'][1] )
102
103 plt.gca().add_patch(
104 patches.Ellipse(
105 ( hillaspar['cog_euc'][0], hillaspar['cog_euc'][1] ),
106 2*hillaspar['length'],
107 2*hillaspar['width'],
108 hillaspar['delta'] /np.pi * 180,
109 facecolor='none' ) )
110
111 plt.gca().add_patch(
112 patches.Circle(
113 (hillaspar['source_pos'][0], hillaspar['source_pos'][1] ),
114 0.5 ) )
115
116 answer = raw_input('hit <Enter> to go on .... hit "q" to quit')
117 if 'q' in answer:
118 break
119print 'good bye'
Note: See TracBrowser for help on using the repository browser.