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