1 | #!/usr/bin/python -tt
|
---|
2 | #
|
---|
3 | # Example
|
---|
4 | # * looping over RawData class object
|
---|
5 | #
|
---|
6 | import matplotlib.pyplot as plt
|
---|
7 | import numpy as np
|
---|
8 | import matplotlib.patches as patches
|
---|
9 |
|
---|
10 | from pyfact import RawData
|
---|
11 | #from plotters import Plotter
|
---|
12 | from plotters import CamPlotter
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 | from drs_spikes import DRSSpikes
|
---|
17 | from fir_filter import SlidingAverage
|
---|
18 | from extractor import GlobalMaxFinder
|
---|
19 | from cleaners import AmplitudeCleaner
|
---|
20 | from image_extractors import HillasParameter
|
---|
21 | from image_extractors import SimpleArea
|
---|
22 | from image_extractors import SimpleSize
|
---|
23 | import sys
|
---|
24 |
|
---|
25 | data_filename = 'data/20120223_210.fits.gz'
|
---|
26 | calib_filename = 'data/20120223_206.drs.fits.gz'
|
---|
27 |
|
---|
28 | run = RawData(data_filename, calib_filename, return_dict = True)
|
---|
29 | despike = DRSSpikes()
|
---|
30 | sa = SlidingAverage(8)
|
---|
31 | gmf = GlobalMaxFinder(30,230)
|
---|
32 | clean = AmplitudeCleaner(45,18)
|
---|
33 | clean.return_bool_mask = False
|
---|
34 | hillas = HillasParameter( source_pos=(1,-1) )
|
---|
35 |
|
---|
36 | p = CamPlotter('cleaned')
|
---|
37 |
|
---|
38 |
|
---|
39 | print 'Source Position for HillasParameter class is:'
|
---|
40 | print hillas.source_pos
|
---|
41 | print 'change it in line 34 if you like'
|
---|
42 |
|
---|
43 | for 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
|
---|
119 | print 'good bye'
|
---|