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