source: fact/tools/pyscripts/fsc3.py@ 18066

Last change on this file since 18066 was 12610, checked in by lusterma, 13 years ago
added pyscripts folder to tools added fsc3.py, fscvolt1.py for plotting voltages and temperature added paux.py for running on a set of data files
File size: 3.9 KB
Line 
1#!/usr/bin/python26
2#
3# FACT SLOW CONTROL DATA
4# FSC_CONTROL_TEMPERATURE DATA
5#
6# Plot temperatures versus time
7# Save plots to disk
8#
9# Werner Lustermann
10# ETH Zurich
11
12import pyfits # module for reading fits files
13
14import numpy as np
15import numpy.ma as ma # masked array module
16
17import matplotlib.pyplot as plt # for plotting
18
19class FSC_TEMPERATURE( object ):
20
21 def __init__(self, dpath = '../temperature/', dfile = '20111103.FSC_CONTROL_TEMPERATURE.fits', plot_groups = True, show_plots = True ):
22
23 self.dfile = dfile
24 self.dpath = dpath
25 self.fname = dpath + dfile
26
27 self.Tgroups = ['T_sens', 'T_ps', 'T_crate', 'T_eth', 'T_back', 'T_aux' ]
28 self.rData()
29
30 def rData( self ):
31
32 try:
33 hdu = pyfits.open( self.fname )
34 except:
35 print 'file: ', fname, ' does not exist! ==> BREAK!!!'
36 exit( 'unknown data file' )
37
38 self.tbdata = hdu[1].data
39 hdu.close()
40
41 t = self.tbdata.field( 'Time' )
42 tt = np.modf( t )[0] * 24.
43 # self.time = np.roll( tt, len( t[ t<12.] ) )
44 for i in range( len( tt[ tt >= 12.] ) + 1, len( tt ) ): tt[i] += 24.
45 self.time = tt
46
47 def tplot_group( self, mT, gr ):
48 """ plot maxumum, minimum and mean of a group of sensors """
49 ax = plt.subplot(111)
50 ax.plot( self.time, np.max(mT, 1), 'b.', label = 'max', markersize = 1 )
51 ax.plot( self.time, np.min(mT, 1), 'b.', label = 'min', markersize = 1 )
52 ax.plot( self.time, np.mean(mT, 1), 'r.', label = 'mean', markersize = 1 )
53
54 ax.grid( 'on' )
55 plt.title( 'Temperatures: ' + gr + ' ' + self.dfile[0:12], fontsize = 18 )
56 plt.xlabel( 'time', fontsize = 14 )
57 plt.ylabel( 'T in degC', fontsize = 14 )
58 #plt.legend( loc = 4 )
59
60 # Shink current axis by 20%
61 box = ax.get_position()
62 ax.set_position([box.x0, box.y0, box.width * 0.9, box.height])
63 plt.legend( fancybox=True, loc='center left', bbox_to_anchor=(1, 0.5), numpoints = 7 )
64#
65 def plot_groups( self ):
66 for i,group in enumerate( self.Tgroups ):
67 T = self.tbdata.field( group )
68 maska = self.tbdata.field( group ) == 0.0
69 maskb = self.tbdata.field( group ) > 50.
70 mask = maska | maskb
71 mT = ma.masked_array( T, mask )
72
73 plt.figure()
74
75 self.tplot_group( mT, group )
76 plt.savefig( self.dpath + self.dfile[0:-5] + '_' + group + '.png')
77
78
79#
80#
81 def plot_means( self ):
82
83 fig = plt.figure()
84 ax = plt.subplot(111)
85 box = ax.get_position()
86 ax.set_position([box.x0, box.y0, box.width * 0.97, box.height])
87
88
89 for i,group in enumerate( self.Tgroups ):
90
91 #print 'i = ', i, group
92 T = self.tbdata.field( group )
93 maska = self.tbdata.field( group ) == 0.0
94 maskb = self.tbdata.field( group ) > 50.
95 mask = maska | maskb
96 mT = ma.masked_array( T, mask )
97
98 ax.plot( self.time, np.mean(mT, 1) , '.', label = group, markersize = 2 )
99
100 ax.grid( 'on' )
101 plt.title( 'Mean Temperatures: ' + self.dfile[0:12], fontsize = 18 )
102 plt.xlabel( 'time', fontsize = 14 )
103 plt.ylabel( 'T in degC', fontsize = 14 )
104
105 # Shink current axis by 20%
106 box = ax.get_position()
107 ax.set_position([box.x0, box.y0, box.width * 0.97, box.height])
108 plt.legend( fancybox=True, loc='center left', bbox_to_anchor=(1, 0.5), numpoints = 7 )
109 plt.savefig( self.dpath + self.dfile[0:-5] + '_means' + '.png' )
110
111
112 def show_plot( self ):
113 plt.show()
114
115if __name__ == '__main__':
116
117 print 'FACT FSC_CONTROL TEMPERATURE DATA'
118
119 fsct = FSC_TEMPERATURE()
120 fsct.plot_means()
121 fsct.plot_groups()
122 fsct.show_plot()
123
124
125
126
127
128
Note: See TracBrowser for help on using the repository browser.