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