1 | ========
|
---|
2 | Examples
|
---|
3 | ========
|
---|
4 |
|
---|
5 |
|
---|
6 | RawData
|
---|
7 | ========
|
---|
8 |
|
---|
9 | one may interactively play with the two most important classes *RawData* and
|
---|
10 | *SlowData* from module pyfact...
|
---|
11 |
|
---|
12 | *datafilepath* and *calibfilepath* should be adjusted in case you are not working
|
---|
13 | on the ISDC cluster.
|
---|
14 |
|
---|
15 | explore class RawData::
|
---|
16 |
|
---|
17 | from pyfact import RawData
|
---|
18 | # or from pyfact import *
|
---|
19 |
|
---|
20 | datafilepath = '/fact/raw/2012/03/04/20120304_018.fits.gz'
|
---|
21 | calibfilepath = '/fact/raw/2012/03/04/20120304_012.drs.fits.gz'
|
---|
22 | run = RawData(datafilepath, calibfilepath)
|
---|
23 | event = run.next()
|
---|
24 |
|
---|
25 | type(event)
|
---|
26 |
|
---|
27 | print 70*'*'
|
---|
28 | for key in event:
|
---|
29 | print 'key :', key
|
---|
30 | print 'value:', event[key]
|
---|
31 | print 70*'*'
|
---|
32 |
|
---|
33 | for historical reasons, an event contains *data* and *acal_data*, where *acal_data*
|
---|
34 | would be the DRS amplitude calibrated data, and *data* would be uncalibrated.
|
---|
35 | But since the calibration was moved into a C++ class, for better performance,
|
---|
36 | these keys now contains the same data.
|
---|
37 |
|
---|
38 | loop over RawData::
|
---|
39 |
|
---|
40 | from pyfact import RawData
|
---|
41 | # or from pyfact import *
|
---|
42 |
|
---|
43 | datafilepath = '/fact/raw/2012/03/04/20120304_018.fits.gz'
|
---|
44 | calibfilepath = '/fact/raw/2012/03/04/20120304_012.drs.fits.gz'
|
---|
45 | run = RawData(datafilepath, calibfilepath)
|
---|
46 |
|
---|
47 | for event in run:
|
---|
48 | print 'event_id:', event['event_id']
|
---|
49 | # the data can be found in event['data']
|
---|
50 |
|
---|
51 | SlowData
|
---|
52 | =========
|
---|
53 |
|
---|
54 | have a look at some SlowData::
|
---|
55 |
|
---|
56 | :~$ cd /fact/aux/2012/05/30
|
---|
57 | :/fact/aux/2012/05/30$ python
|
---|
58 |
|
---|
59 | from pyfact import SlowData
|
---|
60 | file = SlowData('20120530.FTM_CONTROL_TRIGGER_RATES.fits')
|
---|
61 | file.show()
|
---|
62 |
|
---|
63 |
|
---|
64 | have a look at the *columns*, that are available::
|
---|
65 |
|
---|
66 | 'columns': {'BoardRate': (40L, 4L, 'E', 'Hz'),
|
---|
67 | 'ElapsedTime': (1L, 4L, 'E', 'sec'),
|
---|
68 | 'FTMtimeStamp': (1L, 8L, 'K', 'us'),
|
---|
69 | 'OnTime': (1L, 4L, 'E', 'sec'),
|
---|
70 | 'OnTimeCounter': (1L, 8L, 'K', 'us'),
|
---|
71 | 'PatchRate': (160L, 4L, 'E', 'Hz'),
|
---|
72 | 'QoS': (1L, 4L, 'J', ''),
|
---|
73 | 'Time': (1L, 8L, 'D', 'MJD'),
|
---|
74 | 'TriggerCounter': (1L, 4L, 'J', 'int'),
|
---|
75 | 'TriggerRate': (1L, 4L, 'E', 'Hz')},
|
---|
76 |
|
---|
77 | choose the *columns* you would like to retrieve from the file::
|
---|
78 |
|
---|
79 | file.register('TriggerRate')
|
---|
80 | file.register('Time')
|
---|
81 | # or in case you are unsure
|
---|
82 | file.register('all')
|
---|
83 |
|
---|
84 | check, what happened. file has got some new members::
|
---|
85 |
|
---|
86 | file.show()
|
---|
87 |
|
---|
88 | but they are all zero. Now one should call *next()* in order to get
|
---|
89 | the file contents row by row::
|
---|
90 |
|
---|
91 | file.next()
|
---|
92 | file.show()
|
---|
93 |
|
---|
94 | or loop over the file::
|
---|
95 |
|
---|
96 | for row in file:
|
---|
97 | print row.Time, row. OnTime
|
---|
98 |
|
---|
99 | *row* is just be a copy of *file*, but inside the for loop, I think it is
|
---|
100 | convenient to access members of *row* rather than members of *file*.
|
---|
101 | I is just easier to understand for the reader, I think.
|
---|
102 |
|
---|
103 | calling a system command
|
---|
104 | ========================
|
---|
105 | 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::
|
---|
106 |
|
---|
107 | import os
|
---|
108 | os.system('echo long listing of dir; pwd; ls -l')
|
---|
109 |
|
---|
110 | or suppose you created a script my_script.py::
|
---|
111 |
|
---|
112 | from os import system
|
---|
113 | system('python my_scrip.py')
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|