@@ -1,1060 +1,1060 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class CrossSpectraPlot(Figure): |
|
6 | 6 | |
|
7 | 7 | __isConfig = None |
|
8 | 8 | __nsubplots = None |
|
9 | 9 | |
|
10 | 10 | WIDTH = None |
|
11 | 11 | HEIGHT = None |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'cspc' |
|
15 | 15 | |
|
16 | 16 | def __init__(self): |
|
17 | 17 | |
|
18 | 18 | self.__isConfig = False |
|
19 | 19 | self.__nsubplots = 4 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 250 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 0 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | |
|
26 | 26 | def getSubplots(self): |
|
27 | 27 | |
|
28 | 28 | ncol = 4 |
|
29 | 29 | nrow = self.nplots |
|
30 | 30 | |
|
31 | 31 | return nrow, ncol |
|
32 | 32 | |
|
33 | 33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
34 | 34 | |
|
35 | 35 | self.__showprofile = showprofile |
|
36 | 36 | self.nplots = nplots |
|
37 | 37 | |
|
38 | 38 | ncolspan = 1 |
|
39 | 39 | colspan = 1 |
|
40 | 40 | |
|
41 | 41 | self.createFigure(idfigure = idfigure, |
|
42 | 42 | wintitle = wintitle, |
|
43 | 43 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
44 | 44 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
45 | 45 | |
|
46 | 46 | nrow, ncol = self.getSubplots() |
|
47 | 47 | |
|
48 | 48 | counter = 0 |
|
49 | 49 | for y in range(nrow): |
|
50 | 50 | for x in range(ncol): |
|
51 | 51 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
52 | 52 | |
|
53 | 53 | counter += 1 |
|
54 | 54 | |
|
55 | 55 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
56 | 56 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, normalize=True, |
|
57 | 57 | save=False, figpath='./', figfile=None, |
|
58 | 58 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'): |
|
59 | 59 | |
|
60 | 60 | """ |
|
61 | 61 | |
|
62 | 62 | Input: |
|
63 | 63 | dataOut : |
|
64 | 64 | idfigure : |
|
65 | 65 | wintitle : |
|
66 | 66 | channelList : |
|
67 | 67 | showProfile : |
|
68 | 68 | xmin : None, |
|
69 | 69 | xmax : None, |
|
70 | 70 | ymin : None, |
|
71 | 71 | ymax : None, |
|
72 | 72 | zmin : None, |
|
73 | 73 | zmax : None |
|
74 | 74 | """ |
|
75 | 75 | |
|
76 | 76 | if pairsList == None: |
|
77 | 77 | pairsIndexList = dataOut.pairsIndexList |
|
78 | 78 | else: |
|
79 | 79 | pairsIndexList = [] |
|
80 | 80 | for pair in pairsList: |
|
81 | 81 | if pair not in dataOut.pairsList: |
|
82 | 82 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
83 | 83 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
84 | 84 | |
|
85 | 85 | if pairsIndexList == []: |
|
86 | 86 | return |
|
87 | 87 | |
|
88 | 88 | if len(pairsIndexList) > 4: |
|
89 | 89 | pairsIndexList = pairsIndexList[0:4] |
|
90 | 90 | |
|
91 | 91 | factor = 1 |
|
92 | 92 | if normalize: |
|
93 | 93 | factor = dataOut.normFactor |
|
94 | 94 | x = dataOut.getVelRange(1) |
|
95 | 95 | y = dataOut.getHeiRange() |
|
96 | 96 | z = dataOut.data_spc[:,:,:]/factor |
|
97 | 97 | |
|
98 | 98 | avg = numpy.average(z, axis=1) |
|
99 | 99 | noise = dataOut.getNoise()/factor |
|
100 | 100 | |
|
101 | 101 | zdB = 10*numpy.log10(z) |
|
102 | 102 | avgdB = 10*numpy.log10(avg) |
|
103 | 103 | noisedB = 10*numpy.log10(noise) |
|
104 | 104 | |
|
105 | 105 | |
|
106 | 106 | thisDatetime = dataOut.datatime |
|
107 | 107 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
108 | 108 | xlabel = "Velocity (m/s)" |
|
109 | 109 | ylabel = "Range (Km)" |
|
110 | 110 | |
|
111 | 111 | if not self.__isConfig: |
|
112 | 112 | |
|
113 | 113 | nplots = len(pairsIndexList) |
|
114 | 114 | |
|
115 | 115 | self.setup(idfigure=idfigure, |
|
116 | 116 | nplots=nplots, |
|
117 | 117 | wintitle=wintitle, |
|
118 | 118 | showprofile=showprofile) |
|
119 | 119 | |
|
120 | 120 | if xmin == None: xmin = numpy.nanmin(x) |
|
121 | 121 | if xmax == None: xmax = numpy.nanmax(x) |
|
122 | 122 | if ymin == None: ymin = numpy.nanmin(y) |
|
123 | 123 | if ymax == None: ymax = numpy.nanmax(y) |
|
124 | 124 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
125 | 125 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
126 | 126 | |
|
127 | 127 | self.__isConfig = True |
|
128 | 128 | |
|
129 | 129 | self.setWinTitle(title) |
|
130 | 130 | |
|
131 | 131 | for i in range(self.nplots): |
|
132 | 132 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
133 | 133 | |
|
134 | 134 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
135 | 135 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
136 | 136 | axes0 = self.axesList[i*self.__nsubplots] |
|
137 | 137 | axes0.pcolor(x, y, zdB, |
|
138 | 138 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
139 | 139 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
140 | 140 | ticksize=9, colormap=power_cmap, cblabel='') |
|
141 | 141 | |
|
142 | 142 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
143 | 143 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
144 | 144 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
145 | 145 | axes0.pcolor(x, y, zdB, |
|
146 | 146 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
147 | 147 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
148 | 148 | ticksize=9, colormap=power_cmap, cblabel='') |
|
149 | 149 | |
|
150 | 150 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
151 | 151 | coherence = numpy.abs(coherenceComplex) |
|
152 | 152 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
153 | 153 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
154 | 154 | |
|
155 | 155 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
156 | 156 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
157 | 157 | axes0.pcolor(x, y, coherence, |
|
158 | 158 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
159 | 159 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
160 | 160 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
161 | 161 | |
|
162 | 162 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
163 | 163 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
164 | 164 | axes0.pcolor(x, y, phase, |
|
165 | 165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
166 | 166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
167 | 167 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
168 | 168 | |
|
169 | 169 | |
|
170 | 170 | |
|
171 | 171 | self.draw() |
|
172 | 172 | |
|
173 | 173 | if save: |
|
174 | 174 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
175 | 175 | if figfile == None: |
|
176 | 176 | figfile = self.getFilename(name = date) |
|
177 | 177 | |
|
178 | 178 | self.saveFigure(figpath, figfile) |
|
179 | 179 | |
|
180 | 180 | |
|
181 | 181 | class RTIPlot(Figure): |
|
182 | 182 | |
|
183 | 183 | __isConfig = None |
|
184 | 184 | __nsubplots = None |
|
185 | 185 | __missing = 1E30 |
|
186 | 186 | WIDTHPROF = None |
|
187 | 187 | HEIGHTPROF = None |
|
188 | 188 | PREFIX = 'rti' |
|
189 | 189 | |
|
190 | 190 | def __init__(self): |
|
191 | 191 | |
|
192 | 192 | self.timerange = 2*60*60 |
|
193 | 193 | self.__isConfig = False |
|
194 | 194 | self.__nsubplots = 1 |
|
195 | 195 | |
|
196 | 196 | self.WIDTH = 800 |
|
197 |
self.HEIGHT = |
|
|
197 | self.HEIGHT = 180 | |
|
198 | 198 | self.WIDTHPROF = 120 |
|
199 | 199 | self.HEIGHTPROF = 0 |
|
200 | 200 | self.x_buffer = None |
|
201 | 201 | self.avgdB_buffer = None |
|
202 | 202 | |
|
203 | 203 | def getSubplots(self): |
|
204 | 204 | |
|
205 | 205 | ncol = 1 |
|
206 | 206 | nrow = self.nplots |
|
207 | 207 | |
|
208 | 208 | return nrow, ncol |
|
209 | 209 | |
|
210 | 210 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
211 | 211 | |
|
212 | 212 | self.__showprofile = showprofile |
|
213 | 213 | self.nplots = nplots |
|
214 | 214 | |
|
215 | 215 | ncolspan = 1 |
|
216 | 216 | colspan = 1 |
|
217 | 217 | widthplot = self.WIDTH |
|
218 | 218 | heightplot = self.HEIGHT |
|
219 | 219 | if showprofile: |
|
220 | 220 | ncolspan = 7 |
|
221 | 221 | colspan = 6 |
|
222 | 222 | self.__nsubplots = 2 |
|
223 | 223 | widthplot += self.WIDTHPROF |
|
224 | 224 | heightplot += self.HEIGHTPROF |
|
225 | 225 | |
|
226 | 226 | self.createFigure(idfigure = idfigure, |
|
227 | 227 | wintitle = wintitle, |
|
228 | 228 | widthplot = widthplot, |
|
229 | 229 | heightplot = heightplot) |
|
230 | 230 | |
|
231 | 231 | nrow, ncol = self.getSubplots() |
|
232 | 232 | |
|
233 | 233 | counter = 0 |
|
234 | 234 | for y in range(nrow): |
|
235 | 235 | for x in range(ncol): |
|
236 | 236 | |
|
237 | 237 | if counter >= self.nplots: |
|
238 | 238 | break |
|
239 | 239 | |
|
240 | 240 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
241 | 241 | |
|
242 | 242 | if showprofile: |
|
243 | 243 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
244 | 244 | |
|
245 | 245 | counter += 1 |
|
246 | 246 | |
|
247 | 247 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
248 | 248 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, normalize=True, |
|
249 | 249 | timerange=None, |
|
250 | 250 | save=False, figpath='./', figfile=None): |
|
251 | 251 | |
|
252 | 252 | """ |
|
253 | 253 | |
|
254 | 254 | Input: |
|
255 | 255 | dataOut : |
|
256 | 256 | idfigure : |
|
257 | 257 | wintitle : |
|
258 | 258 | channelList : |
|
259 | 259 | showProfile : |
|
260 | 260 | xmin : None, |
|
261 | 261 | xmax : None, |
|
262 | 262 | ymin : None, |
|
263 | 263 | ymax : None, |
|
264 | 264 | zmin : None, |
|
265 | 265 | zmax : None |
|
266 | 266 | """ |
|
267 | 267 | |
|
268 | 268 | if channelList == None: |
|
269 | 269 | channelIndexList = dataOut.channelIndexList |
|
270 | 270 | else: |
|
271 | 271 | channelIndexList = [] |
|
272 | 272 | for channel in channelList: |
|
273 | 273 | if channel not in dataOut.channelList: |
|
274 | 274 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
275 | 275 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
276 | 276 | |
|
277 | 277 | if timerange != None: |
|
278 | 278 | self.timerange = timerange |
|
279 | 279 | |
|
280 | 280 | tmin = None |
|
281 | 281 | tmax = None |
|
282 | 282 | factor = 1 |
|
283 | 283 | if normalize: |
|
284 | 284 | factor = dataOut.normFactor |
|
285 | 285 | x = dataOut.getTimeRange() |
|
286 | 286 | y = dataOut.getHeiRange() |
|
287 | 287 | |
|
288 | 288 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
289 | 289 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
290 | 290 | avg = numpy.average(z, axis=1) |
|
291 | 291 | |
|
292 | 292 | avgdB = 10.*numpy.log10(avg) |
|
293 | 293 | |
|
294 | 294 | |
|
295 | 295 | thisDatetime = dataOut.datatime |
|
296 | 296 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
297 | 297 | xlabel = "Velocity (m/s)" |
|
298 | 298 | ylabel = "Range (Km)" |
|
299 | 299 | |
|
300 | 300 | if not self.__isConfig: |
|
301 | 301 | |
|
302 | 302 | nplots = len(channelIndexList) |
|
303 | 303 | |
|
304 | 304 | self.setup(idfigure=idfigure, |
|
305 | 305 | nplots=nplots, |
|
306 | 306 | wintitle=wintitle, |
|
307 | 307 | showprofile=showprofile) |
|
308 | 308 | |
|
309 | 309 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
310 | 310 | if ymin == None: ymin = numpy.nanmin(y) |
|
311 | 311 | if ymax == None: ymax = numpy.nanmax(y) |
|
312 | 312 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
313 | 313 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
314 | 314 | |
|
315 | 315 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
316 | 316 | self.x_buffer = numpy.array([]) |
|
317 | 317 | self.avgdB_buffer = numpy.array([]) |
|
318 | 318 | self.__isConfig = True |
|
319 | 319 | |
|
320 | 320 | |
|
321 | 321 | self.setWinTitle(title) |
|
322 | 322 | |
|
323 | 323 | if len(self.avgdB_buffer)==0: |
|
324 | 324 | self.avgdB_buffer = avgdB |
|
325 | 325 | newxdim = 1 |
|
326 | 326 | newydim = -1 |
|
327 | 327 | else: |
|
328 | 328 | if x[0]>self.x_buffer[-1]: |
|
329 | 329 | gap = avgdB.copy() |
|
330 | 330 | gap[:] = self.__missing |
|
331 | 331 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, gap)) |
|
332 | 332 | |
|
333 | 333 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, avgdB)) |
|
334 | 334 | newxdim = -1 |
|
335 | 335 | newydim = len(y) |
|
336 | 336 | |
|
337 | 337 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
338 | 338 | |
|
339 | 339 | self.avgdB_buffer = numpy.ma.masked_inside(self.avgdB_buffer,0.99*self.__missing,1.01*self.__missing) |
|
340 | 340 | |
|
341 | 341 | for i in range(self.nplots): |
|
342 | 342 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
343 | 343 | axes = self.axesList[i*self.__nsubplots] |
|
344 | 344 | zdB = self.avgdB_buffer[i].reshape(newxdim,newydim) |
|
345 | 345 | axes.pcolor(self.x_buffer, y, zdB, |
|
346 | 346 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
347 | 347 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
348 | 348 | ticksize=9, cblabel='', cbsize="1%") |
|
349 | 349 | |
|
350 | 350 | if self.__showprofile: |
|
351 | 351 | axes = self.axesList[i*self.__nsubplots +1] |
|
352 | 352 | axes.pline(avgdB[i], y, |
|
353 | 353 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
354 | 354 | xlabel='dB', ylabel='', title='', |
|
355 | 355 | ytick_visible=False, |
|
356 | 356 | grid='x') |
|
357 | 357 | |
|
358 | 358 | self.draw() |
|
359 | 359 | |
|
360 | 360 | if save: |
|
361 | 361 | |
|
362 | 362 | if figfile == None: |
|
363 | 363 | figfile = self.getFilename(name = self.name) |
|
364 | 364 | |
|
365 | 365 | self.saveFigure(figpath, figfile) |
|
366 | 366 | |
|
367 | 367 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
368 | 368 | self.__isConfig = False |
|
369 | 369 | |
|
370 | 370 | class SpectraPlot(Figure): |
|
371 | 371 | |
|
372 | 372 | __isConfig = None |
|
373 | 373 | __nsubplots = None |
|
374 | 374 | |
|
375 | 375 | WIDTHPROF = None |
|
376 | 376 | HEIGHTPROF = None |
|
377 | 377 | PREFIX = 'spc' |
|
378 | 378 | |
|
379 | 379 | def __init__(self): |
|
380 | 380 | |
|
381 | 381 | self.__isConfig = False |
|
382 | 382 | self.__nsubplots = 1 |
|
383 | 383 | |
|
384 |
self.WIDTH = 2 |
|
|
384 | self.WIDTH = 250 | |
|
385 | 385 | self.HEIGHT = 250 |
|
386 | 386 | self.WIDTHPROF = 120 |
|
387 | 387 | self.HEIGHTPROF = 0 |
|
388 | 388 | |
|
389 | 389 | def getSubplots(self): |
|
390 | 390 | |
|
391 | 391 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
392 | 392 | nrow = int(self.nplots*1./ncol + 0.9) |
|
393 | 393 | |
|
394 | 394 | return nrow, ncol |
|
395 | 395 | |
|
396 | 396 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
397 | 397 | |
|
398 | 398 | self.__showprofile = showprofile |
|
399 | 399 | self.nplots = nplots |
|
400 | 400 | |
|
401 | 401 | ncolspan = 1 |
|
402 | 402 | colspan = 1 |
|
403 | 403 | widthplot = self.WIDTH |
|
404 | 404 | heightplot = self.HEIGHT |
|
405 | 405 | if showprofile: |
|
406 | 406 | ncolspan = 3 |
|
407 | 407 | colspan = 2 |
|
408 | 408 | self.__nsubplots = 2 |
|
409 | 409 | widthplot += self.WIDTHPROF |
|
410 | 410 | heightplot += self.HEIGHTPROF |
|
411 | 411 | |
|
412 | 412 | self.createFigure(idfigure = idfigure, |
|
413 | 413 | wintitle = wintitle, |
|
414 | 414 | widthplot = widthplot, |
|
415 | 415 | heightplot = heightplot) |
|
416 | 416 | |
|
417 | 417 | nrow, ncol = self.getSubplots() |
|
418 | 418 | |
|
419 | 419 | counter = 0 |
|
420 | 420 | for y in range(nrow): |
|
421 | 421 | for x in range(ncol): |
|
422 | 422 | |
|
423 | 423 | if counter >= self.nplots: |
|
424 | 424 | break |
|
425 | 425 | |
|
426 | 426 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
427 | 427 | |
|
428 | 428 | if showprofile: |
|
429 | 429 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
430 | 430 | |
|
431 | 431 | counter += 1 |
|
432 | 432 | |
|
433 | 433 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
434 | 434 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, normalize=True, |
|
435 | 435 | save=False, figpath='./', figfile=None): |
|
436 | 436 | |
|
437 | 437 | """ |
|
438 | 438 | |
|
439 | 439 | Input: |
|
440 | 440 | dataOut : |
|
441 | 441 | idfigure : |
|
442 | 442 | wintitle : |
|
443 | 443 | channelList : |
|
444 | 444 | showProfile : |
|
445 | 445 | xmin : None, |
|
446 | 446 | xmax : None, |
|
447 | 447 | ymin : None, |
|
448 | 448 | ymax : None, |
|
449 | 449 | zmin : None, |
|
450 | 450 | zmax : None |
|
451 | 451 | """ |
|
452 | 452 | |
|
453 | 453 | if channelList == None: |
|
454 | 454 | channelIndexList = dataOut.channelIndexList |
|
455 | 455 | else: |
|
456 | 456 | channelIndexList = [] |
|
457 | 457 | for channel in channelList: |
|
458 | 458 | if channel not in dataOut.channelList: |
|
459 | 459 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
460 | 460 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
461 | 461 | factor = 1 |
|
462 | 462 | if normalize: |
|
463 | 463 | factor = dataOut.normFactor |
|
464 | 464 | x = dataOut.getVelRange(1) |
|
465 | 465 | y = dataOut.getHeiRange() |
|
466 | 466 | |
|
467 | 467 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
468 | 468 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
469 | 469 | avg = numpy.average(z, axis=1) |
|
470 | 470 | noise = dataOut.getNoise()/factor |
|
471 | 471 | |
|
472 | 472 | zdB = 10*numpy.log10(z) |
|
473 | 473 | avgdB = 10*numpy.log10(avg) |
|
474 | 474 | noisedB = 10*numpy.log10(noise) |
|
475 | 475 | |
|
476 | 476 | thisDatetime = dataOut.datatime |
|
477 | 477 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
478 | 478 | xlabel = "Velocity (m/s)" |
|
479 | 479 | ylabel = "Range (Km)" |
|
480 | 480 | |
|
481 | 481 | if not self.__isConfig: |
|
482 | 482 | |
|
483 | 483 | nplots = len(channelIndexList) |
|
484 | 484 | |
|
485 | 485 | self.setup(idfigure=idfigure, |
|
486 | 486 | nplots=nplots, |
|
487 | 487 | wintitle=wintitle, |
|
488 | 488 | showprofile=showprofile) |
|
489 | 489 | |
|
490 | 490 | if xmin == None: xmin = numpy.nanmin(x) |
|
491 | 491 | if xmax == None: xmax = numpy.nanmax(x) |
|
492 | 492 | if ymin == None: ymin = numpy.nanmin(y) |
|
493 | 493 | if ymax == None: ymax = numpy.nanmax(y) |
|
494 | 494 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
495 | 495 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
496 | 496 | |
|
497 | 497 | self.__isConfig = True |
|
498 | 498 | |
|
499 | 499 | self.setWinTitle(title) |
|
500 | 500 | |
|
501 | 501 | for i in range(self.nplots): |
|
502 | 502 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) |
|
503 | 503 | axes = self.axesList[i*self.__nsubplots] |
|
504 | 504 | axes.pcolor(x, y, zdB[i,:,:], |
|
505 | 505 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
506 | 506 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
507 | 507 | ticksize=9, cblabel='') |
|
508 | 508 | |
|
509 | 509 | if self.__showprofile: |
|
510 | 510 | axes = self.axesList[i*self.__nsubplots +1] |
|
511 | 511 | axes.pline(avgdB[i], y, |
|
512 | 512 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
513 | 513 | xlabel='dB', ylabel='', title='', |
|
514 | 514 | ytick_visible=False, |
|
515 | 515 | grid='x') |
|
516 | 516 | |
|
517 | 517 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
518 | 518 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
519 | 519 | |
|
520 | 520 | self.draw() |
|
521 | 521 | |
|
522 | 522 | if save: |
|
523 | 523 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
524 | 524 | if figfile == None: |
|
525 | 525 | figfile = self.getFilename(name = date) |
|
526 | 526 | |
|
527 | 527 | self.saveFigure(figpath, figfile) |
|
528 | 528 | |
|
529 | 529 | class Scope(Figure): |
|
530 | 530 | |
|
531 | 531 | __isConfig = None |
|
532 | 532 | |
|
533 | 533 | def __init__(self): |
|
534 | 534 | |
|
535 | 535 | self.__isConfig = False |
|
536 | 536 | self.WIDTH = 600 |
|
537 | 537 | self.HEIGHT = 200 |
|
538 | 538 | |
|
539 | 539 | def getSubplots(self): |
|
540 | 540 | |
|
541 | 541 | nrow = self.nplots |
|
542 | 542 | ncol = 3 |
|
543 | 543 | return nrow, ncol |
|
544 | 544 | |
|
545 | 545 | def setup(self, idfigure, nplots, wintitle): |
|
546 | 546 | |
|
547 | 547 | self.nplots = nplots |
|
548 | 548 | |
|
549 | 549 | self.createFigure(idfigure, wintitle) |
|
550 | 550 | |
|
551 | 551 | nrow,ncol = self.getSubplots() |
|
552 | 552 | colspan = 3 |
|
553 | 553 | rowspan = 1 |
|
554 | 554 | |
|
555 | 555 | for i in range(nplots): |
|
556 | 556 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
557 | 557 | |
|
558 | 558 | |
|
559 | 559 | |
|
560 | 560 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
561 | 561 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
562 | 562 | figpath='./', figfile=None): |
|
563 | 563 | |
|
564 | 564 | """ |
|
565 | 565 | |
|
566 | 566 | Input: |
|
567 | 567 | dataOut : |
|
568 | 568 | idfigure : |
|
569 | 569 | wintitle : |
|
570 | 570 | channelList : |
|
571 | 571 | xmin : None, |
|
572 | 572 | xmax : None, |
|
573 | 573 | ymin : None, |
|
574 | 574 | ymax : None, |
|
575 | 575 | """ |
|
576 | 576 | |
|
577 | 577 | if channelList == None: |
|
578 | 578 | channelIndexList = dataOut.channelIndexList |
|
579 | 579 | else: |
|
580 | 580 | channelIndexList = [] |
|
581 | 581 | for channel in channelList: |
|
582 | 582 | if channel not in dataOut.channelList: |
|
583 | 583 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
584 | 584 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
585 | 585 | |
|
586 | 586 | x = dataOut.heightList |
|
587 | 587 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
588 | 588 | y = y.real |
|
589 | 589 | |
|
590 | 590 | thisDatetime = dataOut.datatime |
|
591 | 591 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
592 | 592 | xlabel = "Range (Km)" |
|
593 | 593 | ylabel = "Intensity" |
|
594 | 594 | |
|
595 | 595 | if not self.__isConfig: |
|
596 | 596 | nplots = len(channelIndexList) |
|
597 | 597 | |
|
598 | 598 | self.setup(idfigure=idfigure, |
|
599 | 599 | nplots=nplots, |
|
600 | 600 | wintitle=wintitle) |
|
601 | 601 | |
|
602 | 602 | if xmin == None: xmin = numpy.nanmin(x) |
|
603 | 603 | if xmax == None: xmax = numpy.nanmax(x) |
|
604 | 604 | if ymin == None: ymin = numpy.nanmin(y) |
|
605 | 605 | if ymax == None: ymax = numpy.nanmax(y) |
|
606 | 606 | |
|
607 | 607 | self.__isConfig = True |
|
608 | 608 | |
|
609 | 609 | self.setWinTitle(title) |
|
610 | 610 | |
|
611 | 611 | for i in range(len(self.axesList)): |
|
612 | 612 | title = "Channel %d" %(i) |
|
613 | 613 | axes = self.axesList[i] |
|
614 | 614 | ychannel = y[i,:] |
|
615 | 615 | axes.pline(x, ychannel, |
|
616 | 616 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
617 | 617 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
618 | 618 | |
|
619 | 619 | self.draw() |
|
620 | 620 | |
|
621 | 621 | if save: |
|
622 | 622 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
623 | 623 | if figfile == None: |
|
624 | 624 | figfile = self.getFilename(name = date) |
|
625 | 625 | |
|
626 | 626 | self.saveFigure(figpath, figfile) |
|
627 | 627 | |
|
628 | 628 | class ProfilePlot(Figure): |
|
629 | 629 | __isConfig = None |
|
630 | 630 | __nsubplots = None |
|
631 | 631 | |
|
632 | 632 | WIDTHPROF = None |
|
633 | 633 | HEIGHTPROF = None |
|
634 | 634 | PREFIX = 'spcprofile' |
|
635 | 635 | |
|
636 | 636 | def __init__(self): |
|
637 | 637 | self.__isConfig = False |
|
638 | 638 | self.__nsubplots = 1 |
|
639 | 639 | |
|
640 | 640 | self.WIDTH = 300 |
|
641 | 641 | self.HEIGHT = 500 |
|
642 | 642 | |
|
643 | 643 | def getSubplots(self): |
|
644 | 644 | ncol = 1 |
|
645 | 645 | nrow = 1 |
|
646 | 646 | |
|
647 | 647 | return nrow, ncol |
|
648 | 648 | |
|
649 | 649 | def setup(self, idfigure, nplots, wintitle): |
|
650 | 650 | |
|
651 | 651 | self.nplots = nplots |
|
652 | 652 | |
|
653 | 653 | ncolspan = 1 |
|
654 | 654 | colspan = 1 |
|
655 | 655 | |
|
656 | 656 | self.createFigure(idfigure = idfigure, |
|
657 | 657 | wintitle = wintitle, |
|
658 | 658 | widthplot = self.WIDTH, |
|
659 | 659 | heightplot = self.HEIGHT) |
|
660 | 660 | |
|
661 | 661 | nrow, ncol = self.getSubplots() |
|
662 | 662 | |
|
663 | 663 | counter = 0 |
|
664 | 664 | for y in range(nrow): |
|
665 | 665 | for x in range(ncol): |
|
666 | 666 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
667 | 667 | |
|
668 | 668 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
669 | 669 | xmin=None, xmax=None, ymin=None, ymax=None, normalize=True, |
|
670 | 670 | save=False, figpath='./', figfile=None): |
|
671 | 671 | |
|
672 | 672 | if channelList == None: |
|
673 | 673 | channelIndexList = dataOut.channelIndexList |
|
674 | 674 | channelList = dataOut.channelList |
|
675 | 675 | else: |
|
676 | 676 | channelIndexList = [] |
|
677 | 677 | for channel in channelList: |
|
678 | 678 | if channel not in dataOut.channelList: |
|
679 | 679 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
680 | 680 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
681 | 681 | |
|
682 | 682 | factor = 1 |
|
683 | 683 | if normalize: |
|
684 | 684 | factor = dataOut.normFactor |
|
685 | 685 | y = dataOut.getHeiRange() |
|
686 | 686 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
687 | 687 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
688 | 688 | avg = numpy.average(x, axis=1) |
|
689 | 689 | |
|
690 | 690 | avgdB = 10*numpy.log10(avg) |
|
691 | 691 | |
|
692 | 692 | thisDatetime = dataOut.datatime |
|
693 | 693 | title = "Power Profile" |
|
694 | 694 | xlabel = "dB" |
|
695 | 695 | ylabel = "Range (Km)" |
|
696 | 696 | |
|
697 | 697 | if not self.__isConfig: |
|
698 | 698 | |
|
699 | 699 | nplots = 1 |
|
700 | 700 | |
|
701 | 701 | self.setup(idfigure=idfigure, |
|
702 | 702 | nplots=nplots, |
|
703 | 703 | wintitle=wintitle) |
|
704 | 704 | |
|
705 | 705 | if ymin == None: ymin = numpy.nanmin(y) |
|
706 | 706 | if ymax == None: ymax = numpy.nanmax(y) |
|
707 | 707 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
708 | 708 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
709 | 709 | |
|
710 | 710 | self.__isConfig = True |
|
711 | 711 | |
|
712 | 712 | self.setWinTitle(title) |
|
713 | 713 | |
|
714 | 714 | |
|
715 | 715 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
716 | 716 | axes = self.axesList[0] |
|
717 | 717 | |
|
718 | 718 | legendlabels = ["channel %d"%x for x in channelList] |
|
719 | 719 | axes.pmultiline(avgdB, y, |
|
720 | 720 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
721 | 721 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
722 | 722 | ytick_visible=True, nxticks=5, |
|
723 | 723 | grid='x') |
|
724 | 724 | |
|
725 | 725 | self.draw() |
|
726 | 726 | |
|
727 | 727 | if save: |
|
728 | 728 | date = thisDatetime.strftime("%Y%m%d") |
|
729 | 729 | if figfile == None: |
|
730 | 730 | figfile = self.getFilename(name = date) |
|
731 | 731 | |
|
732 | 732 | self.saveFigure(figpath, figfile) |
|
733 | 733 | |
|
734 | 734 | class CoherenceMap(Figure): |
|
735 | 735 | __isConfig = None |
|
736 | 736 | __nsubplots = None |
|
737 | 737 | |
|
738 | 738 | WIDTHPROF = None |
|
739 | 739 | HEIGHTPROF = None |
|
740 | 740 | PREFIX = 'cmap' |
|
741 | 741 | __missing = 1E30 |
|
742 | 742 | |
|
743 | 743 | def __init__(self): |
|
744 | 744 | self.timerange = 2*60*60 |
|
745 | 745 | self.__isConfig = False |
|
746 | 746 | self.__nsubplots = 1 |
|
747 | 747 | |
|
748 | 748 | self.WIDTH = 800 |
|
749 | 749 | self.HEIGHT = 200 |
|
750 | 750 | self.WIDTHPROF = 120 |
|
751 | 751 | self.HEIGHTPROF = 0 |
|
752 | 752 | self.x_buffer = None |
|
753 | 753 | self.coherence_buffer = None |
|
754 | 754 | self.phase_buffer = None |
|
755 | 755 | |
|
756 | 756 | def getSubplots(self): |
|
757 | 757 | ncol = 1 |
|
758 | 758 | nrow = self.nplots*2 |
|
759 | 759 | |
|
760 | 760 | return nrow, ncol |
|
761 | 761 | |
|
762 | 762 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
763 | 763 | self.__showprofile = showprofile |
|
764 | 764 | self.nplots = nplots |
|
765 | 765 | |
|
766 | 766 | ncolspan = 1 |
|
767 | 767 | colspan = 1 |
|
768 | 768 | if showprofile: |
|
769 | 769 | ncolspan = 7 |
|
770 | 770 | colspan = 6 |
|
771 | 771 | self.__nsubplots = 2 |
|
772 | 772 | |
|
773 | 773 | self.createFigure(idfigure = idfigure, |
|
774 | 774 | wintitle = wintitle, |
|
775 | 775 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
776 | 776 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
777 | 777 | |
|
778 | 778 | nrow, ncol = self.getSubplots() |
|
779 | 779 | |
|
780 | 780 | for y in range(nrow): |
|
781 | 781 | for x in range(ncol): |
|
782 | 782 | |
|
783 | 783 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
784 | 784 | |
|
785 | 785 | if showprofile: |
|
786 | 786 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
787 | 787 | |
|
788 | 788 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
789 | 789 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
790 | 790 | timerange=None, |
|
791 | 791 | save=False, figpath='./', figfile=None, |
|
792 | 792 | coherence_cmap='jet', phase_cmap='RdBu_r'): |
|
793 | 793 | |
|
794 | 794 | if pairsList == None: |
|
795 | 795 | pairsIndexList = dataOut.pairsIndexList |
|
796 | 796 | else: |
|
797 | 797 | pairsIndexList = [] |
|
798 | 798 | for pair in pairsList: |
|
799 | 799 | if pair not in dataOut.pairsList: |
|
800 | 800 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
801 | 801 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
802 | 802 | |
|
803 | 803 | if timerange != None: |
|
804 | 804 | self.timerange = timerange |
|
805 | 805 | |
|
806 | 806 | if pairsIndexList == []: |
|
807 | 807 | return |
|
808 | 808 | |
|
809 | 809 | if len(pairsIndexList) > 4: |
|
810 | 810 | pairsIndexList = pairsIndexList[0:4] |
|
811 | 811 | |
|
812 | 812 | tmin = None |
|
813 | 813 | tmax = None |
|
814 | 814 | x = dataOut.getTimeRange() |
|
815 | 815 | y = dataOut.getHeiRange() |
|
816 | 816 | |
|
817 | 817 | thisDatetime = dataOut.datatime |
|
818 | 818 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
819 | 819 | xlabel = "" |
|
820 | 820 | ylabel = "Range (Km)" |
|
821 | 821 | |
|
822 | 822 | if not self.__isConfig: |
|
823 | 823 | nplots = len(pairsIndexList) |
|
824 | 824 | self.setup(idfigure=idfigure, |
|
825 | 825 | nplots=nplots, |
|
826 | 826 | wintitle=wintitle, |
|
827 | 827 | showprofile=showprofile) |
|
828 | 828 | |
|
829 | 829 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
830 | 830 | if ymin == None: ymin = numpy.nanmin(y) |
|
831 | 831 | if ymax == None: ymax = numpy.nanmax(y) |
|
832 | 832 | |
|
833 | 833 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
834 | 834 | self.x_buffer = numpy.array([]) |
|
835 | 835 | self.coherence_buffer = numpy.array([]) |
|
836 | 836 | self.phase_buffer = numpy.array([]) |
|
837 | 837 | self.__isConfig = True |
|
838 | 838 | |
|
839 | 839 | self.setWinTitle(title) |
|
840 | 840 | |
|
841 | 841 | |
|
842 | 842 | pairArray = numpy.array(dataOut.pairsList) |
|
843 | 843 | pairArray = pairArray[pairsIndexList] |
|
844 | 844 | pair0ids = pairArray[:,0] |
|
845 | 845 | pair1ids = pairArray[:,1] |
|
846 | 846 | |
|
847 | 847 | coherenceComplex = dataOut.data_cspc[pairsIndexList,:,:]/numpy.sqrt(dataOut.data_spc[pair0ids,:,:]*dataOut.data_spc[pair1ids,:,:]) |
|
848 | 848 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=1) |
|
849 | 849 | coherence = numpy.abs(avgcoherenceComplex) |
|
850 | 850 | |
|
851 | 851 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
852 | 852 | |
|
853 | 853 | if len(self.coherence_buffer)==0: |
|
854 | 854 | self.coherence_buffer = coherence |
|
855 | 855 | self.phase_buffer = phase |
|
856 | 856 | newxdim = 1 |
|
857 | 857 | newydim = -1 |
|
858 | 858 | else: |
|
859 | 859 | if x[0]>self.x_buffer[-1]: |
|
860 | 860 | gap = coherence.copy() |
|
861 | 861 | gap[:] = self.__missing |
|
862 | 862 | self.coherence_buffer = numpy.hstack((self.coherence_buffer, gap)) |
|
863 | 863 | self.phase_buffer = numpy.hstack((self.phase_buffer, gap)) |
|
864 | 864 | |
|
865 | 865 | self.coherence_buffer = numpy.hstack((self.coherence_buffer, coherence)) |
|
866 | 866 | self.phase_buffer = numpy.hstack((self.phase_buffer, phase)) |
|
867 | 867 | newxdim = -1 |
|
868 | 868 | newydim = len(y) |
|
869 | 869 | |
|
870 | 870 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
871 | 871 | |
|
872 | 872 | self.coherence_buffer = numpy.ma.masked_inside(self.coherence_buffer,0.99*self.__missing,1.01*self.__missing) |
|
873 | 873 | self.phase_buffer = numpy.ma.masked_inside(self.phase_buffer,0.99*self.__missing,1.01*self.__missing) |
|
874 | 874 | |
|
875 | 875 | |
|
876 | 876 | for i in range(self.nplots): |
|
877 | 877 | counter = 0 |
|
878 | 878 | z = self.coherence_buffer[i,:].reshape((newxdim,newydim)) |
|
879 | 879 | title = "Coherence %d%d: %s" %(pair0ids[i], pair1ids[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
880 | 880 | axes = self.axesList[i*self.__nsubplots*2] |
|
881 | 881 | axes.pcolor(self.x_buffer, y, z, |
|
882 | 882 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
883 | 883 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
884 | 884 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
885 | 885 | |
|
886 | 886 | if self.__showprofile: |
|
887 | 887 | counter += 1 |
|
888 | 888 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
889 | 889 | axes.pline(coherence[i,:], y, |
|
890 | 890 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
891 | 891 | xlabel='', ylabel='', title='', ticksize=7, |
|
892 | 892 | ytick_visible=False, nxticks=5, |
|
893 | 893 | grid='x') |
|
894 | 894 | |
|
895 | 895 | counter += 1 |
|
896 | 896 | |
|
897 | 897 | z = self.phase_buffer[i,:].reshape((newxdim,newydim)) |
|
898 | 898 | |
|
899 | 899 | title = "Phase %d%d: %s" %(pair0ids[i], pair1ids[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
900 | 900 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
901 | 901 | axes.pcolor(self.x_buffer, y, z, |
|
902 | 902 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
903 | 903 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
904 | 904 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
905 | 905 | |
|
906 | 906 | if self.__showprofile: |
|
907 | 907 | counter += 1 |
|
908 | 908 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
909 | 909 | axes.pline(phase[i,:], y, |
|
910 | 910 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
911 | 911 | xlabel='', ylabel='', title='', ticksize=7, |
|
912 | 912 | ytick_visible=False, nxticks=4, |
|
913 | 913 | grid='x') |
|
914 | 914 | |
|
915 | 915 | self.draw() |
|
916 | 916 | |
|
917 | 917 | if save: |
|
918 | 918 | |
|
919 | 919 | if figfile == None: |
|
920 | 920 | figfile = self.getFilename(name = self.name) |
|
921 | 921 | |
|
922 | 922 | self.saveFigure(figpath, figfile) |
|
923 | 923 | |
|
924 | 924 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
925 | 925 | self.__isConfig = False |
|
926 | 926 | |
|
927 | 927 | class RTIfromNoise(Figure): |
|
928 | 928 | |
|
929 | 929 | __isConfig = None |
|
930 | 930 | __nsubplots = None |
|
931 | 931 | |
|
932 | 932 | PREFIX = 'rtinoise' |
|
933 | 933 | |
|
934 | 934 | def __init__(self): |
|
935 | 935 | |
|
936 | 936 | self.timerange = 24*60*60 |
|
937 | 937 | self.__isConfig = False |
|
938 | 938 | self.__nsubplots = 1 |
|
939 | 939 | |
|
940 | 940 | self.WIDTH = 820 |
|
941 | 941 | self.HEIGHT = 200 |
|
942 | 942 | self.WIDTHPROF = 120 |
|
943 | 943 | self.HEIGHTPROF = 0 |
|
944 | 944 | self.xdata = None |
|
945 | 945 | self.ydata = None |
|
946 | 946 | |
|
947 | 947 | def getSubplots(self): |
|
948 | 948 | |
|
949 | 949 | ncol = 1 |
|
950 | 950 | nrow = 1 |
|
951 | 951 | |
|
952 | 952 | return nrow, ncol |
|
953 | 953 | |
|
954 | 954 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
955 | 955 | |
|
956 | 956 | self.__showprofile = showprofile |
|
957 | 957 | self.nplots = nplots |
|
958 | 958 | |
|
959 | 959 | ncolspan = 7 |
|
960 | 960 | colspan = 6 |
|
961 | 961 | self.__nsubplots = 2 |
|
962 | 962 | |
|
963 | 963 | self.createFigure(idfigure = idfigure, |
|
964 | 964 | wintitle = wintitle, |
|
965 | 965 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
966 | 966 | heightplot = self.HEIGHT+self.HEIGHTPROF) |
|
967 | 967 | |
|
968 | 968 | nrow, ncol = self.getSubplots() |
|
969 | 969 | |
|
970 | 970 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
971 | 971 | |
|
972 | 972 | |
|
973 | 973 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
974 | 974 | xmin=None, xmax=None, ymin=None, ymax=None, normalize=True, |
|
975 | 975 | timerange=None, |
|
976 | 976 | save=False, figpath='./', figfile=None): |
|
977 | 977 | |
|
978 | 978 | if channelList == None: |
|
979 | 979 | channelIndexList = dataOut.channelIndexList |
|
980 | 980 | channelList = dataOut.channelList |
|
981 | 981 | else: |
|
982 | 982 | channelIndexList = [] |
|
983 | 983 | for channel in channelList: |
|
984 | 984 | if channel not in dataOut.channelList: |
|
985 | 985 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
986 | 986 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
987 | 987 | |
|
988 | 988 | if timerange != None: |
|
989 | 989 | self.timerange = timerange |
|
990 | 990 | |
|
991 | 991 | tmin = None |
|
992 | 992 | tmax = None |
|
993 | 993 | x = dataOut.getTimeRange() |
|
994 | 994 | y = dataOut.getHeiRange() |
|
995 | 995 | factor = 1 |
|
996 | 996 | if normalize: |
|
997 | 997 | factor = dataOut.normFactor |
|
998 | 998 | noise = dataOut.getNoise()/factor |
|
999 | 999 | noisedB = 10*numpy.log10(noise) |
|
1000 | 1000 | |
|
1001 | 1001 | thisDatetime = dataOut.datatime |
|
1002 | 1002 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1003 | 1003 | xlabel = "" |
|
1004 | 1004 | ylabel = "Range (Km)" |
|
1005 | 1005 | |
|
1006 | 1006 | if not self.__isConfig: |
|
1007 | 1007 | |
|
1008 | 1008 | nplots = 1 |
|
1009 | 1009 | |
|
1010 | 1010 | self.setup(idfigure=idfigure, |
|
1011 | 1011 | nplots=nplots, |
|
1012 | 1012 | wintitle=wintitle, |
|
1013 | 1013 | showprofile=showprofile) |
|
1014 | 1014 | |
|
1015 | 1015 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1016 | 1016 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
1017 | 1017 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
1018 | 1018 | |
|
1019 | 1019 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1020 | 1020 | self.__isConfig = True |
|
1021 | 1021 | |
|
1022 | 1022 | self.xdata = numpy.array([]) |
|
1023 | 1023 | self.ydata = numpy.array([]) |
|
1024 | 1024 | |
|
1025 | 1025 | self.setWinTitle(title) |
|
1026 | 1026 | |
|
1027 | 1027 | |
|
1028 | 1028 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1029 | 1029 | |
|
1030 | 1030 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1031 | 1031 | axes = self.axesList[0] |
|
1032 | 1032 | |
|
1033 | 1033 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1034 | 1034 | |
|
1035 | 1035 | if len(self.ydata)==0: |
|
1036 | 1036 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1037 | 1037 | else: |
|
1038 | 1038 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1039 | 1039 | |
|
1040 | 1040 | |
|
1041 | 1041 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1042 | 1042 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1043 | 1043 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1044 | 1044 | XAxisAsTime=True |
|
1045 | 1045 | ) |
|
1046 | 1046 | |
|
1047 | 1047 | self.draw() |
|
1048 | 1048 | |
|
1049 | 1049 | if save: |
|
1050 | 1050 | |
|
1051 | 1051 | if figfile == None: |
|
1052 | 1052 | figfile = self.getFilename(name = self.name) |
|
1053 | 1053 | |
|
1054 | 1054 | self.saveFigure(figpath, figfile) |
|
1055 | 1055 | |
|
1056 | 1056 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1057 | 1057 | self.__isConfig = False |
|
1058 | 1058 | del self.xdata |
|
1059 | 1059 | del self.ydata |
|
1060 | 1060 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now