1 | #!/usr/bin/python -tt
|
---|
2 | #
|
---|
3 | # Dominik Neise
|
---|
4 | # TU Dortmund
|
---|
5 | #
|
---|
6 | # example for storing numpy arrays containing FACT analysis results
|
---|
7 | # to file
|
---|
8 |
|
---|
9 | #import this at first, please
|
---|
10 | from pyfact import RawData
|
---|
11 |
|
---|
12 | import os.path
|
---|
13 | import numpy as np
|
---|
14 |
|
---|
15 | from drs_spikes import DRSSpikes
|
---|
16 | from fir_filter import SlidingAverage
|
---|
17 | from extractor import GlobalMaxFinder
|
---|
18 | from cleaners import AmplitudeCleaner
|
---|
19 |
|
---|
20 | ##############################################################################
|
---|
21 | confirm_next_step = False# this is for user interaction
|
---|
22 |
|
---|
23 | data_file_name = '/media/daten_platte/FACT/data/20120229_144.fits.gz'
|
---|
24 | if not os.path.isfile(data_file_name):
|
---|
25 | print 'not able to find file:', data_file_name
|
---|
26 | sys.exit(-1)
|
---|
27 | calib_file_name = '/media/daten_platte/FACT/data/20120229_132.drs.fits.gz'
|
---|
28 | if not os.path.isfile(calib_file_name ):
|
---|
29 | print 'not able to find file:', calib_file_name
|
---|
30 | sys.exit(-1)
|
---|
31 |
|
---|
32 | run = RawData(data_file_name, calib_file_name)
|
---|
33 | despike = DRSSpikes()
|
---|
34 | smooth = SlidingAverage(8)
|
---|
35 | extract = GlobalMaxFinder(40,200)
|
---|
36 | cleaner = AmplitudeCleaner(45, 18)
|
---|
37 |
|
---|
38 | areas = []
|
---|
39 | sizes = []
|
---|
40 | for data,startcell,tt in run:
|
---|
41 | # trigger type 4 means 'physics event'
|
---|
42 | if tt==4:
|
---|
43 | data = despike(data)
|
---|
44 | data = smooth(data)
|
---|
45 | amplitude, time_of_max = extract(data)
|
---|
46 | survivors = cleaner(amplitude, return_bool_mask=False)
|
---|
47 |
|
---|
48 | # this is not python like, should be done in a single line
|
---|
49 | # adding up the amplitude of all survivors
|
---|
50 | size = 0
|
---|
51 | for pixel in survivors:
|
---|
52 | size += amplitude[pixel]
|
---|
53 |
|
---|
54 | area = len(survivors)
|
---|
55 |
|
---|
56 | if area > 0:
|
---|
57 | areas.append( area )
|
---|
58 | sizes.append( size )
|
---|
59 |
|
---|
60 | # This is for ---------- USER INTERACTION -------------------------
|
---|
61 | if confirm_next_step:
|
---|
62 | user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
|
---|
63 | number=None
|
---|
64 | try:
|
---|
65 | number=int(user_input)
|
---|
66 | except:
|
---|
67 | number=None
|
---|
68 | if user_input.find('q') != -1:
|
---|
69 | sys.exit(0)
|
---|
70 | elif user_input.find('r') != -1:
|
---|
71 | confirm_next_step = False
|
---|
72 | elif number!=None:
|
---|
73 | run += number
|
---|
74 | # ---------------END OF USER INTERACTION -------------------------
|
---|
75 |
|
---|
76 | outfname = raw_input("please enter name for outputfile")
|
---|
77 | np.savez(outfname, Area=areas, Size=sizes)
|
---|