##// END OF EJS Templates
The RTI for Spectra-1d Plot shows the normalized power.
Daniel Valdez -
r498:09578ea8c29c
parent child
Show More
@@ -1,326 +1,326
1 '''
1 '''
2
2
3 @author: Daniel Suarez
3 @author: Daniel Suarez
4 '''
4 '''
5
5
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime
10 from figure import Figure, isRealtime
11
11
12 class SpectraHeisScope(Figure):
12 class SpectraHeisScope(Figure):
13
13
14
14
15 isConfig = None
15 isConfig = None
16 __nsubplots = None
16 __nsubplots = None
17
17
18 WIDTHPROF = None
18 WIDTHPROF = None
19 HEIGHTPROF = None
19 HEIGHTPROF = None
20 PREFIX = 'spc'
20 PREFIX = 'spc'
21
21
22 def __init__(self):
22 def __init__(self):
23
23
24 self.isConfig = False
24 self.isConfig = False
25 self.__nsubplots = 1
25 self.__nsubplots = 1
26
26
27 self.WIDTH = 230
27 self.WIDTH = 230
28 self.HEIGHT = 250
28 self.HEIGHT = 250
29 self.WIDTHPROF = 120
29 self.WIDTHPROF = 120
30 self.HEIGHTPROF = 0
30 self.HEIGHTPROF = 0
31 self.counter_imagwr = 0
31 self.counter_imagwr = 0
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
37
37
38 return nrow, ncol
38 return nrow, ncol
39
39
40 def setup(self, id, nplots, wintitle, show):
40 def setup(self, id, nplots, wintitle, show):
41
41
42 showprofile = False
42 showprofile = False
43 self.__showprofile = showprofile
43 self.__showprofile = showprofile
44 self.nplots = nplots
44 self.nplots = nplots
45
45
46 ncolspan = 1
46 ncolspan = 1
47 colspan = 1
47 colspan = 1
48 if showprofile:
48 if showprofile:
49 ncolspan = 3
49 ncolspan = 3
50 colspan = 2
50 colspan = 2
51 self.__nsubplots = 2
51 self.__nsubplots = 2
52
52
53 self.createFigure(id = id,
53 self.createFigure(id = id,
54 wintitle = wintitle,
54 wintitle = wintitle,
55 widthplot = self.WIDTH + self.WIDTHPROF,
55 widthplot = self.WIDTH + self.WIDTHPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 show = show)
57 show = show)
58
58
59 nrow, ncol = self.getSubplots()
59 nrow, ncol = self.getSubplots()
60
60
61 counter = 0
61 counter = 0
62 for y in range(nrow):
62 for y in range(nrow):
63 for x in range(ncol):
63 for x in range(ncol):
64
64
65 if counter >= self.nplots:
65 if counter >= self.nplots:
66 break
66 break
67
67
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69
69
70 if showprofile:
70 if showprofile:
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72
72
73 counter += 1
73 counter += 1
74
74
75
75
76 def run(self, dataOut, id, wintitle="", channelList=None,
76 def run(self, dataOut, id, wintitle="", channelList=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
78 figpath='', figfile=None, ftp=False, wr_period=1, show=True,
78 figpath='', figfile=None, ftp=False, wr_period=1, show=True,
79 server=None, folder=None, username=None, password=None):
79 server=None, folder=None, username=None, password=None):
80
80
81 """
81 """
82
82
83 Input:
83 Input:
84 dataOut :
84 dataOut :
85 id :
85 id :
86 wintitle :
86 wintitle :
87 channelList :
87 channelList :
88 xmin : None,
88 xmin : None,
89 xmax : None,
89 xmax : None,
90 ymin : None,
90 ymin : None,
91 ymax : None,
91 ymax : None,
92 """
92 """
93
93
94 if dataOut.realtime:
94 if dataOut.realtime:
95 if not(isRealtime(utcdatatime = dataOut.utctime)):
95 if not(isRealtime(utcdatatime = dataOut.utctime)):
96 print 'Skipping this plot function'
96 print 'Skipping this plot function'
97 return
97 return
98
98
99 if channelList == None:
99 if channelList == None:
100 channelIndexList = dataOut.channelIndexList
100 channelIndexList = dataOut.channelIndexList
101 else:
101 else:
102 channelIndexList = []
102 channelIndexList = []
103 for channel in channelList:
103 for channel in channelList:
104 if channel not in dataOut.channelList:
104 if channel not in dataOut.channelList:
105 raise ValueError, "Channel %d is not in dataOut.channelList"
105 raise ValueError, "Channel %d is not in dataOut.channelList"
106 channelIndexList.append(dataOut.channelList.index(channel))
106 channelIndexList.append(dataOut.channelList.index(channel))
107
107
108 # x = dataOut.heightList
108 # x = dataOut.heightList
109 c = 3E8
109 c = 3E8
110 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
110 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
111 #deberia cambiar para el caso de 1Mhz y 100KHz
111 #deberia cambiar para el caso de 1Mhz y 100KHz
112 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
112 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
113 #para 1Mhz descomentar la siguiente linea
113 #para 1Mhz descomentar la siguiente linea
114 #x= x/(10000.0)
114 #x= x/(10000.0)
115 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
115 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
116 # y = y.real
116 # y = y.real
117 factor = dataOut.normFactor
117 factor = dataOut.normFactor
118 data = dataOut.data_spc / factor
118 data = dataOut.data_spc / factor
119 datadB = 10.*numpy.log10(data)
119 datadB = 10.*numpy.log10(data)
120 y = datadB
120 y = datadB
121
121
122 #thisDatetime = dataOut.datatime
122 #thisDatetime = dataOut.datatime
123 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
123 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
124 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
124 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
125 xlabel = ""
125 xlabel = ""
126 #para 1Mhz descomentar la siguiente linea
126 #para 1Mhz descomentar la siguiente linea
127 #xlabel = "Frequency x 10000"
127 #xlabel = "Frequency x 10000"
128 ylabel = "Intensity (dB)"
128 ylabel = "Intensity (dB)"
129
129
130 if not self.isConfig:
130 if not self.isConfig:
131 nplots = len(channelIndexList)
131 nplots = len(channelIndexList)
132
132
133 self.setup(id=id,
133 self.setup(id=id,
134 nplots=nplots,
134 nplots=nplots,
135 wintitle=wintitle,
135 wintitle=wintitle,
136 show=show)
136 show=show)
137
137
138 if xmin == None: xmin = numpy.nanmin(x)
138 if xmin == None: xmin = numpy.nanmin(x)
139 if xmax == None: xmax = numpy.nanmax(x)
139 if xmax == None: xmax = numpy.nanmax(x)
140 if ymin == None: ymin = numpy.nanmin(y)
140 if ymin == None: ymin = numpy.nanmin(y)
141 if ymax == None: ymax = numpy.nanmax(y)
141 if ymax == None: ymax = numpy.nanmax(y)
142
142
143 self.isConfig = True
143 self.isConfig = True
144
144
145 self.setWinTitle(title)
145 self.setWinTitle(title)
146
146
147 for i in range(len(self.axesList)):
147 for i in range(len(self.axesList)):
148 ychannel = y[i,:]
148 ychannel = y[i,:]
149 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
149 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
150 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
150 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
151 axes = self.axesList[i]
151 axes = self.axesList[i]
152 axes.pline(x, ychannel,
152 axes.pline(x, ychannel,
153 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
153 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
154 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
154 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
155
155
156
156
157 self.draw()
157 self.draw()
158
158
159 if figfile == None:
159 if figfile == None:
160 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
160 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
161 figfile = self.getFilename(name = str_datetime)
161 figfile = self.getFilename(name = str_datetime)
162
162
163 if figpath != '':
163 if figpath != '':
164 self.counter_imagwr += 1
164 self.counter_imagwr += 1
165 if (self.counter_imagwr>=wr_period):
165 if (self.counter_imagwr>=wr_period):
166 # store png plot to local folder
166 # store png plot to local folder
167 self.saveFigure(figpath, figfile)
167 self.saveFigure(figpath, figfile)
168 # store png plot to FTP server according to RT-Web format
168 # store png plot to FTP server according to RT-Web format
169 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
169 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
170 #ftp_filename = os.path.join(figpath, name)
170 #ftp_filename = os.path.join(figpath, name)
171 #self.saveFigure(figpath, ftp_filename)
171 #self.saveFigure(figpath, ftp_filename)
172 self.counter_imagwr = 0
172 self.counter_imagwr = 0
173
173
174 class RTIfromSpectraHeis(Figure):
174 class RTIfromSpectraHeis(Figure):
175
175
176 isConfig = None
176 isConfig = None
177 __nsubplots = None
177 __nsubplots = None
178
178
179 PREFIX = 'rtinoise'
179 PREFIX = 'rtinoise'
180
180
181 def __init__(self):
181 def __init__(self):
182
182
183 self.timerange = 24*60*60
183 self.timerange = 24*60*60
184 self.isConfig = False
184 self.isConfig = False
185 self.__nsubplots = 1
185 self.__nsubplots = 1
186
186
187 self.WIDTH = 820
187 self.WIDTH = 820
188 self.HEIGHT = 200
188 self.HEIGHT = 200
189 self.WIDTHPROF = 120
189 self.WIDTHPROF = 120
190 self.HEIGHTPROF = 0
190 self.HEIGHTPROF = 0
191 self.counter_imagwr = 0
191 self.counter_imagwr = 0
192 self.xdata = None
192 self.xdata = None
193 self.ydata = None
193 self.ydata = None
194 self.figfile = None
194 self.figfile = None
195
195
196 def getSubplots(self):
196 def getSubplots(self):
197
197
198 ncol = 1
198 ncol = 1
199 nrow = 1
199 nrow = 1
200
200
201 return nrow, ncol
201 return nrow, ncol
202
202
203 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
203 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
204
204
205 self.__showprofile = showprofile
205 self.__showprofile = showprofile
206 self.nplots = nplots
206 self.nplots = nplots
207
207
208 ncolspan = 7
208 ncolspan = 7
209 colspan = 6
209 colspan = 6
210 self.__nsubplots = 2
210 self.__nsubplots = 2
211
211
212 self.createFigure(id = id,
212 self.createFigure(id = id,
213 wintitle = wintitle,
213 wintitle = wintitle,
214 widthplot = self.WIDTH+self.WIDTHPROF,
214 widthplot = self.WIDTH+self.WIDTHPROF,
215 heightplot = self.HEIGHT+self.HEIGHTPROF,
215 heightplot = self.HEIGHT+self.HEIGHTPROF,
216 show = show)
216 show = show)
217
217
218 nrow, ncol = self.getSubplots()
218 nrow, ncol = self.getSubplots()
219
219
220 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
220 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
221
221
222
222
223 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
223 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
224 xmin=None, xmax=None, ymin=None, ymax=None,
224 xmin=None, xmax=None, ymin=None, ymax=None,
225 timerange=None,
225 timerange=None,
226 save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True,
226 save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True,
227 server=None, folder=None, username=None, password=None):
227 server=None, folder=None, username=None, password=None):
228
228
229 if channelList == None:
229 if channelList == None:
230 channelIndexList = dataOut.channelIndexList
230 channelIndexList = dataOut.channelIndexList
231 channelList = dataOut.channelList
231 channelList = dataOut.channelList
232 else:
232 else:
233 channelIndexList = []
233 channelIndexList = []
234 for channel in channelList:
234 for channel in channelList:
235 if channel not in dataOut.channelList:
235 if channel not in dataOut.channelList:
236 raise ValueError, "Channel %d is not in dataOut.channelList"
236 raise ValueError, "Channel %d is not in dataOut.channelList"
237 channelIndexList.append(dataOut.channelList.index(channel))
237 channelIndexList.append(dataOut.channelList.index(channel))
238
238
239 if timerange != None:
239 if timerange != None:
240 self.timerange = timerange
240 self.timerange = timerange
241
241
242 tmin = None
242 tmin = None
243 tmax = None
243 tmax = None
244 x = dataOut.getTimeRange()
244 x = dataOut.getTimeRange()
245 y = dataOut.getHeiRange()
245 y = dataOut.getHeiRange()
246
246
247
247 factor = dataOut.normFactor
248 data = dataOut.data_spc
248 data = dataOut.data_spc / factor
249 data = numpy.average(data,axis=1)
249 data = numpy.average(data,axis=1)
250 datadB = 10*numpy.log10(data)
250 datadB = 10*numpy.log10(data)
251
251
252 # factor = dataOut.normFactor
252 # factor = dataOut.normFactor
253 # noise = dataOut.getNoise()/factor
253 # noise = dataOut.getNoise()/factor
254 # noisedB = 10*numpy.log10(noise)
254 # noisedB = 10*numpy.log10(noise)
255
255
256 #thisDatetime = dataOut.datatime
256 #thisDatetime = dataOut.datatime
257 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
257 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
258 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
258 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
259 xlabel = "Local Time"
259 xlabel = "Local Time"
260 ylabel = "Intensity (dB)"
260 ylabel = "Intensity (dB)"
261
261
262 if not self.isConfig:
262 if not self.isConfig:
263
263
264 nplots = 1
264 nplots = 1
265
265
266 self.setup(id=id,
266 self.setup(id=id,
267 nplots=nplots,
267 nplots=nplots,
268 wintitle=wintitle,
268 wintitle=wintitle,
269 showprofile=showprofile,
269 showprofile=showprofile,
270 show=show)
270 show=show)
271
271
272 tmin, tmax = self.getTimeLim(x, xmin, xmax)
272 tmin, tmax = self.getTimeLim(x, xmin, xmax)
273 if ymin == None: ymin = numpy.nanmin(datadB)
273 if ymin == None: ymin = numpy.nanmin(datadB)
274 if ymax == None: ymax = numpy.nanmax(datadB)
274 if ymax == None: ymax = numpy.nanmax(datadB)
275
275
276 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
276 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
277 self.isConfig = True
277 self.isConfig = True
278 self.figfile = figfile
278 self.figfile = figfile
279 self.xdata = numpy.array([])
279 self.xdata = numpy.array([])
280 self.ydata = numpy.array([])
280 self.ydata = numpy.array([])
281
281
282 self.setWinTitle(title)
282 self.setWinTitle(title)
283
283
284
284
285 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
285 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
286 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
286 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
287
287
288 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
288 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
289 axes = self.axesList[0]
289 axes = self.axesList[0]
290
290
291 self.xdata = numpy.hstack((self.xdata, x[0:1]))
291 self.xdata = numpy.hstack((self.xdata, x[0:1]))
292
292
293 if len(self.ydata)==0:
293 if len(self.ydata)==0:
294 self.ydata = datadB[channelIndexList].reshape(-1,1)
294 self.ydata = datadB[channelIndexList].reshape(-1,1)
295 else:
295 else:
296 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
296 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
297
297
298
298
299 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
299 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
300 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
300 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
301 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
301 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
302 XAxisAsTime=True
302 XAxisAsTime=True
303 )
303 )
304
304
305 self.draw()
305 self.draw()
306
306
307 if x[1] >= self.axesList[0].xmax:
307 if x[1] >= self.axesList[0].xmax:
308 self.counter_imagwr = wr_period
308 self.counter_imagwr = wr_period
309 del self.xdata
309 del self.xdata
310 del self.ydata
310 del self.ydata
311 self.__isConfig = False
311 self.__isConfig = False
312
312
313 if self.figfile == None:
313 if self.figfile == None:
314 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
314 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
315 self.figfile = self.getFilename(name = str_datetime)
315 self.figfile = self.getFilename(name = str_datetime)
316
316
317 if figpath != '':
317 if figpath != '':
318 self.counter_imagwr += 1
318 self.counter_imagwr += 1
319 if (self.counter_imagwr>=wr_period):
319 if (self.counter_imagwr>=wr_period):
320 # store png plot to local folder
320 # store png plot to local folder
321 self.saveFigure(figpath, self.figfile)
321 self.saveFigure(figpath, self.figfile)
322 # store png plot to FTP server according to RT-Web format
322 # store png plot to FTP server according to RT-Web format
323 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
323 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
324 #ftp_filename = os.path.join(figpath, name)
324 #ftp_filename = os.path.join(figpath, name)
325 #self.saveFigure(figpath, ftp_filename)
325 #self.saveFigure(figpath, ftp_filename)
326 self.counter_imagwr = 0
326 self.counter_imagwr = 0
General Comments 0
You need to be logged in to leave comments. Login now