| 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()
|
|---|
| 35 |
|
|---|
| 36 | #p = CamPlotter('cleaned')
|
|---|
| 37 | #p2 = CamPlotter('not')
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | for 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
|
|---|
| 109 | print 'good bye' |
|---|