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