@@ -1,1363 +1,1487 | |||
|
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, isTimeInHourRange |
|
11 | 11 | from plotting_codes import * |
|
12 | 12 | |
|
13 | 13 | class SpectraPlot(Figure): |
|
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 = 250 |
|
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 | self.PLOT_CODE = SPEC_CODE |
|
34 | 34 | |
|
35 | 35 | self.FTP_WEI = None |
|
36 | 36 | self.EXP_CODE = None |
|
37 | 37 | self.SUB_EXP_CODE = None |
|
38 | 38 | self.PLOT_POS = None |
|
39 | 39 | |
|
40 | 40 | self.__xfilter_ena = False |
|
41 | 41 | self.__yfilter_ena = False |
|
42 | 42 | |
|
43 | 43 | def getSubplots(self): |
|
44 | 44 | |
|
45 | 45 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
46 | 46 | nrow = int(self.nplots*1./ncol + 0.9) |
|
47 | 47 | |
|
48 | 48 | return nrow, ncol |
|
49 | 49 | |
|
50 | 50 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
51 | 51 | |
|
52 | 52 | self.__showprofile = showprofile |
|
53 | 53 | self.nplots = nplots |
|
54 | 54 | |
|
55 | 55 | ncolspan = 1 |
|
56 | 56 | colspan = 1 |
|
57 | 57 | if showprofile: |
|
58 | 58 | ncolspan = 3 |
|
59 | 59 | colspan = 2 |
|
60 | 60 | self.__nsubplots = 2 |
|
61 | 61 | |
|
62 | 62 | self.createFigure(id = id, |
|
63 | 63 | wintitle = wintitle, |
|
64 | 64 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
65 | 65 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
66 | 66 | show=show) |
|
67 | 67 | |
|
68 | 68 | nrow, ncol = self.getSubplots() |
|
69 | 69 | |
|
70 | 70 | counter = 0 |
|
71 | 71 | for y in range(nrow): |
|
72 | 72 | for x in range(ncol): |
|
73 | 73 | |
|
74 | 74 | if counter >= self.nplots: |
|
75 | 75 | break |
|
76 | 76 | |
|
77 | 77 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
78 | 78 | |
|
79 | 79 | if showprofile: |
|
80 | 80 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
81 | 81 | |
|
82 | 82 | counter += 1 |
|
83 | 83 | |
|
84 | 84 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
85 | 85 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
86 | 86 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
87 | 87 | server=None, folder=None, username=None, password=None, |
|
88 | 88 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
89 | 89 | |
|
90 | 90 | """ |
|
91 | 91 | |
|
92 | 92 | Input: |
|
93 | 93 | dataOut : |
|
94 | 94 | id : |
|
95 | 95 | wintitle : |
|
96 | 96 | channelList : |
|
97 | 97 | showProfile : |
|
98 | 98 | xmin : None, |
|
99 | 99 | xmax : None, |
|
100 | 100 | ymin : None, |
|
101 | 101 | ymax : None, |
|
102 | 102 | zmin : None, |
|
103 | 103 | zmax : None |
|
104 | 104 | """ |
|
105 | 105 | |
|
106 | 106 | if realtime: |
|
107 | 107 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
108 | 108 | print 'Skipping this plot function' |
|
109 | 109 | return |
|
110 | 110 | |
|
111 | 111 | if channelList == None: |
|
112 | 112 | channelIndexList = dataOut.channelIndexList |
|
113 | 113 | else: |
|
114 | 114 | channelIndexList = [] |
|
115 | 115 | for channel in channelList: |
|
116 | 116 | if channel not in dataOut.channelList: |
|
117 | 117 | raise ValueError, "Channel %d is not in dataOut.channelList" %channel |
|
118 | 118 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
119 | 119 | |
|
120 | 120 | factor = dataOut.normFactor |
|
121 | 121 | |
|
122 |
x = dataOut.get |
|
|
122 | x = dataOut.getFreqRange(1)/1000 | |
|
123 | # x = dataOut.getVelRange(1) | |
|
123 | 124 | y = dataOut.getHeiRange() |
|
124 | 125 | |
|
125 | 126 | z = dataOut.data_spc/factor |
|
126 | 127 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
127 | 128 | zdB = 10*numpy.log10(z) |
|
128 | 129 | |
|
129 | 130 | avg = numpy.average(z, axis=1) |
|
130 | 131 | avgdB = 10*numpy.log10(avg) |
|
131 | 132 | |
|
132 | 133 | noise = dataOut.getNoise()/factor |
|
133 | 134 | noisedB = 10*numpy.log10(noise) |
|
134 | 135 | |
|
135 | 136 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
136 | 137 | title = wintitle + " Spectra" |
|
137 | 138 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
138 | 139 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
139 | 140 | |
|
140 |
xlabel = " |
|
|
141 | xlabel = "Frequency (KHz)" | |
|
141 | 142 | ylabel = "Range (Km)" |
|
142 | 143 | |
|
143 | 144 | if not self.isConfig: |
|
144 | 145 | |
|
145 | 146 | nplots = len(channelIndexList) |
|
146 | 147 | |
|
147 | 148 | self.setup(id=id, |
|
148 | 149 | nplots=nplots, |
|
149 | 150 | wintitle=wintitle, |
|
150 | 151 | showprofile=showprofile, |
|
151 | 152 | show=show) |
|
152 | 153 | |
|
153 | 154 | if xmin == None: xmin = numpy.nanmin(x) |
|
154 | 155 | if xmax == None: xmax = numpy.nanmax(x) |
|
155 | 156 | if ymin == None: ymin = numpy.nanmin(y) |
|
156 | 157 | if ymax == None: ymax = numpy.nanmax(y) |
|
157 | 158 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
158 | 159 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
159 | 160 | |
|
160 | 161 | self.FTP_WEI = ftp_wei |
|
161 | 162 | self.EXP_CODE = exp_code |
|
162 | 163 | self.SUB_EXP_CODE = sub_exp_code |
|
163 | 164 | self.PLOT_POS = plot_pos |
|
164 | 165 | |
|
165 | 166 | self.isConfig = True |
|
166 | 167 | |
|
167 | 168 | self.setWinTitle(title) |
|
168 | 169 | |
|
169 | 170 | for i in range(self.nplots): |
|
170 | 171 | index = channelIndexList[i] |
|
171 | 172 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
172 | 173 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
173 | 174 | if len(dataOut.beam.codeList) != 0: |
|
174 | 175 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
175 | 176 | |
|
176 | 177 | axes = self.axesList[i*self.__nsubplots] |
|
177 | 178 | axes.pcolor(x, y, zdB[index,:,:], |
|
178 | 179 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
179 | 180 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
180 | 181 | ticksize=9, cblabel='') |
|
181 | 182 | |
|
182 | 183 | if self.__showprofile: |
|
183 | 184 | axes = self.axesList[i*self.__nsubplots +1] |
|
184 | 185 | axes.pline(avgdB[index,:], y, |
|
185 | 186 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
186 | 187 | xlabel='dB', ylabel='', title='', |
|
187 | 188 | ytick_visible=False, |
|
188 | 189 | grid='x') |
|
189 | 190 | |
|
190 | 191 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
191 | 192 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
192 | 193 | |
|
193 | 194 | self.draw() |
|
194 | 195 | |
|
195 | 196 | if figfile == None: |
|
196 | 197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
197 | 198 | name = str_datetime |
|
198 | 199 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
199 | 200 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
200 | 201 | figfile = self.getFilename(name) |
|
201 | 202 | |
|
202 | 203 | self.save(figpath=figpath, |
|
203 | 204 | figfile=figfile, |
|
204 | 205 | save=save, |
|
205 | 206 | ftp=ftp, |
|
206 | 207 | wr_period=wr_period, |
|
207 | 208 | thisDatetime=thisDatetime) |
|
208 | 209 | |
|
209 | 210 | class CrossSpectraPlot(Figure): |
|
210 | 211 | |
|
211 | 212 | isConfig = None |
|
212 | 213 | __nsubplots = None |
|
213 | 214 | |
|
214 | 215 | WIDTH = None |
|
215 | 216 | HEIGHT = None |
|
216 | 217 | WIDTHPROF = None |
|
217 | 218 | HEIGHTPROF = None |
|
218 | 219 | PREFIX = 'cspc' |
|
219 | 220 | |
|
220 | 221 | def __init__(self): |
|
221 | 222 | |
|
222 | 223 | self.isConfig = False |
|
223 | 224 | self.__nsubplots = 4 |
|
224 | 225 | self.counter_imagwr = 0 |
|
225 | 226 | self.WIDTH = 250 |
|
226 | 227 | self.HEIGHT = 250 |
|
227 | 228 | self.WIDTHPROF = 0 |
|
228 | 229 | self.HEIGHTPROF = 0 |
|
229 | 230 | |
|
230 | 231 | self.PLOT_CODE = CROSS_CODE |
|
231 | 232 | self.FTP_WEI = None |
|
232 | 233 | self.EXP_CODE = None |
|
233 | 234 | self.SUB_EXP_CODE = None |
|
234 | 235 | self.PLOT_POS = None |
|
235 | 236 | |
|
236 | 237 | def getSubplots(self): |
|
237 | 238 | |
|
238 | 239 | ncol = 4 |
|
239 | 240 | nrow = self.nplots |
|
240 | 241 | |
|
241 | 242 | return nrow, ncol |
|
242 | 243 | |
|
243 | 244 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
244 | 245 | |
|
245 | 246 | self.__showprofile = showprofile |
|
246 | 247 | self.nplots = nplots |
|
247 | 248 | |
|
248 | 249 | ncolspan = 1 |
|
249 | 250 | colspan = 1 |
|
250 | 251 | |
|
251 | 252 | self.createFigure(id = id, |
|
252 | 253 | wintitle = wintitle, |
|
253 | 254 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
254 | 255 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
255 | 256 | show=True) |
|
256 | 257 | |
|
257 | 258 | nrow, ncol = self.getSubplots() |
|
258 | 259 | |
|
259 | 260 | counter = 0 |
|
260 | 261 | for y in range(nrow): |
|
261 | 262 | for x in range(ncol): |
|
262 | 263 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
263 | 264 | |
|
264 | 265 | counter += 1 |
|
265 | 266 | |
|
266 | 267 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
267 | 268 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
268 | 269 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, |
|
269 | 270 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
270 | 271 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
271 | 272 | server=None, folder=None, username=None, password=None, |
|
272 | 273 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
273 | 274 | |
|
274 | 275 | """ |
|
275 | 276 | |
|
276 | 277 | Input: |
|
277 | 278 | dataOut : |
|
278 | 279 | id : |
|
279 | 280 | wintitle : |
|
280 | 281 | channelList : |
|
281 | 282 | showProfile : |
|
282 | 283 | xmin : None, |
|
283 | 284 | xmax : None, |
|
284 | 285 | ymin : None, |
|
285 | 286 | ymax : None, |
|
286 | 287 | zmin : None, |
|
287 | 288 | zmax : None |
|
288 | 289 | """ |
|
289 | 290 | |
|
290 | 291 | if pairsList == None: |
|
291 | 292 | pairsIndexList = dataOut.pairsIndexList |
|
292 | 293 | else: |
|
293 | 294 | pairsIndexList = [] |
|
294 | 295 | for pair in pairsList: |
|
295 | 296 | if pair not in dataOut.pairsList: |
|
296 | 297 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) |
|
297 | 298 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
298 | 299 | |
|
299 | 300 | if not pairsIndexList: |
|
300 | 301 | return |
|
301 | 302 | |
|
302 | 303 | if len(pairsIndexList) > 4: |
|
303 | 304 | pairsIndexList = pairsIndexList[0:4] |
|
304 | 305 | |
|
305 | 306 | factor = dataOut.normFactor |
|
306 | 307 | x = dataOut.getVelRange(1) |
|
307 | 308 | y = dataOut.getHeiRange() |
|
308 | 309 | z = dataOut.data_spc[:,:,:]/factor |
|
309 | 310 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
310 | 311 | |
|
311 | 312 | noise = dataOut.noise/factor |
|
312 | 313 | |
|
313 | 314 | zdB = 10*numpy.log10(z) |
|
314 | 315 | noisedB = 10*numpy.log10(noise) |
|
315 | 316 | |
|
316 | 317 | if coh_min == None: |
|
317 | 318 | coh_min = 0.0 |
|
318 | 319 | if coh_max == None: |
|
319 | 320 | coh_max = 1.0 |
|
320 | 321 | |
|
321 | 322 | if phase_min == None: |
|
322 | 323 | phase_min = -180 |
|
323 | 324 | if phase_max == None: |
|
324 | 325 | phase_max = 180 |
|
325 | 326 | |
|
326 | 327 | #thisDatetime = dataOut.datatime |
|
327 | 328 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
328 | 329 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
329 | 330 | xlabel = "Velocity (m/s)" |
|
330 | 331 | ylabel = "Range (Km)" |
|
331 | 332 | |
|
332 | 333 | if not self.isConfig: |
|
333 | 334 | |
|
334 | 335 | nplots = len(pairsIndexList) |
|
335 | 336 | |
|
336 | 337 | self.setup(id=id, |
|
337 | 338 | nplots=nplots, |
|
338 | 339 | wintitle=wintitle, |
|
339 | 340 | showprofile=False, |
|
340 | 341 | show=show) |
|
341 | 342 | |
|
342 | 343 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
343 | 344 | avgdB = 10*numpy.log10(avg) |
|
344 | 345 | |
|
345 | 346 | if xmin == None: xmin = numpy.nanmin(x) |
|
346 | 347 | if xmax == None: xmax = numpy.nanmax(x) |
|
347 | 348 | if ymin == None: ymin = numpy.nanmin(y) |
|
348 | 349 | if ymax == None: ymax = numpy.nanmax(y) |
|
349 | 350 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
350 | 351 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
351 | 352 | |
|
352 | 353 | self.FTP_WEI = ftp_wei |
|
353 | 354 | self.EXP_CODE = exp_code |
|
354 | 355 | self.SUB_EXP_CODE = sub_exp_code |
|
355 | 356 | self.PLOT_POS = plot_pos |
|
356 | 357 | |
|
357 | 358 | self.isConfig = True |
|
358 | 359 | |
|
359 | 360 | self.setWinTitle(title) |
|
360 | 361 | |
|
361 | 362 | for i in range(self.nplots): |
|
362 | 363 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
364 | ||
|
365 | chan_index0 = dataOut.channelList.index(pair[0]) | |
|
366 | chan_index1 = dataOut.channelList.index(pair[1]) | |
|
367 | ||
|
363 | 368 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
364 |
title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[ |
|
|
365 |
zdB = 10.*numpy.log10(dataOut.data_spc[ |
|
|
369 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) | |
|
370 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) | |
|
366 | 371 | axes0 = self.axesList[i*self.__nsubplots] |
|
367 | 372 | axes0.pcolor(x, y, zdB, |
|
368 | 373 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
369 | 374 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
370 | 375 | ticksize=9, colormap=power_cmap, cblabel='') |
|
371 | 376 | |
|
372 |
title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[ |
|
|
373 |
zdB = 10.*numpy.log10(dataOut.data_spc[ |
|
|
377 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) | |
|
378 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) | |
|
374 | 379 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
375 | 380 | axes0.pcolor(x, y, zdB, |
|
376 | 381 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
377 | 382 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
378 | 383 | ticksize=9, colormap=power_cmap, cblabel='') |
|
379 | 384 | |
|
380 |
coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[ |
|
|
385 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:]) | |
|
381 | 386 | coherence = numpy.abs(coherenceComplex) |
|
382 | 387 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
383 | 388 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
384 | 389 | |
|
385 | 390 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) |
|
386 | 391 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
387 | 392 | axes0.pcolor(x, y, coherence, |
|
388 | 393 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, |
|
389 | 394 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
390 | 395 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
391 | 396 | |
|
392 | 397 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) |
|
393 | 398 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
394 | 399 | axes0.pcolor(x, y, phase, |
|
395 | 400 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
396 | 401 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
397 | 402 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
398 | 403 | |
|
399 | 404 | |
|
400 | 405 | |
|
401 | 406 | self.draw() |
|
402 | 407 | |
|
403 | 408 | self.save(figpath=figpath, |
|
404 | 409 | figfile=figfile, |
|
405 | 410 | save=save, |
|
406 | 411 | ftp=ftp, |
|
407 | 412 | wr_period=wr_period, |
|
408 | 413 | thisDatetime=thisDatetime) |
|
409 | 414 | |
|
410 | 415 | |
|
411 | 416 | class RTIPlot(Figure): |
|
412 | 417 | |
|
413 | 418 | __isConfig = None |
|
414 | 419 | __nsubplots = None |
|
415 | 420 | |
|
416 | 421 | WIDTHPROF = None |
|
417 | 422 | HEIGHTPROF = None |
|
418 | 423 | PREFIX = 'rti' |
|
419 | 424 | |
|
420 | 425 | def __init__(self): |
|
421 | 426 | |
|
422 | 427 | self.timerange = None |
|
423 | 428 | self.isConfig = False |
|
424 | 429 | self.__nsubplots = 1 |
|
425 | 430 | |
|
426 | 431 | self.WIDTH = 800 |
|
427 | 432 | self.HEIGHT = 180 |
|
428 | 433 | self.WIDTHPROF = 120 |
|
429 | 434 | self.HEIGHTPROF = 0 |
|
430 | 435 | self.counter_imagwr = 0 |
|
431 | 436 | |
|
432 | 437 | self.PLOT_CODE = RTI_CODE |
|
433 | 438 | |
|
434 | 439 | self.FTP_WEI = None |
|
435 | 440 | self.EXP_CODE = None |
|
436 | 441 | self.SUB_EXP_CODE = None |
|
437 | 442 | self.PLOT_POS = None |
|
438 | 443 | self.tmin = None |
|
439 | 444 | self.tmax = None |
|
440 | 445 | |
|
441 | 446 | self.xmin = None |
|
442 | 447 | self.xmax = None |
|
443 | 448 | |
|
444 | 449 | self.figfile = None |
|
445 | 450 | |
|
446 | 451 | def getSubplots(self): |
|
447 | 452 | |
|
448 | 453 | ncol = 1 |
|
449 | 454 | nrow = self.nplots |
|
450 | 455 | |
|
451 | 456 | return nrow, ncol |
|
452 | 457 | |
|
453 | 458 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
454 | 459 | |
|
455 | 460 | self.__showprofile = showprofile |
|
456 | 461 | self.nplots = nplots |
|
457 | 462 | |
|
458 | 463 | ncolspan = 1 |
|
459 | 464 | colspan = 1 |
|
460 | 465 | if showprofile: |
|
461 | 466 | ncolspan = 7 |
|
462 | 467 | colspan = 6 |
|
463 | 468 | self.__nsubplots = 2 |
|
464 | 469 | |
|
465 | 470 | self.createFigure(id = id, |
|
466 | 471 | wintitle = wintitle, |
|
467 | 472 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
468 | 473 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
469 | 474 | show=show) |
|
470 | 475 | |
|
471 | 476 | nrow, ncol = self.getSubplots() |
|
472 | 477 | |
|
473 | 478 | counter = 0 |
|
474 | 479 | for y in range(nrow): |
|
475 | 480 | for x in range(ncol): |
|
476 | 481 | |
|
477 | 482 | if counter >= self.nplots: |
|
478 | 483 | break |
|
479 | 484 | |
|
480 | 485 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
481 | 486 | |
|
482 | 487 | if showprofile: |
|
483 | 488 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
484 | 489 | |
|
485 | 490 | counter += 1 |
|
486 | 491 | |
|
487 | 492 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
488 | 493 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
489 | 494 | timerange=None, |
|
490 | 495 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
491 | 496 | server=None, folder=None, username=None, password=None, |
|
492 | 497 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
493 | 498 | |
|
494 | 499 | """ |
|
495 | 500 | |
|
496 | 501 | Input: |
|
497 | 502 | dataOut : |
|
498 | 503 | id : |
|
499 | 504 | wintitle : |
|
500 | 505 | channelList : |
|
501 | 506 | showProfile : |
|
502 | 507 | xmin : None, |
|
503 | 508 | xmax : None, |
|
504 | 509 | ymin : None, |
|
505 | 510 | ymax : None, |
|
506 | 511 | zmin : None, |
|
507 | 512 | zmax : None |
|
508 | 513 | """ |
|
509 | 514 | |
|
510 | 515 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
511 | 516 | return |
|
512 | 517 | |
|
513 | 518 | if channelList == None: |
|
514 | 519 | channelIndexList = dataOut.channelIndexList |
|
515 | 520 | else: |
|
516 | 521 | channelIndexList = [] |
|
517 | 522 | for channel in channelList: |
|
518 | 523 | if channel not in dataOut.channelList: |
|
519 | 524 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
520 | 525 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
521 | 526 | |
|
522 | 527 | factor = dataOut.normFactor |
|
523 | 528 | x = dataOut.getTimeRange() |
|
524 | 529 | y = dataOut.getHeiRange() |
|
525 | 530 | |
|
526 | 531 | z = dataOut.data_spc/factor |
|
527 | 532 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
528 | 533 | avg = numpy.average(z, axis=1) |
|
529 | 534 | |
|
530 | 535 | avgdB = 10.*numpy.log10(avg) |
|
531 | 536 | |
|
532 | 537 | thisDatetime = dataOut.datatime |
|
533 | 538 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
534 | 539 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
535 | 540 | xlabel = "" |
|
536 | 541 | ylabel = "Range (Km)" |
|
537 | 542 | |
|
538 | 543 | update_figfile = False |
|
539 | 544 | |
|
540 | 545 | if not self.isConfig: |
|
541 | 546 | |
|
542 | 547 | nplots = len(channelIndexList) |
|
543 | 548 | |
|
544 | 549 | self.setup(id=id, |
|
545 | 550 | nplots=nplots, |
|
546 | 551 | wintitle=wintitle, |
|
547 | 552 | showprofile=showprofile, |
|
548 | 553 | show=show) |
|
549 | 554 | |
|
550 | 555 | if timerange != None: |
|
551 | 556 | self.timerange = timerange |
|
552 | 557 | |
|
553 | 558 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
554 | 559 | |
|
555 | 560 | noise = dataOut.noise/factor |
|
556 | 561 | noisedB = 10*numpy.log10(noise) |
|
557 | 562 | |
|
558 | 563 | if ymin == None: ymin = numpy.nanmin(y) |
|
559 | 564 | if ymax == None: ymax = numpy.nanmax(y) |
|
560 | 565 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
561 | 566 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
562 | 567 | |
|
563 | 568 | self.FTP_WEI = ftp_wei |
|
564 | 569 | self.EXP_CODE = exp_code |
|
565 | 570 | self.SUB_EXP_CODE = sub_exp_code |
|
566 | 571 | self.PLOT_POS = plot_pos |
|
567 | 572 | |
|
568 | 573 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
569 | 574 | self.isConfig = True |
|
570 | 575 | self.figfile = figfile |
|
571 | 576 | update_figfile = True |
|
572 | 577 | |
|
573 | 578 | self.setWinTitle(title) |
|
574 | 579 | |
|
575 | 580 | for i in range(self.nplots): |
|
576 | 581 | index = channelIndexList[i] |
|
577 | 582 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
578 | 583 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
579 | 584 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
580 | 585 | axes = self.axesList[i*self.__nsubplots] |
|
581 | 586 | zdB = avgdB[index].reshape((1,-1)) |
|
582 | 587 | axes.pcolorbuffer(x, y, zdB, |
|
583 | 588 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
584 | 589 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
585 | 590 | ticksize=9, cblabel='', cbsize="1%") |
|
586 | 591 | |
|
587 | 592 | if self.__showprofile: |
|
588 | 593 | axes = self.axesList[i*self.__nsubplots +1] |
|
589 | 594 | axes.pline(avgdB[index], y, |
|
590 | 595 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
591 | 596 | xlabel='dB', ylabel='', title='', |
|
592 | 597 | ytick_visible=False, |
|
593 | 598 | grid='x') |
|
594 | 599 | |
|
595 | 600 | self.draw() |
|
596 | 601 | |
|
597 | 602 | if dataOut.ltctime >= self.xmax: |
|
598 | 603 | self.counter_imagwr = wr_period |
|
599 | 604 | self.isConfig = False |
|
600 | 605 | update_figfile = True |
|
601 | 606 | |
|
602 | 607 | self.save(figpath=figpath, |
|
603 | 608 | figfile=figfile, |
|
604 | 609 | save=save, |
|
605 | 610 | ftp=ftp, |
|
606 | 611 | wr_period=wr_period, |
|
607 | 612 | thisDatetime=thisDatetime, |
|
608 | 613 | update_figfile=update_figfile) |
|
609 | 614 | |
|
610 | 615 | class CoherenceMap(Figure): |
|
611 | 616 | isConfig = None |
|
612 | 617 | __nsubplots = None |
|
613 | 618 | |
|
614 | 619 | WIDTHPROF = None |
|
615 | 620 | HEIGHTPROF = None |
|
616 | 621 | PREFIX = 'cmap' |
|
617 | 622 | |
|
618 | 623 | def __init__(self): |
|
619 | 624 | self.timerange = 2*60*60 |
|
620 | 625 | self.isConfig = False |
|
621 | 626 | self.__nsubplots = 1 |
|
622 | 627 | |
|
623 | 628 | self.WIDTH = 800 |
|
624 | 629 | self.HEIGHT = 180 |
|
625 | 630 | self.WIDTHPROF = 120 |
|
626 | 631 | self.HEIGHTPROF = 0 |
|
627 | 632 | self.counter_imagwr = 0 |
|
628 | 633 | |
|
629 | 634 | self.PLOT_CODE = COH_CODE |
|
630 | 635 | |
|
631 | 636 | self.FTP_WEI = None |
|
632 | 637 | self.EXP_CODE = None |
|
633 | 638 | self.SUB_EXP_CODE = None |
|
634 | 639 | self.PLOT_POS = None |
|
635 | 640 | self.counter_imagwr = 0 |
|
636 | 641 | |
|
637 | 642 | self.xmin = None |
|
638 | 643 | self.xmax = None |
|
639 | 644 | |
|
640 | 645 | def getSubplots(self): |
|
641 | 646 | ncol = 1 |
|
642 | 647 | nrow = self.nplots*2 |
|
643 | 648 | |
|
644 | 649 | return nrow, ncol |
|
645 | 650 | |
|
646 | 651 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
647 | 652 | self.__showprofile = showprofile |
|
648 | 653 | self.nplots = nplots |
|
649 | 654 | |
|
650 | 655 | ncolspan = 1 |
|
651 | 656 | colspan = 1 |
|
652 | 657 | if showprofile: |
|
653 | 658 | ncolspan = 7 |
|
654 | 659 | colspan = 6 |
|
655 | 660 | self.__nsubplots = 2 |
|
656 | 661 | |
|
657 | 662 | self.createFigure(id = id, |
|
658 | 663 | wintitle = wintitle, |
|
659 | 664 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
660 | 665 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
661 | 666 | show=True) |
|
662 | 667 | |
|
663 | 668 | nrow, ncol = self.getSubplots() |
|
664 | 669 | |
|
665 | 670 | for y in range(nrow): |
|
666 | 671 | for x in range(ncol): |
|
667 | 672 | |
|
668 | 673 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
669 | 674 | |
|
670 | 675 | if showprofile: |
|
671 | 676 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
672 | 677 | |
|
673 | 678 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
674 | 679 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
675 | 680 | timerange=None, phase_min=None, phase_max=None, |
|
676 | 681 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
677 | 682 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
678 | 683 | server=None, folder=None, username=None, password=None, |
|
679 | 684 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
680 | 685 | |
|
681 | 686 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
682 | 687 | return |
|
683 | 688 | |
|
684 | 689 | if pairsList == None: |
|
685 | 690 | pairsIndexList = dataOut.pairsIndexList |
|
686 | 691 | else: |
|
687 | 692 | pairsIndexList = [] |
|
688 | 693 | for pair in pairsList: |
|
689 | 694 | if pair not in dataOut.pairsList: |
|
690 | 695 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
691 | 696 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
692 | 697 | |
|
693 | 698 | if pairsIndexList == []: |
|
694 | 699 | return |
|
695 | 700 | |
|
696 | 701 | if len(pairsIndexList) > 4: |
|
697 | 702 | pairsIndexList = pairsIndexList[0:4] |
|
698 | 703 | |
|
699 | 704 | if phase_min == None: |
|
700 | 705 | phase_min = -180 |
|
701 | 706 | if phase_max == None: |
|
702 | 707 | phase_max = 180 |
|
703 | 708 | |
|
704 | 709 | x = dataOut.getTimeRange() |
|
705 | 710 | y = dataOut.getHeiRange() |
|
706 | 711 | |
|
707 | 712 | thisDatetime = dataOut.datatime |
|
708 | 713 | |
|
709 | 714 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
710 | 715 | xlabel = "" |
|
711 | 716 | ylabel = "Range (Km)" |
|
712 | 717 | update_figfile = False |
|
713 | 718 | |
|
714 | 719 | if not self.isConfig: |
|
715 | 720 | nplots = len(pairsIndexList) |
|
716 | 721 | self.setup(id=id, |
|
717 | 722 | nplots=nplots, |
|
718 | 723 | wintitle=wintitle, |
|
719 | 724 | showprofile=showprofile, |
|
720 | 725 | show=show) |
|
721 | 726 | |
|
722 | 727 | if timerange != None: |
|
723 | 728 | self.timerange = timerange |
|
724 | 729 | |
|
725 | 730 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
726 | 731 | |
|
727 | 732 | if ymin == None: ymin = numpy.nanmin(y) |
|
728 | 733 | if ymax == None: ymax = numpy.nanmax(y) |
|
729 | 734 | if zmin == None: zmin = 0. |
|
730 | 735 | if zmax == None: zmax = 1. |
|
731 | 736 | |
|
732 | 737 | self.FTP_WEI = ftp_wei |
|
733 | 738 | self.EXP_CODE = exp_code |
|
734 | 739 | self.SUB_EXP_CODE = sub_exp_code |
|
735 | 740 | self.PLOT_POS = plot_pos |
|
736 | 741 | |
|
737 | 742 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
738 | 743 | |
|
739 | 744 | self.isConfig = True |
|
740 | 745 | update_figfile = True |
|
741 | 746 | |
|
742 | 747 | self.setWinTitle(title) |
|
743 | 748 | |
|
744 | 749 | for i in range(self.nplots): |
|
745 | 750 | |
|
746 | 751 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
747 | 752 | |
|
748 | 753 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
749 | 754 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
750 | 755 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
751 | 756 | |
|
752 | 757 | |
|
753 | 758 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
754 | 759 | coherence = numpy.abs(avgcoherenceComplex) |
|
755 | 760 | |
|
756 | 761 | z = coherence.reshape((1,-1)) |
|
757 | 762 | |
|
758 | 763 | counter = 0 |
|
759 | 764 | |
|
760 | 765 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
761 | 766 | axes = self.axesList[i*self.__nsubplots*2] |
|
762 | 767 | axes.pcolorbuffer(x, y, z, |
|
763 | 768 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
764 | 769 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
765 | 770 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
766 | 771 | |
|
767 | 772 | if self.__showprofile: |
|
768 | 773 | counter += 1 |
|
769 | 774 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
770 | 775 | axes.pline(coherence, y, |
|
771 | 776 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
772 | 777 | xlabel='', ylabel='', title='', ticksize=7, |
|
773 | 778 | ytick_visible=False, nxticks=5, |
|
774 | 779 | grid='x') |
|
775 | 780 | |
|
776 | 781 | counter += 1 |
|
777 | 782 | |
|
778 | 783 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
779 | 784 | |
|
780 | 785 | z = phase.reshape((1,-1)) |
|
781 | 786 | |
|
782 | 787 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
783 | 788 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
784 | 789 | axes.pcolorbuffer(x, y, z, |
|
785 | 790 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
786 | 791 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
787 | 792 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
788 | 793 | |
|
789 | 794 | if self.__showprofile: |
|
790 | 795 | counter += 1 |
|
791 | 796 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
792 | 797 | axes.pline(phase, y, |
|
793 | 798 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, |
|
794 | 799 | xlabel='', ylabel='', title='', ticksize=7, |
|
795 | 800 | ytick_visible=False, nxticks=4, |
|
796 | 801 | grid='x') |
|
797 | 802 | |
|
798 | 803 | self.draw() |
|
799 | 804 | |
|
800 | 805 | if dataOut.ltctime >= self.xmax: |
|
801 | 806 | self.counter_imagwr = wr_period |
|
802 | 807 | self.isConfig = False |
|
803 | 808 | update_figfile = True |
|
804 | 809 | |
|
805 | 810 | self.save(figpath=figpath, |
|
806 | 811 | figfile=figfile, |
|
807 | 812 | save=save, |
|
808 | 813 | ftp=ftp, |
|
809 | 814 | wr_period=wr_period, |
|
810 | 815 | thisDatetime=thisDatetime, |
|
811 | 816 | update_figfile=update_figfile) |
|
812 | 817 | |
|
813 | 818 | class PowerProfilePlot(Figure): |
|
814 | 819 | |
|
815 | 820 | isConfig = None |
|
816 | 821 | __nsubplots = None |
|
817 | 822 | |
|
818 | 823 | WIDTHPROF = None |
|
819 | 824 | HEIGHTPROF = None |
|
820 | 825 | PREFIX = 'spcprofile' |
|
821 | 826 | |
|
822 | 827 | def __init__(self): |
|
823 | 828 | self.isConfig = False |
|
824 | 829 | self.__nsubplots = 1 |
|
825 | 830 | |
|
826 | 831 | self.PLOT_CODE = POWER_CODE |
|
827 | 832 | |
|
828 | 833 | self.WIDTH = 300 |
|
829 | 834 | self.HEIGHT = 500 |
|
830 | 835 | self.counter_imagwr = 0 |
|
831 | 836 | |
|
832 | 837 | def getSubplots(self): |
|
833 | 838 | ncol = 1 |
|
834 | 839 | nrow = 1 |
|
835 | 840 | |
|
836 | 841 | return nrow, ncol |
|
837 | 842 | |
|
838 | 843 | def setup(self, id, nplots, wintitle, show): |
|
839 | 844 | |
|
840 | 845 | self.nplots = nplots |
|
841 | 846 | |
|
842 | 847 | ncolspan = 1 |
|
843 | 848 | colspan = 1 |
|
844 | 849 | |
|
845 | 850 | self.createFigure(id = id, |
|
846 | 851 | wintitle = wintitle, |
|
847 | 852 | widthplot = self.WIDTH, |
|
848 | 853 | heightplot = self.HEIGHT, |
|
849 | 854 | show=show) |
|
850 | 855 | |
|
851 | 856 | nrow, ncol = self.getSubplots() |
|
852 | 857 | |
|
853 | 858 | counter = 0 |
|
854 | 859 | for y in range(nrow): |
|
855 | 860 | for x in range(ncol): |
|
856 | 861 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
857 | 862 | |
|
858 | 863 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
859 | 864 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
860 | 865 | save=False, figpath='./', figfile=None, show=True, |
|
861 | 866 | ftp=False, wr_period=1, server=None, |
|
862 | 867 | folder=None, username=None, password=None): |
|
863 | 868 | |
|
864 | 869 | |
|
865 | 870 | if channelList == None: |
|
866 | 871 | channelIndexList = dataOut.channelIndexList |
|
867 | 872 | channelList = dataOut.channelList |
|
868 | 873 | else: |
|
869 | 874 | channelIndexList = [] |
|
870 | 875 | for channel in channelList: |
|
871 | 876 | if channel not in dataOut.channelList: |
|
872 | 877 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
873 | 878 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
874 | 879 | |
|
875 | 880 | factor = dataOut.normFactor |
|
876 | 881 | |
|
877 | 882 | y = dataOut.getHeiRange() |
|
878 | 883 | |
|
879 | 884 | #for voltage |
|
880 | 885 | if dataOut.type == 'Voltage': |
|
881 | 886 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
882 | 887 | x = x.real |
|
883 | 888 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
884 | 889 | |
|
885 | 890 | #for spectra |
|
886 | 891 | if dataOut.type == 'Spectra': |
|
887 | 892 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
888 | 893 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
889 | 894 | x = numpy.average(x, axis=1) |
|
890 | 895 | |
|
891 | 896 | |
|
892 | 897 | xdB = 10*numpy.log10(x) |
|
893 | 898 | |
|
894 | 899 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
895 | 900 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
896 | 901 | xlabel = "dB" |
|
897 | 902 | ylabel = "Range (Km)" |
|
898 | 903 | |
|
899 | 904 | if not self.isConfig: |
|
900 | 905 | |
|
901 | 906 | nplots = 1 |
|
902 | 907 | |
|
903 | 908 | self.setup(id=id, |
|
904 | 909 | nplots=nplots, |
|
905 | 910 | wintitle=wintitle, |
|
906 | 911 | show=show) |
|
907 | 912 | |
|
908 | 913 | if ymin == None: ymin = numpy.nanmin(y) |
|
909 | 914 | if ymax == None: ymax = numpy.nanmax(y) |
|
910 | 915 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
911 | 916 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
912 | 917 | |
|
913 | 918 | self.isConfig = True |
|
914 | 919 | |
|
915 | 920 | self.setWinTitle(title) |
|
916 | 921 | |
|
917 | 922 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
918 | 923 | axes = self.axesList[0] |
|
919 | 924 | |
|
920 | 925 | legendlabels = ["channel %d"%x for x in channelList] |
|
921 | 926 | axes.pmultiline(xdB, y, |
|
922 | 927 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
923 | 928 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
924 | 929 | ytick_visible=True, nxticks=5, |
|
925 | 930 | grid='x') |
|
926 | 931 | |
|
927 | 932 | self.draw() |
|
928 | 933 | |
|
929 | 934 | self.save(figpath=figpath, |
|
930 | 935 | figfile=figfile, |
|
931 | 936 | save=save, |
|
932 | 937 | ftp=ftp, |
|
933 | 938 | wr_period=wr_period, |
|
934 | 939 | thisDatetime=thisDatetime) |
|
935 | 940 | |
|
941 | class SpectraCutPlot(Figure): | |
|
942 | ||
|
943 | isConfig = None | |
|
944 | __nsubplots = None | |
|
945 | ||
|
946 | WIDTHPROF = None | |
|
947 | HEIGHTPROF = None | |
|
948 | PREFIX = 'spc_cut' | |
|
949 | ||
|
950 | def __init__(self): | |
|
951 | self.isConfig = False | |
|
952 | self.__nsubplots = 1 | |
|
953 | ||
|
954 | self.PLOT_CODE = POWER_CODE | |
|
955 | ||
|
956 | self.WIDTH = 700 | |
|
957 | self.HEIGHT = 500 | |
|
958 | self.counter_imagwr = 0 | |
|
959 | ||
|
960 | def getSubplots(self): | |
|
961 | ncol = 1 | |
|
962 | nrow = 1 | |
|
963 | ||
|
964 | return nrow, ncol | |
|
965 | ||
|
966 | def setup(self, id, nplots, wintitle, show): | |
|
967 | ||
|
968 | self.nplots = nplots | |
|
969 | ||
|
970 | ncolspan = 1 | |
|
971 | colspan = 1 | |
|
972 | ||
|
973 | self.createFigure(id = id, | |
|
974 | wintitle = wintitle, | |
|
975 | widthplot = self.WIDTH, | |
|
976 | heightplot = self.HEIGHT, | |
|
977 | show=show) | |
|
978 | ||
|
979 | nrow, ncol = self.getSubplots() | |
|
980 | ||
|
981 | counter = 0 | |
|
982 | for y in range(nrow): | |
|
983 | for x in range(ncol): | |
|
984 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
|
985 | ||
|
986 | def run(self, dataOut, id, wintitle="", channelList=None, | |
|
987 | xmin=None, xmax=None, ymin=None, ymax=None, | |
|
988 | save=False, figpath='./', figfile=None, show=True, | |
|
989 | ftp=False, wr_period=1, server=None, | |
|
990 | folder=None, username=None, password=None): | |
|
991 | ||
|
992 | ||
|
993 | if channelList == None: | |
|
994 | channelIndexList = dataOut.channelIndexList | |
|
995 | channelList = dataOut.channelList | |
|
996 | else: | |
|
997 | channelIndexList = [] | |
|
998 | for channel in channelList: | |
|
999 | if channel not in dataOut.channelList: | |
|
1000 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
|
1001 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
1002 | ||
|
1003 | factor = dataOut.normFactor | |
|
1004 | ||
|
1005 | x = dataOut.getFreqRangeTimeResponse()/1000 | |
|
1006 | y = dataOut.getHeiRange() | |
|
1007 | ||
|
1008 | z = dataOut.data_spc/factor | |
|
1009 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
|
1010 | ||
|
1011 | hei_index = numpy.arange(30)*4 + 60 | |
|
1012 | ||
|
1013 | zdB = 10*numpy.log10(z[0,:,hei_index]) | |
|
1014 | # zdB = numpy.swapaxes(zdB, 0, 1) | |
|
1015 | ||
|
1016 | ||
|
1017 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
1018 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
1019 | xlabel = "Frequency (KHz)" | |
|
1020 | ylabel = "Power (dB)" | |
|
1021 | ||
|
1022 | if not self.isConfig: | |
|
1023 | ||
|
1024 | nplots = 1 | |
|
1025 | ||
|
1026 | self.setup(id=id, | |
|
1027 | nplots=nplots, | |
|
1028 | wintitle=wintitle, | |
|
1029 | show=show) | |
|
1030 | ||
|
1031 | if xmin == None: xmin = numpy.nanmin(x)*0.9 | |
|
1032 | if xmax == None: xmax = numpy.nanmax(x)*1.1 | |
|
1033 | if ymin == None: ymin = numpy.nanmin(zdB) | |
|
1034 | if ymax == None: ymax = numpy.nanmax(zdB) | |
|
1035 | ||
|
1036 | self.isConfig = True | |
|
1037 | ||
|
1038 | self.setWinTitle(title) | |
|
1039 | ||
|
1040 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
1041 | axes = self.axesList[0] | |
|
1042 | ||
|
1043 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] | |
|
1044 | ||
|
1045 | axes.pmultilineyaxis( x, zdB, | |
|
1046 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
1047 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
|
1048 | ytick_visible=True, nxticks=5, | |
|
1049 | grid='x') | |
|
1050 | ||
|
1051 | self.draw() | |
|
1052 | ||
|
1053 | self.save(figpath=figpath, | |
|
1054 | figfile=figfile, | |
|
1055 | save=save, | |
|
1056 | ftp=ftp, | |
|
1057 | wr_period=wr_period, | |
|
1058 | thisDatetime=thisDatetime) | |
|
1059 | ||
|
936 | 1060 | class Noise(Figure): |
|
937 | 1061 | |
|
938 | 1062 | isConfig = None |
|
939 | 1063 | __nsubplots = None |
|
940 | 1064 | |
|
941 | 1065 | PREFIX = 'noise' |
|
942 | 1066 | |
|
943 | 1067 | def __init__(self): |
|
944 | 1068 | |
|
945 | 1069 | self.timerange = 24*60*60 |
|
946 | 1070 | self.isConfig = False |
|
947 | 1071 | self.__nsubplots = 1 |
|
948 | 1072 | self.counter_imagwr = 0 |
|
949 | 1073 | self.WIDTH = 800 |
|
950 | 1074 | self.HEIGHT = 400 |
|
951 | 1075 | self.WIDTHPROF = 120 |
|
952 | 1076 | self.HEIGHTPROF = 0 |
|
953 | 1077 | self.xdata = None |
|
954 | 1078 | self.ydata = None |
|
955 | 1079 | |
|
956 | 1080 | self.PLOT_CODE = NOISE_CODE |
|
957 | 1081 | |
|
958 | 1082 | self.FTP_WEI = None |
|
959 | 1083 | self.EXP_CODE = None |
|
960 | 1084 | self.SUB_EXP_CODE = None |
|
961 | 1085 | self.PLOT_POS = None |
|
962 | 1086 | self.figfile = None |
|
963 | 1087 | |
|
964 | 1088 | self.xmin = None |
|
965 | 1089 | self.xmax = None |
|
966 | 1090 | |
|
967 | 1091 | def getSubplots(self): |
|
968 | 1092 | |
|
969 | 1093 | ncol = 1 |
|
970 | 1094 | nrow = 1 |
|
971 | 1095 | |
|
972 | 1096 | return nrow, ncol |
|
973 | 1097 | |
|
974 | 1098 | def openfile(self, filename): |
|
975 | 1099 | dirname = os.path.dirname(filename) |
|
976 | 1100 | |
|
977 | 1101 | if not os.path.exists(dirname): |
|
978 | 1102 | os.mkdir(dirname) |
|
979 | 1103 | |
|
980 | 1104 | f = open(filename,'w+') |
|
981 | 1105 | f.write('\n\n') |
|
982 | 1106 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
983 | 1107 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
984 | 1108 | f.close() |
|
985 | 1109 | |
|
986 | 1110 | def save_data(self, filename_phase, data, data_datetime): |
|
987 | 1111 | |
|
988 | 1112 | f=open(filename_phase,'a') |
|
989 | 1113 | |
|
990 | 1114 | timetuple_data = data_datetime.timetuple() |
|
991 | 1115 | day = str(timetuple_data.tm_mday) |
|
992 | 1116 | month = str(timetuple_data.tm_mon) |
|
993 | 1117 | year = str(timetuple_data.tm_year) |
|
994 | 1118 | hour = str(timetuple_data.tm_hour) |
|
995 | 1119 | minute = str(timetuple_data.tm_min) |
|
996 | 1120 | second = str(timetuple_data.tm_sec) |
|
997 | 1121 | |
|
998 | 1122 | data_msg = '' |
|
999 | 1123 | for i in range(len(data)): |
|
1000 | 1124 | data_msg += str(data[i]) + ' ' |
|
1001 | 1125 | |
|
1002 | 1126 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
1003 | 1127 | f.close() |
|
1004 | 1128 | |
|
1005 | 1129 | |
|
1006 | 1130 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1007 | 1131 | |
|
1008 | 1132 | self.__showprofile = showprofile |
|
1009 | 1133 | self.nplots = nplots |
|
1010 | 1134 | |
|
1011 | 1135 | ncolspan = 7 |
|
1012 | 1136 | colspan = 6 |
|
1013 | 1137 | self.__nsubplots = 2 |
|
1014 | 1138 | |
|
1015 | 1139 | self.createFigure(id = id, |
|
1016 | 1140 | wintitle = wintitle, |
|
1017 | 1141 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1018 | 1142 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1019 | 1143 | show=show) |
|
1020 | 1144 | |
|
1021 | 1145 | nrow, ncol = self.getSubplots() |
|
1022 | 1146 | |
|
1023 | 1147 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1024 | 1148 | |
|
1025 | 1149 | |
|
1026 | 1150 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1027 | 1151 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1028 | 1152 | timerange=None, |
|
1029 | 1153 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1030 | 1154 | server=None, folder=None, username=None, password=None, |
|
1031 | 1155 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1032 | 1156 | |
|
1033 | 1157 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1034 | 1158 | return |
|
1035 | 1159 | |
|
1036 | 1160 | if channelList == None: |
|
1037 | 1161 | channelIndexList = dataOut.channelIndexList |
|
1038 | 1162 | channelList = dataOut.channelList |
|
1039 | 1163 | else: |
|
1040 | 1164 | channelIndexList = [] |
|
1041 | 1165 | for channel in channelList: |
|
1042 | 1166 | if channel not in dataOut.channelList: |
|
1043 | 1167 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1044 | 1168 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1045 | 1169 | |
|
1046 | 1170 | x = dataOut.getTimeRange() |
|
1047 | 1171 | #y = dataOut.getHeiRange() |
|
1048 | 1172 | factor = dataOut.normFactor |
|
1049 | 1173 | noise = dataOut.noise[channelIndexList]/factor |
|
1050 | 1174 | noisedB = 10*numpy.log10(noise) |
|
1051 | 1175 | |
|
1052 | 1176 | thisDatetime = dataOut.datatime |
|
1053 | 1177 | |
|
1054 | 1178 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1055 | 1179 | xlabel = "" |
|
1056 | 1180 | ylabel = "Intensity (dB)" |
|
1057 | 1181 | update_figfile = False |
|
1058 | 1182 | |
|
1059 | 1183 | if not self.isConfig: |
|
1060 | 1184 | |
|
1061 | 1185 | nplots = 1 |
|
1062 | 1186 | |
|
1063 | 1187 | self.setup(id=id, |
|
1064 | 1188 | nplots=nplots, |
|
1065 | 1189 | wintitle=wintitle, |
|
1066 | 1190 | showprofile=showprofile, |
|
1067 | 1191 | show=show) |
|
1068 | 1192 | |
|
1069 | 1193 | if timerange != None: |
|
1070 | 1194 | self.timerange = timerange |
|
1071 | 1195 | |
|
1072 | 1196 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1073 | 1197 | |
|
1074 | 1198 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1075 | 1199 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1076 | 1200 | |
|
1077 | 1201 | self.FTP_WEI = ftp_wei |
|
1078 | 1202 | self.EXP_CODE = exp_code |
|
1079 | 1203 | self.SUB_EXP_CODE = sub_exp_code |
|
1080 | 1204 | self.PLOT_POS = plot_pos |
|
1081 | 1205 | |
|
1082 | 1206 | |
|
1083 | 1207 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1084 | 1208 | self.isConfig = True |
|
1085 | 1209 | self.figfile = figfile |
|
1086 | 1210 | self.xdata = numpy.array([]) |
|
1087 | 1211 | self.ydata = numpy.array([]) |
|
1088 | 1212 | |
|
1089 | 1213 | update_figfile = True |
|
1090 | 1214 | |
|
1091 | 1215 | #open file beacon phase |
|
1092 | 1216 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1093 | 1217 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1094 | 1218 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1095 | 1219 | |
|
1096 | 1220 | self.setWinTitle(title) |
|
1097 | 1221 | |
|
1098 | 1222 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1099 | 1223 | |
|
1100 | 1224 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] |
|
1101 | 1225 | axes = self.axesList[0] |
|
1102 | 1226 | |
|
1103 | 1227 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1104 | 1228 | |
|
1105 | 1229 | if len(self.ydata)==0: |
|
1106 | 1230 | self.ydata = noisedB.reshape(-1,1) |
|
1107 | 1231 | else: |
|
1108 | 1232 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) |
|
1109 | 1233 | |
|
1110 | 1234 | |
|
1111 | 1235 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1112 | 1236 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1113 | 1237 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1114 | 1238 | XAxisAsTime=True, grid='both' |
|
1115 | 1239 | ) |
|
1116 | 1240 | |
|
1117 | 1241 | self.draw() |
|
1118 | 1242 | |
|
1119 | 1243 | if dataOut.ltctime >= self.xmax: |
|
1120 | 1244 | self.counter_imagwr = wr_period |
|
1121 | 1245 | self.isConfig = False |
|
1122 | 1246 | update_figfile = True |
|
1123 | 1247 | |
|
1124 | 1248 | self.save(figpath=figpath, |
|
1125 | 1249 | figfile=figfile, |
|
1126 | 1250 | save=save, |
|
1127 | 1251 | ftp=ftp, |
|
1128 | 1252 | wr_period=wr_period, |
|
1129 | 1253 | thisDatetime=thisDatetime, |
|
1130 | 1254 | update_figfile=update_figfile) |
|
1131 | 1255 | |
|
1132 | 1256 | #store data beacon phase |
|
1133 | 1257 | if save: |
|
1134 | 1258 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1135 | 1259 | |
|
1136 | 1260 | class BeaconPhase(Figure): |
|
1137 | 1261 | |
|
1138 | 1262 | __isConfig = None |
|
1139 | 1263 | __nsubplots = None |
|
1140 | 1264 | |
|
1141 | 1265 | PREFIX = 'beacon_phase' |
|
1142 | 1266 | |
|
1143 | 1267 | def __init__(self): |
|
1144 | 1268 | |
|
1145 | 1269 | self.timerange = 24*60*60 |
|
1146 | 1270 | self.isConfig = False |
|
1147 | 1271 | self.__nsubplots = 1 |
|
1148 | 1272 | self.counter_imagwr = 0 |
|
1149 | 1273 | self.WIDTH = 800 |
|
1150 | 1274 | self.HEIGHT = 400 |
|
1151 | 1275 | self.WIDTHPROF = 120 |
|
1152 | 1276 | self.HEIGHTPROF = 0 |
|
1153 | 1277 | self.xdata = None |
|
1154 | 1278 | self.ydata = None |
|
1155 | 1279 | |
|
1156 | 1280 | self.PLOT_CODE = BEACON_CODE |
|
1157 | 1281 | |
|
1158 | 1282 | self.FTP_WEI = None |
|
1159 | 1283 | self.EXP_CODE = None |
|
1160 | 1284 | self.SUB_EXP_CODE = None |
|
1161 | 1285 | self.PLOT_POS = None |
|
1162 | 1286 | |
|
1163 | 1287 | self.filename_phase = None |
|
1164 | 1288 | |
|
1165 | 1289 | self.figfile = None |
|
1166 | 1290 | |
|
1167 | 1291 | self.xmin = None |
|
1168 | 1292 | self.xmax = None |
|
1169 | 1293 | |
|
1170 | 1294 | def getSubplots(self): |
|
1171 | 1295 | |
|
1172 | 1296 | ncol = 1 |
|
1173 | 1297 | nrow = 1 |
|
1174 | 1298 | |
|
1175 | 1299 | return nrow, ncol |
|
1176 | 1300 | |
|
1177 | 1301 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1178 | 1302 | |
|
1179 | 1303 | self.__showprofile = showprofile |
|
1180 | 1304 | self.nplots = nplots |
|
1181 | 1305 | |
|
1182 | 1306 | ncolspan = 7 |
|
1183 | 1307 | colspan = 6 |
|
1184 | 1308 | self.__nsubplots = 2 |
|
1185 | 1309 | |
|
1186 | 1310 | self.createFigure(id = id, |
|
1187 | 1311 | wintitle = wintitle, |
|
1188 | 1312 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1189 | 1313 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1190 | 1314 | show=show) |
|
1191 | 1315 | |
|
1192 | 1316 | nrow, ncol = self.getSubplots() |
|
1193 | 1317 | |
|
1194 | 1318 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1195 | 1319 | |
|
1196 | 1320 | def save_phase(self, filename_phase): |
|
1197 | 1321 | f = open(filename_phase,'w+') |
|
1198 | 1322 | f.write('\n\n') |
|
1199 | 1323 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1200 | 1324 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1201 | 1325 | f.close() |
|
1202 | 1326 | |
|
1203 | 1327 | def save_data(self, filename_phase, data, data_datetime): |
|
1204 | 1328 | f=open(filename_phase,'a') |
|
1205 | 1329 | timetuple_data = data_datetime.timetuple() |
|
1206 | 1330 | day = str(timetuple_data.tm_mday) |
|
1207 | 1331 | month = str(timetuple_data.tm_mon) |
|
1208 | 1332 | year = str(timetuple_data.tm_year) |
|
1209 | 1333 | hour = str(timetuple_data.tm_hour) |
|
1210 | 1334 | minute = str(timetuple_data.tm_min) |
|
1211 | 1335 | second = str(timetuple_data.tm_sec) |
|
1212 | 1336 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1213 | 1337 | f.close() |
|
1214 | 1338 | |
|
1215 | 1339 | |
|
1216 | 1340 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1217 | 1341 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, |
|
1218 | 1342 | timerange=None, |
|
1219 | 1343 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1220 | 1344 | server=None, folder=None, username=None, password=None, |
|
1221 | 1345 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1222 | 1346 | |
|
1223 | 1347 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1224 | 1348 | return |
|
1225 | 1349 | |
|
1226 | 1350 | if pairsList == None: |
|
1227 | 1351 | pairsIndexList = dataOut.pairsIndexList[:10] |
|
1228 | 1352 | else: |
|
1229 | 1353 | pairsIndexList = [] |
|
1230 | 1354 | for pair in pairsList: |
|
1231 | 1355 | if pair not in dataOut.pairsList: |
|
1232 | 1356 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1233 | 1357 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1234 | 1358 | |
|
1235 | 1359 | if pairsIndexList == []: |
|
1236 | 1360 | return |
|
1237 | 1361 | |
|
1238 | 1362 | # if len(pairsIndexList) > 4: |
|
1239 | 1363 | # pairsIndexList = pairsIndexList[0:4] |
|
1240 | 1364 | |
|
1241 | 1365 | hmin_index = None |
|
1242 | 1366 | hmax_index = None |
|
1243 | 1367 | |
|
1244 | 1368 | if hmin != None and hmax != None: |
|
1245 | 1369 | indexes = numpy.arange(dataOut.nHeights) |
|
1246 | 1370 | hmin_list = indexes[dataOut.heightList >= hmin] |
|
1247 | 1371 | hmax_list = indexes[dataOut.heightList <= hmax] |
|
1248 | 1372 | |
|
1249 | 1373 | if hmin_list.any(): |
|
1250 | 1374 | hmin_index = hmin_list[0] |
|
1251 | 1375 | |
|
1252 | 1376 | if hmax_list.any(): |
|
1253 | 1377 | hmax_index = hmax_list[-1]+1 |
|
1254 | 1378 | |
|
1255 | 1379 | x = dataOut.getTimeRange() |
|
1256 | 1380 | #y = dataOut.getHeiRange() |
|
1257 | 1381 | |
|
1258 | 1382 | |
|
1259 | 1383 | thisDatetime = dataOut.datatime |
|
1260 | 1384 | |
|
1261 | 1385 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1262 | 1386 | xlabel = "Local Time" |
|
1263 | 1387 | ylabel = "Phase (degrees)" |
|
1264 | 1388 | |
|
1265 | 1389 | update_figfile = False |
|
1266 | 1390 | |
|
1267 | 1391 | nplots = len(pairsIndexList) |
|
1268 | 1392 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1269 | 1393 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1270 | 1394 | for i in range(nplots): |
|
1271 | 1395 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1272 | 1396 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) |
|
1273 | 1397 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) |
|
1274 | 1398 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) |
|
1275 | 1399 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1276 | 1400 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1277 | 1401 | |
|
1278 | 1402 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1279 | 1403 | #print phase[dataOut.beacon_heiIndexList] |
|
1280 | 1404 | |
|
1281 | 1405 | if dataOut.beacon_heiIndexList: |
|
1282 | 1406 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1283 | 1407 | else: |
|
1284 | 1408 | phase_beacon[i] = numpy.average(phase) |
|
1285 | 1409 | |
|
1286 | 1410 | if not self.isConfig: |
|
1287 | 1411 | |
|
1288 | 1412 | nplots = len(pairsIndexList) |
|
1289 | 1413 | |
|
1290 | 1414 | self.setup(id=id, |
|
1291 | 1415 | nplots=nplots, |
|
1292 | 1416 | wintitle=wintitle, |
|
1293 | 1417 | showprofile=showprofile, |
|
1294 | 1418 | show=show) |
|
1295 | 1419 | |
|
1296 | 1420 | if timerange != None: |
|
1297 | 1421 | self.timerange = timerange |
|
1298 | 1422 | |
|
1299 | 1423 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1300 | 1424 | |
|
1301 | 1425 | if ymin == None: ymin = 0 |
|
1302 | 1426 | if ymax == None: ymax = 360 |
|
1303 | 1427 | |
|
1304 | 1428 | self.FTP_WEI = ftp_wei |
|
1305 | 1429 | self.EXP_CODE = exp_code |
|
1306 | 1430 | self.SUB_EXP_CODE = sub_exp_code |
|
1307 | 1431 | self.PLOT_POS = plot_pos |
|
1308 | 1432 | |
|
1309 | 1433 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1310 | 1434 | self.isConfig = True |
|
1311 | 1435 | self.figfile = figfile |
|
1312 | 1436 | self.xdata = numpy.array([]) |
|
1313 | 1437 | self.ydata = numpy.array([]) |
|
1314 | 1438 | |
|
1315 | 1439 | update_figfile = True |
|
1316 | 1440 | |
|
1317 | 1441 | #open file beacon phase |
|
1318 | 1442 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1319 | 1443 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1320 | 1444 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1321 | 1445 | #self.save_phase(self.filename_phase) |
|
1322 | 1446 | |
|
1323 | 1447 | |
|
1324 | 1448 | #store data beacon phase |
|
1325 | 1449 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1326 | 1450 | |
|
1327 | 1451 | self.setWinTitle(title) |
|
1328 | 1452 | |
|
1329 | 1453 | |
|
1330 | 1454 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1331 | 1455 | |
|
1332 | 1456 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1333 | 1457 | |
|
1334 | 1458 | axes = self.axesList[0] |
|
1335 | 1459 | |
|
1336 | 1460 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1337 | 1461 | |
|
1338 | 1462 | if len(self.ydata)==0: |
|
1339 | 1463 | self.ydata = phase_beacon.reshape(-1,1) |
|
1340 | 1464 | else: |
|
1341 | 1465 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1342 | 1466 | |
|
1343 | 1467 | |
|
1344 | 1468 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1345 | 1469 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1346 | 1470 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1347 | 1471 | XAxisAsTime=True, grid='both' |
|
1348 | 1472 | ) |
|
1349 | 1473 | |
|
1350 | 1474 | self.draw() |
|
1351 | 1475 | |
|
1352 | 1476 | if dataOut.ltctime >= self.xmax: |
|
1353 | 1477 | self.counter_imagwr = wr_period |
|
1354 | 1478 | self.isConfig = False |
|
1355 | 1479 | update_figfile = True |
|
1356 | 1480 | |
|
1357 | 1481 | self.save(figpath=figpath, |
|
1358 | 1482 | figfile=figfile, |
|
1359 | 1483 | save=save, |
|
1360 | 1484 | ftp=ftp, |
|
1361 | 1485 | wr_period=wr_period, |
|
1362 | 1486 | thisDatetime=thisDatetime, |
|
1363 | 1487 | update_figfile=update_figfile) |
General Comments 0
You need to be logged in to leave comments.
Login now