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