| 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
|
|---|
| 13 | import sys
|
|---|
| 14 | import pickle
|
|---|
| 15 | import random
|
|---|
| 16 | confirm_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
|
|---|
| 23 | analysis = {}
|
|---|
| 24 | can['input'] = {} #
|
|---|
| 25 | can['settings'] = {} # a subspace for holdind all settings
|
|---|
| 26 | can['output'] = {} # a subspace for holding all results... or similar stuff
|
|---|
| 27 | can['logbook'] = [] # a list of statements ... human readable logbook
|
|---|
| 28 | can['src'] = [] # this script and other sources
|
|---|
| 29 |
|
|---|
| 30 | # store this scipt in the list of sources.
|
|---|
| 31 | can['src'].append( open(sys.argv[0], 'r').read() )
|
|---|
| 32 |
|
|---|
| 33 | # declare filenames to work with:
|
|---|
| 34 | can['settings']['data_file_names'] = ['/media/daten_platte/FACT/data/20120229_144.fits.gz']
|
|---|
| 35 | can['settings']['calib_file_names'] = ['/media/daten_platte/FACT/data/20120229_132.drs.fits.gz']
|
|---|
| 36 | # we even tell the can, where we are going to store it
|
|---|
| 37 | can['settings']['outfile_name'] = './can.pkl' # <-- no list ... simple string
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | # put the settings for all the extractors and similar data processors
|
|---|
| 41 | # into the settings
|
|---|
| 42 | can['settings']['SlidingAverage'] = [8]
|
|---|
| 43 | can['settings']['DRSSpikes'] = []
|
|---|
| 44 | can['settings']['GlobalMaxFinder'] = [40,200]
|
|---|
| 45 | can['settings']['AmplitudeCleaner'] = [45,18,'return_bool_mask=False']
|
|---|
| 46 |
|
|---|
| 47 | # prepare some space in the can, for the results of this script
|
|---|
| 48 | can['results']['areas'] = []
|
|---|
| 49 | can['results']['sizes'] = []
|
|---|
| 50 | # and make some shortcuts
|
|---|
| 51 | areas = can['results']['areas']
|
|---|
| 52 | sizes = can['results']['sizes']
|
|---|
| 53 |
|
|---|
| 54 | # this loop will loop over all events, out of all data files in the can,
|
|---|
| 55 | # so the analysis loop doesn't even know, there are more files involved.
|
|---|
| 56 | # of course in the logbook the opening and closing will be stored
|
|---|
| 57 | for data in range(100):
|
|---|
| 58 | if True:
|
|---|
| 59 |
|
|---|
| 60 | size = 0
|
|---|
| 61 | for i in range(data):
|
|---|
| 62 | size += data
|
|---|
| 63 |
|
|---|
| 64 | area = random.randint(0,data)
|
|---|
| 65 | if area > 4:
|
|---|
| 66 | areas.append( area )
|
|---|
| 67 | sizes.append( size )
|
|---|
| 68 | # we suddenly realize, that we would like to store
|
|---|
| 69 | # the event IDs of events, which are have no survivors
|
|---|
| 70 | # we should scroll up ... before the loop and declare an empty list
|
|---|
| 71 | # like: can['results']['no_survivor_ids'] = []
|
|---|
| 72 | # but imagine we are writing a function, which is beeing called inside the loop
|
|---|
| 73 | # and this function has no possibility to declare that ...
|
|---|
| 74 | # well then this function can still put new things inside the can!
|
|---|
| 75 | else:
|
|---|
| 76 | if 'no_survivor_ids' not in can['results']:
|
|---|
| 77 | can['results']['no_survivor_ids'] = [data]
|
|---|
| 78 | else:
|
|---|
| 79 | can['results']['no_survivor_ids'].append(data)
|
|---|
| 80 |
|
|---|
| 81 | if confirm_next_step:
|
|---|
| 82 | user_input = raw_input("'q'-quit, 'r'-run, anything else goes one step")
|
|---|
| 83 | number=None
|
|---|
| 84 | try:
|
|---|
| 85 | number=int(user_input)
|
|---|
| 86 | except:
|
|---|
| 87 | number=None
|
|---|
| 88 | if user_input.find('q') != -1:
|
|---|
| 89 | sys.exit(0)
|
|---|
| 90 | elif user_input.find('r') != -1:
|
|---|
| 91 | confirm_next_step = False
|
|---|
| 92 | elif number!=None:
|
|---|
| 93 | run += number
|
|---|
| 94 |
|
|---|
| 95 | # Now our analysis is done and we save the can
|
|---|
| 96 | output = open(can['settings']['outfile_name'], 'wb')
|
|---|
| 97 | pickle.dump(can, output)
|
|---|
| 98 | output.close() |
|---|