@@ -1,1530 +1,1509 | |||||
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 | print ValueError, 'Error FTP' |
|
214 | print 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 | print ValueError, 'Error FTP' |
|
406 | print 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 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
599 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
600 | self.counter_imagwr = 0 |
|
600 | self.counter_imagwr = 0 | |
601 |
|
601 | |||
602 |
|
602 | |||
603 | self.counter_imagwr = 0 |
|
603 | self.counter_imagwr = 0 | |
604 |
|
604 | |||
605 |
|
605 | |||
606 | class Scope(Figure): |
|
606 | class Scope(Figure): | |
607 |
|
607 | |||
608 | __isConfig = None |
|
608 | __isConfig = None | |
609 |
|
609 | |||
610 | def __init__(self): |
|
610 | def __init__(self): | |
611 |
|
611 | |||
612 | self.__isConfig = False |
|
612 | self.__isConfig = False | |
613 | self.WIDTH = 600 |
|
613 | self.WIDTH = 600 | |
614 | self.HEIGHT = 200 |
|
614 | self.HEIGHT = 200 | |
615 |
|
615 | |||
616 | def getSubplots(self): |
|
616 | def getSubplots(self): | |
617 |
|
617 | |||
618 | nrow = self.nplots |
|
618 | nrow = self.nplots | |
619 | ncol = 3 |
|
619 | ncol = 3 | |
620 | return nrow, ncol |
|
620 | return nrow, ncol | |
621 |
|
621 | |||
622 | def setup(self, id, nplots, wintitle, show): |
|
622 | def setup(self, id, nplots, wintitle, show): | |
623 |
|
623 | |||
624 | self.nplots = nplots |
|
624 | self.nplots = nplots | |
625 |
|
625 | |||
626 | self.createFigure(id=id, |
|
626 | self.createFigure(id=id, | |
627 | wintitle=wintitle, |
|
627 | wintitle=wintitle, | |
628 | show=show) |
|
628 | show=show) | |
629 |
|
629 | |||
630 | nrow,ncol = self.getSubplots() |
|
630 | nrow,ncol = self.getSubplots() | |
631 | colspan = 3 |
|
631 | colspan = 3 | |
632 | rowspan = 1 |
|
632 | rowspan = 1 | |
633 |
|
633 | |||
634 | for i in range(nplots): |
|
634 | for i in range(nplots): | |
635 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
635 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
636 |
|
636 | |||
637 |
|
637 | |||
638 |
|
638 | |||
639 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
639 | def run(self, dataOut, id, wintitle="", channelList=None, | |
640 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
640 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
641 | figpath='./', figfile=None, show=True): |
|
641 | figpath='./', figfile=None, show=True): | |
642 |
|
642 | |||
643 | """ |
|
643 | """ | |
644 |
|
644 | |||
645 | Input: |
|
645 | Input: | |
646 | dataOut : |
|
646 | dataOut : | |
647 | id : |
|
647 | id : | |
648 | wintitle : |
|
648 | wintitle : | |
649 | channelList : |
|
649 | channelList : | |
650 | xmin : None, |
|
650 | xmin : None, | |
651 | xmax : None, |
|
651 | xmax : None, | |
652 | ymin : None, |
|
652 | ymin : None, | |
653 | ymax : None, |
|
653 | ymax : None, | |
654 | """ |
|
654 | """ | |
655 |
|
655 | |||
656 | if channelList == None: |
|
656 | if channelList == None: | |
657 | channelIndexList = dataOut.channelIndexList |
|
657 | channelIndexList = dataOut.channelIndexList | |
658 | else: |
|
658 | else: | |
659 | channelIndexList = [] |
|
659 | channelIndexList = [] | |
660 | for channel in channelList: |
|
660 | for channel in channelList: | |
661 | if channel not in dataOut.channelList: |
|
661 | if channel not in dataOut.channelList: | |
662 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
662 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
663 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
663 | channelIndexList.append(dataOut.channelList.index(channel)) | |
664 |
|
664 | |||
665 | x = dataOut.heightList |
|
665 | x = dataOut.heightList | |
666 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
666 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
667 | y = y.real |
|
667 | y = y.real | |
668 |
|
668 | |||
669 | #thisDatetime = dataOut.datatime |
|
669 | #thisDatetime = dataOut.datatime | |
670 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
670 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
671 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
671 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
672 | xlabel = "Range (Km)" |
|
672 | xlabel = "Range (Km)" | |
673 | ylabel = "Intensity" |
|
673 | ylabel = "Intensity" | |
674 |
|
674 | |||
675 | if not self.__isConfig: |
|
675 | if not self.__isConfig: | |
676 | nplots = len(channelIndexList) |
|
676 | nplots = len(channelIndexList) | |
677 |
|
677 | |||
678 | self.setup(id=id, |
|
678 | self.setup(id=id, | |
679 | nplots=nplots, |
|
679 | nplots=nplots, | |
680 | wintitle=wintitle, |
|
680 | wintitle=wintitle, | |
681 | show=show) |
|
681 | show=show) | |
682 |
|
682 | |||
683 | if xmin == None: xmin = numpy.nanmin(x) |
|
683 | if xmin == None: xmin = numpy.nanmin(x) | |
684 | if xmax == None: xmax = numpy.nanmax(x) |
|
684 | if xmax == None: xmax = numpy.nanmax(x) | |
685 | if ymin == None: ymin = numpy.nanmin(y) |
|
685 | if ymin == None: ymin = numpy.nanmin(y) | |
686 | if ymax == None: ymax = numpy.nanmax(y) |
|
686 | if ymax == None: ymax = numpy.nanmax(y) | |
687 |
|
687 | |||
688 | self.__isConfig = True |
|
688 | self.__isConfig = True | |
689 |
|
689 | |||
690 | self.setWinTitle(title) |
|
690 | self.setWinTitle(title) | |
691 |
|
691 | |||
692 | for i in range(len(self.axesList)): |
|
692 | for i in range(len(self.axesList)): | |
693 | title = "Channel %d" %(i) |
|
693 | title = "Channel %d" %(i) | |
694 | axes = self.axesList[i] |
|
694 | axes = self.axesList[i] | |
695 | ychannel = y[i,:] |
|
695 | ychannel = y[i,:] | |
696 | axes.pline(x, ychannel, |
|
696 | axes.pline(x, ychannel, | |
697 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
697 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
698 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
698 | xlabel=xlabel, ylabel=ylabel, title=title) | |
699 |
|
699 | |||
700 | self.draw() |
|
700 | self.draw() | |
701 |
|
701 | |||
702 | if save: |
|
702 | if save: | |
703 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
703 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
704 | if figfile == None: |
|
704 | if figfile == None: | |
705 | figfile = self.getFilename(name = date) |
|
705 | figfile = self.getFilename(name = date) | |
706 |
|
706 | |||
707 | self.saveFigure(figpath, figfile) |
|
707 | self.saveFigure(figpath, figfile) | |
708 |
|
708 | |||
709 | class PowerProfilePlot(Figure): |
|
709 | class PowerProfilePlot(Figure): | |
710 | __isConfig = None |
|
710 | __isConfig = None | |
711 | __nsubplots = None |
|
711 | __nsubplots = None | |
712 |
|
712 | |||
713 | WIDTHPROF = None |
|
713 | WIDTHPROF = None | |
714 | HEIGHTPROF = None |
|
714 | HEIGHTPROF = None | |
715 | PREFIX = 'spcprofile' |
|
715 | PREFIX = 'spcprofile' | |
716 |
|
716 | |||
717 | def __init__(self): |
|
717 | def __init__(self): | |
718 | self.__isConfig = False |
|
718 | self.__isConfig = False | |
719 | self.__nsubplots = 1 |
|
719 | self.__nsubplots = 1 | |
720 |
|
720 | |||
721 | self.WIDTH = 300 |
|
721 | self.WIDTH = 300 | |
722 | self.HEIGHT = 500 |
|
722 | self.HEIGHT = 500 | |
723 |
|
723 | |||
724 | def getSubplots(self): |
|
724 | def getSubplots(self): | |
725 | ncol = 1 |
|
725 | ncol = 1 | |
726 | nrow = 1 |
|
726 | nrow = 1 | |
727 |
|
727 | |||
728 | return nrow, ncol |
|
728 | return nrow, ncol | |
729 |
|
729 | |||
730 | def setup(self, id, nplots, wintitle, show): |
|
730 | def setup(self, id, nplots, wintitle, show): | |
731 |
|
731 | |||
732 | self.nplots = nplots |
|
732 | self.nplots = nplots | |
733 |
|
733 | |||
734 | ncolspan = 1 |
|
734 | ncolspan = 1 | |
735 | colspan = 1 |
|
735 | colspan = 1 | |
736 |
|
736 | |||
737 | self.createFigure(id = id, |
|
737 | self.createFigure(id = id, | |
738 | wintitle = wintitle, |
|
738 | wintitle = wintitle, | |
739 | widthplot = self.WIDTH, |
|
739 | widthplot = self.WIDTH, | |
740 | heightplot = self.HEIGHT, |
|
740 | heightplot = self.HEIGHT, | |
741 | show=show) |
|
741 | show=show) | |
742 |
|
742 | |||
743 | nrow, ncol = self.getSubplots() |
|
743 | nrow, ncol = self.getSubplots() | |
744 |
|
744 | |||
745 | counter = 0 |
|
745 | counter = 0 | |
746 | for y in range(nrow): |
|
746 | for y in range(nrow): | |
747 | for x in range(ncol): |
|
747 | for x in range(ncol): | |
748 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
748 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
749 |
|
749 | |||
750 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
750 | def run(self, dataOut, id, wintitle="", channelList=None, | |
751 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
751 | xmin=None, xmax=None, ymin=None, ymax=None, | |
752 | save=False, figpath='./', figfile=None, show=True): |
|
752 | save=False, figpath='./', figfile=None, show=True): | |
753 |
|
753 | |||
754 | if channelList == None: |
|
754 | if channelList == None: | |
755 | channelIndexList = dataOut.channelIndexList |
|
755 | channelIndexList = dataOut.channelIndexList | |
756 | channelList = dataOut.channelList |
|
756 | channelList = dataOut.channelList | |
757 | else: |
|
757 | else: | |
758 | channelIndexList = [] |
|
758 | channelIndexList = [] | |
759 | for channel in channelList: |
|
759 | for channel in channelList: | |
760 | if channel not in dataOut.channelList: |
|
760 | if channel not in dataOut.channelList: | |
761 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
761 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
762 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
762 | channelIndexList.append(dataOut.channelList.index(channel)) | |
763 |
|
763 | |||
764 | factor = dataOut.normFactor |
|
764 | factor = dataOut.normFactor | |
765 | y = dataOut.getHeiRange() |
|
765 | y = dataOut.getHeiRange() | |
766 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
766 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
767 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
767 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
768 | avg = numpy.average(x, axis=1) |
|
768 | avg = numpy.average(x, axis=1) | |
769 |
|
769 | |||
770 | avgdB = 10*numpy.log10(avg) |
|
770 | avgdB = 10*numpy.log10(avg) | |
771 |
|
771 | |||
772 | #thisDatetime = dataOut.datatime |
|
772 | #thisDatetime = dataOut.datatime | |
773 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
773 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
774 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
774 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
775 | xlabel = "dB" |
|
775 | xlabel = "dB" | |
776 | ylabel = "Range (Km)" |
|
776 | ylabel = "Range (Km)" | |
777 |
|
777 | |||
778 | if not self.__isConfig: |
|
778 | if not self.__isConfig: | |
779 |
|
779 | |||
780 | nplots = 1 |
|
780 | nplots = 1 | |
781 |
|
781 | |||
782 | self.setup(id=id, |
|
782 | self.setup(id=id, | |
783 | nplots=nplots, |
|
783 | nplots=nplots, | |
784 | wintitle=wintitle, |
|
784 | wintitle=wintitle, | |
785 | show=show) |
|
785 | show=show) | |
786 |
|
786 | |||
787 | if ymin == None: ymin = numpy.nanmin(y) |
|
787 | if ymin == None: ymin = numpy.nanmin(y) | |
788 | if ymax == None: ymax = numpy.nanmax(y) |
|
788 | if ymax == None: ymax = numpy.nanmax(y) | |
789 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
789 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 | |
790 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
790 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 | |
791 |
|
791 | |||
792 | self.__isConfig = True |
|
792 | self.__isConfig = True | |
793 |
|
793 | |||
794 | self.setWinTitle(title) |
|
794 | self.setWinTitle(title) | |
795 |
|
795 | |||
796 |
|
796 | |||
797 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
797 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
798 | axes = self.axesList[0] |
|
798 | axes = self.axesList[0] | |
799 |
|
799 | |||
800 | legendlabels = ["channel %d"%x for x in channelList] |
|
800 | legendlabels = ["channel %d"%x for x in channelList] | |
801 | axes.pmultiline(avgdB, y, |
|
801 | axes.pmultiline(avgdB, y, | |
802 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
802 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
803 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
803 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
804 | ytick_visible=True, nxticks=5, |
|
804 | ytick_visible=True, nxticks=5, | |
805 | grid='x') |
|
805 | grid='x') | |
806 |
|
806 | |||
807 | self.draw() |
|
807 | self.draw() | |
808 |
|
808 | |||
809 | if save: |
|
809 | if save: | |
810 | date = thisDatetime.strftime("%Y%m%d") |
|
810 | date = thisDatetime.strftime("%Y%m%d") | |
811 | if figfile == None: |
|
811 | if figfile == None: | |
812 | figfile = self.getFilename(name = date) |
|
812 | figfile = self.getFilename(name = date) | |
813 |
|
813 | |||
814 | self.saveFigure(figpath, figfile) |
|
814 | self.saveFigure(figpath, figfile) | |
815 |
|
815 | |||
816 | class CoherenceMap(Figure): |
|
816 | class CoherenceMap(Figure): | |
817 | __isConfig = None |
|
817 | __isConfig = None | |
818 | __nsubplots = None |
|
818 | __nsubplots = None | |
819 |
|
819 | |||
820 | WIDTHPROF = None |
|
820 | WIDTHPROF = None | |
821 | HEIGHTPROF = None |
|
821 | HEIGHTPROF = None | |
822 | PREFIX = 'cmap' |
|
822 | PREFIX = 'cmap' | |
823 |
|
823 | |||
824 | def __init__(self): |
|
824 | def __init__(self): | |
825 | self.timerange = 2*60*60 |
|
825 | self.timerange = 2*60*60 | |
826 | self.__isConfig = False |
|
826 | self.__isConfig = False | |
827 | self.__nsubplots = 1 |
|
827 | self.__nsubplots = 1 | |
828 |
|
828 | |||
829 | self.WIDTH = 800 |
|
829 | self.WIDTH = 800 | |
830 | self.HEIGHT = 150 |
|
830 | self.HEIGHT = 150 | |
831 | self.WIDTHPROF = 120 |
|
831 | self.WIDTHPROF = 120 | |
832 | self.HEIGHTPROF = 0 |
|
832 | self.HEIGHTPROF = 0 | |
833 | self.counter_imagwr = 0 |
|
833 | self.counter_imagwr = 0 | |
834 |
|
834 | |||
835 | self.PLOT_CODE = 3 |
|
835 | self.PLOT_CODE = 3 | |
836 | self.FTP_WEI = None |
|
836 | self.FTP_WEI = None | |
837 | self.EXP_CODE = None |
|
837 | self.EXP_CODE = None | |
838 | self.SUB_EXP_CODE = None |
|
838 | self.SUB_EXP_CODE = None | |
839 | self.PLOT_POS = None |
|
839 | self.PLOT_POS = None | |
840 | self.counter_imagwr = 0 |
|
840 | self.counter_imagwr = 0 | |
841 |
|
841 | |||
842 | def getSubplots(self): |
|
842 | def getSubplots(self): | |
843 | ncol = 1 |
|
843 | ncol = 1 | |
844 | nrow = self.nplots*2 |
|
844 | nrow = self.nplots*2 | |
845 |
|
845 | |||
846 | return nrow, ncol |
|
846 | return nrow, ncol | |
847 |
|
847 | |||
848 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
848 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
849 | self.__showprofile = showprofile |
|
849 | self.__showprofile = showprofile | |
850 | self.nplots = nplots |
|
850 | self.nplots = nplots | |
851 |
|
851 | |||
852 | ncolspan = 1 |
|
852 | ncolspan = 1 | |
853 | colspan = 1 |
|
853 | colspan = 1 | |
854 | if showprofile: |
|
854 | if showprofile: | |
855 | ncolspan = 7 |
|
855 | ncolspan = 7 | |
856 | colspan = 6 |
|
856 | colspan = 6 | |
857 | self.__nsubplots = 2 |
|
857 | self.__nsubplots = 2 | |
858 |
|
858 | |||
859 | self.createFigure(id = id, |
|
859 | self.createFigure(id = id, | |
860 | wintitle = wintitle, |
|
860 | wintitle = wintitle, | |
861 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
861 | widthplot = self.WIDTH + self.WIDTHPROF, | |
862 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
862 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
863 | show=True) |
|
863 | show=True) | |
864 |
|
864 | |||
865 | nrow, ncol = self.getSubplots() |
|
865 | nrow, ncol = self.getSubplots() | |
866 |
|
866 | |||
867 | for y in range(nrow): |
|
867 | for y in range(nrow): | |
868 | for x in range(ncol): |
|
868 | for x in range(ncol): | |
869 |
|
869 | |||
870 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
870 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
871 |
|
871 | |||
872 | if showprofile: |
|
872 | if showprofile: | |
873 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
873 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
874 |
|
874 | |||
875 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
875 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
876 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
876 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
877 | timerange=None, |
|
877 | timerange=None, | |
878 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
878 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
879 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
879 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
880 | server=None, folder=None, username=None, password=None, |
|
880 | server=None, folder=None, username=None, password=None, | |
881 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
881 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
882 |
|
882 | |||
883 | if pairsList == None: |
|
883 | if pairsList == None: | |
884 | pairsIndexList = dataOut.pairsIndexList |
|
884 | pairsIndexList = dataOut.pairsIndexList | |
885 | else: |
|
885 | else: | |
886 | pairsIndexList = [] |
|
886 | pairsIndexList = [] | |
887 | for pair in pairsList: |
|
887 | for pair in pairsList: | |
888 | if pair not in dataOut.pairsList: |
|
888 | if pair not in dataOut.pairsList: | |
889 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
889 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
890 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
890 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
891 |
|
891 | |||
892 | if timerange != None: |
|
892 | if timerange != None: | |
893 | self.timerange = timerange |
|
893 | self.timerange = timerange | |
894 |
|
894 | |||
895 | if pairsIndexList == []: |
|
895 | if pairsIndexList == []: | |
896 | return |
|
896 | return | |
897 |
|
897 | |||
898 | if len(pairsIndexList) > 4: |
|
898 | if len(pairsIndexList) > 4: | |
899 | pairsIndexList = pairsIndexList[0:4] |
|
899 | pairsIndexList = pairsIndexList[0:4] | |
900 |
|
900 | |||
901 | tmin = None |
|
901 | tmin = None | |
902 | tmax = None |
|
902 | tmax = None | |
903 | x = dataOut.getTimeRange() |
|
903 | x = dataOut.getTimeRange() | |
904 | y = dataOut.getHeiRange() |
|
904 | y = dataOut.getHeiRange() | |
905 |
|
905 | |||
906 | #thisDatetime = dataOut.datatime |
|
906 | #thisDatetime = dataOut.datatime | |
907 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
907 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
908 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
908 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
909 | xlabel = "" |
|
909 | xlabel = "" | |
910 | ylabel = "Range (Km)" |
|
910 | ylabel = "Range (Km)" | |
911 |
|
911 | |||
912 | if not self.__isConfig: |
|
912 | if not self.__isConfig: | |
913 | nplots = len(pairsIndexList) |
|
913 | nplots = len(pairsIndexList) | |
914 | self.setup(id=id, |
|
914 | self.setup(id=id, | |
915 | nplots=nplots, |
|
915 | nplots=nplots, | |
916 | wintitle=wintitle, |
|
916 | wintitle=wintitle, | |
917 | showprofile=showprofile, |
|
917 | showprofile=showprofile, | |
918 | show=show) |
|
918 | show=show) | |
919 |
|
919 | |||
920 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
920 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
921 | if ymin == None: ymin = numpy.nanmin(y) |
|
921 | if ymin == None: ymin = numpy.nanmin(y) | |
922 | if ymax == None: ymax = numpy.nanmax(y) |
|
922 | if ymax == None: ymax = numpy.nanmax(y) | |
923 | if zmin == None: zmin = 0. |
|
923 | if zmin == None: zmin = 0. | |
924 | if zmax == None: zmax = 1. |
|
924 | if zmax == None: zmax = 1. | |
925 |
|
925 | |||
926 | self.FTP_WEI = ftp_wei |
|
926 | self.FTP_WEI = ftp_wei | |
927 | self.EXP_CODE = exp_code |
|
927 | self.EXP_CODE = exp_code | |
928 | self.SUB_EXP_CODE = sub_exp_code |
|
928 | self.SUB_EXP_CODE = sub_exp_code | |
929 | self.PLOT_POS = plot_pos |
|
929 | self.PLOT_POS = plot_pos | |
930 |
|
930 | |||
931 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
931 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
932 |
|
932 | |||
933 | self.__isConfig = True |
|
933 | self.__isConfig = True | |
934 |
|
934 | |||
935 | self.setWinTitle(title) |
|
935 | self.setWinTitle(title) | |
936 |
|
936 | |||
937 | for i in range(self.nplots): |
|
937 | for i in range(self.nplots): | |
938 |
|
938 | |||
939 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
939 | pair = dataOut.pairsList[pairsIndexList[i]] | |
940 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
940 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
941 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
941 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) | |
942 | # coherence = numpy.abs(avgcoherenceComplex) |
|
942 | # coherence = numpy.abs(avgcoherenceComplex) | |
943 |
|
943 | |||
944 | ## coherence = numpy.abs(coherenceComplex) |
|
944 | ## coherence = numpy.abs(coherenceComplex) | |
945 | ## avg = numpy.average(coherence, axis=0) |
|
945 | ## avg = numpy.average(coherence, axis=0) | |
946 |
|
946 | |||
947 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
947 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
948 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
948 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
949 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
949 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
950 |
|
950 | |||
951 |
|
951 | |||
952 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
952 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
953 | coherence = numpy.abs(avgcoherenceComplex) |
|
953 | coherence = numpy.abs(avgcoherenceComplex) | |
954 |
|
954 | |||
955 | z = coherence.reshape((1,-1)) |
|
955 | z = coherence.reshape((1,-1)) | |
956 |
|
956 | |||
957 | counter = 0 |
|
957 | counter = 0 | |
958 |
|
958 | |||
959 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
959 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
960 | axes = self.axesList[i*self.__nsubplots*2] |
|
960 | axes = self.axesList[i*self.__nsubplots*2] | |
961 | axes.pcolorbuffer(x, y, z, |
|
961 | axes.pcolorbuffer(x, y, z, | |
962 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
962 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
963 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
963 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
964 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
964 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
965 |
|
965 | |||
966 | if self.__showprofile: |
|
966 | if self.__showprofile: | |
967 | counter += 1 |
|
967 | counter += 1 | |
968 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
968 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
969 | axes.pline(coherence, y, |
|
969 | axes.pline(coherence, y, | |
970 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
970 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
971 | xlabel='', ylabel='', title='', ticksize=7, |
|
971 | xlabel='', ylabel='', title='', ticksize=7, | |
972 | ytick_visible=False, nxticks=5, |
|
972 | ytick_visible=False, nxticks=5, | |
973 | grid='x') |
|
973 | grid='x') | |
974 |
|
974 | |||
975 | counter += 1 |
|
975 | counter += 1 | |
976 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
976 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
977 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
977 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
978 | # avg = numpy.average(phase, axis=0) |
|
978 | # avg = numpy.average(phase, axis=0) | |
979 | z = phase.reshape((1,-1)) |
|
979 | z = phase.reshape((1,-1)) | |
980 |
|
980 | |||
981 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
981 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
982 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
982 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
983 | axes.pcolorbuffer(x, y, z, |
|
983 | axes.pcolorbuffer(x, y, z, | |
984 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
984 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
985 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
985 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
986 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
986 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
987 |
|
987 | |||
988 | if self.__showprofile: |
|
988 | if self.__showprofile: | |
989 | counter += 1 |
|
989 | counter += 1 | |
990 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
990 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
991 | axes.pline(phase, y, |
|
991 | axes.pline(phase, y, | |
992 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
992 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
993 | xlabel='', ylabel='', title='', ticksize=7, |
|
993 | xlabel='', ylabel='', title='', ticksize=7, | |
994 | ytick_visible=False, nxticks=4, |
|
994 | ytick_visible=False, nxticks=4, | |
995 | grid='x') |
|
995 | grid='x') | |
996 |
|
996 | |||
997 | self.draw() |
|
997 | self.draw() | |
998 |
|
998 | |||
999 | if save: |
|
999 | if save: | |
1000 |
|
1000 | |||
1001 | self.counter_imagwr += 1 |
|
1001 | self.counter_imagwr += 1 | |
1002 | if (self.counter_imagwr==wr_period): |
|
1002 | if (self.counter_imagwr==wr_period): | |
1003 | if figfile == None: |
|
1003 | if figfile == None: | |
1004 | figfile = self.getFilename(name = self.name) |
|
1004 | figfile = self.getFilename(name = self.name) | |
1005 | self.saveFigure(figpath, figfile) |
|
1005 | self.saveFigure(figpath, figfile) | |
1006 |
|
1006 | |||
1007 | if ftp: |
|
1007 | if ftp: | |
1008 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1008 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1009 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1009 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1010 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1010 | path = '%s%03d' %(self.PREFIX, self.id) | |
1011 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1011 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1012 | self.saveFigure(figpath, ftp_file) |
|
1012 | self.saveFigure(figpath, ftp_file) | |
1013 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1013 | ftp_filename = os.path.join(figpath,ftp_file) | |
1014 | try: |
|
1014 | try: | |
1015 | self.sendByFTP(ftp_filename, server, folder, username, password) |
|
1015 | self.sendByFTP(ftp_filename, server, folder, username, password) | |
1016 | except: |
|
1016 | except: | |
1017 | self.counter_imagwr = 0 |
|
1017 | self.counter_imagwr = 0 | |
1018 | print ValueError, 'Error FTP' |
|
1018 | print ValueError, 'Error FTP' | |
1019 |
|
1019 | |||
1020 | self.counter_imagwr = 0 |
|
1020 | self.counter_imagwr = 0 | |
1021 |
|
1021 | |||
1022 |
|
1022 | |||
1023 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1023 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1024 | self.__isConfig = False |
|
1024 | self.__isConfig = False | |
1025 |
|
1025 | |||
1026 | class Noise(Figure): |
|
1026 | class Noise(Figure): | |
1027 |
|
1027 | |||
1028 | __isConfig = None |
|
1028 | __isConfig = None | |
1029 | __nsubplots = None |
|
1029 | __nsubplots = None | |
1030 |
|
1030 | |||
1031 | PREFIX = 'noise' |
|
1031 | PREFIX = 'noise' | |
1032 |
|
1032 | |||
1033 | def __init__(self): |
|
1033 | def __init__(self): | |
1034 |
|
1034 | |||
1035 | self.timerange = 24*60*60 |
|
1035 | self.timerange = 24*60*60 | |
1036 | self.__isConfig = False |
|
1036 | self.__isConfig = False | |
1037 | self.__nsubplots = 1 |
|
1037 | self.__nsubplots = 1 | |
1038 | self.counter_imagwr = 0 |
|
1038 | self.counter_imagwr = 0 | |
1039 | self.WIDTH = 600 |
|
1039 | self.WIDTH = 600 | |
1040 | self.HEIGHT = 300 |
|
1040 | self.HEIGHT = 300 | |
1041 | self.WIDTHPROF = 120 |
|
1041 | self.WIDTHPROF = 120 | |
1042 | self.HEIGHTPROF = 0 |
|
1042 | self.HEIGHTPROF = 0 | |
1043 | self.xdata = None |
|
1043 | self.xdata = None | |
1044 | self.ydata = None |
|
1044 | self.ydata = None | |
1045 |
|
1045 | |||
1046 | self.PLOT_CODE = 77 |
|
1046 | self.PLOT_CODE = 77 | |
1047 | self.FTP_WEI = None |
|
1047 | self.FTP_WEI = None | |
1048 | self.EXP_CODE = None |
|
1048 | self.EXP_CODE = None | |
1049 | self.SUB_EXP_CODE = None |
|
1049 | self.SUB_EXP_CODE = None | |
1050 | self.PLOT_POS = None |
|
1050 | self.PLOT_POS = None | |
1051 |
|
1051 | |||
1052 | def getSubplots(self): |
|
1052 | def getSubplots(self): | |
1053 |
|
1053 | |||
1054 | ncol = 1 |
|
1054 | ncol = 1 | |
1055 | nrow = 1 |
|
1055 | nrow = 1 | |
1056 |
|
1056 | |||
1057 | return nrow, ncol |
|
1057 | return nrow, ncol | |
1058 |
|
1058 | |||
1059 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1059 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1060 |
|
1060 | |||
1061 | self.__showprofile = showprofile |
|
1061 | self.__showprofile = showprofile | |
1062 | self.nplots = nplots |
|
1062 | self.nplots = nplots | |
1063 |
|
1063 | |||
1064 | ncolspan = 7 |
|
1064 | ncolspan = 7 | |
1065 | colspan = 6 |
|
1065 | colspan = 6 | |
1066 | self.__nsubplots = 2 |
|
1066 | self.__nsubplots = 2 | |
1067 |
|
1067 | |||
1068 | self.createFigure(id = id, |
|
1068 | self.createFigure(id = id, | |
1069 | wintitle = wintitle, |
|
1069 | wintitle = wintitle, | |
1070 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1070 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1071 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1071 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1072 | show=show) |
|
1072 | show=show) | |
1073 |
|
1073 | |||
1074 | nrow, ncol = self.getSubplots() |
|
1074 | nrow, ncol = self.getSubplots() | |
1075 |
|
1075 | |||
1076 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1076 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1077 |
|
1077 | |||
1078 |
|
1078 | |||
1079 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1079 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1080 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1080 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1081 | timerange=None, |
|
1081 | timerange=None, | |
1082 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1082 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1083 | server=None, folder=None, username=None, password=None, |
|
1083 | server=None, folder=None, username=None, password=None, | |
1084 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1084 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1085 |
|
1085 | |||
1086 | if channelList == None: |
|
1086 | if channelList == None: | |
1087 | channelIndexList = dataOut.channelIndexList |
|
1087 | channelIndexList = dataOut.channelIndexList | |
1088 | channelList = dataOut.channelList |
|
1088 | channelList = dataOut.channelList | |
1089 | else: |
|
1089 | else: | |
1090 | channelIndexList = [] |
|
1090 | channelIndexList = [] | |
1091 | for channel in channelList: |
|
1091 | for channel in channelList: | |
1092 | if channel not in dataOut.channelList: |
|
1092 | if channel not in dataOut.channelList: | |
1093 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1093 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1094 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1094 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1095 |
|
1095 | |||
1096 | if timerange != None: |
|
1096 | if timerange != None: | |
1097 | self.timerange = timerange |
|
1097 | self.timerange = timerange | |
1098 |
|
1098 | |||
1099 | tmin = None |
|
1099 | tmin = None | |
1100 | tmax = None |
|
1100 | tmax = None | |
1101 | x = dataOut.getTimeRange() |
|
1101 | x = dataOut.getTimeRange() | |
1102 | y = dataOut.getHeiRange() |
|
1102 | y = dataOut.getHeiRange() | |
1103 | factor = dataOut.normFactor |
|
1103 | factor = dataOut.normFactor | |
1104 | noise = dataOut.getNoise()/factor |
|
1104 | noise = dataOut.getNoise()/factor | |
1105 | noisedB = 10*numpy.log10(noise) |
|
1105 | noisedB = 10*numpy.log10(noise) | |
1106 |
|
1106 | |||
1107 | #thisDatetime = dataOut.datatime |
|
1107 | #thisDatetime = dataOut.datatime | |
1108 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1108 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1109 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1109 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1110 | xlabel = "" |
|
1110 | xlabel = "" | |
1111 | ylabel = "Intensity (dB)" |
|
1111 | ylabel = "Intensity (dB)" | |
1112 |
|
1112 | |||
1113 | if not self.__isConfig: |
|
1113 | if not self.__isConfig: | |
1114 |
|
1114 | |||
1115 | nplots = 1 |
|
1115 | nplots = 1 | |
1116 |
|
1116 | |||
1117 | self.setup(id=id, |
|
1117 | self.setup(id=id, | |
1118 | nplots=nplots, |
|
1118 | nplots=nplots, | |
1119 | wintitle=wintitle, |
|
1119 | wintitle=wintitle, | |
1120 | showprofile=showprofile, |
|
1120 | showprofile=showprofile, | |
1121 | show=show) |
|
1121 | show=show) | |
1122 |
|
1122 | |||
1123 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1123 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1124 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 |
|
1124 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 | |
1125 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1125 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | |
1126 |
|
1126 | |||
1127 | self.FTP_WEI = ftp_wei |
|
1127 | self.FTP_WEI = ftp_wei | |
1128 | self.EXP_CODE = exp_code |
|
1128 | self.EXP_CODE = exp_code | |
1129 | self.SUB_EXP_CODE = sub_exp_code |
|
1129 | self.SUB_EXP_CODE = sub_exp_code | |
1130 | self.PLOT_POS = plot_pos |
|
1130 | self.PLOT_POS = plot_pos | |
1131 |
|
1131 | |||
1132 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1132 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1133 |
|
1133 | |||
1134 |
|
1134 | |||
1135 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1135 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1136 | self.__isConfig = True |
|
1136 | self.__isConfig = True | |
1137 |
|
1137 | |||
1138 | self.xdata = numpy.array([]) |
|
1138 | self.xdata = numpy.array([]) | |
1139 | self.ydata = numpy.array([]) |
|
1139 | self.ydata = numpy.array([]) | |
1140 |
|
1140 | |||
1141 | self.setWinTitle(title) |
|
1141 | self.setWinTitle(title) | |
1142 |
|
1142 | |||
1143 |
|
1143 | |||
1144 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1144 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1145 |
|
1145 | |||
1146 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1146 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] | |
1147 | axes = self.axesList[0] |
|
1147 | axes = self.axesList[0] | |
1148 |
|
1148 | |||
1149 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1149 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1150 |
|
1150 | |||
1151 | if len(self.ydata)==0: |
|
1151 | if len(self.ydata)==0: | |
1152 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1152 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1153 | else: |
|
1153 | else: | |
1154 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1154 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1155 |
|
1155 | |||
1156 |
|
1156 | |||
1157 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1157 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1158 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1158 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1159 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1159 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1160 | XAxisAsTime=True, grid='both' |
|
1160 | XAxisAsTime=True, grid='both' | |
1161 | ) |
|
1161 | ) | |
1162 |
|
1162 | |||
1163 | self.draw() |
|
1163 | self.draw() | |
1164 |
|
1164 | |||
1165 | # if save: |
|
1165 | # if save: | |
1166 | # |
|
1166 | # | |
1167 | # if figfile == None: |
|
1167 | # if figfile == None: | |
1168 | # figfile = self.getFilename(name = self.name) |
|
1168 | # figfile = self.getFilename(name = self.name) | |
1169 | # |
|
1169 | # | |
1170 | # self.saveFigure(figpath, figfile) |
|
1170 | # self.saveFigure(figpath, figfile) | |
1171 |
|
1171 | |||
1172 | if save: |
|
1172 | if save: | |
1173 |
|
1173 | |||
1174 | self.counter_imagwr += 1 |
|
1174 | self.counter_imagwr += 1 | |
1175 | if (self.counter_imagwr==wr_period): |
|
1175 | if (self.counter_imagwr==wr_period): | |
1176 | if figfile == None: |
|
1176 | if figfile == None: | |
1177 | figfile = self.getFilename(name = self.name) |
|
1177 | figfile = self.getFilename(name = self.name) | |
1178 | self.saveFigure(figpath, figfile) |
|
1178 | self.saveFigure(figpath, figfile) | |
1179 |
|
1179 | |||
1180 | if ftp: |
|
1180 | if ftp: | |
1181 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1181 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1182 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1182 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1183 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1183 | path = '%s%03d' %(self.PREFIX, self.id) | |
1184 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1184 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1185 | self.saveFigure(figpath, ftp_file) |
|
1185 | self.saveFigure(figpath, ftp_file) | |
1186 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1186 | ftp_filename = os.path.join(figpath,ftp_file) | |
1187 | try: |
|
1187 | try: | |
1188 | self.sendByFTP(ftp_filename, server, folder, username, password) |
|
1188 | self.sendByFTP(ftp_filename, server, folder, username, password) | |
1189 | except: |
|
1189 | except: | |
1190 | self.counter_imagwr = 0 |
|
1190 | self.counter_imagwr = 0 | |
1191 | print ValueError, 'Error FTP' |
|
1191 | print ValueError, 'Error FTP' | |
1192 |
|
1192 | |||
1193 | self.counter_imagwr = 0 |
|
1193 | self.counter_imagwr = 0 | |
1194 |
|
1194 | |||
1195 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1195 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1196 | self.__isConfig = False |
|
1196 | self.__isConfig = False | |
1197 | del self.xdata |
|
1197 | del self.xdata | |
1198 | del self.ydata |
|
1198 | del self.ydata | |
1199 |
|
1199 | |||
1200 |
|
1200 | |||
1201 | class SpectraHeisScope(Figure): |
|
1201 | class SpectraHeisScope(Figure): | |
1202 |
|
1202 | |||
1203 |
|
1203 | |||
1204 | __isConfig = None |
|
1204 | __isConfig = None | |
1205 | __nsubplots = None |
|
1205 | __nsubplots = None | |
1206 |
|
1206 | |||
1207 | WIDTHPROF = None |
|
1207 | WIDTHPROF = None | |
1208 | HEIGHTPROF = None |
|
1208 | HEIGHTPROF = None | |
1209 | PREFIX = 'spc' |
|
1209 | PREFIX = 'spc' | |
1210 |
|
1210 | |||
1211 | def __init__(self): |
|
1211 | def __init__(self): | |
1212 |
|
1212 | |||
1213 | self.__isConfig = False |
|
1213 | self.__isConfig = False | |
1214 | self.__nsubplots = 1 |
|
1214 | self.__nsubplots = 1 | |
1215 |
|
1215 | |||
1216 | self.WIDTH = 230 |
|
1216 | self.WIDTH = 230 | |
1217 | self.HEIGHT = 250 |
|
1217 | self.HEIGHT = 250 | |
1218 | self.WIDTHPROF = 120 |
|
1218 | self.WIDTHPROF = 120 | |
1219 | self.HEIGHTPROF = 0 |
|
1219 | self.HEIGHTPROF = 0 | |
1220 | self.counter_imagwr = 0 |
|
1220 | self.counter_imagwr = 0 | |
1221 |
|
1221 | |||
1222 | def getSubplots(self): |
|
1222 | def getSubplots(self): | |
1223 |
|
1223 | |||
1224 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1224 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
1225 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1225 | nrow = int(self.nplots*1./ncol + 0.9) | |
1226 |
|
1226 | |||
1227 | return nrow, ncol |
|
1227 | return nrow, ncol | |
1228 |
|
1228 | |||
1229 | def setup(self, id, nplots, wintitle, show): |
|
1229 | def setup(self, id, nplots, wintitle, show): | |
1230 |
|
1230 | |||
1231 | showprofile = False |
|
1231 | showprofile = False | |
1232 | self.__showprofile = showprofile |
|
1232 | self.__showprofile = showprofile | |
1233 | self.nplots = nplots |
|
1233 | self.nplots = nplots | |
1234 |
|
1234 | |||
1235 | ncolspan = 1 |
|
1235 | ncolspan = 1 | |
1236 | colspan = 1 |
|
1236 | colspan = 1 | |
1237 | if showprofile: |
|
1237 | if showprofile: | |
1238 | ncolspan = 3 |
|
1238 | ncolspan = 3 | |
1239 | colspan = 2 |
|
1239 | colspan = 2 | |
1240 | self.__nsubplots = 2 |
|
1240 | self.__nsubplots = 2 | |
1241 |
|
1241 | |||
1242 | self.createFigure(id = id, |
|
1242 | self.createFigure(id = id, | |
1243 | wintitle = wintitle, |
|
1243 | wintitle = wintitle, | |
1244 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1244 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1245 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1245 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1246 | show = show) |
|
1246 | show = show) | |
1247 |
|
1247 | |||
1248 | nrow, ncol = self.getSubplots() |
|
1248 | nrow, ncol = self.getSubplots() | |
1249 |
|
1249 | |||
1250 | counter = 0 |
|
1250 | counter = 0 | |
1251 | for y in range(nrow): |
|
1251 | for y in range(nrow): | |
1252 | for x in range(ncol): |
|
1252 | for x in range(ncol): | |
1253 |
|
1253 | |||
1254 | if counter >= self.nplots: |
|
1254 | if counter >= self.nplots: | |
1255 | break |
|
1255 | break | |
1256 |
|
1256 | |||
1257 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1257 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1258 |
|
1258 | |||
1259 | if showprofile: |
|
1259 | if showprofile: | |
1260 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1260 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1261 |
|
1261 | |||
1262 | counter += 1 |
|
1262 | counter += 1 | |
1263 |
|
1263 | |||
1264 | # __isConfig = None |
|
|||
1265 | # def __init__(self): |
|
|||
1266 | # |
|
|||
1267 | # self.__isConfig = False |
|
|||
1268 | # self.WIDTH = 600 |
|
|||
1269 | # self.HEIGHT = 200 |
|
|||
1270 | # |
|
|||
1271 | # def getSubplots(self): |
|
|||
1272 | # |
|
|||
1273 | # nrow = self.nplots |
|
|||
1274 | # ncol = 3 |
|
|||
1275 | # return nrow, ncol |
|
|||
1276 | # |
|
|||
1277 | # def setup(self, id, nplots, wintitle): |
|
|||
1278 | # |
|
|||
1279 | # self.nplots = nplots |
|
|||
1280 | # |
|
|||
1281 | # self.createFigure(id, wintitle) |
|
|||
1282 | # |
|
|||
1283 | # nrow,ncol = self.getSubplots() |
|
|||
1284 | # colspan = 3 |
|
|||
1285 | # rowspan = 1 |
|
|||
1286 | # |
|
|||
1287 | # for i in range(nplots): |
|
|||
1288 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
|||
1289 |
|
1264 | |||
1290 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1265 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1291 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1266 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
1292 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True): |
|
1267 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True): | |
1293 |
|
1268 | |||
1294 | """ |
|
1269 | """ | |
1295 |
|
1270 | |||
1296 | Input: |
|
1271 | Input: | |
1297 | dataOut : |
|
1272 | dataOut : | |
1298 | id : |
|
1273 | id : | |
1299 | wintitle : |
|
1274 | wintitle : | |
1300 | channelList : |
|
1275 | channelList : | |
1301 | xmin : None, |
|
1276 | xmin : None, | |
1302 | xmax : None, |
|
1277 | xmax : None, | |
1303 | ymin : None, |
|
1278 | ymin : None, | |
1304 | ymax : None, |
|
1279 | ymax : None, | |
1305 | """ |
|
1280 | """ | |
1306 |
|
1281 | |||
1307 | if dataOut.realtime: |
|
1282 | if dataOut.realtime: | |
1308 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1283 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
1309 | print 'Skipping this plot function' |
|
1284 | print 'Skipping this plot function' | |
1310 | return |
|
1285 | return | |
1311 |
|
1286 | |||
1312 | if channelList == None: |
|
1287 | if channelList == None: | |
1313 | channelIndexList = dataOut.channelIndexList |
|
1288 | channelIndexList = dataOut.channelIndexList | |
1314 | else: |
|
1289 | else: | |
1315 | channelIndexList = [] |
|
1290 | channelIndexList = [] | |
1316 | for channel in channelList: |
|
1291 | for channel in channelList: | |
1317 | if channel not in dataOut.channelList: |
|
1292 | if channel not in dataOut.channelList: | |
1318 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1293 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1319 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1294 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1320 |
|
1295 | |||
1321 | # x = dataOut.heightList |
|
1296 | # x = dataOut.heightList | |
1322 | c = 3E8 |
|
1297 | c = 3E8 | |
1323 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1298 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1324 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1299 | #deberia cambiar para el caso de 1Mhz y 100KHz | |
1325 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1300 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) | |
1326 | x= x/(10000.0) |
|
1301 | #para 1Mhz descomentar la siguiente linea | |
|
1302 | #x= x/(10000.0) | |||
1327 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1303 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
1328 | # y = y.real |
|
1304 | # y = y.real | |
1329 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1305 | datadB = 10.*numpy.log10(dataOut.data_spc) | |
1330 | y = datadB |
|
1306 | y = datadB | |
1331 |
|
1307 | |||
1332 | #thisDatetime = dataOut.datatime |
|
1308 | #thisDatetime = dataOut.datatime | |
1333 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1309 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1334 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1310 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1335 |
xlabel = " |
|
1311 | xlabel = "" | |
|
1312 | #para 1Mhz descomentar la siguiente linea | |||
|
1313 | #xlabel = "Frequency x 10000" | |||
1336 | ylabel = "Intensity (dB)" |
|
1314 | ylabel = "Intensity (dB)" | |
1337 |
|
1315 | |||
1338 | if not self.__isConfig: |
|
1316 | if not self.__isConfig: | |
1339 | nplots = len(channelIndexList) |
|
1317 | nplots = len(channelIndexList) | |
1340 |
|
1318 | |||
1341 | self.setup(id=id, |
|
1319 | self.setup(id=id, | |
1342 | nplots=nplots, |
|
1320 | nplots=nplots, | |
1343 | wintitle=wintitle, |
|
1321 | wintitle=wintitle, | |
1344 | show=show) |
|
1322 | show=show) | |
1345 |
|
1323 | |||
1346 | if xmin == None: xmin = numpy.nanmin(x) |
|
1324 | if xmin == None: xmin = numpy.nanmin(x) | |
1347 | if xmax == None: xmax = numpy.nanmax(x) |
|
1325 | if xmax == None: xmax = numpy.nanmax(x) | |
1348 | if ymin == None: ymin = numpy.nanmin(y) |
|
1326 | if ymin == None: ymin = numpy.nanmin(y) | |
1349 | if ymax == None: ymax = numpy.nanmax(y) |
|
1327 | if ymax == None: ymax = numpy.nanmax(y) | |
1350 |
|
1328 | |||
1351 | self.__isConfig = True |
|
1329 | self.__isConfig = True | |
1352 |
|
1330 | |||
1353 | self.setWinTitle(title) |
|
1331 | self.setWinTitle(title) | |
1354 |
|
1332 | |||
1355 | for i in range(len(self.axesList)): |
|
1333 | for i in range(len(self.axesList)): | |
1356 | ychannel = y[i,:] |
|
1334 | ychannel = y[i,:] | |
1357 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) |
|
1335 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
|
1336 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) | |||
1358 | axes = self.axesList[i] |
|
1337 | axes = self.axesList[i] | |
1359 | axes.pline(x, ychannel, |
|
1338 | axes.pline(x, ychannel, | |
1360 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1339 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1361 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1340 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') | |
1362 |
|
1341 | |||
1363 |
|
1342 | |||
1364 | self.draw() |
|
1343 | self.draw() | |
1365 |
|
1344 | |||
1366 | if save: |
|
1345 | if save: | |
1367 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1346 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1368 | if figfile == None: |
|
1347 | if figfile == None: | |
1369 | figfile = self.getFilename(name = date) |
|
1348 | figfile = self.getFilename(name = date) | |
1370 |
|
1349 | |||
1371 | self.saveFigure(figpath, figfile) |
|
1350 | self.saveFigure(figpath, figfile) | |
1372 |
|
1351 | |||
1373 | self.counter_imagwr += 1 |
|
1352 | self.counter_imagwr += 1 | |
1374 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1353 | if (ftp and (self.counter_imagwr==wr_period)): | |
1375 | figfilename = os.path.join(figpath,figfile) |
|
1354 | figfilename = os.path.join(figpath,figfile) | |
1376 | self.sendByFTP(figfilename) |
|
1355 | self.sendByFTP(figfilename) | |
1377 | self.counter_imagwr = 0 |
|
1356 | self.counter_imagwr = 0 | |
1378 |
|
1357 | |||
1379 |
|
1358 | |||
1380 | class RTIfromSpectraHeis(Figure): |
|
1359 | class RTIfromSpectraHeis(Figure): | |
1381 |
|
1360 | |||
1382 | __isConfig = None |
|
1361 | __isConfig = None | |
1383 | __nsubplots = None |
|
1362 | __nsubplots = None | |
1384 |
|
1363 | |||
1385 | PREFIX = 'rtinoise' |
|
1364 | PREFIX = 'rtinoise' | |
1386 |
|
1365 | |||
1387 | def __init__(self): |
|
1366 | def __init__(self): | |
1388 |
|
1367 | |||
1389 | self.timerange = 24*60*60 |
|
1368 | self.timerange = 24*60*60 | |
1390 | self.__isConfig = False |
|
1369 | self.__isConfig = False | |
1391 | self.__nsubplots = 1 |
|
1370 | self.__nsubplots = 1 | |
1392 |
|
1371 | |||
1393 | self.WIDTH = 820 |
|
1372 | self.WIDTH = 820 | |
1394 | self.HEIGHT = 200 |
|
1373 | self.HEIGHT = 200 | |
1395 | self.WIDTHPROF = 120 |
|
1374 | self.WIDTHPROF = 120 | |
1396 | self.HEIGHTPROF = 0 |
|
1375 | self.HEIGHTPROF = 0 | |
1397 | self.counter_imagwr = 0 |
|
1376 | self.counter_imagwr = 0 | |
1398 | self.xdata = None |
|
1377 | self.xdata = None | |
1399 | self.ydata = None |
|
1378 | self.ydata = None | |
1400 |
|
1379 | |||
1401 | def getSubplots(self): |
|
1380 | def getSubplots(self): | |
1402 |
|
1381 | |||
1403 | ncol = 1 |
|
1382 | ncol = 1 | |
1404 | nrow = 1 |
|
1383 | nrow = 1 | |
1405 |
|
1384 | |||
1406 | return nrow, ncol |
|
1385 | return nrow, ncol | |
1407 |
|
1386 | |||
1408 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1387 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1409 |
|
1388 | |||
1410 | self.__showprofile = showprofile |
|
1389 | self.__showprofile = showprofile | |
1411 | self.nplots = nplots |
|
1390 | self.nplots = nplots | |
1412 |
|
1391 | |||
1413 | ncolspan = 7 |
|
1392 | ncolspan = 7 | |
1414 | colspan = 6 |
|
1393 | colspan = 6 | |
1415 | self.__nsubplots = 2 |
|
1394 | self.__nsubplots = 2 | |
1416 |
|
1395 | |||
1417 | self.createFigure(id = id, |
|
1396 | self.createFigure(id = id, | |
1418 | wintitle = wintitle, |
|
1397 | wintitle = wintitle, | |
1419 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1398 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1420 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1399 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1421 | show = show) |
|
1400 | show = show) | |
1422 |
|
1401 | |||
1423 | nrow, ncol = self.getSubplots() |
|
1402 | nrow, ncol = self.getSubplots() | |
1424 |
|
1403 | |||
1425 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1404 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1426 |
|
1405 | |||
1427 |
|
1406 | |||
1428 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1407 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1429 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1408 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1430 | timerange=None, |
|
1409 | timerange=None, | |
1431 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True): |
|
1410 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True): | |
1432 |
|
1411 | |||
1433 | if channelList == None: |
|
1412 | if channelList == None: | |
1434 | channelIndexList = dataOut.channelIndexList |
|
1413 | channelIndexList = dataOut.channelIndexList | |
1435 | channelList = dataOut.channelList |
|
1414 | channelList = dataOut.channelList | |
1436 | else: |
|
1415 | else: | |
1437 | channelIndexList = [] |
|
1416 | channelIndexList = [] | |
1438 | for channel in channelList: |
|
1417 | for channel in channelList: | |
1439 | if channel not in dataOut.channelList: |
|
1418 | if channel not in dataOut.channelList: | |
1440 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1419 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1441 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1420 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1442 |
|
1421 | |||
1443 | if timerange != None: |
|
1422 | if timerange != None: | |
1444 | self.timerange = timerange |
|
1423 | self.timerange = timerange | |
1445 |
|
1424 | |||
1446 | tmin = None |
|
1425 | tmin = None | |
1447 | tmax = None |
|
1426 | tmax = None | |
1448 | x = dataOut.getTimeRange() |
|
1427 | x = dataOut.getTimeRange() | |
1449 | y = dataOut.getHeiRange() |
|
1428 | y = dataOut.getHeiRange() | |
1450 |
|
1429 | |||
1451 | factor = 1 |
|
1430 | factor = 1 | |
1452 | data = dataOut.data_spc/factor |
|
1431 | data = dataOut.data_spc/factor | |
1453 | data = numpy.average(data,axis=1) |
|
1432 | data = numpy.average(data,axis=1) | |
1454 | datadB = 10*numpy.log10(data) |
|
1433 | datadB = 10*numpy.log10(data) | |
1455 |
|
1434 | |||
1456 | # factor = dataOut.normFactor |
|
1435 | # factor = dataOut.normFactor | |
1457 | # noise = dataOut.getNoise()/factor |
|
1436 | # noise = dataOut.getNoise()/factor | |
1458 | # noisedB = 10*numpy.log10(noise) |
|
1437 | # noisedB = 10*numpy.log10(noise) | |
1459 |
|
1438 | |||
1460 | #thisDatetime = dataOut.datatime |
|
1439 | #thisDatetime = dataOut.datatime | |
1461 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1440 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1462 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1441 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1463 | xlabel = "Local Time" |
|
1442 | xlabel = "Local Time" | |
1464 | ylabel = "Intensity (dB)" |
|
1443 | ylabel = "Intensity (dB)" | |
1465 |
|
1444 | |||
1466 | if not self.__isConfig: |
|
1445 | if not self.__isConfig: | |
1467 |
|
1446 | |||
1468 | nplots = 1 |
|
1447 | nplots = 1 | |
1469 |
|
1448 | |||
1470 | self.setup(id=id, |
|
1449 | self.setup(id=id, | |
1471 | nplots=nplots, |
|
1450 | nplots=nplots, | |
1472 | wintitle=wintitle, |
|
1451 | wintitle=wintitle, | |
1473 | showprofile=showprofile, |
|
1452 | showprofile=showprofile, | |
1474 | show=show) |
|
1453 | show=show) | |
1475 |
|
1454 | |||
1476 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1455 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1477 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1456 | if ymin == None: ymin = numpy.nanmin(datadB) | |
1478 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1457 | if ymax == None: ymax = numpy.nanmax(datadB) | |
1479 |
|
1458 | |||
1480 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1459 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1481 | self.__isConfig = True |
|
1460 | self.__isConfig = True | |
1482 |
|
1461 | |||
1483 | self.xdata = numpy.array([]) |
|
1462 | self.xdata = numpy.array([]) | |
1484 | self.ydata = numpy.array([]) |
|
1463 | self.ydata = numpy.array([]) | |
1485 |
|
1464 | |||
1486 | self.setWinTitle(title) |
|
1465 | self.setWinTitle(title) | |
1487 |
|
1466 | |||
1488 |
|
1467 | |||
1489 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1468 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1490 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1469 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1491 |
|
1470 | |||
1492 | legendlabels = ["channel %d"%idchannel for idchannel in channelIndexList] |
|
1471 | legendlabels = ["channel %d"%idchannel for idchannel in channelIndexList] | |
1493 | axes = self.axesList[0] |
|
1472 | axes = self.axesList[0] | |
1494 |
|
1473 | |||
1495 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1474 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1496 |
|
1475 | |||
1497 | if len(self.ydata)==0: |
|
1476 | if len(self.ydata)==0: | |
1498 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
1477 | self.ydata = datadB[channelIndexList].reshape(-1,1) | |
1499 | else: |
|
1478 | else: | |
1500 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
1479 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) | |
1501 |
|
1480 | |||
1502 |
|
1481 | |||
1503 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1482 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1504 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1483 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1505 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
1484 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', | |
1506 | XAxisAsTime=True |
|
1485 | XAxisAsTime=True | |
1507 | ) |
|
1486 | ) | |
1508 |
|
1487 | |||
1509 | self.draw() |
|
1488 | self.draw() | |
1510 |
|
1489 | |||
1511 | if save: |
|
1490 | if save: | |
1512 |
|
1491 | |||
1513 | if figfile == None: |
|
1492 | if figfile == None: | |
1514 | figfile = self.getFilename(name = self.name) |
|
1493 | figfile = self.getFilename(name = self.name) | |
1515 |
|
1494 | |||
1516 | self.saveFigure(figpath, figfile) |
|
1495 | self.saveFigure(figpath, figfile) | |
1517 |
|
1496 | |||
1518 | self.counter_imagwr += 1 |
|
1497 | self.counter_imagwr += 1 | |
1519 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1498 | if (ftp and (self.counter_imagwr==wr_period)): | |
1520 | figfilename = os.path.join(figpath,figfile) |
|
1499 | figfilename = os.path.join(figpath,figfile) | |
1521 | self.sendByFTP(figfilename) |
|
1500 | self.sendByFTP(figfilename) | |
1522 | self.counter_imagwr = 0 |
|
1501 | self.counter_imagwr = 0 | |
1523 |
|
1502 | |||
1524 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1503 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1525 | self.__isConfig = False |
|
1504 | self.__isConfig = False | |
1526 | del self.xdata |
|
1505 | del self.xdata | |
1527 | del self.ydata |
|
1506 | del self.ydata | |
1528 |
|
1507 | |||
1529 |
|
1508 | |||
1530 | No newline at end of file |
|
1509 |
General Comments 0
You need to be logged in to leave comments.
Login now