source: fact/tools/pyscripts/examples/introductory_course/produce_npz.py@ 13128

Last change on this file since 13128 was 13120, checked in by neise, 13 years ago
tidied up a bit. moved examples to examples and deleted scripts, I never used anymore
File size: 2.3 KB
Line 
1#!/usr/bin/python
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
10from pyfact_rename import RawData
11
12import os.path
13import numpy as np
14
15from drs_spikes import DRSSpikes
16from fir_filter import SlidingAverage
17from extractor import GlobalMaxFinder
18from cleaners import AmplitudeCleaner
19
20##############################################################################
21confirm_next_step = False# this is for user interaction
22
23data_file_name = '/media/daten_platte/FACT/data/20120229_144.fits.gz'
24if not os.path.isfile(data_file_name):
25 print 'not able to find file:', data_file_name
26 sys.exit(-1)
27calib_file_name = '/media/daten_platte/FACT/data/20120229_132.drs.fits.gz'
28if not os.path.isfile(calib_file_name ):
29 print 'not able to find file:', calib_file_name
30 sys.exit(-1)
31
32run = RawData(data_file_name, calib_file_name)
33despike = DRSSpikes()
34smooth = SlidingAverage(8)
35extract = GlobalMaxFinder(40,200)
36cleaner = AmplitudeCleaner(45, 18)
37
38areas = []
39sizes = []
40for 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
76outfname = raw_input("please enter name for outputfile")
77np.savez(outfname, Area=areas, Size=sizes)
Note: See TracBrowser for help on using the repository browser.