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