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