======== Examples ======== RawData ======== one may interactively play with the two most important classes *RawData* and *SlowData* from module pyfact... *datafilepath* and *calibfilepath* should be adjusted in case you are not working on the ISDC cluster. explore class RawData:: from pyfact import RawData # or from pyfact import * datafilepath = '/fact/raw/2012/03/04/20120304_018.fits.gz' calibfilepath = '/fact/raw/2012/03/04/20120304_012.drs.fits.gz' run = RawData(datafilepath, calibfilepath) event = run.next() type(event) print 70*'*' for key in event: print 'key :', key print 'value:', event[key] print 70*'*' for historical reasons, an event contains *data* and *acal_data*, where *acal_data* would be the DRS amplitude calibrated data, and *data* would be uncalibrated. But since the calibration was moved into a C++ class, for better performance, these keys now contains the same data. loop over RawData:: from pyfact import RawData # or from pyfact import * datafilepath = '/fact/raw/2012/03/04/20120304_018.fits.gz' calibfilepath = '/fact/raw/2012/03/04/20120304_012.drs.fits.gz' run = RawData(datafilepath, calibfilepath) for event in run: print 'event_id:', event['event_id'] # the data can be found in event['data'] SlowData ========= have a look at some SlowData:: :~$ cd /fact/aux/2012/05/30 :/fact/aux/2012/05/30$ python from pyfact import SlowData file = SlowData('20120530.FTM_CONTROL_TRIGGER_RATES.fits') file.show() have a look at the *columns*, that are available:: 'columns': {'BoardRate': (40L, 4L, 'E', 'Hz'), 'ElapsedTime': (1L, 4L, 'E', 'sec'), 'FTMtimeStamp': (1L, 8L, 'K', 'us'), 'OnTime': (1L, 4L, 'E', 'sec'), 'OnTimeCounter': (1L, 8L, 'K', 'us'), 'PatchRate': (160L, 4L, 'E', 'Hz'), 'QoS': (1L, 4L, 'J', ''), 'Time': (1L, 8L, 'D', 'MJD'), 'TriggerCounter': (1L, 4L, 'J', 'int'), 'TriggerRate': (1L, 4L, 'E', 'Hz')}, choose the *columns* you would like to retrieve from the file:: file.register('TriggerRate') file.register('Time') # or in case you are unsure file.register('all') check, what happened. file has got some new members:: file.show() but they are all zero. Now one should call *next()* in order to get the file contents row by row:: file.next() file.show() or loop over the file:: for row in file: print row.Time, row. OnTime *row* is just be a copy of *file*, but inside the for loop, I think it is convenient to access members of *row* rather than members of *file*. I is just easier to understand for the reader, I think. Stack some slow Data into numpy arrays ====================================== This example shows how to stack some columns from slow data into numpy arrays. One first open the file as usual, and *registers* the columns one is interested in. Then one informs the SlowData object about ones intention to have the data stacked. Now the SlowData object will create 2D-arrays, which contain the registered data while one loops over the slowdata file. The looping is important! Have a look:: #!/usr/bin/python -tti import time import numpy as np from pyfact import SlowData f = SlowData('20120601.FTM_STATIC_DATA.fits') # # do here --> f.show() if you are not sure about the column names # f.register('PatchThresh') f.register('Time') f.stack() # now loop over the file and let SlowData do the magic for row in f: pass # the stacked data can be found in the dict SlowData.stacked_cols # put the Time array into a variable and convert into seconds since 01.01.1970 t = f.stacked_cols['Time'] * 24. * 3600 # put the thresholds into another var, for convenience dtr = f.stacked_cols['PatchThresh'] # give the user some diagnostic info print 'start time:', time.asctime(time.gmtime(t[0])) print 'stop time:', time.asctime(time.gmtime(t[-1])) print 'mean/median threshold:', dtr.mean(), np.median(dtr) print 'min/max threshold:', dtr.min(), dtr.max() print 'std deviation:', dtr.std() calling a system command ======================== Using the os module any command executable on the command line can be called within a script. This is in particular true for your own python scripts:: import os os.system('echo long listing of dir; pwd; ls -l') or suppose you created a script my_script.py:: from os import system system('python my_scrip.py')