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