source: fact/tools/pyscripts/examples/result_collection/fake_analysis.py@ 13148

Last change on this file since 13148 was 13113, checked in by neise, 13 years ago
initial commit of first thoughts about how to collect anaysis results
  • Property svn:executable set to *
File size: 3.5 KB
Line 
1#!/usr/bin/python -i
2
3# Please read first:
4# * readme.1st and
5# * area_vs_hist_with_can.py
6#
7# this scipt is just a funny test, how such a can, might be filled during an
8# analysis ...
9# it is possible to execute this script
10#
11# the output can be read in, and will be displayed by
12# canread.py
13import sys
14import pickle
15import random
16confirm_next_step = False
17
18# this little can will hold
19# * all the settings,
20# * all results and intermediate results
21# * as well as this script itself
22# and then it will be written, to an output file
23can = {} # the FACT can
24can['settings'] = {} # a subspace for holdind all settings
25can['results'] = {} # a subspace for holding all results... or similar stuff
26can['logbook'] = [] # a list of statements ... human readable logbook
27can['src'] = [] # this script and other sources
28
29# store this scipt in the list of sources.
30can['src'].append( open(sys.argv[0], 'r').read() )
31
32# declare filenames to work with:
33can['settings']['data_file_names'] = ['/media/daten_platte/FACT/data/20120229_144.fits.gz']
34can['settings']['calib_file_names'] = ['/media/daten_platte/FACT/data/20120229_132.drs.fits.gz']
35# we even tell the can, where we are going to store it
36can['settings']['outfile_name'] = './can.pkl' # <-- no list ... simple string
37
38
39# put the settings for all the extractors and similar data processors
40# into the settings
41can['settings']['SlidingAverage'] = [8]
42can['settings']['DRSSpikes'] = []
43can['settings']['GlobalMaxFinder'] = [40,200]
44can['settings']['AmplitudeCleaner'] = [45,18,'return_bool_mask=False']
45
46# prepare some space in the can, for the results of this script
47can['results']['areas'] = []
48can['results']['sizes'] = []
49# and make some shortcuts
50areas = can['results']['areas']
51sizes = can['results']['sizes']
52
53# this loop will loop over all events, out of all data files in the can,
54# so the analysis loop doesn't even know, there are more files involved.
55# of course in the logbook the opening and closing will be stored
56for data in range(100):
57 if True:
58
59 size = 0
60 for i in range(data):
61 size += data
62
63 area = random.randint(0,data)
64 if area > 4:
65 areas.append( area )
66 sizes.append( size )
67 # we suddenly realize, that we would like to store
68 # the event IDs of events, which are have no survivors
69 # we should scroll up ... before the loop and declare an empty list
70 # like: can['results']['no_survivor_ids'] = []
71 # but imagine we are writing a function, which is beeing called inside the loop
72 # and this function has no possibility to declare that ...
73 # well then this function can still put new things inside the can!
74 else:
75 if 'no_survivor_ids' not in can['results']:
76 can['results']['no_survivor_ids'] = [data]
77 else:
78 can['results']['no_survivor_ids'].append(data)
79
80 if confirm_next_step:
81 user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
82 number=None
83 try:
84 number=int(user_input)
85 except:
86 number=None
87 if user_input.find('q') != -1:
88 sys.exit(0)
89 elif user_input.find('r') != -1:
90 confirm_next_step = False
91 elif number!=None:
92 run += number
93
94# Now our analysis is done and we save the can
95output = open(can['settings']['outfile_name'], 'wb')
96pickle.dump(can, output)
97output.close()
Note: See TracBrowser for help on using the repository browser.