##// END OF EJS Templates
SpectraHeisScope: show the right channel on figures
Miguel Valdez -
r649:c7df72c32712
parent child
Show More
@@ -1,312 +1,312
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
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()[0])
123 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
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" %(dataOut.channelList[channelIndexList[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 self.save(figpath=figpath,
159 self.save(figpath=figpath,
160 figfile=figfile,
160 figfile=figfile,
161 save=save,
161 save=save,
162 ftp=ftp,
162 ftp=ftp,
163 wr_period=wr_period,
163 wr_period=wr_period,
164 thisDatetime=thisDatetime)
164 thisDatetime=thisDatetime)
165
165
166 class RTIfromSpectraHeis(Figure):
166 class RTIfromSpectraHeis(Figure):
167
167
168 isConfig = None
168 isConfig = None
169 __nsubplots = None
169 __nsubplots = None
170
170
171 PREFIX = 'rtinoise'
171 PREFIX = 'rtinoise'
172
172
173 def __init__(self):
173 def __init__(self):
174
174
175 self.timerange = 24*60*60
175 self.timerange = 24*60*60
176 self.isConfig = False
176 self.isConfig = False
177 self.__nsubplots = 1
177 self.__nsubplots = 1
178
178
179 self.WIDTH = 820
179 self.WIDTH = 820
180 self.HEIGHT = 200
180 self.HEIGHT = 200
181 self.WIDTHPROF = 120
181 self.WIDTHPROF = 120
182 self.HEIGHTPROF = 0
182 self.HEIGHTPROF = 0
183 self.counter_imagwr = 0
183 self.counter_imagwr = 0
184 self.xdata = None
184 self.xdata = None
185 self.ydata = None
185 self.ydata = None
186 self.figfile = None
186 self.figfile = None
187
187
188 def getSubplots(self):
188 def getSubplots(self):
189
189
190 ncol = 1
190 ncol = 1
191 nrow = 1
191 nrow = 1
192
192
193 return nrow, ncol
193 return nrow, ncol
194
194
195 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
195 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
196
196
197 self.__showprofile = showprofile
197 self.__showprofile = showprofile
198 self.nplots = nplots
198 self.nplots = nplots
199
199
200 ncolspan = 7
200 ncolspan = 7
201 colspan = 6
201 colspan = 6
202 self.__nsubplots = 2
202 self.__nsubplots = 2
203
203
204 self.createFigure(id = id,
204 self.createFigure(id = id,
205 wintitle = wintitle,
205 wintitle = wintitle,
206 widthplot = self.WIDTH+self.WIDTHPROF,
206 widthplot = self.WIDTH+self.WIDTHPROF,
207 heightplot = self.HEIGHT+self.HEIGHTPROF,
207 heightplot = self.HEIGHT+self.HEIGHTPROF,
208 show = show)
208 show = show)
209
209
210 nrow, ncol = self.getSubplots()
210 nrow, ncol = self.getSubplots()
211
211
212 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
212 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
213
213
214
214
215 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
215 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
216 xmin=None, xmax=None, ymin=None, ymax=None,
216 xmin=None, xmax=None, ymin=None, ymax=None,
217 timerange=None,
217 timerange=None,
218 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
218 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
219 server=None, folder=None, username=None, password=None):
219 server=None, folder=None, username=None, password=None):
220
220
221 if channelList == None:
221 if channelList == None:
222 channelIndexList = dataOut.channelIndexList
222 channelIndexList = dataOut.channelIndexList
223 channelList = dataOut.channelList
223 channelList = dataOut.channelList
224 else:
224 else:
225 channelIndexList = []
225 channelIndexList = []
226 for channel in channelList:
226 for channel in channelList:
227 if channel not in dataOut.channelList:
227 if channel not in dataOut.channelList:
228 raise ValueError, "Channel %d is not in dataOut.channelList"
228 raise ValueError, "Channel %d is not in dataOut.channelList"
229 channelIndexList.append(dataOut.channelList.index(channel))
229 channelIndexList.append(dataOut.channelList.index(channel))
230
230
231 if timerange != None:
231 if timerange != None:
232 self.timerange = timerange
232 self.timerange = timerange
233
233
234 tmin = None
234 tmin = None
235 tmax = None
235 tmax = None
236 x = dataOut.getTimeRange()
236 x = dataOut.getTimeRange()
237 y = dataOut.getHeiRange()
237 y = dataOut.getHeiRange()
238
238
239 factor = dataOut.normFactor
239 factor = dataOut.normFactor
240 data = dataOut.data_spc / factor
240 data = dataOut.data_spc / factor
241 data = numpy.average(data,axis=1)
241 data = numpy.average(data,axis=1)
242 datadB = 10*numpy.log10(data)
242 datadB = 10*numpy.log10(data)
243
243
244 # factor = dataOut.normFactor
244 # factor = dataOut.normFactor
245 # noise = dataOut.getNoise()/factor
245 # noise = dataOut.getNoise()/factor
246 # noisedB = 10*numpy.log10(noise)
246 # noisedB = 10*numpy.log10(noise)
247
247
248 #thisDatetime = dataOut.datatime
248 #thisDatetime = dataOut.datatime
249 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
249 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
250 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
250 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
251 xlabel = "Local Time"
251 xlabel = "Local Time"
252 ylabel = "Intensity (dB)"
252 ylabel = "Intensity (dB)"
253
253
254 if not self.isConfig:
254 if not self.isConfig:
255
255
256 nplots = 1
256 nplots = 1
257
257
258 self.setup(id=id,
258 self.setup(id=id,
259 nplots=nplots,
259 nplots=nplots,
260 wintitle=wintitle,
260 wintitle=wintitle,
261 showprofile=showprofile,
261 showprofile=showprofile,
262 show=show)
262 show=show)
263
263
264 tmin, tmax = self.getTimeLim(x, xmin, xmax)
264 tmin, tmax = self.getTimeLim(x, xmin, xmax)
265 if ymin == None: ymin = numpy.nanmin(datadB)
265 if ymin == None: ymin = numpy.nanmin(datadB)
266 if ymax == None: ymax = numpy.nanmax(datadB)
266 if ymax == None: ymax = numpy.nanmax(datadB)
267
267
268 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
268 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
269 self.isConfig = True
269 self.isConfig = True
270 self.figfile = figfile
270 self.figfile = figfile
271 self.xdata = numpy.array([])
271 self.xdata = numpy.array([])
272 self.ydata = numpy.array([])
272 self.ydata = numpy.array([])
273
273
274 self.setWinTitle(title)
274 self.setWinTitle(title)
275
275
276
276
277 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
277 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
278 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
278 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
279
279
280 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
280 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
281 axes = self.axesList[0]
281 axes = self.axesList[0]
282
282
283 self.xdata = numpy.hstack((self.xdata, x[0:1]))
283 self.xdata = numpy.hstack((self.xdata, x[0:1]))
284
284
285 if len(self.ydata)==0:
285 if len(self.ydata)==0:
286 self.ydata = datadB[channelIndexList].reshape(-1,1)
286 self.ydata = datadB[channelIndexList].reshape(-1,1)
287 else:
287 else:
288 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
288 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
289
289
290
290
291 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
291 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
292 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
292 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
293 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
293 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
294 XAxisAsTime=True
294 XAxisAsTime=True
295 )
295 )
296
296
297 self.draw()
297 self.draw()
298
298
299 if x[1] >= self.axesList[0].xmax:
299 if x[1] >= self.axesList[0].xmax:
300 self.counter_imagwr = wr_period
300 self.counter_imagwr = wr_period
301 del self.xdata
301 del self.xdata
302 del self.ydata
302 del self.ydata
303 self.__isConfig = False
303 self.__isConfig = False
304 self.figfile = None
304 self.figfile = None
305
305
306 self.save(figpath=figpath,
306 self.save(figpath=figpath,
307 figfile=figfile,
307 figfile=figfile,
308 save=save,
308 save=save,
309 ftp=ftp,
309 ftp=ftp,
310 wr_period=wr_period,
310 wr_period=wr_period,
311 thisDatetime=thisDatetime,
311 thisDatetime=thisDatetime,
312 update_figfile=False)
312 update_figfile=False)
General Comments 0
You need to be logged in to leave comments. Login now