@@ -1,1543 +1,1695 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 9, 2014 |
|
2 | Created on Jul 9, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import datetime |
|
7 | import datetime | |
8 | import numpy |
|
8 | import numpy | |
9 |
|
9 | |||
10 | from figure import Figure, isRealtime, isTimeInHourRange |
|
10 | from figure import Figure, isRealtime, isTimeInHourRange | |
11 | from plotting_codes import * |
|
11 | from plotting_codes import * | |
12 |
|
12 | |||
13 |
|
13 | |||
14 | class SpectraPlot(Figure): |
|
14 | class SpectraPlot(Figure): | |
15 |
|
15 | |||
16 | isConfig = None |
|
16 | isConfig = None | |
17 | __nsubplots = None |
|
17 | __nsubplots = None | |
18 |
|
18 | |||
19 | WIDTHPROF = None |
|
19 | WIDTHPROF = None | |
20 | HEIGHTPROF = None |
|
20 | HEIGHTPROF = None | |
21 | PREFIX = 'spc' |
|
21 | PREFIX = 'spc' | |
22 |
|
22 | |||
23 | def __init__(self, **kwargs): |
|
23 | def __init__(self, **kwargs): | |
24 | Figure.__init__(self, **kwargs) |
|
24 | Figure.__init__(self, **kwargs) | |
25 | self.isConfig = False |
|
25 | self.isConfig = False | |
26 | self.__nsubplots = 1 |
|
26 | self.__nsubplots = 1 | |
27 |
|
27 | |||
28 | self.WIDTH = 250 |
|
28 | self.WIDTH = 250 | |
29 | self.HEIGHT = 250 |
|
29 | self.HEIGHT = 250 | |
30 | self.WIDTHPROF = 120 |
|
30 | self.WIDTHPROF = 120 | |
31 | self.HEIGHTPROF = 0 |
|
31 | self.HEIGHTPROF = 0 | |
32 | self.counter_imagwr = 0 |
|
32 | self.counter_imagwr = 0 | |
33 |
|
33 | |||
34 | self.PLOT_CODE = SPEC_CODE |
|
34 | self.PLOT_CODE = SPEC_CODE | |
35 |
|
35 | |||
36 | self.FTP_WEI = None |
|
36 | self.FTP_WEI = None | |
37 | self.EXP_CODE = None |
|
37 | self.EXP_CODE = None | |
38 | self.SUB_EXP_CODE = None |
|
38 | self.SUB_EXP_CODE = None | |
39 | self.PLOT_POS = None |
|
39 | self.PLOT_POS = None | |
40 |
|
40 | |||
41 | self.__xfilter_ena = False |
|
41 | self.__xfilter_ena = False | |
42 | self.__yfilter_ena = False |
|
42 | self.__yfilter_ena = False | |
43 |
|
43 | |||
44 | def getSubplots(self): |
|
44 | def getSubplots(self): | |
45 |
|
45 | |||
46 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
46 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
47 | nrow = int(self.nplots*1./ncol + 0.9) |
|
47 | nrow = int(self.nplots*1./ncol + 0.9) | |
48 |
|
48 | |||
49 | return nrow, ncol |
|
49 | return nrow, ncol | |
50 |
|
50 | |||
51 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
51 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
52 |
|
52 | |||
53 | self.__showprofile = showprofile |
|
53 | self.__showprofile = showprofile | |
54 | self.nplots = nplots |
|
54 | self.nplots = nplots | |
55 |
|
55 | |||
56 | ncolspan = 1 |
|
56 | ncolspan = 1 | |
57 | colspan = 1 |
|
57 | colspan = 1 | |
58 | if showprofile: |
|
58 | if showprofile: | |
59 | ncolspan = 3 |
|
59 | ncolspan = 3 | |
60 | colspan = 2 |
|
60 | colspan = 2 | |
61 | self.__nsubplots = 2 |
|
61 | self.__nsubplots = 2 | |
62 |
|
62 | |||
63 | self.createFigure(id = id, |
|
63 | self.createFigure(id = id, | |
64 | wintitle = wintitle, |
|
64 | wintitle = wintitle, | |
65 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
65 | widthplot = self.WIDTH + self.WIDTHPROF, | |
66 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
66 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
67 | show=show) |
|
67 | show=show) | |
68 |
|
68 | |||
69 | nrow, ncol = self.getSubplots() |
|
69 | nrow, ncol = self.getSubplots() | |
70 |
|
70 | |||
71 | counter = 0 |
|
71 | counter = 0 | |
72 | for y in range(nrow): |
|
72 | for y in range(nrow): | |
73 | for x in range(ncol): |
|
73 | for x in range(ncol): | |
74 |
|
74 | |||
75 | if counter >= self.nplots: |
|
75 | if counter >= self.nplots: | |
76 | break |
|
76 | break | |
77 |
|
77 | |||
78 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
78 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
79 |
|
79 | |||
80 | if showprofile: |
|
80 | if showprofile: | |
81 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
81 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
82 |
|
82 | |||
83 | counter += 1 |
|
83 | counter += 1 | |
84 |
|
84 | |||
85 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
85 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
86 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
86 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
87 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
87 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
88 | server=None, folder=None, username=None, password=None, |
|
88 | server=None, folder=None, username=None, password=None, | |
89 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
89 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, | |
90 | xaxis="frequency", colormap='jet', normFactor=None): |
|
90 | xaxis="frequency", colormap='jet', normFactor=None): | |
91 |
|
91 | |||
92 | """ |
|
92 | """ | |
93 |
|
93 | |||
94 | Input: |
|
94 | Input: | |
95 | dataOut : |
|
95 | dataOut : | |
96 | id : |
|
96 | id : | |
97 | wintitle : |
|
97 | wintitle : | |
98 | channelList : |
|
98 | channelList : | |
99 | showProfile : |
|
99 | showProfile : | |
100 | xmin : None, |
|
100 | xmin : None, | |
101 | xmax : None, |
|
101 | xmax : None, | |
102 | ymin : None, |
|
102 | ymin : None, | |
103 | ymax : None, |
|
103 | ymax : None, | |
104 | zmin : None, |
|
104 | zmin : None, | |
105 | zmax : None |
|
105 | zmax : None | |
106 | """ |
|
106 | """ | |
107 | if realtime: |
|
107 | if realtime: | |
108 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
108 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
109 | print 'Skipping this plot function' |
|
109 | print 'Skipping this plot function' | |
110 | return |
|
110 | return | |
111 |
|
111 | |||
112 | if channelList == None: |
|
112 | if channelList == None: | |
113 | channelIndexList = dataOut.channelIndexList |
|
113 | channelIndexList = dataOut.channelIndexList | |
114 | else: |
|
114 | else: | |
115 | channelIndexList = [] |
|
115 | channelIndexList = [] | |
116 | for channel in channelList: |
|
116 | for channel in channelList: | |
117 | if channel not in dataOut.channelList: |
|
117 | if channel not in dataOut.channelList: | |
118 | raise ValueError, "Channel %d is not in dataOut.channelList" %channel |
|
118 | raise ValueError, "Channel %d is not in dataOut.channelList" %channel | |
119 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
119 | channelIndexList.append(dataOut.channelList.index(channel)) | |
120 |
|
120 | |||
121 | if normFactor is None: |
|
121 | if normFactor is None: | |
122 | factor = dataOut.normFactor |
|
122 | factor = dataOut.normFactor | |
123 | else: |
|
123 | else: | |
124 | factor = normFactor |
|
124 | factor = normFactor | |
125 | if xaxis == "frequency": |
|
125 | if xaxis == "frequency": | |
126 | x = dataOut.getFreqRange(1)/1000. |
|
126 | x = dataOut.getFreqRange(1)/1000. | |
127 | xlabel = "Frequency (kHz)" |
|
127 | xlabel = "Frequency (kHz)" | |
128 |
|
128 | |||
129 | elif xaxis == "time": |
|
129 | elif xaxis == "time": | |
130 | x = dataOut.getAcfRange(1) |
|
130 | x = dataOut.getAcfRange(1) | |
131 | xlabel = "Time (ms)" |
|
131 | xlabel = "Time (ms)" | |
132 |
|
132 | |||
133 | else: |
|
133 | else: | |
134 | x = dataOut.getVelRange(1) |
|
134 | x = dataOut.getVelRange(1) | |
135 | xlabel = "Velocity (m/s)" |
|
135 | xlabel = "Velocity (m/s)" | |
136 |
|
136 | |||
137 | ylabel = "Range (Km)" |
|
137 | ylabel = "Range (Km)" | |
138 |
|
138 | |||
139 | y = dataOut.getHeiRange() |
|
139 | y = dataOut.getHeiRange() | |
140 |
|
140 | |||
141 | z = dataOut.data_spc/factor |
|
141 | z = dataOut.data_spc/factor | |
142 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
142 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
143 | zdB = 10*numpy.log10(z) |
|
143 | zdB = 10*numpy.log10(z) | |
144 |
|
144 | |||
145 | #print "a000",dataOut.data_spc.dtype |
|
145 | #print "a000",dataOut.data_spc.dtype | |
146 | avg = numpy.average(z, axis=1) |
|
146 | avg = numpy.average(z, axis=1) | |
147 | avgdB = 10*numpy.log10(avg) |
|
147 | avgdB = 10*numpy.log10(avg) | |
148 | #print "before plot" |
|
148 | #print "before plot" | |
149 | noise = dataOut.getNoise()/factor |
|
149 | noise = dataOut.getNoise()/factor | |
150 | noisedB = 10*numpy.log10(noise) |
|
150 | noisedB = 10*numpy.log10(noise) | |
151 |
|
151 | |||
152 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
152 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
153 | title = wintitle + " Spectra" |
|
153 | title = wintitle + " Spectra" | |
154 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
154 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
155 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
155 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |
156 |
|
156 | |||
157 | if not self.isConfig: |
|
157 | if not self.isConfig: | |
158 |
|
158 | |||
159 | nplots = len(channelIndexList) |
|
159 | nplots = len(channelIndexList) | |
160 |
|
160 | |||
161 | self.setup(id=id, |
|
161 | self.setup(id=id, | |
162 | nplots=nplots, |
|
162 | nplots=nplots, | |
163 | wintitle=wintitle, |
|
163 | wintitle=wintitle, | |
164 | showprofile=showprofile, |
|
164 | showprofile=showprofile, | |
165 | show=show) |
|
165 | show=show) | |
166 |
|
166 | |||
167 | if xmin == None: xmin = numpy.nanmin(x) |
|
167 | if xmin == None: xmin = numpy.nanmin(x) | |
168 | if xmax == None: xmax = numpy.nanmax(x) |
|
168 | if xmax == None: xmax = numpy.nanmax(x) | |
169 | if ymin == None: ymin = numpy.nanmin(y) |
|
169 | if ymin == None: ymin = numpy.nanmin(y) | |
170 | if ymax == None: ymax = numpy.nanmax(y) |
|
170 | if ymax == None: ymax = numpy.nanmax(y) | |
171 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
171 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
172 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
172 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
173 |
|
173 | |||
174 | self.FTP_WEI = ftp_wei |
|
174 | self.FTP_WEI = ftp_wei | |
175 | self.EXP_CODE = exp_code |
|
175 | self.EXP_CODE = exp_code | |
176 | self.SUB_EXP_CODE = sub_exp_code |
|
176 | self.SUB_EXP_CODE = sub_exp_code | |
177 | self.PLOT_POS = plot_pos |
|
177 | self.PLOT_POS = plot_pos | |
178 |
|
178 | |||
179 | self.isConfig = True |
|
179 | self.isConfig = True | |
180 |
|
180 | |||
181 | self.setWinTitle(title) |
|
181 | self.setWinTitle(title) | |
182 |
|
182 | |||
183 | for i in range(self.nplots): |
|
183 | for i in range(self.nplots): | |
184 | index = channelIndexList[i] |
|
184 | index = channelIndexList[i] | |
185 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
185 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
186 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
186 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) | |
187 | if len(dataOut.beam.codeList) != 0: |
|
187 | if len(dataOut.beam.codeList) != 0: | |
188 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
188 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) | |
189 |
|
189 | |||
190 | axes = self.axesList[i*self.__nsubplots] |
|
190 | axes = self.axesList[i*self.__nsubplots] | |
191 | axes.pcolor(x, y, zdB[index,:,:], |
|
191 | axes.pcolor(x, y, zdB[index,:,:], | |
192 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
192 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
193 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
193 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, | |
194 | ticksize=9, cblabel='') |
|
194 | ticksize=9, cblabel='') | |
195 |
|
195 | |||
196 | if self.__showprofile: |
|
196 | if self.__showprofile: | |
197 | axes = self.axesList[i*self.__nsubplots +1] |
|
197 | axes = self.axesList[i*self.__nsubplots +1] | |
198 | axes.pline(avgdB[index,:], y, |
|
198 | axes.pline(avgdB[index,:], y, | |
199 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
199 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
200 | xlabel='dB', ylabel='', title='', |
|
200 | xlabel='dB', ylabel='', title='', | |
201 | ytick_visible=False, |
|
201 | ytick_visible=False, | |
202 | grid='x') |
|
202 | grid='x') | |
203 |
|
203 | |||
204 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
204 | noiseline = numpy.repeat(noisedB[index], len(y)) | |
205 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
205 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
206 |
|
206 | |||
207 | self.draw() |
|
207 | self.draw() | |
208 |
|
208 | |||
209 | if figfile == None: |
|
209 | if figfile == None: | |
210 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
210 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
211 | name = str_datetime |
|
211 | name = str_datetime | |
212 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
212 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
213 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
213 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) | |
214 | figfile = self.getFilename(name) |
|
214 | figfile = self.getFilename(name) | |
215 |
|
215 | |||
216 | self.save(figpath=figpath, |
|
216 | self.save(figpath=figpath, | |
217 | figfile=figfile, |
|
217 | figfile=figfile, | |
218 | save=save, |
|
218 | save=save, | |
219 | ftp=ftp, |
|
219 | ftp=ftp, | |
220 | wr_period=wr_period, |
|
220 | wr_period=wr_period, | |
221 | thisDatetime=thisDatetime) |
|
221 | thisDatetime=thisDatetime) | |
222 |
|
222 | |||
|
223 | class ACFPlot(Figure): | |||
|
224 | ||||
|
225 | isConfig = None | |||
|
226 | __nsubplots = None | |||
|
227 | ||||
|
228 | WIDTHPROF = None | |||
|
229 | HEIGHTPROF = None | |||
|
230 | PREFIX = 'acf' | |||
|
231 | ||||
|
232 | def __init__(self, **kwargs): | |||
|
233 | Figure.__init__(self, **kwargs) | |||
|
234 | self.isConfig = False | |||
|
235 | self.__nsubplots = 1 | |||
|
236 | ||||
|
237 | self.PLOT_CODE = POWER_CODE | |||
|
238 | ||||
|
239 | self.WIDTH = 700 | |||
|
240 | self.HEIGHT = 500 | |||
|
241 | self.counter_imagwr = 0 | |||
|
242 | ||||
|
243 | def getSubplots(self): | |||
|
244 | ncol = 1 | |||
|
245 | nrow = 1 | |||
|
246 | ||||
|
247 | return nrow, ncol | |||
|
248 | ||||
|
249 | def setup(self, id, nplots, wintitle, show): | |||
|
250 | ||||
|
251 | self.nplots = nplots | |||
|
252 | ||||
|
253 | ncolspan = 1 | |||
|
254 | colspan = 1 | |||
|
255 | ||||
|
256 | self.createFigure(id = id, | |||
|
257 | wintitle = wintitle, | |||
|
258 | widthplot = self.WIDTH, | |||
|
259 | heightplot = self.HEIGHT, | |||
|
260 | show=show) | |||
|
261 | ||||
|
262 | nrow, ncol = self.getSubplots() | |||
|
263 | ||||
|
264 | counter = 0 | |||
|
265 | for y in range(nrow): | |||
|
266 | for x in range(ncol): | |||
|
267 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |||
|
268 | ||||
|
269 | def run(self, dataOut, id, wintitle="", channelList=None, | |||
|
270 | xmin=None, xmax=None, ymin=None, ymax=None, | |||
|
271 | save=False, figpath='./', figfile=None, show=True, | |||
|
272 | ftp=False, wr_period=1, server=None, | |||
|
273 | folder=None, username=None, password=None, | |||
|
274 | xaxis="frequency"): | |||
|
275 | ||||
|
276 | ||||
|
277 | if channelList == None: | |||
|
278 | channelIndexList = dataOut.channelIndexList | |||
|
279 | channelList = dataOut.channelList | |||
|
280 | else: | |||
|
281 | channelIndexList = [] | |||
|
282 | for channel in channelList: | |||
|
283 | if channel not in dataOut.channelList: | |||
|
284 | raise ValueError, "Channel %d is not in dataOut.channelList" | |||
|
285 | channelIndexList.append(dataOut.channelList.index(channel)) | |||
|
286 | ||||
|
287 | factor = dataOut.normFactor | |||
|
288 | ||||
|
289 | y = dataOut.getHeiRange() | |||
|
290 | ||||
|
291 | #z = dataOut.data_spc/factor | |||
|
292 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |||
|
293 | print deltaHeight | |||
|
294 | z = dataOut.data_spc | |||
|
295 | ||||
|
296 | #z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |||
|
297 | shape = dataOut.data_spc.shape | |||
|
298 | for i in range(shape[0]): | |||
|
299 | for j in range(shape[2]): | |||
|
300 | z[i,:,j]= (z[i,:,j]+1.0)*deltaHeight*5/2.0 + j*deltaHeight | |||
|
301 | #z[i,:,j]= (z[i,:,j]+1.0)*deltaHeight*dataOut.step/2.0 + j*deltaHeight*dataOut.step | |||
|
302 | ||||
|
303 | hei_index = numpy.arange(shape[2]) | |||
|
304 | #print hei_index.shape | |||
|
305 | #b = [] | |||
|
306 | #for i in range(hei_index.shape[0]): | |||
|
307 | # if hei_index[i]%30 == 0: | |||
|
308 | # b.append(hei_index[i]) | |||
|
309 | ||||
|
310 | #hei_index= numpy.array(b) | |||
|
311 | hei_index = hei_index[300:320] | |||
|
312 | #hei_index = numpy.arange(20)*30+80 | |||
|
313 | hei_index= numpy.arange(20)*5 | |||
|
314 | if xaxis == "frequency": | |||
|
315 | x = dataOut.getFreqRange()/1000. | |||
|
316 | zdB = 10*numpy.log10(z[0,:,hei_index]) | |||
|
317 | xlabel = "Frequency (kHz)" | |||
|
318 | ylabel = "Power (dB)" | |||
|
319 | ||||
|
320 | elif xaxis == "time": | |||
|
321 | x = dataOut.getAcfRange() | |||
|
322 | zdB = z[0,:,hei_index] | |||
|
323 | xlabel = "Time (ms)" | |||
|
324 | ylabel = "ACF" | |||
|
325 | ||||
|
326 | else: | |||
|
327 | x = dataOut.getVelRange() | |||
|
328 | zdB = 10*numpy.log10(z[0,:,hei_index]) | |||
|
329 | xlabel = "Velocity (m/s)" | |||
|
330 | ylabel = "Power (dB)" | |||
|
331 | ||||
|
332 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |||
|
333 | title = wintitle + " ACF Plot %s" %(thisDatetime.strftime("%d-%b-%Y")) | |||
|
334 | ||||
|
335 | if not self.isConfig: | |||
|
336 | ||||
|
337 | nplots = 1 | |||
|
338 | ||||
|
339 | self.setup(id=id, | |||
|
340 | nplots=nplots, | |||
|
341 | wintitle=wintitle, | |||
|
342 | show=show) | |||
|
343 | ||||
|
344 | if xmin == None: xmin = numpy.nanmin(x)*0.9 | |||
|
345 | if xmax == None: xmax = numpy.nanmax(x)*1.1 | |||
|
346 | if ymin == None: ymin = numpy.nanmin(zdB) | |||
|
347 | if ymax == None: ymax = numpy.nanmax(zdB) | |||
|
348 | ||||
|
349 | self.isConfig = True | |||
|
350 | ||||
|
351 | self.setWinTitle(title) | |||
|
352 | ||||
|
353 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
354 | axes = self.axesList[0] | |||
|
355 | ||||
|
356 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] | |||
|
357 | ||||
|
358 | axes.pmultilineyaxis( x, zdB, | |||
|
359 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |||
|
360 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |||
|
361 | ytick_visible=True, nxticks=5, | |||
|
362 | grid='x') | |||
|
363 | ||||
|
364 | self.draw() | |||
|
365 | ||||
|
366 | self.save(figpath=figpath, | |||
|
367 | figfile=figfile, | |||
|
368 | save=save, | |||
|
369 | ftp=ftp, | |||
|
370 | wr_period=wr_period, | |||
|
371 | thisDatetime=thisDatetime) | |||
|
372 | ||||
|
373 | ||||
|
374 | ||||
223 | class CrossSpectraPlot(Figure): |
|
375 | class CrossSpectraPlot(Figure): | |
224 |
|
376 | |||
225 | isConfig = None |
|
377 | isConfig = None | |
226 | __nsubplots = None |
|
378 | __nsubplots = None | |
227 |
|
379 | |||
228 | WIDTH = None |
|
380 | WIDTH = None | |
229 | HEIGHT = None |
|
381 | HEIGHT = None | |
230 | WIDTHPROF = None |
|
382 | WIDTHPROF = None | |
231 | HEIGHTPROF = None |
|
383 | HEIGHTPROF = None | |
232 | PREFIX = 'cspc' |
|
384 | PREFIX = 'cspc' | |
233 |
|
385 | |||
234 | def __init__(self, **kwargs): |
|
386 | def __init__(self, **kwargs): | |
235 | Figure.__init__(self, **kwargs) |
|
387 | Figure.__init__(self, **kwargs) | |
236 | self.isConfig = False |
|
388 | self.isConfig = False | |
237 | self.__nsubplots = 4 |
|
389 | self.__nsubplots = 4 | |
238 | self.counter_imagwr = 0 |
|
390 | self.counter_imagwr = 0 | |
239 | self.WIDTH = 250 |
|
391 | self.WIDTH = 250 | |
240 | self.HEIGHT = 250 |
|
392 | self.HEIGHT = 250 | |
241 | self.WIDTHPROF = 0 |
|
393 | self.WIDTHPROF = 0 | |
242 | self.HEIGHTPROF = 0 |
|
394 | self.HEIGHTPROF = 0 | |
243 |
|
395 | |||
244 | self.PLOT_CODE = CROSS_CODE |
|
396 | self.PLOT_CODE = CROSS_CODE | |
245 | self.FTP_WEI = None |
|
397 | self.FTP_WEI = None | |
246 | self.EXP_CODE = None |
|
398 | self.EXP_CODE = None | |
247 | self.SUB_EXP_CODE = None |
|
399 | self.SUB_EXP_CODE = None | |
248 | self.PLOT_POS = None |
|
400 | self.PLOT_POS = None | |
249 |
|
401 | |||
250 | def getSubplots(self): |
|
402 | def getSubplots(self): | |
251 |
|
403 | |||
252 | ncol = 4 |
|
404 | ncol = 4 | |
253 | nrow = self.nplots |
|
405 | nrow = self.nplots | |
254 |
|
406 | |||
255 | return nrow, ncol |
|
407 | return nrow, ncol | |
256 |
|
408 | |||
257 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
409 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
258 |
|
410 | |||
259 | self.__showprofile = showprofile |
|
411 | self.__showprofile = showprofile | |
260 | self.nplots = nplots |
|
412 | self.nplots = nplots | |
261 |
|
413 | |||
262 | ncolspan = 1 |
|
414 | ncolspan = 1 | |
263 | colspan = 1 |
|
415 | colspan = 1 | |
264 |
|
416 | |||
265 | self.createFigure(id = id, |
|
417 | self.createFigure(id = id, | |
266 | wintitle = wintitle, |
|
418 | wintitle = wintitle, | |
267 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
419 | widthplot = self.WIDTH + self.WIDTHPROF, | |
268 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
420 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
269 | show=True) |
|
421 | show=True) | |
270 |
|
422 | |||
271 | nrow, ncol = self.getSubplots() |
|
423 | nrow, ncol = self.getSubplots() | |
272 |
|
424 | |||
273 | counter = 0 |
|
425 | counter = 0 | |
274 | for y in range(nrow): |
|
426 | for y in range(nrow): | |
275 | for x in range(ncol): |
|
427 | for x in range(ncol): | |
276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
428 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
277 |
|
429 | |||
278 | counter += 1 |
|
430 | counter += 1 | |
279 |
|
431 | |||
280 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
432 | def run(self, dataOut, id, wintitle="", pairsList=None, | |
281 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
433 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
282 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, |
|
434 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, | |
283 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
435 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
284 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
436 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
285 | server=None, folder=None, username=None, password=None, |
|
437 | server=None, folder=None, username=None, password=None, | |
286 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, |
|
438 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, | |
287 | xaxis='frequency'): |
|
439 | xaxis='frequency'): | |
288 |
|
440 | |||
289 | """ |
|
441 | """ | |
290 |
|
442 | |||
291 | Input: |
|
443 | Input: | |
292 | dataOut : |
|
444 | dataOut : | |
293 | id : |
|
445 | id : | |
294 | wintitle : |
|
446 | wintitle : | |
295 | channelList : |
|
447 | channelList : | |
296 | showProfile : |
|
448 | showProfile : | |
297 | xmin : None, |
|
449 | xmin : None, | |
298 | xmax : None, |
|
450 | xmax : None, | |
299 | ymin : None, |
|
451 | ymin : None, | |
300 | ymax : None, |
|
452 | ymax : None, | |
301 | zmin : None, |
|
453 | zmin : None, | |
302 | zmax : None |
|
454 | zmax : None | |
303 | """ |
|
455 | """ | |
304 |
|
456 | |||
305 | if pairsList == None: |
|
457 | if pairsList == None: | |
306 | pairsIndexList = dataOut.pairsIndexList |
|
458 | pairsIndexList = dataOut.pairsIndexList | |
307 | else: |
|
459 | else: | |
308 | pairsIndexList = [] |
|
460 | pairsIndexList = [] | |
309 | for pair in pairsList: |
|
461 | for pair in pairsList: | |
310 | if pair not in dataOut.pairsList: |
|
462 | if pair not in dataOut.pairsList: | |
311 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) |
|
463 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) | |
312 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
464 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
313 |
|
465 | |||
314 | if not pairsIndexList: |
|
466 | if not pairsIndexList: | |
315 | return |
|
467 | return | |
316 |
|
468 | |||
317 | if len(pairsIndexList) > 4: |
|
469 | if len(pairsIndexList) > 4: | |
318 | pairsIndexList = pairsIndexList[0:4] |
|
470 | pairsIndexList = pairsIndexList[0:4] | |
319 |
|
471 | |||
320 | if normFactor is None: |
|
472 | if normFactor is None: | |
321 | factor = dataOut.normFactor |
|
473 | factor = dataOut.normFactor | |
322 | else: |
|
474 | else: | |
323 | factor = normFactor |
|
475 | factor = normFactor | |
324 | x = dataOut.getVelRange(1) |
|
476 | x = dataOut.getVelRange(1) | |
325 | y = dataOut.getHeiRange() |
|
477 | y = dataOut.getHeiRange() | |
326 | z = dataOut.data_spc[:,:,:]/factor |
|
478 | z = dataOut.data_spc[:,:,:]/factor | |
327 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
479 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
328 |
|
480 | |||
329 | noise = dataOut.noise/factor |
|
481 | noise = dataOut.noise/factor | |
330 |
|
482 | |||
331 | zdB = 10*numpy.log10(z) |
|
483 | zdB = 10*numpy.log10(z) | |
332 | noisedB = 10*numpy.log10(noise) |
|
484 | noisedB = 10*numpy.log10(noise) | |
333 |
|
485 | |||
334 | if coh_min == None: |
|
486 | if coh_min == None: | |
335 | coh_min = 0.0 |
|
487 | coh_min = 0.0 | |
336 | if coh_max == None: |
|
488 | if coh_max == None: | |
337 | coh_max = 1.0 |
|
489 | coh_max = 1.0 | |
338 |
|
490 | |||
339 | if phase_min == None: |
|
491 | if phase_min == None: | |
340 | phase_min = -180 |
|
492 | phase_min = -180 | |
341 | if phase_max == None: |
|
493 | if phase_max == None: | |
342 | phase_max = 180 |
|
494 | phase_max = 180 | |
343 |
|
495 | |||
344 | #thisDatetime = dataOut.datatime |
|
496 | #thisDatetime = dataOut.datatime | |
345 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
497 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
346 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
498 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
347 | # xlabel = "Velocity (m/s)" |
|
499 | # xlabel = "Velocity (m/s)" | |
348 | ylabel = "Range (Km)" |
|
500 | ylabel = "Range (Km)" | |
349 |
|
501 | |||
350 | if xaxis == "frequency": |
|
502 | if xaxis == "frequency": | |
351 | x = dataOut.getFreqRange(1)/1000. |
|
503 | x = dataOut.getFreqRange(1)/1000. | |
352 | xlabel = "Frequency (kHz)" |
|
504 | xlabel = "Frequency (kHz)" | |
353 |
|
505 | |||
354 | elif xaxis == "time": |
|
506 | elif xaxis == "time": | |
355 | x = dataOut.getAcfRange(1) |
|
507 | x = dataOut.getAcfRange(1) | |
356 | xlabel = "Time (ms)" |
|
508 | xlabel = "Time (ms)" | |
357 |
|
509 | |||
358 | else: |
|
510 | else: | |
359 | x = dataOut.getVelRange(1) |
|
511 | x = dataOut.getVelRange(1) | |
360 | xlabel = "Velocity (m/s)" |
|
512 | xlabel = "Velocity (m/s)" | |
361 |
|
513 | |||
362 | if not self.isConfig: |
|
514 | if not self.isConfig: | |
363 |
|
515 | |||
364 | nplots = len(pairsIndexList) |
|
516 | nplots = len(pairsIndexList) | |
365 |
|
517 | |||
366 | self.setup(id=id, |
|
518 | self.setup(id=id, | |
367 | nplots=nplots, |
|
519 | nplots=nplots, | |
368 | wintitle=wintitle, |
|
520 | wintitle=wintitle, | |
369 | showprofile=False, |
|
521 | showprofile=False, | |
370 | show=show) |
|
522 | show=show) | |
371 |
|
523 | |||
372 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
524 | avg = numpy.abs(numpy.average(z, axis=1)) | |
373 | avgdB = 10*numpy.log10(avg) |
|
525 | avgdB = 10*numpy.log10(avg) | |
374 |
|
526 | |||
375 | if xmin == None: xmin = numpy.nanmin(x) |
|
527 | if xmin == None: xmin = numpy.nanmin(x) | |
376 | if xmax == None: xmax = numpy.nanmax(x) |
|
528 | if xmax == None: xmax = numpy.nanmax(x) | |
377 | if ymin == None: ymin = numpy.nanmin(y) |
|
529 | if ymin == None: ymin = numpy.nanmin(y) | |
378 | if ymax == None: ymax = numpy.nanmax(y) |
|
530 | if ymax == None: ymax = numpy.nanmax(y) | |
379 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
531 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
380 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
532 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
381 |
|
533 | |||
382 | self.FTP_WEI = ftp_wei |
|
534 | self.FTP_WEI = ftp_wei | |
383 | self.EXP_CODE = exp_code |
|
535 | self.EXP_CODE = exp_code | |
384 | self.SUB_EXP_CODE = sub_exp_code |
|
536 | self.SUB_EXP_CODE = sub_exp_code | |
385 | self.PLOT_POS = plot_pos |
|
537 | self.PLOT_POS = plot_pos | |
386 |
|
538 | |||
387 | self.isConfig = True |
|
539 | self.isConfig = True | |
388 |
|
540 | |||
389 | self.setWinTitle(title) |
|
541 | self.setWinTitle(title) | |
390 |
|
542 | |||
391 | for i in range(self.nplots): |
|
543 | for i in range(self.nplots): | |
392 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
544 | pair = dataOut.pairsList[pairsIndexList[i]] | |
393 |
|
545 | |||
394 | chan_index0 = dataOut.channelList.index(pair[0]) |
|
546 | chan_index0 = dataOut.channelList.index(pair[0]) | |
395 | chan_index1 = dataOut.channelList.index(pair[1]) |
|
547 | chan_index1 = dataOut.channelList.index(pair[1]) | |
396 |
|
548 | |||
397 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
549 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
398 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) |
|
550 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) | |
399 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) |
|
551 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) | |
400 | axes0 = self.axesList[i*self.__nsubplots] |
|
552 | axes0 = self.axesList[i*self.__nsubplots] | |
401 | axes0.pcolor(x, y, zdB, |
|
553 | axes0.pcolor(x, y, zdB, | |
402 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
554 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
403 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
555 | xlabel=xlabel, ylabel=ylabel, title=title, | |
404 | ticksize=9, colormap=power_cmap, cblabel='') |
|
556 | ticksize=9, colormap=power_cmap, cblabel='') | |
405 |
|
557 | |||
406 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) |
|
558 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) | |
407 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) |
|
559 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) | |
408 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
560 | axes0 = self.axesList[i*self.__nsubplots+1] | |
409 | axes0.pcolor(x, y, zdB, |
|
561 | axes0.pcolor(x, y, zdB, | |
410 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
562 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
411 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
563 | xlabel=xlabel, ylabel=ylabel, title=title, | |
412 | ticksize=9, colormap=power_cmap, cblabel='') |
|
564 | ticksize=9, colormap=power_cmap, cblabel='') | |
413 |
|
565 | |||
414 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:]) |
|
566 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:]) | |
415 | coherence = numpy.abs(coherenceComplex) |
|
567 | coherence = numpy.abs(coherenceComplex) | |
416 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
568 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
417 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
569 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
418 |
|
570 | |||
419 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) |
|
571 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) | |
420 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
572 | axes0 = self.axesList[i*self.__nsubplots+2] | |
421 | axes0.pcolor(x, y, coherence, |
|
573 | axes0.pcolor(x, y, coherence, | |
422 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, |
|
574 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, | |
423 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
575 | xlabel=xlabel, ylabel=ylabel, title=title, | |
424 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
576 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
425 |
|
577 | |||
426 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) |
|
578 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) | |
427 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
579 | axes0 = self.axesList[i*self.__nsubplots+3] | |
428 | axes0.pcolor(x, y, phase, |
|
580 | axes0.pcolor(x, y, phase, | |
429 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
581 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, | |
430 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
582 | xlabel=xlabel, ylabel=ylabel, title=title, | |
431 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
583 | ticksize=9, colormap=phase_cmap, cblabel='') | |
432 |
|
584 | |||
433 |
|
585 | |||
434 |
|
586 | |||
435 | self.draw() |
|
587 | self.draw() | |
436 |
|
588 | |||
437 | self.save(figpath=figpath, |
|
589 | self.save(figpath=figpath, | |
438 | figfile=figfile, |
|
590 | figfile=figfile, | |
439 | save=save, |
|
591 | save=save, | |
440 | ftp=ftp, |
|
592 | ftp=ftp, | |
441 | wr_period=wr_period, |
|
593 | wr_period=wr_period, | |
442 | thisDatetime=thisDatetime) |
|
594 | thisDatetime=thisDatetime) | |
443 |
|
595 | |||
444 |
|
596 | |||
445 | class RTIPlot(Figure): |
|
597 | class RTIPlot(Figure): | |
446 |
|
598 | |||
447 | __isConfig = None |
|
599 | __isConfig = None | |
448 | __nsubplots = None |
|
600 | __nsubplots = None | |
449 |
|
601 | |||
450 | WIDTHPROF = None |
|
602 | WIDTHPROF = None | |
451 | HEIGHTPROF = None |
|
603 | HEIGHTPROF = None | |
452 | PREFIX = 'rti' |
|
604 | PREFIX = 'rti' | |
453 |
|
605 | |||
454 | def __init__(self, **kwargs): |
|
606 | def __init__(self, **kwargs): | |
455 |
|
607 | |||
456 | Figure.__init__(self, **kwargs) |
|
608 | Figure.__init__(self, **kwargs) | |
457 | self.timerange = None |
|
609 | self.timerange = None | |
458 | self.isConfig = False |
|
610 | self.isConfig = False | |
459 | self.__nsubplots = 1 |
|
611 | self.__nsubplots = 1 | |
460 |
|
612 | |||
461 | self.WIDTH = 800 |
|
613 | self.WIDTH = 800 | |
462 | self.HEIGHT = 180 |
|
614 | self.HEIGHT = 180 | |
463 | self.WIDTHPROF = 120 |
|
615 | self.WIDTHPROF = 120 | |
464 | self.HEIGHTPROF = 0 |
|
616 | self.HEIGHTPROF = 0 | |
465 | self.counter_imagwr = 0 |
|
617 | self.counter_imagwr = 0 | |
466 |
|
618 | |||
467 | self.PLOT_CODE = RTI_CODE |
|
619 | self.PLOT_CODE = RTI_CODE | |
468 |
|
620 | |||
469 | self.FTP_WEI = None |
|
621 | self.FTP_WEI = None | |
470 | self.EXP_CODE = None |
|
622 | self.EXP_CODE = None | |
471 | self.SUB_EXP_CODE = None |
|
623 | self.SUB_EXP_CODE = None | |
472 | self.PLOT_POS = None |
|
624 | self.PLOT_POS = None | |
473 | self.tmin = None |
|
625 | self.tmin = None | |
474 | self.tmax = None |
|
626 | self.tmax = None | |
475 |
|
627 | |||
476 | self.xmin = None |
|
628 | self.xmin = None | |
477 | self.xmax = None |
|
629 | self.xmax = None | |
478 |
|
630 | |||
479 | self.figfile = None |
|
631 | self.figfile = None | |
480 |
|
632 | |||
481 | def getSubplots(self): |
|
633 | def getSubplots(self): | |
482 |
|
634 | |||
483 | ncol = 1 |
|
635 | ncol = 1 | |
484 | nrow = self.nplots |
|
636 | nrow = self.nplots | |
485 |
|
637 | |||
486 | return nrow, ncol |
|
638 | return nrow, ncol | |
487 |
|
639 | |||
488 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
640 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
489 |
|
641 | |||
490 | self.__showprofile = showprofile |
|
642 | self.__showprofile = showprofile | |
491 | self.nplots = nplots |
|
643 | self.nplots = nplots | |
492 |
|
644 | |||
493 | ncolspan = 1 |
|
645 | ncolspan = 1 | |
494 | colspan = 1 |
|
646 | colspan = 1 | |
495 | if showprofile: |
|
647 | if showprofile: | |
496 | ncolspan = 7 |
|
648 | ncolspan = 7 | |
497 | colspan = 6 |
|
649 | colspan = 6 | |
498 | self.__nsubplots = 2 |
|
650 | self.__nsubplots = 2 | |
499 |
|
651 | |||
500 | self.createFigure(id = id, |
|
652 | self.createFigure(id = id, | |
501 | wintitle = wintitle, |
|
653 | wintitle = wintitle, | |
502 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
654 | widthplot = self.WIDTH + self.WIDTHPROF, | |
503 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
655 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
504 | show=show) |
|
656 | show=show) | |
505 |
|
657 | |||
506 | nrow, ncol = self.getSubplots() |
|
658 | nrow, ncol = self.getSubplots() | |
507 |
|
659 | |||
508 | counter = 0 |
|
660 | counter = 0 | |
509 | for y in range(nrow): |
|
661 | for y in range(nrow): | |
510 | for x in range(ncol): |
|
662 | for x in range(ncol): | |
511 |
|
663 | |||
512 | if counter >= self.nplots: |
|
664 | if counter >= self.nplots: | |
513 | break |
|
665 | break | |
514 |
|
666 | |||
515 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
667 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
516 |
|
668 | |||
517 | if showprofile: |
|
669 | if showprofile: | |
518 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
670 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
519 |
|
671 | |||
520 | counter += 1 |
|
672 | counter += 1 | |
521 |
|
673 | |||
522 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
674 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
523 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
675 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
524 | timerange=None, colormap='jet', |
|
676 | timerange=None, colormap='jet', | |
525 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
677 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
526 | server=None, folder=None, username=None, password=None, |
|
678 | server=None, folder=None, username=None, password=None, | |
527 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None): |
|
679 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None): | |
528 |
|
680 | |||
529 | """ |
|
681 | """ | |
530 |
|
682 | |||
531 | Input: |
|
683 | Input: | |
532 | dataOut : |
|
684 | dataOut : | |
533 | id : |
|
685 | id : | |
534 | wintitle : |
|
686 | wintitle : | |
535 | channelList : |
|
687 | channelList : | |
536 | showProfile : |
|
688 | showProfile : | |
537 | xmin : None, |
|
689 | xmin : None, | |
538 | xmax : None, |
|
690 | xmax : None, | |
539 | ymin : None, |
|
691 | ymin : None, | |
540 | ymax : None, |
|
692 | ymax : None, | |
541 | zmin : None, |
|
693 | zmin : None, | |
542 | zmax : None |
|
694 | zmax : None | |
543 | """ |
|
695 | """ | |
544 |
|
696 | |||
545 | #colormap = kwargs.get('colormap', 'jet') |
|
697 | #colormap = kwargs.get('colormap', 'jet') | |
546 | if HEIGHT is not None: |
|
698 | if HEIGHT is not None: | |
547 | self.HEIGHT = HEIGHT |
|
699 | self.HEIGHT = HEIGHT | |
548 |
|
700 | |||
549 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
701 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | |
550 | return |
|
702 | return | |
551 |
|
703 | |||
552 | if channelList == None: |
|
704 | if channelList == None: | |
553 | channelIndexList = dataOut.channelIndexList |
|
705 | channelIndexList = dataOut.channelIndexList | |
554 | else: |
|
706 | else: | |
555 | channelIndexList = [] |
|
707 | channelIndexList = [] | |
556 | for channel in channelList: |
|
708 | for channel in channelList: | |
557 | if channel not in dataOut.channelList: |
|
709 | if channel not in dataOut.channelList: | |
558 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
710 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
559 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
711 | channelIndexList.append(dataOut.channelList.index(channel)) | |
560 |
|
712 | |||
561 | if normFactor is None: |
|
713 | if normFactor is None: | |
562 | factor = dataOut.normFactor |
|
714 | factor = dataOut.normFactor | |
563 | else: |
|
715 | else: | |
564 | factor = normFactor |
|
716 | factor = normFactor | |
565 |
|
717 | |||
566 | # factor = dataOut.normFactor |
|
718 | # factor = dataOut.normFactor | |
567 | x = dataOut.getTimeRange() |
|
719 | x = dataOut.getTimeRange() | |
568 | y = dataOut.getHeiRange() |
|
720 | y = dataOut.getHeiRange() | |
569 |
|
721 | |||
570 | z = dataOut.data_spc/factor |
|
722 | z = dataOut.data_spc/factor | |
571 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
723 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
572 | avg = numpy.average(z, axis=1) |
|
724 | avg = numpy.average(z, axis=1) | |
573 | avgdB = 10.*numpy.log10(avg) |
|
725 | avgdB = 10.*numpy.log10(avg) | |
574 | # avgdB = dataOut.getPower() |
|
726 | # avgdB = dataOut.getPower() | |
575 |
|
727 | |||
576 |
|
728 | |||
577 | thisDatetime = dataOut.datatime |
|
729 | thisDatetime = dataOut.datatime | |
578 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
730 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
579 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
731 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
580 | xlabel = "" |
|
732 | xlabel = "" | |
581 | ylabel = "Range (Km)" |
|
733 | ylabel = "Range (Km)" | |
582 |
|
734 | |||
583 | update_figfile = False |
|
735 | update_figfile = False | |
584 |
|
736 | |||
585 | if dataOut.ltctime >= self.xmax: |
|
737 | if dataOut.ltctime >= self.xmax: | |
586 | self.counter_imagwr = wr_period |
|
738 | self.counter_imagwr = wr_period | |
587 | self.isConfig = False |
|
739 | self.isConfig = False | |
588 | update_figfile = True |
|
740 | update_figfile = True | |
589 |
|
741 | |||
590 | if not self.isConfig: |
|
742 | if not self.isConfig: | |
591 |
|
743 | |||
592 | nplots = len(channelIndexList) |
|
744 | nplots = len(channelIndexList) | |
593 |
|
745 | |||
594 | self.setup(id=id, |
|
746 | self.setup(id=id, | |
595 | nplots=nplots, |
|
747 | nplots=nplots, | |
596 | wintitle=wintitle, |
|
748 | wintitle=wintitle, | |
597 | showprofile=showprofile, |
|
749 | showprofile=showprofile, | |
598 | show=show) |
|
750 | show=show) | |
599 |
|
751 | |||
600 | if timerange != None: |
|
752 | if timerange != None: | |
601 | self.timerange = timerange |
|
753 | self.timerange = timerange | |
602 |
|
754 | |||
603 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
755 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
604 |
|
756 | |||
605 | noise = dataOut.noise/factor |
|
757 | noise = dataOut.noise/factor | |
606 | noisedB = 10*numpy.log10(noise) |
|
758 | noisedB = 10*numpy.log10(noise) | |
607 |
|
759 | |||
608 | if ymin == None: ymin = numpy.nanmin(y) |
|
760 | if ymin == None: ymin = numpy.nanmin(y) | |
609 | if ymax == None: ymax = numpy.nanmax(y) |
|
761 | if ymax == None: ymax = numpy.nanmax(y) | |
610 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
762 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
611 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
763 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
612 |
|
764 | |||
613 | self.FTP_WEI = ftp_wei |
|
765 | self.FTP_WEI = ftp_wei | |
614 | self.EXP_CODE = exp_code |
|
766 | self.EXP_CODE = exp_code | |
615 | self.SUB_EXP_CODE = sub_exp_code |
|
767 | self.SUB_EXP_CODE = sub_exp_code | |
616 | self.PLOT_POS = plot_pos |
|
768 | self.PLOT_POS = plot_pos | |
617 |
|
769 | |||
618 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
770 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
619 | self.isConfig = True |
|
771 | self.isConfig = True | |
620 | self.figfile = figfile |
|
772 | self.figfile = figfile | |
621 | update_figfile = True |
|
773 | update_figfile = True | |
622 |
|
774 | |||
623 | self.setWinTitle(title) |
|
775 | self.setWinTitle(title) | |
624 |
|
776 | |||
625 | for i in range(self.nplots): |
|
777 | for i in range(self.nplots): | |
626 | index = channelIndexList[i] |
|
778 | index = channelIndexList[i] | |
627 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
779 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
628 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
780 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
629 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
781 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |
630 | axes = self.axesList[i*self.__nsubplots] |
|
782 | axes = self.axesList[i*self.__nsubplots] | |
631 | zdB = avgdB[index].reshape((1,-1)) |
|
783 | zdB = avgdB[index].reshape((1,-1)) | |
632 | axes.pcolorbuffer(x, y, zdB, |
|
784 | axes.pcolorbuffer(x, y, zdB, | |
633 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
785 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
634 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
786 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
635 | ticksize=9, cblabel='', cbsize="1%", colormap=colormap) |
|
787 | ticksize=9, cblabel='', cbsize="1%", colormap=colormap) | |
636 |
|
788 | |||
637 | if self.__showprofile: |
|
789 | if self.__showprofile: | |
638 | axes = self.axesList[i*self.__nsubplots +1] |
|
790 | axes = self.axesList[i*self.__nsubplots +1] | |
639 | axes.pline(avgdB[index], y, |
|
791 | axes.pline(avgdB[index], y, | |
640 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
792 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
641 | xlabel='dB', ylabel='', title='', |
|
793 | xlabel='dB', ylabel='', title='', | |
642 | ytick_visible=False, |
|
794 | ytick_visible=False, | |
643 | grid='x') |
|
795 | grid='x') | |
644 |
|
796 | |||
645 | self.draw() |
|
797 | self.draw() | |
646 |
|
798 | |||
647 | self.save(figpath=figpath, |
|
799 | self.save(figpath=figpath, | |
648 | figfile=figfile, |
|
800 | figfile=figfile, | |
649 | save=save, |
|
801 | save=save, | |
650 | ftp=ftp, |
|
802 | ftp=ftp, | |
651 | wr_period=wr_period, |
|
803 | wr_period=wr_period, | |
652 | thisDatetime=thisDatetime, |
|
804 | thisDatetime=thisDatetime, | |
653 | update_figfile=update_figfile) |
|
805 | update_figfile=update_figfile) | |
654 |
|
806 | |||
655 | class CoherenceMap(Figure): |
|
807 | class CoherenceMap(Figure): | |
656 | isConfig = None |
|
808 | isConfig = None | |
657 | __nsubplots = None |
|
809 | __nsubplots = None | |
658 |
|
810 | |||
659 | WIDTHPROF = None |
|
811 | WIDTHPROF = None | |
660 | HEIGHTPROF = None |
|
812 | HEIGHTPROF = None | |
661 | PREFIX = 'cmap' |
|
813 | PREFIX = 'cmap' | |
662 |
|
814 | |||
663 | def __init__(self, **kwargs): |
|
815 | def __init__(self, **kwargs): | |
664 | Figure.__init__(self, **kwargs) |
|
816 | Figure.__init__(self, **kwargs) | |
665 | self.timerange = 2*60*60 |
|
817 | self.timerange = 2*60*60 | |
666 | self.isConfig = False |
|
818 | self.isConfig = False | |
667 | self.__nsubplots = 1 |
|
819 | self.__nsubplots = 1 | |
668 |
|
820 | |||
669 | self.WIDTH = 800 |
|
821 | self.WIDTH = 800 | |
670 | self.HEIGHT = 180 |
|
822 | self.HEIGHT = 180 | |
671 | self.WIDTHPROF = 120 |
|
823 | self.WIDTHPROF = 120 | |
672 | self.HEIGHTPROF = 0 |
|
824 | self.HEIGHTPROF = 0 | |
673 | self.counter_imagwr = 0 |
|
825 | self.counter_imagwr = 0 | |
674 |
|
826 | |||
675 | self.PLOT_CODE = COH_CODE |
|
827 | self.PLOT_CODE = COH_CODE | |
676 |
|
828 | |||
677 | self.FTP_WEI = None |
|
829 | self.FTP_WEI = None | |
678 | self.EXP_CODE = None |
|
830 | self.EXP_CODE = None | |
679 | self.SUB_EXP_CODE = None |
|
831 | self.SUB_EXP_CODE = None | |
680 | self.PLOT_POS = None |
|
832 | self.PLOT_POS = None | |
681 | self.counter_imagwr = 0 |
|
833 | self.counter_imagwr = 0 | |
682 |
|
834 | |||
683 | self.xmin = None |
|
835 | self.xmin = None | |
684 | self.xmax = None |
|
836 | self.xmax = None | |
685 |
|
837 | |||
686 | def getSubplots(self): |
|
838 | def getSubplots(self): | |
687 | ncol = 1 |
|
839 | ncol = 1 | |
688 | nrow = self.nplots*2 |
|
840 | nrow = self.nplots*2 | |
689 |
|
841 | |||
690 | return nrow, ncol |
|
842 | return nrow, ncol | |
691 |
|
843 | |||
692 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
844 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
693 | self.__showprofile = showprofile |
|
845 | self.__showprofile = showprofile | |
694 | self.nplots = nplots |
|
846 | self.nplots = nplots | |
695 |
|
847 | |||
696 | ncolspan = 1 |
|
848 | ncolspan = 1 | |
697 | colspan = 1 |
|
849 | colspan = 1 | |
698 | if showprofile: |
|
850 | if showprofile: | |
699 | ncolspan = 7 |
|
851 | ncolspan = 7 | |
700 | colspan = 6 |
|
852 | colspan = 6 | |
701 | self.__nsubplots = 2 |
|
853 | self.__nsubplots = 2 | |
702 |
|
854 | |||
703 | self.createFigure(id = id, |
|
855 | self.createFigure(id = id, | |
704 | wintitle = wintitle, |
|
856 | wintitle = wintitle, | |
705 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
857 | widthplot = self.WIDTH + self.WIDTHPROF, | |
706 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
858 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
707 | show=True) |
|
859 | show=True) | |
708 |
|
860 | |||
709 | nrow, ncol = self.getSubplots() |
|
861 | nrow, ncol = self.getSubplots() | |
710 |
|
862 | |||
711 | for y in range(nrow): |
|
863 | for y in range(nrow): | |
712 | for x in range(ncol): |
|
864 | for x in range(ncol): | |
713 |
|
865 | |||
714 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
866 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
715 |
|
867 | |||
716 | if showprofile: |
|
868 | if showprofile: | |
717 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
869 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
718 |
|
870 | |||
719 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
871 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
720 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
872 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
721 | timerange=None, phase_min=None, phase_max=None, |
|
873 | timerange=None, phase_min=None, phase_max=None, | |
722 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
874 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
723 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
875 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
724 | server=None, folder=None, username=None, password=None, |
|
876 | server=None, folder=None, username=None, password=None, | |
725 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
877 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
726 |
|
878 | |||
727 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
879 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | |
728 | return |
|
880 | return | |
729 |
|
881 | |||
730 | if pairsList == None: |
|
882 | if pairsList == None: | |
731 | pairsIndexList = dataOut.pairsIndexList |
|
883 | pairsIndexList = dataOut.pairsIndexList | |
732 | else: |
|
884 | else: | |
733 | pairsIndexList = [] |
|
885 | pairsIndexList = [] | |
734 | for pair in pairsList: |
|
886 | for pair in pairsList: | |
735 | if pair not in dataOut.pairsList: |
|
887 | if pair not in dataOut.pairsList: | |
736 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
888 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
737 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
889 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
738 |
|
890 | |||
739 | if pairsIndexList == []: |
|
891 | if pairsIndexList == []: | |
740 | return |
|
892 | return | |
741 |
|
893 | |||
742 | if len(pairsIndexList) > 4: |
|
894 | if len(pairsIndexList) > 4: | |
743 | pairsIndexList = pairsIndexList[0:4] |
|
895 | pairsIndexList = pairsIndexList[0:4] | |
744 |
|
896 | |||
745 | if phase_min == None: |
|
897 | if phase_min == None: | |
746 | phase_min = -180 |
|
898 | phase_min = -180 | |
747 | if phase_max == None: |
|
899 | if phase_max == None: | |
748 | phase_max = 180 |
|
900 | phase_max = 180 | |
749 |
|
901 | |||
750 | x = dataOut.getTimeRange() |
|
902 | x = dataOut.getTimeRange() | |
751 | y = dataOut.getHeiRange() |
|
903 | y = dataOut.getHeiRange() | |
752 |
|
904 | |||
753 | thisDatetime = dataOut.datatime |
|
905 | thisDatetime = dataOut.datatime | |
754 |
|
906 | |||
755 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
907 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
756 | xlabel = "" |
|
908 | xlabel = "" | |
757 | ylabel = "Range (Km)" |
|
909 | ylabel = "Range (Km)" | |
758 | update_figfile = False |
|
910 | update_figfile = False | |
759 |
|
911 | |||
760 | if not self.isConfig: |
|
912 | if not self.isConfig: | |
761 | nplots = len(pairsIndexList) |
|
913 | nplots = len(pairsIndexList) | |
762 | self.setup(id=id, |
|
914 | self.setup(id=id, | |
763 | nplots=nplots, |
|
915 | nplots=nplots, | |
764 | wintitle=wintitle, |
|
916 | wintitle=wintitle, | |
765 | showprofile=showprofile, |
|
917 | showprofile=showprofile, | |
766 | show=show) |
|
918 | show=show) | |
767 |
|
919 | |||
768 | if timerange != None: |
|
920 | if timerange != None: | |
769 | self.timerange = timerange |
|
921 | self.timerange = timerange | |
770 |
|
922 | |||
771 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
923 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
772 |
|
924 | |||
773 | if ymin == None: ymin = numpy.nanmin(y) |
|
925 | if ymin == None: ymin = numpy.nanmin(y) | |
774 | if ymax == None: ymax = numpy.nanmax(y) |
|
926 | if ymax == None: ymax = numpy.nanmax(y) | |
775 | if zmin == None: zmin = 0. |
|
927 | if zmin == None: zmin = 0. | |
776 | if zmax == None: zmax = 1. |
|
928 | if zmax == None: zmax = 1. | |
777 |
|
929 | |||
778 | self.FTP_WEI = ftp_wei |
|
930 | self.FTP_WEI = ftp_wei | |
779 | self.EXP_CODE = exp_code |
|
931 | self.EXP_CODE = exp_code | |
780 | self.SUB_EXP_CODE = sub_exp_code |
|
932 | self.SUB_EXP_CODE = sub_exp_code | |
781 | self.PLOT_POS = plot_pos |
|
933 | self.PLOT_POS = plot_pos | |
782 |
|
934 | |||
783 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
935 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
784 |
|
936 | |||
785 | self.isConfig = True |
|
937 | self.isConfig = True | |
786 | update_figfile = True |
|
938 | update_figfile = True | |
787 |
|
939 | |||
788 | self.setWinTitle(title) |
|
940 | self.setWinTitle(title) | |
789 |
|
941 | |||
790 | for i in range(self.nplots): |
|
942 | for i in range(self.nplots): | |
791 |
|
943 | |||
792 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
944 | pair = dataOut.pairsList[pairsIndexList[i]] | |
793 |
|
945 | |||
794 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
946 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
795 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
947 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
796 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
948 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
797 |
|
949 | |||
798 |
|
950 | |||
799 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
951 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
800 | coherence = numpy.abs(avgcoherenceComplex) |
|
952 | coherence = numpy.abs(avgcoherenceComplex) | |
801 |
|
953 | |||
802 | z = coherence.reshape((1,-1)) |
|
954 | z = coherence.reshape((1,-1)) | |
803 |
|
955 | |||
804 | counter = 0 |
|
956 | counter = 0 | |
805 |
|
957 | |||
806 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
958 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
807 | axes = self.axesList[i*self.__nsubplots*2] |
|
959 | axes = self.axesList[i*self.__nsubplots*2] | |
808 | axes.pcolorbuffer(x, y, z, |
|
960 | axes.pcolorbuffer(x, y, z, | |
809 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
961 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
810 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
962 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
811 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
963 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
812 |
|
964 | |||
813 | if self.__showprofile: |
|
965 | if self.__showprofile: | |
814 | counter += 1 |
|
966 | counter += 1 | |
815 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
967 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
816 | axes.pline(coherence, y, |
|
968 | axes.pline(coherence, y, | |
817 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
969 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
818 | xlabel='', ylabel='', title='', ticksize=7, |
|
970 | xlabel='', ylabel='', title='', ticksize=7, | |
819 | ytick_visible=False, nxticks=5, |
|
971 | ytick_visible=False, nxticks=5, | |
820 | grid='x') |
|
972 | grid='x') | |
821 |
|
973 | |||
822 | counter += 1 |
|
974 | counter += 1 | |
823 |
|
975 | |||
824 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
976 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
825 |
|
977 | |||
826 | z = phase.reshape((1,-1)) |
|
978 | z = phase.reshape((1,-1)) | |
827 |
|
979 | |||
828 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
980 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
829 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
981 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
830 | axes.pcolorbuffer(x, y, z, |
|
982 | axes.pcolorbuffer(x, y, z, | |
831 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
983 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, | |
832 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
984 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
833 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
985 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
834 |
|
986 | |||
835 | if self.__showprofile: |
|
987 | if self.__showprofile: | |
836 | counter += 1 |
|
988 | counter += 1 | |
837 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
989 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
838 | axes.pline(phase, y, |
|
990 | axes.pline(phase, y, | |
839 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, |
|
991 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, | |
840 | xlabel='', ylabel='', title='', ticksize=7, |
|
992 | xlabel='', ylabel='', title='', ticksize=7, | |
841 | ytick_visible=False, nxticks=4, |
|
993 | ytick_visible=False, nxticks=4, | |
842 | grid='x') |
|
994 | grid='x') | |
843 |
|
995 | |||
844 | self.draw() |
|
996 | self.draw() | |
845 |
|
997 | |||
846 | if dataOut.ltctime >= self.xmax: |
|
998 | if dataOut.ltctime >= self.xmax: | |
847 | self.counter_imagwr = wr_period |
|
999 | self.counter_imagwr = wr_period | |
848 | self.isConfig = False |
|
1000 | self.isConfig = False | |
849 | update_figfile = True |
|
1001 | update_figfile = True | |
850 |
|
1002 | |||
851 | self.save(figpath=figpath, |
|
1003 | self.save(figpath=figpath, | |
852 | figfile=figfile, |
|
1004 | figfile=figfile, | |
853 | save=save, |
|
1005 | save=save, | |
854 | ftp=ftp, |
|
1006 | ftp=ftp, | |
855 | wr_period=wr_period, |
|
1007 | wr_period=wr_period, | |
856 | thisDatetime=thisDatetime, |
|
1008 | thisDatetime=thisDatetime, | |
857 | update_figfile=update_figfile) |
|
1009 | update_figfile=update_figfile) | |
858 |
|
1010 | |||
859 | class PowerProfilePlot(Figure): |
|
1011 | class PowerProfilePlot(Figure): | |
860 |
|
1012 | |||
861 | isConfig = None |
|
1013 | isConfig = None | |
862 | __nsubplots = None |
|
1014 | __nsubplots = None | |
863 |
|
1015 | |||
864 | WIDTHPROF = None |
|
1016 | WIDTHPROF = None | |
865 | HEIGHTPROF = None |
|
1017 | HEIGHTPROF = None | |
866 | PREFIX = 'spcprofile' |
|
1018 | PREFIX = 'spcprofile' | |
867 |
|
1019 | |||
868 | def __init__(self, **kwargs): |
|
1020 | def __init__(self, **kwargs): | |
869 | Figure.__init__(self, **kwargs) |
|
1021 | Figure.__init__(self, **kwargs) | |
870 | self.isConfig = False |
|
1022 | self.isConfig = False | |
871 | self.__nsubplots = 1 |
|
1023 | self.__nsubplots = 1 | |
872 |
|
1024 | |||
873 | self.PLOT_CODE = POWER_CODE |
|
1025 | self.PLOT_CODE = POWER_CODE | |
874 |
|
1026 | |||
875 | self.WIDTH = 300 |
|
1027 | self.WIDTH = 300 | |
876 | self.HEIGHT = 500 |
|
1028 | self.HEIGHT = 500 | |
877 | self.counter_imagwr = 0 |
|
1029 | self.counter_imagwr = 0 | |
878 |
|
1030 | |||
879 | def getSubplots(self): |
|
1031 | def getSubplots(self): | |
880 | ncol = 1 |
|
1032 | ncol = 1 | |
881 | nrow = 1 |
|
1033 | nrow = 1 | |
882 |
|
1034 | |||
883 | return nrow, ncol |
|
1035 | return nrow, ncol | |
884 |
|
1036 | |||
885 | def setup(self, id, nplots, wintitle, show): |
|
1037 | def setup(self, id, nplots, wintitle, show): | |
886 |
|
1038 | |||
887 | self.nplots = nplots |
|
1039 | self.nplots = nplots | |
888 |
|
1040 | |||
889 | ncolspan = 1 |
|
1041 | ncolspan = 1 | |
890 | colspan = 1 |
|
1042 | colspan = 1 | |
891 |
|
1043 | |||
892 | self.createFigure(id = id, |
|
1044 | self.createFigure(id = id, | |
893 | wintitle = wintitle, |
|
1045 | wintitle = wintitle, | |
894 | widthplot = self.WIDTH, |
|
1046 | widthplot = self.WIDTH, | |
895 | heightplot = self.HEIGHT, |
|
1047 | heightplot = self.HEIGHT, | |
896 | show=show) |
|
1048 | show=show) | |
897 |
|
1049 | |||
898 | nrow, ncol = self.getSubplots() |
|
1050 | nrow, ncol = self.getSubplots() | |
899 |
|
1051 | |||
900 | counter = 0 |
|
1052 | counter = 0 | |
901 | for y in range(nrow): |
|
1053 | for y in range(nrow): | |
902 | for x in range(ncol): |
|
1054 | for x in range(ncol): | |
903 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1055 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
904 |
|
1056 | |||
905 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1057 | def run(self, dataOut, id, wintitle="", channelList=None, | |
906 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1058 | xmin=None, xmax=None, ymin=None, ymax=None, | |
907 | save=False, figpath='./', figfile=None, show=True, |
|
1059 | save=False, figpath='./', figfile=None, show=True, | |
908 | ftp=False, wr_period=1, server=None, |
|
1060 | ftp=False, wr_period=1, server=None, | |
909 | folder=None, username=None, password=None): |
|
1061 | folder=None, username=None, password=None): | |
910 |
|
1062 | |||
911 |
|
1063 | |||
912 | if channelList == None: |
|
1064 | if channelList == None: | |
913 | channelIndexList = dataOut.channelIndexList |
|
1065 | channelIndexList = dataOut.channelIndexList | |
914 | channelList = dataOut.channelList |
|
1066 | channelList = dataOut.channelList | |
915 | else: |
|
1067 | else: | |
916 | channelIndexList = [] |
|
1068 | channelIndexList = [] | |
917 | for channel in channelList: |
|
1069 | for channel in channelList: | |
918 | if channel not in dataOut.channelList: |
|
1070 | if channel not in dataOut.channelList: | |
919 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1071 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
920 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1072 | channelIndexList.append(dataOut.channelList.index(channel)) | |
921 |
|
1073 | |||
922 | factor = dataOut.normFactor |
|
1074 | factor = dataOut.normFactor | |
923 |
|
1075 | |||
924 | y = dataOut.getHeiRange() |
|
1076 | y = dataOut.getHeiRange() | |
925 |
|
1077 | |||
926 | #for voltage |
|
1078 | #for voltage | |
927 | if dataOut.type == 'Voltage': |
|
1079 | if dataOut.type == 'Voltage': | |
928 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1080 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
929 | x = x.real |
|
1081 | x = x.real | |
930 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
1082 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
931 |
|
1083 | |||
932 | #for spectra |
|
1084 | #for spectra | |
933 | if dataOut.type == 'Spectra': |
|
1085 | if dataOut.type == 'Spectra': | |
934 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
1086 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
935 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
1087 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
936 | x = numpy.average(x, axis=1) |
|
1088 | x = numpy.average(x, axis=1) | |
937 |
|
1089 | |||
938 |
|
1090 | |||
939 | xdB = 10*numpy.log10(x) |
|
1091 | xdB = 10*numpy.log10(x) | |
940 |
|
1092 | |||
941 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1093 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
942 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1094 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
943 | xlabel = "dB" |
|
1095 | xlabel = "dB" | |
944 | ylabel = "Range (Km)" |
|
1096 | ylabel = "Range (Km)" | |
945 |
|
1097 | |||
946 | if not self.isConfig: |
|
1098 | if not self.isConfig: | |
947 |
|
1099 | |||
948 | nplots = 1 |
|
1100 | nplots = 1 | |
949 |
|
1101 | |||
950 | self.setup(id=id, |
|
1102 | self.setup(id=id, | |
951 | nplots=nplots, |
|
1103 | nplots=nplots, | |
952 | wintitle=wintitle, |
|
1104 | wintitle=wintitle, | |
953 | show=show) |
|
1105 | show=show) | |
954 |
|
1106 | |||
955 | if ymin == None: ymin = numpy.nanmin(y) |
|
1107 | if ymin == None: ymin = numpy.nanmin(y) | |
956 | if ymax == None: ymax = numpy.nanmax(y) |
|
1108 | if ymax == None: ymax = numpy.nanmax(y) | |
957 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
1109 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 | |
958 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
1110 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 | |
959 |
|
1111 | |||
960 | self.isConfig = True |
|
1112 | self.isConfig = True | |
961 |
|
1113 | |||
962 | self.setWinTitle(title) |
|
1114 | self.setWinTitle(title) | |
963 |
|
1115 | |||
964 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1116 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
965 | axes = self.axesList[0] |
|
1117 | axes = self.axesList[0] | |
966 |
|
1118 | |||
967 | legendlabels = ["channel %d"%x for x in channelList] |
|
1119 | legendlabels = ["channel %d"%x for x in channelList] | |
968 | axes.pmultiline(xdB, y, |
|
1120 | axes.pmultiline(xdB, y, | |
969 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1121 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
970 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1122 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
971 | ytick_visible=True, nxticks=5, |
|
1123 | ytick_visible=True, nxticks=5, | |
972 | grid='x') |
|
1124 | grid='x') | |
973 |
|
1125 | |||
974 | self.draw() |
|
1126 | self.draw() | |
975 |
|
1127 | |||
976 | self.save(figpath=figpath, |
|
1128 | self.save(figpath=figpath, | |
977 | figfile=figfile, |
|
1129 | figfile=figfile, | |
978 | save=save, |
|
1130 | save=save, | |
979 | ftp=ftp, |
|
1131 | ftp=ftp, | |
980 | wr_period=wr_period, |
|
1132 | wr_period=wr_period, | |
981 | thisDatetime=thisDatetime) |
|
1133 | thisDatetime=thisDatetime) | |
982 |
|
1134 | |||
983 | class SpectraCutPlot(Figure): |
|
1135 | class SpectraCutPlot(Figure): | |
984 |
|
1136 | |||
985 | isConfig = None |
|
1137 | isConfig = None | |
986 | __nsubplots = None |
|
1138 | __nsubplots = None | |
987 |
|
1139 | |||
988 | WIDTHPROF = None |
|
1140 | WIDTHPROF = None | |
989 | HEIGHTPROF = None |
|
1141 | HEIGHTPROF = None | |
990 | PREFIX = 'spc_cut' |
|
1142 | PREFIX = 'spc_cut' | |
991 |
|
1143 | |||
992 | def __init__(self, **kwargs): |
|
1144 | def __init__(self, **kwargs): | |
993 | Figure.__init__(self, **kwargs) |
|
1145 | Figure.__init__(self, **kwargs) | |
994 | self.isConfig = False |
|
1146 | self.isConfig = False | |
995 | self.__nsubplots = 1 |
|
1147 | self.__nsubplots = 1 | |
996 |
|
1148 | |||
997 | self.PLOT_CODE = POWER_CODE |
|
1149 | self.PLOT_CODE = POWER_CODE | |
998 |
|
1150 | |||
999 | self.WIDTH = 700 |
|
1151 | self.WIDTH = 700 | |
1000 | self.HEIGHT = 500 |
|
1152 | self.HEIGHT = 500 | |
1001 | self.counter_imagwr = 0 |
|
1153 | self.counter_imagwr = 0 | |
1002 |
|
1154 | |||
1003 | def getSubplots(self): |
|
1155 | def getSubplots(self): | |
1004 | ncol = 1 |
|
1156 | ncol = 1 | |
1005 | nrow = 1 |
|
1157 | nrow = 1 | |
1006 |
|
1158 | |||
1007 | return nrow, ncol |
|
1159 | return nrow, ncol | |
1008 |
|
1160 | |||
1009 | def setup(self, id, nplots, wintitle, show): |
|
1161 | def setup(self, id, nplots, wintitle, show): | |
1010 |
|
1162 | |||
1011 | self.nplots = nplots |
|
1163 | self.nplots = nplots | |
1012 |
|
1164 | |||
1013 | ncolspan = 1 |
|
1165 | ncolspan = 1 | |
1014 | colspan = 1 |
|
1166 | colspan = 1 | |
1015 |
|
1167 | |||
1016 | self.createFigure(id = id, |
|
1168 | self.createFigure(id = id, | |
1017 | wintitle = wintitle, |
|
1169 | wintitle = wintitle, | |
1018 | widthplot = self.WIDTH, |
|
1170 | widthplot = self.WIDTH, | |
1019 | heightplot = self.HEIGHT, |
|
1171 | heightplot = self.HEIGHT, | |
1020 | show=show) |
|
1172 | show=show) | |
1021 |
|
1173 | |||
1022 | nrow, ncol = self.getSubplots() |
|
1174 | nrow, ncol = self.getSubplots() | |
1023 |
|
1175 | |||
1024 | counter = 0 |
|
1176 | counter = 0 | |
1025 | for y in range(nrow): |
|
1177 | for y in range(nrow): | |
1026 | for x in range(ncol): |
|
1178 | for x in range(ncol): | |
1027 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1179 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1028 |
|
1180 | |||
1029 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1181 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1030 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1182 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1031 | save=False, figpath='./', figfile=None, show=True, |
|
1183 | save=False, figpath='./', figfile=None, show=True, | |
1032 | ftp=False, wr_period=1, server=None, |
|
1184 | ftp=False, wr_period=1, server=None, | |
1033 | folder=None, username=None, password=None, |
|
1185 | folder=None, username=None, password=None, | |
1034 | xaxis="frequency"): |
|
1186 | xaxis="frequency"): | |
1035 |
|
1187 | |||
1036 |
|
1188 | |||
1037 | if channelList == None: |
|
1189 | if channelList == None: | |
1038 | channelIndexList = dataOut.channelIndexList |
|
1190 | channelIndexList = dataOut.channelIndexList | |
1039 | channelList = dataOut.channelList |
|
1191 | channelList = dataOut.channelList | |
1040 | else: |
|
1192 | else: | |
1041 | channelIndexList = [] |
|
1193 | channelIndexList = [] | |
1042 | for channel in channelList: |
|
1194 | for channel in channelList: | |
1043 | if channel not in dataOut.channelList: |
|
1195 | if channel not in dataOut.channelList: | |
1044 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1196 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1045 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1197 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1046 |
|
1198 | |||
1047 | factor = dataOut.normFactor |
|
1199 | factor = dataOut.normFactor | |
1048 |
|
1200 | |||
1049 | y = dataOut.getHeiRange() |
|
1201 | y = dataOut.getHeiRange() | |
1050 |
|
1202 | |||
1051 | z = dataOut.data_spc/factor |
|
1203 | z = dataOut.data_spc/factor | |
1052 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1204 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
1053 |
|
1205 | |||
1054 | hei_index = numpy.arange(25)*3 + 20 |
|
1206 | hei_index = numpy.arange(25)*3 + 20 | |
1055 |
|
1207 | |||
1056 | if xaxis == "frequency": |
|
1208 | if xaxis == "frequency": | |
1057 | x = dataOut.getFreqRange()/1000. |
|
1209 | x = dataOut.getFreqRange()/1000. | |
1058 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1210 | zdB = 10*numpy.log10(z[0,:,hei_index]) | |
1059 | xlabel = "Frequency (kHz)" |
|
1211 | xlabel = "Frequency (kHz)" | |
1060 | ylabel = "Power (dB)" |
|
1212 | ylabel = "Power (dB)" | |
1061 |
|
1213 | |||
1062 | elif xaxis == "time": |
|
1214 | elif xaxis == "time": | |
1063 | x = dataOut.getAcfRange() |
|
1215 | x = dataOut.getAcfRange() | |
1064 | zdB = z[0,:,hei_index] |
|
1216 | zdB = z[0,:,hei_index] | |
1065 | xlabel = "Time (ms)" |
|
1217 | xlabel = "Time (ms)" | |
1066 | ylabel = "ACF" |
|
1218 | ylabel = "ACF" | |
1067 |
|
1219 | |||
1068 | else: |
|
1220 | else: | |
1069 | x = dataOut.getVelRange() |
|
1221 | x = dataOut.getVelRange() | |
1070 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1222 | zdB = 10*numpy.log10(z[0,:,hei_index]) | |
1071 | xlabel = "Velocity (m/s)" |
|
1223 | xlabel = "Velocity (m/s)" | |
1072 | ylabel = "Power (dB)" |
|
1224 | ylabel = "Power (dB)" | |
1073 |
|
1225 | |||
1074 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1226 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
1075 | title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1227 | title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1076 |
|
1228 | |||
1077 | if not self.isConfig: |
|
1229 | if not self.isConfig: | |
1078 |
|
1230 | |||
1079 | nplots = 1 |
|
1231 | nplots = 1 | |
1080 |
|
1232 | |||
1081 | self.setup(id=id, |
|
1233 | self.setup(id=id, | |
1082 | nplots=nplots, |
|
1234 | nplots=nplots, | |
1083 | wintitle=wintitle, |
|
1235 | wintitle=wintitle, | |
1084 | show=show) |
|
1236 | show=show) | |
1085 |
|
1237 | |||
1086 | if xmin == None: xmin = numpy.nanmin(x)*0.9 |
|
1238 | if xmin == None: xmin = numpy.nanmin(x)*0.9 | |
1087 | if xmax == None: xmax = numpy.nanmax(x)*1.1 |
|
1239 | if xmax == None: xmax = numpy.nanmax(x)*1.1 | |
1088 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1240 | if ymin == None: ymin = numpy.nanmin(zdB) | |
1089 | if ymax == None: ymax = numpy.nanmax(zdB) |
|
1241 | if ymax == None: ymax = numpy.nanmax(zdB) | |
1090 |
|
1242 | |||
1091 | self.isConfig = True |
|
1243 | self.isConfig = True | |
1092 |
|
1244 | |||
1093 | self.setWinTitle(title) |
|
1245 | self.setWinTitle(title) | |
1094 |
|
1246 | |||
1095 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1247 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1096 | axes = self.axesList[0] |
|
1248 | axes = self.axesList[0] | |
1097 |
|
1249 | |||
1098 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] |
|
1250 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] | |
1099 |
|
1251 | |||
1100 | axes.pmultilineyaxis( x, zdB, |
|
1252 | axes.pmultilineyaxis( x, zdB, | |
1101 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1253 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1102 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1254 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
1103 | ytick_visible=True, nxticks=5, |
|
1255 | ytick_visible=True, nxticks=5, | |
1104 | grid='x') |
|
1256 | grid='x') | |
1105 |
|
1257 | |||
1106 | self.draw() |
|
1258 | self.draw() | |
1107 |
|
1259 | |||
1108 | self.save(figpath=figpath, |
|
1260 | self.save(figpath=figpath, | |
1109 | figfile=figfile, |
|
1261 | figfile=figfile, | |
1110 | save=save, |
|
1262 | save=save, | |
1111 | ftp=ftp, |
|
1263 | ftp=ftp, | |
1112 | wr_period=wr_period, |
|
1264 | wr_period=wr_period, | |
1113 | thisDatetime=thisDatetime) |
|
1265 | thisDatetime=thisDatetime) | |
1114 |
|
1266 | |||
1115 | class Noise(Figure): |
|
1267 | class Noise(Figure): | |
1116 |
|
1268 | |||
1117 | isConfig = None |
|
1269 | isConfig = None | |
1118 | __nsubplots = None |
|
1270 | __nsubplots = None | |
1119 |
|
1271 | |||
1120 | PREFIX = 'noise' |
|
1272 | PREFIX = 'noise' | |
1121 |
|
1273 | |||
1122 |
|
1274 | |||
1123 | def __init__(self, **kwargs): |
|
1275 | def __init__(self, **kwargs): | |
1124 | Figure.__init__(self, **kwargs) |
|
1276 | Figure.__init__(self, **kwargs) | |
1125 | self.timerange = 24*60*60 |
|
1277 | self.timerange = 24*60*60 | |
1126 | self.isConfig = False |
|
1278 | self.isConfig = False | |
1127 | self.__nsubplots = 1 |
|
1279 | self.__nsubplots = 1 | |
1128 | self.counter_imagwr = 0 |
|
1280 | self.counter_imagwr = 0 | |
1129 | self.WIDTH = 800 |
|
1281 | self.WIDTH = 800 | |
1130 | self.HEIGHT = 400 |
|
1282 | self.HEIGHT = 400 | |
1131 | self.WIDTHPROF = 120 |
|
1283 | self.WIDTHPROF = 120 | |
1132 | self.HEIGHTPROF = 0 |
|
1284 | self.HEIGHTPROF = 0 | |
1133 | self.xdata = None |
|
1285 | self.xdata = None | |
1134 | self.ydata = None |
|
1286 | self.ydata = None | |
1135 |
|
1287 | |||
1136 | self.PLOT_CODE = NOISE_CODE |
|
1288 | self.PLOT_CODE = NOISE_CODE | |
1137 |
|
1289 | |||
1138 | self.FTP_WEI = None |
|
1290 | self.FTP_WEI = None | |
1139 | self.EXP_CODE = None |
|
1291 | self.EXP_CODE = None | |
1140 | self.SUB_EXP_CODE = None |
|
1292 | self.SUB_EXP_CODE = None | |
1141 | self.PLOT_POS = None |
|
1293 | self.PLOT_POS = None | |
1142 | self.figfile = None |
|
1294 | self.figfile = None | |
1143 |
|
1295 | |||
1144 | self.xmin = None |
|
1296 | self.xmin = None | |
1145 | self.xmax = None |
|
1297 | self.xmax = None | |
1146 |
|
1298 | |||
1147 | def getSubplots(self): |
|
1299 | def getSubplots(self): | |
1148 |
|
1300 | |||
1149 | ncol = 1 |
|
1301 | ncol = 1 | |
1150 | nrow = 1 |
|
1302 | nrow = 1 | |
1151 |
|
1303 | |||
1152 | return nrow, ncol |
|
1304 | return nrow, ncol | |
1153 |
|
1305 | |||
1154 | def openfile(self, filename): |
|
1306 | def openfile(self, filename): | |
1155 | dirname = os.path.dirname(filename) |
|
1307 | dirname = os.path.dirname(filename) | |
1156 |
|
1308 | |||
1157 | if not os.path.exists(dirname): |
|
1309 | if not os.path.exists(dirname): | |
1158 | os.mkdir(dirname) |
|
1310 | os.mkdir(dirname) | |
1159 |
|
1311 | |||
1160 | f = open(filename,'w+') |
|
1312 | f = open(filename,'w+') | |
1161 | f.write('\n\n') |
|
1313 | f.write('\n\n') | |
1162 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1314 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') | |
1163 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1315 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) | |
1164 | f.close() |
|
1316 | f.close() | |
1165 |
|
1317 | |||
1166 | def save_data(self, filename_phase, data, data_datetime): |
|
1318 | def save_data(self, filename_phase, data, data_datetime): | |
1167 |
|
1319 | |||
1168 | f=open(filename_phase,'a') |
|
1320 | f=open(filename_phase,'a') | |
1169 |
|
1321 | |||
1170 | timetuple_data = data_datetime.timetuple() |
|
1322 | timetuple_data = data_datetime.timetuple() | |
1171 | day = str(timetuple_data.tm_mday) |
|
1323 | day = str(timetuple_data.tm_mday) | |
1172 | month = str(timetuple_data.tm_mon) |
|
1324 | month = str(timetuple_data.tm_mon) | |
1173 | year = str(timetuple_data.tm_year) |
|
1325 | year = str(timetuple_data.tm_year) | |
1174 | hour = str(timetuple_data.tm_hour) |
|
1326 | hour = str(timetuple_data.tm_hour) | |
1175 | minute = str(timetuple_data.tm_min) |
|
1327 | minute = str(timetuple_data.tm_min) | |
1176 | second = str(timetuple_data.tm_sec) |
|
1328 | second = str(timetuple_data.tm_sec) | |
1177 |
|
1329 | |||
1178 | data_msg = '' |
|
1330 | data_msg = '' | |
1179 | for i in range(len(data)): |
|
1331 | for i in range(len(data)): | |
1180 | data_msg += str(data[i]) + ' ' |
|
1332 | data_msg += str(data[i]) + ' ' | |
1181 |
|
1333 | |||
1182 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
1334 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') | |
1183 | f.close() |
|
1335 | f.close() | |
1184 |
|
1336 | |||
1185 |
|
1337 | |||
1186 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1338 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1187 |
|
1339 | |||
1188 | self.__showprofile = showprofile |
|
1340 | self.__showprofile = showprofile | |
1189 | self.nplots = nplots |
|
1341 | self.nplots = nplots | |
1190 |
|
1342 | |||
1191 | ncolspan = 7 |
|
1343 | ncolspan = 7 | |
1192 | colspan = 6 |
|
1344 | colspan = 6 | |
1193 | self.__nsubplots = 2 |
|
1345 | self.__nsubplots = 2 | |
1194 |
|
1346 | |||
1195 | self.createFigure(id = id, |
|
1347 | self.createFigure(id = id, | |
1196 | wintitle = wintitle, |
|
1348 | wintitle = wintitle, | |
1197 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1349 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1198 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1350 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1199 | show=show) |
|
1351 | show=show) | |
1200 |
|
1352 | |||
1201 | nrow, ncol = self.getSubplots() |
|
1353 | nrow, ncol = self.getSubplots() | |
1202 |
|
1354 | |||
1203 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1355 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1204 |
|
1356 | |||
1205 |
|
1357 | |||
1206 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1358 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1207 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1359 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1208 | timerange=None, |
|
1360 | timerange=None, | |
1209 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1361 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1210 | server=None, folder=None, username=None, password=None, |
|
1362 | server=None, folder=None, username=None, password=None, | |
1211 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1363 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1212 |
|
1364 | |||
1213 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1365 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | |
1214 | return |
|
1366 | return | |
1215 |
|
1367 | |||
1216 | if channelList == None: |
|
1368 | if channelList == None: | |
1217 | channelIndexList = dataOut.channelIndexList |
|
1369 | channelIndexList = dataOut.channelIndexList | |
1218 | channelList = dataOut.channelList |
|
1370 | channelList = dataOut.channelList | |
1219 | else: |
|
1371 | else: | |
1220 | channelIndexList = [] |
|
1372 | channelIndexList = [] | |
1221 | for channel in channelList: |
|
1373 | for channel in channelList: | |
1222 | if channel not in dataOut.channelList: |
|
1374 | if channel not in dataOut.channelList: | |
1223 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1375 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1224 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1376 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1225 |
|
1377 | |||
1226 | x = dataOut.getTimeRange() |
|
1378 | x = dataOut.getTimeRange() | |
1227 | #y = dataOut.getHeiRange() |
|
1379 | #y = dataOut.getHeiRange() | |
1228 | factor = dataOut.normFactor |
|
1380 | factor = dataOut.normFactor | |
1229 | noise = dataOut.noise[channelIndexList]/factor |
|
1381 | noise = dataOut.noise[channelIndexList]/factor | |
1230 | noisedB = 10*numpy.log10(noise) |
|
1382 | noisedB = 10*numpy.log10(noise) | |
1231 |
|
1383 | |||
1232 | thisDatetime = dataOut.datatime |
|
1384 | thisDatetime = dataOut.datatime | |
1233 |
|
1385 | |||
1234 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1386 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1235 | xlabel = "" |
|
1387 | xlabel = "" | |
1236 | ylabel = "Intensity (dB)" |
|
1388 | ylabel = "Intensity (dB)" | |
1237 | update_figfile = False |
|
1389 | update_figfile = False | |
1238 |
|
1390 | |||
1239 | if not self.isConfig: |
|
1391 | if not self.isConfig: | |
1240 |
|
1392 | |||
1241 | nplots = 1 |
|
1393 | nplots = 1 | |
1242 |
|
1394 | |||
1243 | self.setup(id=id, |
|
1395 | self.setup(id=id, | |
1244 | nplots=nplots, |
|
1396 | nplots=nplots, | |
1245 | wintitle=wintitle, |
|
1397 | wintitle=wintitle, | |
1246 | showprofile=showprofile, |
|
1398 | showprofile=showprofile, | |
1247 | show=show) |
|
1399 | show=show) | |
1248 |
|
1400 | |||
1249 | if timerange != None: |
|
1401 | if timerange != None: | |
1250 | self.timerange = timerange |
|
1402 | self.timerange = timerange | |
1251 |
|
1403 | |||
1252 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1404 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
1253 |
|
1405 | |||
1254 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1406 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 | |
1255 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1407 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | |
1256 |
|
1408 | |||
1257 | self.FTP_WEI = ftp_wei |
|
1409 | self.FTP_WEI = ftp_wei | |
1258 | self.EXP_CODE = exp_code |
|
1410 | self.EXP_CODE = exp_code | |
1259 | self.SUB_EXP_CODE = sub_exp_code |
|
1411 | self.SUB_EXP_CODE = sub_exp_code | |
1260 | self.PLOT_POS = plot_pos |
|
1412 | self.PLOT_POS = plot_pos | |
1261 |
|
1413 | |||
1262 |
|
1414 | |||
1263 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1415 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1264 | self.isConfig = True |
|
1416 | self.isConfig = True | |
1265 | self.figfile = figfile |
|
1417 | self.figfile = figfile | |
1266 | self.xdata = numpy.array([]) |
|
1418 | self.xdata = numpy.array([]) | |
1267 | self.ydata = numpy.array([]) |
|
1419 | self.ydata = numpy.array([]) | |
1268 |
|
1420 | |||
1269 | update_figfile = True |
|
1421 | update_figfile = True | |
1270 |
|
1422 | |||
1271 | #open file beacon phase |
|
1423 | #open file beacon phase | |
1272 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1424 | path = '%s%03d' %(self.PREFIX, self.id) | |
1273 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1425 | noise_file = os.path.join(path,'%s.txt'%self.name) | |
1274 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1426 | self.filename_noise = os.path.join(figpath,noise_file) | |
1275 |
|
1427 | |||
1276 | self.setWinTitle(title) |
|
1428 | self.setWinTitle(title) | |
1277 |
|
1429 | |||
1278 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1430 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1279 |
|
1431 | |||
1280 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] |
|
1432 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] | |
1281 | axes = self.axesList[0] |
|
1433 | axes = self.axesList[0] | |
1282 |
|
1434 | |||
1283 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1435 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1284 |
|
1436 | |||
1285 | if len(self.ydata)==0: |
|
1437 | if len(self.ydata)==0: | |
1286 | self.ydata = noisedB.reshape(-1,1) |
|
1438 | self.ydata = noisedB.reshape(-1,1) | |
1287 | else: |
|
1439 | else: | |
1288 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) |
|
1440 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) | |
1289 |
|
1441 | |||
1290 |
|
1442 | |||
1291 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1443 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1292 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1444 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
1293 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1445 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1294 | XAxisAsTime=True, grid='both' |
|
1446 | XAxisAsTime=True, grid='both' | |
1295 | ) |
|
1447 | ) | |
1296 |
|
1448 | |||
1297 | self.draw() |
|
1449 | self.draw() | |
1298 |
|
1450 | |||
1299 | if dataOut.ltctime >= self.xmax: |
|
1451 | if dataOut.ltctime >= self.xmax: | |
1300 | self.counter_imagwr = wr_period |
|
1452 | self.counter_imagwr = wr_period | |
1301 | self.isConfig = False |
|
1453 | self.isConfig = False | |
1302 | update_figfile = True |
|
1454 | update_figfile = True | |
1303 |
|
1455 | |||
1304 | self.save(figpath=figpath, |
|
1456 | self.save(figpath=figpath, | |
1305 | figfile=figfile, |
|
1457 | figfile=figfile, | |
1306 | save=save, |
|
1458 | save=save, | |
1307 | ftp=ftp, |
|
1459 | ftp=ftp, | |
1308 | wr_period=wr_period, |
|
1460 | wr_period=wr_period, | |
1309 | thisDatetime=thisDatetime, |
|
1461 | thisDatetime=thisDatetime, | |
1310 | update_figfile=update_figfile) |
|
1462 | update_figfile=update_figfile) | |
1311 |
|
1463 | |||
1312 | #store data beacon phase |
|
1464 | #store data beacon phase | |
1313 | if save: |
|
1465 | if save: | |
1314 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1466 | self.save_data(self.filename_noise, noisedB, thisDatetime) | |
1315 |
|
1467 | |||
1316 | class BeaconPhase(Figure): |
|
1468 | class BeaconPhase(Figure): | |
1317 |
|
1469 | |||
1318 | __isConfig = None |
|
1470 | __isConfig = None | |
1319 | __nsubplots = None |
|
1471 | __nsubplots = None | |
1320 |
|
1472 | |||
1321 | PREFIX = 'beacon_phase' |
|
1473 | PREFIX = 'beacon_phase' | |
1322 |
|
1474 | |||
1323 | def __init__(self, **kwargs): |
|
1475 | def __init__(self, **kwargs): | |
1324 | Figure.__init__(self, **kwargs) |
|
1476 | Figure.__init__(self, **kwargs) | |
1325 | self.timerange = 24*60*60 |
|
1477 | self.timerange = 24*60*60 | |
1326 | self.isConfig = False |
|
1478 | self.isConfig = False | |
1327 | self.__nsubplots = 1 |
|
1479 | self.__nsubplots = 1 | |
1328 | self.counter_imagwr = 0 |
|
1480 | self.counter_imagwr = 0 | |
1329 | self.WIDTH = 800 |
|
1481 | self.WIDTH = 800 | |
1330 | self.HEIGHT = 400 |
|
1482 | self.HEIGHT = 400 | |
1331 | self.WIDTHPROF = 120 |
|
1483 | self.WIDTHPROF = 120 | |
1332 | self.HEIGHTPROF = 0 |
|
1484 | self.HEIGHTPROF = 0 | |
1333 | self.xdata = None |
|
1485 | self.xdata = None | |
1334 | self.ydata = None |
|
1486 | self.ydata = None | |
1335 |
|
1487 | |||
1336 | self.PLOT_CODE = BEACON_CODE |
|
1488 | self.PLOT_CODE = BEACON_CODE | |
1337 |
|
1489 | |||
1338 | self.FTP_WEI = None |
|
1490 | self.FTP_WEI = None | |
1339 | self.EXP_CODE = None |
|
1491 | self.EXP_CODE = None | |
1340 | self.SUB_EXP_CODE = None |
|
1492 | self.SUB_EXP_CODE = None | |
1341 | self.PLOT_POS = None |
|
1493 | self.PLOT_POS = None | |
1342 |
|
1494 | |||
1343 | self.filename_phase = None |
|
1495 | self.filename_phase = None | |
1344 |
|
1496 | |||
1345 | self.figfile = None |
|
1497 | self.figfile = None | |
1346 |
|
1498 | |||
1347 | self.xmin = None |
|
1499 | self.xmin = None | |
1348 | self.xmax = None |
|
1500 | self.xmax = None | |
1349 |
|
1501 | |||
1350 | def getSubplots(self): |
|
1502 | def getSubplots(self): | |
1351 |
|
1503 | |||
1352 | ncol = 1 |
|
1504 | ncol = 1 | |
1353 | nrow = 1 |
|
1505 | nrow = 1 | |
1354 |
|
1506 | |||
1355 | return nrow, ncol |
|
1507 | return nrow, ncol | |
1356 |
|
1508 | |||
1357 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1509 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1358 |
|
1510 | |||
1359 | self.__showprofile = showprofile |
|
1511 | self.__showprofile = showprofile | |
1360 | self.nplots = nplots |
|
1512 | self.nplots = nplots | |
1361 |
|
1513 | |||
1362 | ncolspan = 7 |
|
1514 | ncolspan = 7 | |
1363 | colspan = 6 |
|
1515 | colspan = 6 | |
1364 | self.__nsubplots = 2 |
|
1516 | self.__nsubplots = 2 | |
1365 |
|
1517 | |||
1366 | self.createFigure(id = id, |
|
1518 | self.createFigure(id = id, | |
1367 | wintitle = wintitle, |
|
1519 | wintitle = wintitle, | |
1368 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1520 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1369 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1521 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1370 | show=show) |
|
1522 | show=show) | |
1371 |
|
1523 | |||
1372 | nrow, ncol = self.getSubplots() |
|
1524 | nrow, ncol = self.getSubplots() | |
1373 |
|
1525 | |||
1374 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1526 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1375 |
|
1527 | |||
1376 | def save_phase(self, filename_phase): |
|
1528 | def save_phase(self, filename_phase): | |
1377 | f = open(filename_phase,'w+') |
|
1529 | f = open(filename_phase,'w+') | |
1378 | f.write('\n\n') |
|
1530 | f.write('\n\n') | |
1379 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1531 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | |
1380 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1532 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | |
1381 | f.close() |
|
1533 | f.close() | |
1382 |
|
1534 | |||
1383 | def save_data(self, filename_phase, data, data_datetime): |
|
1535 | def save_data(self, filename_phase, data, data_datetime): | |
1384 | f=open(filename_phase,'a') |
|
1536 | f=open(filename_phase,'a') | |
1385 | timetuple_data = data_datetime.timetuple() |
|
1537 | timetuple_data = data_datetime.timetuple() | |
1386 | day = str(timetuple_data.tm_mday) |
|
1538 | day = str(timetuple_data.tm_mday) | |
1387 | month = str(timetuple_data.tm_mon) |
|
1539 | month = str(timetuple_data.tm_mon) | |
1388 | year = str(timetuple_data.tm_year) |
|
1540 | year = str(timetuple_data.tm_year) | |
1389 | hour = str(timetuple_data.tm_hour) |
|
1541 | hour = str(timetuple_data.tm_hour) | |
1390 | minute = str(timetuple_data.tm_min) |
|
1542 | minute = str(timetuple_data.tm_min) | |
1391 | second = str(timetuple_data.tm_sec) |
|
1543 | second = str(timetuple_data.tm_sec) | |
1392 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1544 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1393 | f.close() |
|
1545 | f.close() | |
1394 |
|
1546 | |||
1395 |
|
1547 | |||
1396 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1548 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1397 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, |
|
1549 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, | |
1398 | timerange=None, |
|
1550 | timerange=None, | |
1399 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1551 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1400 | server=None, folder=None, username=None, password=None, |
|
1552 | server=None, folder=None, username=None, password=None, | |
1401 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1553 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1402 |
|
1554 | |||
1403 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1555 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): | |
1404 | return |
|
1556 | return | |
1405 |
|
1557 | |||
1406 | if pairsList == None: |
|
1558 | if pairsList == None: | |
1407 | pairsIndexList = dataOut.pairsIndexList[:10] |
|
1559 | pairsIndexList = dataOut.pairsIndexList[:10] | |
1408 | else: |
|
1560 | else: | |
1409 | pairsIndexList = [] |
|
1561 | pairsIndexList = [] | |
1410 | for pair in pairsList: |
|
1562 | for pair in pairsList: | |
1411 | if pair not in dataOut.pairsList: |
|
1563 | if pair not in dataOut.pairsList: | |
1412 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1564 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1413 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1565 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1414 |
|
1566 | |||
1415 | if pairsIndexList == []: |
|
1567 | if pairsIndexList == []: | |
1416 | return |
|
1568 | return | |
1417 |
|
1569 | |||
1418 | # if len(pairsIndexList) > 4: |
|
1570 | # if len(pairsIndexList) > 4: | |
1419 | # pairsIndexList = pairsIndexList[0:4] |
|
1571 | # pairsIndexList = pairsIndexList[0:4] | |
1420 |
|
1572 | |||
1421 | hmin_index = None |
|
1573 | hmin_index = None | |
1422 | hmax_index = None |
|
1574 | hmax_index = None | |
1423 |
|
1575 | |||
1424 | if hmin != None and hmax != None: |
|
1576 | if hmin != None and hmax != None: | |
1425 | indexes = numpy.arange(dataOut.nHeights) |
|
1577 | indexes = numpy.arange(dataOut.nHeights) | |
1426 | hmin_list = indexes[dataOut.heightList >= hmin] |
|
1578 | hmin_list = indexes[dataOut.heightList >= hmin] | |
1427 | hmax_list = indexes[dataOut.heightList <= hmax] |
|
1579 | hmax_list = indexes[dataOut.heightList <= hmax] | |
1428 |
|
1580 | |||
1429 | if hmin_list.any(): |
|
1581 | if hmin_list.any(): | |
1430 | hmin_index = hmin_list[0] |
|
1582 | hmin_index = hmin_list[0] | |
1431 |
|
1583 | |||
1432 | if hmax_list.any(): |
|
1584 | if hmax_list.any(): | |
1433 | hmax_index = hmax_list[-1]+1 |
|
1585 | hmax_index = hmax_list[-1]+1 | |
1434 |
|
1586 | |||
1435 | x = dataOut.getTimeRange() |
|
1587 | x = dataOut.getTimeRange() | |
1436 | #y = dataOut.getHeiRange() |
|
1588 | #y = dataOut.getHeiRange() | |
1437 |
|
1589 | |||
1438 |
|
1590 | |||
1439 | thisDatetime = dataOut.datatime |
|
1591 | thisDatetime = dataOut.datatime | |
1440 |
|
1592 | |||
1441 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1593 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1442 | xlabel = "Local Time" |
|
1594 | xlabel = "Local Time" | |
1443 | ylabel = "Phase (degrees)" |
|
1595 | ylabel = "Phase (degrees)" | |
1444 |
|
1596 | |||
1445 | update_figfile = False |
|
1597 | update_figfile = False | |
1446 |
|
1598 | |||
1447 | nplots = len(pairsIndexList) |
|
1599 | nplots = len(pairsIndexList) | |
1448 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1600 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
1449 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1601 | phase_beacon = numpy.zeros(len(pairsIndexList)) | |
1450 | for i in range(nplots): |
|
1602 | for i in range(nplots): | |
1451 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1603 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1452 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) |
|
1604 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) | |
1453 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) |
|
1605 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) | |
1454 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) |
|
1606 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) | |
1455 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1607 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1456 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1608 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1457 |
|
1609 | |||
1458 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1610 | #print "Phase %d%d" %(pair[0], pair[1]) | |
1459 | #print phase[dataOut.beacon_heiIndexList] |
|
1611 | #print phase[dataOut.beacon_heiIndexList] | |
1460 |
|
1612 | |||
1461 | if dataOut.beacon_heiIndexList: |
|
1613 | if dataOut.beacon_heiIndexList: | |
1462 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1614 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | |
1463 | else: |
|
1615 | else: | |
1464 | phase_beacon[i] = numpy.average(phase) |
|
1616 | phase_beacon[i] = numpy.average(phase) | |
1465 |
|
1617 | |||
1466 | if not self.isConfig: |
|
1618 | if not self.isConfig: | |
1467 |
|
1619 | |||
1468 | nplots = len(pairsIndexList) |
|
1620 | nplots = len(pairsIndexList) | |
1469 |
|
1621 | |||
1470 | self.setup(id=id, |
|
1622 | self.setup(id=id, | |
1471 | nplots=nplots, |
|
1623 | nplots=nplots, | |
1472 | wintitle=wintitle, |
|
1624 | wintitle=wintitle, | |
1473 | showprofile=showprofile, |
|
1625 | showprofile=showprofile, | |
1474 | show=show) |
|
1626 | show=show) | |
1475 |
|
1627 | |||
1476 | if timerange != None: |
|
1628 | if timerange != None: | |
1477 | self.timerange = timerange |
|
1629 | self.timerange = timerange | |
1478 |
|
1630 | |||
1479 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1631 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
1480 |
|
1632 | |||
1481 | if ymin == None: ymin = 0 |
|
1633 | if ymin == None: ymin = 0 | |
1482 | if ymax == None: ymax = 360 |
|
1634 | if ymax == None: ymax = 360 | |
1483 |
|
1635 | |||
1484 | self.FTP_WEI = ftp_wei |
|
1636 | self.FTP_WEI = ftp_wei | |
1485 | self.EXP_CODE = exp_code |
|
1637 | self.EXP_CODE = exp_code | |
1486 | self.SUB_EXP_CODE = sub_exp_code |
|
1638 | self.SUB_EXP_CODE = sub_exp_code | |
1487 | self.PLOT_POS = plot_pos |
|
1639 | self.PLOT_POS = plot_pos | |
1488 |
|
1640 | |||
1489 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1641 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1490 | self.isConfig = True |
|
1642 | self.isConfig = True | |
1491 | self.figfile = figfile |
|
1643 | self.figfile = figfile | |
1492 | self.xdata = numpy.array([]) |
|
1644 | self.xdata = numpy.array([]) | |
1493 | self.ydata = numpy.array([]) |
|
1645 | self.ydata = numpy.array([]) | |
1494 |
|
1646 | |||
1495 | update_figfile = True |
|
1647 | update_figfile = True | |
1496 |
|
1648 | |||
1497 | #open file beacon phase |
|
1649 | #open file beacon phase | |
1498 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1650 | path = '%s%03d' %(self.PREFIX, self.id) | |
1499 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1651 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
1500 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1652 | self.filename_phase = os.path.join(figpath,beacon_file) | |
1501 | #self.save_phase(self.filename_phase) |
|
1653 | #self.save_phase(self.filename_phase) | |
1502 |
|
1654 | |||
1503 |
|
1655 | |||
1504 | #store data beacon phase |
|
1656 | #store data beacon phase | |
1505 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1657 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
1506 |
|
1658 | |||
1507 | self.setWinTitle(title) |
|
1659 | self.setWinTitle(title) | |
1508 |
|
1660 | |||
1509 |
|
1661 | |||
1510 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1662 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1511 |
|
1663 | |||
1512 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1664 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] | |
1513 |
|
1665 | |||
1514 | axes = self.axesList[0] |
|
1666 | axes = self.axesList[0] | |
1515 |
|
1667 | |||
1516 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1668 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1517 |
|
1669 | |||
1518 | if len(self.ydata)==0: |
|
1670 | if len(self.ydata)==0: | |
1519 | self.ydata = phase_beacon.reshape(-1,1) |
|
1671 | self.ydata = phase_beacon.reshape(-1,1) | |
1520 | else: |
|
1672 | else: | |
1521 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1673 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
1522 |
|
1674 | |||
1523 |
|
1675 | |||
1524 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1676 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1525 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1677 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
1526 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1678 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1527 | XAxisAsTime=True, grid='both' |
|
1679 | XAxisAsTime=True, grid='both' | |
1528 | ) |
|
1680 | ) | |
1529 |
|
1681 | |||
1530 | self.draw() |
|
1682 | self.draw() | |
1531 |
|
1683 | |||
1532 | if dataOut.ltctime >= self.xmax: |
|
1684 | if dataOut.ltctime >= self.xmax: | |
1533 | self.counter_imagwr = wr_period |
|
1685 | self.counter_imagwr = wr_period | |
1534 | self.isConfig = False |
|
1686 | self.isConfig = False | |
1535 | update_figfile = True |
|
1687 | update_figfile = True | |
1536 |
|
1688 | |||
1537 | self.save(figpath=figpath, |
|
1689 | self.save(figpath=figpath, | |
1538 | figfile=figfile, |
|
1690 | figfile=figfile, | |
1539 | save=save, |
|
1691 | save=save, | |
1540 | ftp=ftp, |
|
1692 | ftp=ftp, | |
1541 | wr_period=wr_period, |
|
1693 | wr_period=wr_period, | |
1542 | thisDatetime=thisDatetime, |
|
1694 | thisDatetime=thisDatetime, | |
1543 | update_figfile=update_figfile) |
|
1695 | update_figfile=update_figfile) |
@@ -1,28 +1,29 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: roj-idl71 |
|
2 | @author: roj-idl71 | |
3 | ''' |
|
3 | ''' | |
4 | #USED IN jroplot_spectra.py |
|
4 | #USED IN jroplot_spectra.py | |
5 | RTI_CODE = 0 #Range time intensity (RTI). |
|
5 | RTI_CODE = 0 #Range time intensity (RTI). | |
6 | SPEC_CODE = 1 #Spectra (and Cross-spectra) information. |
|
6 | SPEC_CODE = 1 #Spectra (and Cross-spectra) information. | |
7 | CROSS_CODE = 2 #Cross-Correlation information. |
|
7 | CROSS_CODE = 2 #Cross-Correlation information. | |
8 | COH_CODE = 3 #Coherence map. |
|
8 | COH_CODE = 3 #Coherence map. | |
9 | BASE_CODE = 4 #Base lines graphic. |
|
9 | BASE_CODE = 4 #Base lines graphic. | |
10 | ROW_CODE = 5 #Row Spectra. |
|
10 | ROW_CODE = 5 #Row Spectra. | |
11 | TOTAL_CODE = 6 #Total Power. |
|
11 | TOTAL_CODE = 6 #Total Power. | |
12 | DRIFT_CODE = 7 #Drifts graphics. |
|
12 | DRIFT_CODE = 7 #Drifts graphics. | |
13 | HEIGHT_CODE = 8 #Height profile. |
|
13 | HEIGHT_CODE = 8 #Height profile. | |
14 | PHASE_CODE = 9 #Signal Phase. |
|
14 | PHASE_CODE = 9 #Signal Phase. | |
|
15 | AFC_CODE = 10 #Autocorrelation function. | |||
15 |
|
16 | |||
16 | POWER_CODE = 16 |
|
17 | POWER_CODE = 16 | |
17 | NOISE_CODE = 17 |
|
18 | NOISE_CODE = 17 | |
18 | BEACON_CODE = 18 |
|
19 | BEACON_CODE = 18 | |
19 |
|
20 | |||
20 | #USED IN jroplot_parameters.py |
|
21 | #USED IN jroplot_parameters.py | |
21 | WIND_CODE = 22 |
|
22 | WIND_CODE = 22 | |
22 | MSKYMAP_CODE = 23 |
|
23 | MSKYMAP_CODE = 23 | |
23 | MPHASE_CODE = 24 |
|
24 | MPHASE_CODE = 24 | |
24 |
|
25 | |||
25 | MOMENTS_CODE = 25 |
|
26 | MOMENTS_CODE = 25 | |
26 | PARMS_CODE = 26 |
|
27 | PARMS_CODE = 26 | |
27 | SPECFIT_CODE = 27 |
|
28 | SPECFIT_CODE = 27 | |
28 | EWDRIFT_CODE = 28 |
|
29 | EWDRIFT_CODE = 28 |
@@ -1,960 +1,962 | |||||
1 | import itertools |
|
1 | import itertools | |
2 |
|
2 | |||
3 | import numpy |
|
3 | import numpy | |
4 |
|
4 | |||
5 | from jroproc_base import ProcessingUnit, Operation |
|
5 | from jroproc_base import ProcessingUnit, Operation | |
6 | from schainpy.model.data.jrodata import Spectra |
|
6 | from schainpy.model.data.jrodata import Spectra | |
7 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
7 | from schainpy.model.data.jrodata import hildebrand_sekhon | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | class SpectraProc(ProcessingUnit): |
|
10 | class SpectraProc(ProcessingUnit): | |
11 |
|
11 | |||
12 | def __init__(self, **kwargs): |
|
12 | def __init__(self, **kwargs): | |
13 |
|
13 | |||
14 | ProcessingUnit.__init__(self, **kwargs) |
|
14 | ProcessingUnit.__init__(self, **kwargs) | |
15 |
|
15 | |||
16 | self.buffer = None |
|
16 | self.buffer = None | |
17 | self.firstdatatime = None |
|
17 | self.firstdatatime = None | |
18 | self.profIndex = 0 |
|
18 | self.profIndex = 0 | |
19 | self.dataOut = Spectra() |
|
19 | self.dataOut = Spectra() | |
20 | self.id_min = None |
|
20 | self.id_min = None | |
21 | self.id_max = None |
|
21 | self.id_max = None | |
22 |
|
22 | |||
23 | def __updateSpecFromVoltage(self): |
|
23 | def __updateSpecFromVoltage(self): | |
24 |
|
24 | |||
25 | self.dataOut.timeZone = self.dataIn.timeZone |
|
25 | self.dataOut.timeZone = self.dataIn.timeZone | |
26 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
26 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
27 | self.dataOut.errorCount = self.dataIn.errorCount |
|
27 | self.dataOut.errorCount = self.dataIn.errorCount | |
28 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
28 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
29 | try: |
|
29 | try: | |
30 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() |
|
30 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() | |
31 | except: |
|
31 | except: | |
32 | pass |
|
32 | pass | |
33 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
33 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
34 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
34 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
35 | self.dataOut.channelList = self.dataIn.channelList |
|
35 | self.dataOut.channelList = self.dataIn.channelList | |
36 | self.dataOut.heightList = self.dataIn.heightList |
|
36 | self.dataOut.heightList = self.dataIn.heightList | |
37 | #print self.dataOut.heightList.shape,"spec4" |
|
37 | #print self.dataOut.heightList.shape,"spec4" | |
38 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
38 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
39 |
|
39 | |||
40 | self.dataOut.nBaud = self.dataIn.nBaud |
|
40 | self.dataOut.nBaud = self.dataIn.nBaud | |
41 | self.dataOut.nCode = self.dataIn.nCode |
|
41 | self.dataOut.nCode = self.dataIn.nCode | |
42 | self.dataOut.code = self.dataIn.code |
|
42 | self.dataOut.code = self.dataIn.code | |
43 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
43 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
44 |
|
44 | |||
45 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
45 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
46 | self.dataOut.utctime = self.firstdatatime |
|
46 | self.dataOut.utctime = self.firstdatatime | |
47 | # asumo q la data esta decodificada |
|
47 | # asumo q la data esta decodificada | |
48 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData |
|
48 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData | |
49 | # asumo q la data esta sin flip |
|
49 | # asumo q la data esta sin flip | |
50 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData |
|
50 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData | |
51 | self.dataOut.flagShiftFFT = False |
|
51 | self.dataOut.flagShiftFFT = False | |
52 |
|
52 | |||
53 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
53 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
54 | self.dataOut.nIncohInt = 1 |
|
54 | self.dataOut.nIncohInt = 1 | |
55 |
|
55 | |||
56 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
56 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
57 |
|
57 | |||
58 | self.dataOut.frequency = self.dataIn.frequency |
|
58 | self.dataOut.frequency = self.dataIn.frequency | |
59 | self.dataOut.realtime = self.dataIn.realtime |
|
59 | self.dataOut.realtime = self.dataIn.realtime | |
60 |
|
60 | |||
61 | self.dataOut.azimuth = self.dataIn.azimuth |
|
61 | self.dataOut.azimuth = self.dataIn.azimuth | |
62 | self.dataOut.zenith = self.dataIn.zenith |
|
62 | self.dataOut.zenith = self.dataIn.zenith | |
63 |
|
63 | |||
64 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
64 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
65 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
65 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
66 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
66 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
67 |
|
67 | |||
|
68 | self.dataOut.step = self.dataIn.step | |||
|
69 | ||||
68 | def __getFft(self): |
|
70 | def __getFft(self): | |
69 | """ |
|
71 | """ | |
70 | Convierte valores de Voltaje a Spectra |
|
72 | Convierte valores de Voltaje a Spectra | |
71 |
|
73 | |||
72 | Affected: |
|
74 | Affected: | |
73 | self.dataOut.data_spc |
|
75 | self.dataOut.data_spc | |
74 | self.dataOut.data_cspc |
|
76 | self.dataOut.data_cspc | |
75 | self.dataOut.data_dc |
|
77 | self.dataOut.data_dc | |
76 | self.dataOut.heightList |
|
78 | self.dataOut.heightList | |
77 | self.profIndex |
|
79 | self.profIndex | |
78 | self.buffer |
|
80 | self.buffer | |
79 | self.dataOut.flagNoData |
|
81 | self.dataOut.flagNoData | |
80 | """ |
|
82 | """ | |
81 | fft_volt = numpy.fft.fft( |
|
83 | fft_volt = numpy.fft.fft( | |
82 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) |
|
84 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) | |
83 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
85 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
84 | dc = fft_volt[:, 0, :] |
|
86 | dc = fft_volt[:, 0, :] | |
85 |
|
87 | |||
86 | # calculo de self-spectra |
|
88 | # calculo de self-spectra | |
87 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) |
|
89 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) | |
88 | #print "spec dtype 0",fft_volt.dtype |
|
90 | #print "spec dtype 0",fft_volt.dtype | |
89 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
91 | spc = fft_volt * numpy.conjugate(fft_volt) | |
90 | spc = spc.real |
|
92 | spc = spc.real | |
91 | #print "spec dtype 1",spc.dtype |
|
93 | #print "spec dtype 1",spc.dtype | |
92 |
|
94 | |||
93 | blocksize = 0 |
|
95 | blocksize = 0 | |
94 | blocksize += dc.size |
|
96 | blocksize += dc.size | |
95 | blocksize += spc.size |
|
97 | blocksize += spc.size | |
96 |
|
98 | |||
97 | cspc = None |
|
99 | cspc = None | |
98 | pairIndex = 0 |
|
100 | pairIndex = 0 | |
99 | if self.dataOut.pairsList != None: |
|
101 | if self.dataOut.pairsList != None: | |
100 | # calculo de cross-spectra |
|
102 | # calculo de cross-spectra | |
101 | cspc = numpy.zeros( |
|
103 | cspc = numpy.zeros( | |
102 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
104 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
103 | for pair in self.dataOut.pairsList: |
|
105 | for pair in self.dataOut.pairsList: | |
104 | if pair[0] not in self.dataOut.channelList: |
|
106 | if pair[0] not in self.dataOut.channelList: | |
105 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( |
|
107 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( | |
106 | str(pair), str(self.dataOut.channelList)) |
|
108 | str(pair), str(self.dataOut.channelList)) | |
107 | if pair[1] not in self.dataOut.channelList: |
|
109 | if pair[1] not in self.dataOut.channelList: | |
108 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( |
|
110 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( | |
109 | str(pair), str(self.dataOut.channelList)) |
|
111 | str(pair), str(self.dataOut.channelList)) | |
110 |
|
112 | |||
111 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ |
|
113 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ | |
112 | numpy.conjugate(fft_volt[pair[1], :, :]) |
|
114 | numpy.conjugate(fft_volt[pair[1], :, :]) | |
113 | pairIndex += 1 |
|
115 | pairIndex += 1 | |
114 | blocksize += cspc.size |
|
116 | blocksize += cspc.size | |
115 |
|
117 | |||
116 | self.dataOut.data_spc = spc |
|
118 | self.dataOut.data_spc = spc | |
117 | self.dataOut.data_cspc = cspc |
|
119 | self.dataOut.data_cspc = cspc | |
118 | self.dataOut.data_dc = dc |
|
120 | self.dataOut.data_dc = dc | |
119 | self.dataOut.blockSize = blocksize |
|
121 | self.dataOut.blockSize = blocksize | |
120 | self.dataOut.flagShiftFFT = True |
|
122 | self.dataOut.flagShiftFFT = True | |
121 |
|
123 | |||
122 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False): |
|
124 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False): | |
123 |
|
125 | |||
124 | self.dataOut.flagNoData = True |
|
126 | self.dataOut.flagNoData = True | |
125 |
|
127 | |||
126 | if self.dataIn.type == "Spectra": |
|
128 | if self.dataIn.type == "Spectra": | |
127 | self.dataOut.copy(self.dataIn) |
|
129 | self.dataOut.copy(self.dataIn) | |
128 | # if not pairsList: |
|
130 | # if not pairsList: | |
129 | # pairsList = itertools.combinations(self.dataOut.channelList, 2) |
|
131 | # pairsList = itertools.combinations(self.dataOut.channelList, 2) | |
130 | # if self.dataOut.data_cspc is not None: |
|
132 | # if self.dataOut.data_cspc is not None: | |
131 | # self.__selectPairs(pairsList) |
|
133 | # self.__selectPairs(pairsList) | |
132 | if shift_fft: |
|
134 | if shift_fft: | |
133 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
135 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
134 | shift = int(self.dataOut.nFFTPoints/2) |
|
136 | shift = int(self.dataOut.nFFTPoints/2) | |
135 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) |
|
137 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) | |
136 |
|
138 | |||
137 | if self.dataOut.data_cspc is not None: |
|
139 | if self.dataOut.data_cspc is not None: | |
138 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
140 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
139 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) |
|
141 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) | |
140 |
|
142 | |||
141 | return True |
|
143 | return True | |
142 |
|
144 | |||
143 | if self.dataIn.type == "Voltage": |
|
145 | if self.dataIn.type == "Voltage": | |
144 |
|
146 | |||
145 | if nFFTPoints == None: |
|
147 | if nFFTPoints == None: | |
146 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
148 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" | |
147 |
|
149 | |||
148 | if nProfiles == None: |
|
150 | if nProfiles == None: | |
149 | nProfiles = nFFTPoints |
|
151 | nProfiles = nFFTPoints | |
150 |
|
152 | |||
151 | if ippFactor == None: |
|
153 | if ippFactor == None: | |
152 | ippFactor = 1 |
|
154 | ippFactor = 1 | |
153 |
|
155 | |||
154 | self.dataOut.ippFactor = ippFactor |
|
156 | self.dataOut.ippFactor = ippFactor | |
155 |
|
157 | |||
156 | self.dataOut.nFFTPoints = nFFTPoints |
|
158 | self.dataOut.nFFTPoints = nFFTPoints | |
157 | self.dataOut.pairsList = pairsList |
|
159 | self.dataOut.pairsList = pairsList | |
158 |
|
160 | |||
159 | if self.buffer is None: |
|
161 | if self.buffer is None: | |
160 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
162 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
161 | nProfiles, |
|
163 | nProfiles, | |
162 | self.dataIn.heightList.shape[0]), |
|
164 | self.dataIn.heightList.shape[0]), | |
163 | dtype='complex') |
|
165 | dtype='complex') | |
164 |
|
166 | |||
165 | #print self.buffer.shape,"spec2" |
|
167 | #print self.buffer.shape,"spec2" | |
166 | #print self.dataIn.heightList.shape[0],"spec3" |
|
168 | #print self.dataIn.heightList.shape[0],"spec3" | |
167 |
|
169 | |||
168 | if self.dataIn.flagDataAsBlock: |
|
170 | if self.dataIn.flagDataAsBlock: | |
169 | # data dimension: [nChannels, nProfiles, nSamples] |
|
171 | # data dimension: [nChannels, nProfiles, nSamples] | |
170 | nVoltProfiles = self.dataIn.data.shape[1] |
|
172 | nVoltProfiles = self.dataIn.data.shape[1] | |
171 | # nVoltProfiles = self.dataIn.nProfiles |
|
173 | # nVoltProfiles = self.dataIn.nProfiles | |
172 |
|
174 | |||
173 | #print nVoltProfiles,"spec1" |
|
175 | #print nVoltProfiles,"spec1" | |
174 | #print nProfiles |
|
176 | #print nProfiles | |
175 | if nVoltProfiles == nProfiles: |
|
177 | if nVoltProfiles == nProfiles: | |
176 | self.buffer = self.dataIn.data.copy() |
|
178 | self.buffer = self.dataIn.data.copy() | |
177 | self.profIndex = nVoltProfiles |
|
179 | self.profIndex = nVoltProfiles | |
178 |
|
180 | |||
179 | elif nVoltProfiles < nProfiles: |
|
181 | elif nVoltProfiles < nProfiles: | |
180 |
|
182 | |||
181 | if self.profIndex == 0: |
|
183 | if self.profIndex == 0: | |
182 | self.id_min = 0 |
|
184 | self.id_min = 0 | |
183 | self.id_max = nVoltProfiles |
|
185 | self.id_max = nVoltProfiles | |
184 |
|
186 | |||
185 | self.buffer[:, self.id_min:self.id_max,:] = self.dataIn.data |
|
187 | self.buffer[:, self.id_min:self.id_max,:] = self.dataIn.data | |
186 | self.profIndex += nVoltProfiles |
|
188 | self.profIndex += nVoltProfiles | |
187 | self.id_min += nVoltProfiles |
|
189 | self.id_min += nVoltProfiles | |
188 | self.id_max += nVoltProfiles |
|
190 | self.id_max += nVoltProfiles | |
189 | else: |
|
191 | else: | |
190 | raise ValueError, "The type object %s has %d profiles, it should just has %d profiles" % ( |
|
192 | raise ValueError, "The type object %s has %d profiles, it should just has %d profiles" % ( | |
191 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles) |
|
193 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles) | |
192 | self.dataOut.flagNoData = True |
|
194 | self.dataOut.flagNoData = True | |
193 | return 0 |
|
195 | return 0 | |
194 | else: |
|
196 | else: | |
195 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() |
|
197 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() | |
196 | self.profIndex += 1 |
|
198 | self.profIndex += 1 | |
197 | #print self.profIndex,"spectra D" |
|
199 | #print self.profIndex,"spectra D" | |
198 |
|
200 | |||
199 | if self.firstdatatime == None: |
|
201 | if self.firstdatatime == None: | |
200 | self.firstdatatime = self.dataIn.utctime |
|
202 | self.firstdatatime = self.dataIn.utctime | |
201 |
|
203 | |||
202 | if self.profIndex == nProfiles: |
|
204 | if self.profIndex == nProfiles: | |
203 | self.__updateSpecFromVoltage() |
|
205 | self.__updateSpecFromVoltage() | |
204 | self.__getFft() |
|
206 | self.__getFft() | |
205 |
|
207 | |||
206 | self.dataOut.flagNoData = False |
|
208 | self.dataOut.flagNoData = False | |
207 | self.firstdatatime = None |
|
209 | self.firstdatatime = None | |
208 | self.profIndex = 0 |
|
210 | self.profIndex = 0 | |
209 |
|
211 | |||
210 | return True |
|
212 | return True | |
211 |
|
213 | |||
212 | raise ValueError, "The type of input object '%s' is not valid" % ( |
|
214 | raise ValueError, "The type of input object '%s' is not valid" % ( | |
213 | self.dataIn.type) |
|
215 | self.dataIn.type) | |
214 |
|
216 | |||
215 | def __selectPairs(self, pairsList): |
|
217 | def __selectPairs(self, pairsList): | |
216 |
|
218 | |||
217 | if not pairsList: |
|
219 | if not pairsList: | |
218 | return |
|
220 | return | |
219 |
|
221 | |||
220 | pairs = [] |
|
222 | pairs = [] | |
221 | pairsIndex = [] |
|
223 | pairsIndex = [] | |
222 |
|
224 | |||
223 | for pair in pairsList: |
|
225 | for pair in pairsList: | |
224 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: |
|
226 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: | |
225 | continue |
|
227 | continue | |
226 | pairs.append(pair) |
|
228 | pairs.append(pair) | |
227 | pairsIndex.append(pairs.index(pair)) |
|
229 | pairsIndex.append(pairs.index(pair)) | |
228 |
|
230 | |||
229 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] |
|
231 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] | |
230 | self.dataOut.pairsList = pairs |
|
232 | self.dataOut.pairsList = pairs | |
231 |
|
233 | |||
232 | return |
|
234 | return | |
233 |
|
235 | |||
234 | def __selectPairsByChannel(self, channelList=None): |
|
236 | def __selectPairsByChannel(self, channelList=None): | |
235 |
|
237 | |||
236 | if channelList == None: |
|
238 | if channelList == None: | |
237 | return |
|
239 | return | |
238 |
|
240 | |||
239 | pairsIndexListSelected = [] |
|
241 | pairsIndexListSelected = [] | |
240 | for pairIndex in self.dataOut.pairsIndexList: |
|
242 | for pairIndex in self.dataOut.pairsIndexList: | |
241 | # First pair |
|
243 | # First pair | |
242 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
244 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
243 | continue |
|
245 | continue | |
244 | # Second pair |
|
246 | # Second pair | |
245 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
247 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
246 | continue |
|
248 | continue | |
247 |
|
249 | |||
248 | pairsIndexListSelected.append(pairIndex) |
|
250 | pairsIndexListSelected.append(pairIndex) | |
249 |
|
251 | |||
250 | if not pairsIndexListSelected: |
|
252 | if not pairsIndexListSelected: | |
251 | self.dataOut.data_cspc = None |
|
253 | self.dataOut.data_cspc = None | |
252 | self.dataOut.pairsList = [] |
|
254 | self.dataOut.pairsList = [] | |
253 | return |
|
255 | return | |
254 |
|
256 | |||
255 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
257 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
256 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
258 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
257 | for i in pairsIndexListSelected] |
|
259 | for i in pairsIndexListSelected] | |
258 |
|
260 | |||
259 | return |
|
261 | return | |
260 |
|
262 | |||
261 | def selectChannels(self, channelList): |
|
263 | def selectChannels(self, channelList): | |
262 |
|
264 | |||
263 | channelIndexList = [] |
|
265 | channelIndexList = [] | |
264 |
|
266 | |||
265 | for channel in channelList: |
|
267 | for channel in channelList: | |
266 | if channel not in self.dataOut.channelList: |
|
268 | if channel not in self.dataOut.channelList: | |
267 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % ( |
|
269 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % ( | |
268 | channel, str(self.dataOut.channelList)) |
|
270 | channel, str(self.dataOut.channelList)) | |
269 |
|
271 | |||
270 | index = self.dataOut.channelList.index(channel) |
|
272 | index = self.dataOut.channelList.index(channel) | |
271 | channelIndexList.append(index) |
|
273 | channelIndexList.append(index) | |
272 |
|
274 | |||
273 | self.selectChannelsByIndex(channelIndexList) |
|
275 | self.selectChannelsByIndex(channelIndexList) | |
274 |
|
276 | |||
275 | def selectChannelsByIndex(self, channelIndexList): |
|
277 | def selectChannelsByIndex(self, channelIndexList): | |
276 | """ |
|
278 | """ | |
277 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
279 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
278 |
|
280 | |||
279 | Input: |
|
281 | Input: | |
280 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
282 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
281 |
|
283 | |||
282 | Affected: |
|
284 | Affected: | |
283 | self.dataOut.data_spc |
|
285 | self.dataOut.data_spc | |
284 | self.dataOut.channelIndexList |
|
286 | self.dataOut.channelIndexList | |
285 | self.dataOut.nChannels |
|
287 | self.dataOut.nChannels | |
286 |
|
288 | |||
287 | Return: |
|
289 | Return: | |
288 | None |
|
290 | None | |
289 | """ |
|
291 | """ | |
290 |
|
292 | |||
291 | for channelIndex in channelIndexList: |
|
293 | for channelIndex in channelIndexList: | |
292 | if channelIndex not in self.dataOut.channelIndexList: |
|
294 | if channelIndex not in self.dataOut.channelIndexList: | |
293 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % ( |
|
295 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % ( | |
294 | channelIndex, self.dataOut.channelIndexList) |
|
296 | channelIndex, self.dataOut.channelIndexList) | |
295 |
|
297 | |||
296 | # nChannels = len(channelIndexList) |
|
298 | # nChannels = len(channelIndexList) | |
297 |
|
299 | |||
298 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
300 | data_spc = self.dataOut.data_spc[channelIndexList, :] | |
299 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
301 | data_dc = self.dataOut.data_dc[channelIndexList, :] | |
300 |
|
302 | |||
301 | self.dataOut.data_spc = data_spc |
|
303 | self.dataOut.data_spc = data_spc | |
302 | self.dataOut.data_dc = data_dc |
|
304 | self.dataOut.data_dc = data_dc | |
303 |
|
305 | |||
304 | self.dataOut.channelList = [ |
|
306 | self.dataOut.channelList = [ | |
305 | self.dataOut.channelList[i] for i in channelIndexList] |
|
307 | self.dataOut.channelList[i] for i in channelIndexList] | |
306 | # self.dataOut.nChannels = nChannels |
|
308 | # self.dataOut.nChannels = nChannels | |
307 |
|
309 | |||
308 | self.__selectPairsByChannel(self.dataOut.channelList) |
|
310 | self.__selectPairsByChannel(self.dataOut.channelList) | |
309 |
|
311 | |||
310 | return 1 |
|
312 | return 1 | |
311 |
|
313 | |||
312 | def selectHeights(self, minHei, maxHei): |
|
314 | def selectHeights(self, minHei, maxHei): | |
313 | """ |
|
315 | """ | |
314 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
316 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
315 | minHei <= height <= maxHei |
|
317 | minHei <= height <= maxHei | |
316 |
|
318 | |||
317 | Input: |
|
319 | Input: | |
318 | minHei : valor minimo de altura a considerar |
|
320 | minHei : valor minimo de altura a considerar | |
319 | maxHei : valor maximo de altura a considerar |
|
321 | maxHei : valor maximo de altura a considerar | |
320 |
|
322 | |||
321 | Affected: |
|
323 | Affected: | |
322 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
324 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
323 |
|
325 | |||
324 | Return: |
|
326 | Return: | |
325 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
327 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
326 | """ |
|
328 | """ | |
327 |
|
329 | |||
328 | if (minHei > maxHei): |
|
330 | if (minHei > maxHei): | |
329 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % ( |
|
331 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % ( | |
330 | minHei, maxHei) |
|
332 | minHei, maxHei) | |
331 |
|
333 | |||
332 | if (minHei < self.dataOut.heightList[0]): |
|
334 | if (minHei < self.dataOut.heightList[0]): | |
333 | minHei = self.dataOut.heightList[0] |
|
335 | minHei = self.dataOut.heightList[0] | |
334 |
|
336 | |||
335 | if (maxHei > self.dataOut.heightList[-1]): |
|
337 | if (maxHei > self.dataOut.heightList[-1]): | |
336 | maxHei = self.dataOut.heightList[-1] |
|
338 | maxHei = self.dataOut.heightList[-1] | |
337 |
|
339 | |||
338 | minIndex = 0 |
|
340 | minIndex = 0 | |
339 | maxIndex = 0 |
|
341 | maxIndex = 0 | |
340 | heights = self.dataOut.heightList |
|
342 | heights = self.dataOut.heightList | |
341 |
|
343 | |||
342 | inda = numpy.where(heights >= minHei) |
|
344 | inda = numpy.where(heights >= minHei) | |
343 | indb = numpy.where(heights <= maxHei) |
|
345 | indb = numpy.where(heights <= maxHei) | |
344 |
|
346 | |||
345 | try: |
|
347 | try: | |
346 | minIndex = inda[0][0] |
|
348 | minIndex = inda[0][0] | |
347 | except: |
|
349 | except: | |
348 | minIndex = 0 |
|
350 | minIndex = 0 | |
349 |
|
351 | |||
350 | try: |
|
352 | try: | |
351 | maxIndex = indb[0][-1] |
|
353 | maxIndex = indb[0][-1] | |
352 | except: |
|
354 | except: | |
353 | maxIndex = len(heights) |
|
355 | maxIndex = len(heights) | |
354 |
|
356 | |||
355 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
357 | self.selectHeightsByIndex(minIndex, maxIndex) | |
356 |
|
358 | |||
357 | return 1 |
|
359 | return 1 | |
358 |
|
360 | |||
359 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): |
|
361 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): | |
360 | newheis = numpy.where( |
|
362 | newheis = numpy.where( | |
361 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
363 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
362 |
|
364 | |||
363 | if hei_ref != None: |
|
365 | if hei_ref != None: | |
364 | newheis = numpy.where(self.dataOut.heightList > hei_ref) |
|
366 | newheis = numpy.where(self.dataOut.heightList > hei_ref) | |
365 |
|
367 | |||
366 | minIndex = min(newheis[0]) |
|
368 | minIndex = min(newheis[0]) | |
367 | maxIndex = max(newheis[0]) |
|
369 | maxIndex = max(newheis[0]) | |
368 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
370 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
369 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
371 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
370 |
|
372 | |||
371 | # determina indices |
|
373 | # determina indices | |
372 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / |
|
374 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / | |
373 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) |
|
375 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) | |
374 | avg_dB = 10 * \ |
|
376 | avg_dB = 10 * \ | |
375 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) |
|
377 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) | |
376 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
378 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
377 | beacon_heiIndexList = [] |
|
379 | beacon_heiIndexList = [] | |
378 | for val in avg_dB.tolist(): |
|
380 | for val in avg_dB.tolist(): | |
379 | if val >= beacon_dB[0]: |
|
381 | if val >= beacon_dB[0]: | |
380 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
382 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
381 |
|
383 | |||
382 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
384 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
383 | data_cspc = None |
|
385 | data_cspc = None | |
384 | if self.dataOut.data_cspc is not None: |
|
386 | if self.dataOut.data_cspc is not None: | |
385 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
387 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
386 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
388 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
387 |
|
389 | |||
388 | data_dc = None |
|
390 | data_dc = None | |
389 | if self.dataOut.data_dc is not None: |
|
391 | if self.dataOut.data_dc is not None: | |
390 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
392 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
391 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
393 | #data_dc = data_dc[:,beacon_heiIndexList] | |
392 |
|
394 | |||
393 | self.dataOut.data_spc = data_spc |
|
395 | self.dataOut.data_spc = data_spc | |
394 | self.dataOut.data_cspc = data_cspc |
|
396 | self.dataOut.data_cspc = data_cspc | |
395 | self.dataOut.data_dc = data_dc |
|
397 | self.dataOut.data_dc = data_dc | |
396 | self.dataOut.heightList = heightList |
|
398 | self.dataOut.heightList = heightList | |
397 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
399 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
398 |
|
400 | |||
399 | return 1 |
|
401 | return 1 | |
400 |
|
402 | |||
401 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
403 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
402 | """ |
|
404 | """ | |
403 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
405 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
404 | minIndex <= index <= maxIndex |
|
406 | minIndex <= index <= maxIndex | |
405 |
|
407 | |||
406 | Input: |
|
408 | Input: | |
407 | minIndex : valor de indice minimo de altura a considerar |
|
409 | minIndex : valor de indice minimo de altura a considerar | |
408 | maxIndex : valor de indice maximo de altura a considerar |
|
410 | maxIndex : valor de indice maximo de altura a considerar | |
409 |
|
411 | |||
410 | Affected: |
|
412 | Affected: | |
411 | self.dataOut.data_spc |
|
413 | self.dataOut.data_spc | |
412 | self.dataOut.data_cspc |
|
414 | self.dataOut.data_cspc | |
413 | self.dataOut.data_dc |
|
415 | self.dataOut.data_dc | |
414 | self.dataOut.heightList |
|
416 | self.dataOut.heightList | |
415 |
|
417 | |||
416 | Return: |
|
418 | Return: | |
417 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
419 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
418 | """ |
|
420 | """ | |
419 |
|
421 | |||
420 | if (minIndex < 0) or (minIndex > maxIndex): |
|
422 | if (minIndex < 0) or (minIndex > maxIndex): | |
421 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
423 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % ( | |
422 | minIndex, maxIndex) |
|
424 | minIndex, maxIndex) | |
423 |
|
425 | |||
424 | if (maxIndex >= self.dataOut.nHeights): |
|
426 | if (maxIndex >= self.dataOut.nHeights): | |
425 | maxIndex = self.dataOut.nHeights - 1 |
|
427 | maxIndex = self.dataOut.nHeights - 1 | |
426 |
|
428 | |||
427 | # Spectra |
|
429 | # Spectra | |
428 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
430 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
429 |
|
431 | |||
430 | data_cspc = None |
|
432 | data_cspc = None | |
431 | if self.dataOut.data_cspc is not None: |
|
433 | if self.dataOut.data_cspc is not None: | |
432 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
434 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
433 |
|
435 | |||
434 | data_dc = None |
|
436 | data_dc = None | |
435 | if self.dataOut.data_dc is not None: |
|
437 | if self.dataOut.data_dc is not None: | |
436 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
438 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
437 |
|
439 | |||
438 | self.dataOut.data_spc = data_spc |
|
440 | self.dataOut.data_spc = data_spc | |
439 | self.dataOut.data_cspc = data_cspc |
|
441 | self.dataOut.data_cspc = data_cspc | |
440 | self.dataOut.data_dc = data_dc |
|
442 | self.dataOut.data_dc = data_dc | |
441 |
|
443 | |||
442 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
444 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
443 |
|
445 | |||
444 | return 1 |
|
446 | return 1 | |
445 |
|
447 | |||
446 | def removeDC(self, mode=2): |
|
448 | def removeDC(self, mode=2): | |
447 | jspectra = self.dataOut.data_spc |
|
449 | jspectra = self.dataOut.data_spc | |
448 | jcspectra = self.dataOut.data_cspc |
|
450 | jcspectra = self.dataOut.data_cspc | |
449 |
|
451 | |||
450 | num_chan = jspectra.shape[0] |
|
452 | num_chan = jspectra.shape[0] | |
451 | num_hei = jspectra.shape[2] |
|
453 | num_hei = jspectra.shape[2] | |
452 |
|
454 | |||
453 | if jcspectra is not None: |
|
455 | if jcspectra is not None: | |
454 | jcspectraExist = True |
|
456 | jcspectraExist = True | |
455 | num_pairs = jcspectra.shape[0] |
|
457 | num_pairs = jcspectra.shape[0] | |
456 | else: |
|
458 | else: | |
457 | jcspectraExist = False |
|
459 | jcspectraExist = False | |
458 |
|
460 | |||
459 | freq_dc = jspectra.shape[1] / 2 |
|
461 | freq_dc = jspectra.shape[1] / 2 | |
460 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
462 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
461 |
|
463 | |||
462 | if ind_vel[0] < 0: |
|
464 | if ind_vel[0] < 0: | |
463 | ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof |
|
465 | ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof | |
464 |
|
466 | |||
465 | if mode == 1: |
|
467 | if mode == 1: | |
466 | jspectra[:, freq_dc, :] = ( |
|
468 | jspectra[:, freq_dc, :] = ( | |
467 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
469 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |
468 |
|
470 | |||
469 | if jcspectraExist: |
|
471 | if jcspectraExist: | |
470 | jcspectra[:, freq_dc, :] = ( |
|
472 | jcspectra[:, freq_dc, :] = ( | |
471 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 |
|
473 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 | |
472 |
|
474 | |||
473 | if mode == 2: |
|
475 | if mode == 2: | |
474 |
|
476 | |||
475 | vel = numpy.array([-2, -1, 1, 2]) |
|
477 | vel = numpy.array([-2, -1, 1, 2]) | |
476 | xx = numpy.zeros([4, 4]) |
|
478 | xx = numpy.zeros([4, 4]) | |
477 |
|
479 | |||
478 | for fil in range(4): |
|
480 | for fil in range(4): | |
479 | xx[fil, :] = vel[fil]**numpy.asarray(range(4)) |
|
481 | xx[fil, :] = vel[fil]**numpy.asarray(range(4)) | |
480 |
|
482 | |||
481 | xx_inv = numpy.linalg.inv(xx) |
|
483 | xx_inv = numpy.linalg.inv(xx) | |
482 | xx_aux = xx_inv[0, :] |
|
484 | xx_aux = xx_inv[0, :] | |
483 |
|
485 | |||
484 | for ich in range(num_chan): |
|
486 | for ich in range(num_chan): | |
485 | yy = jspectra[ich, ind_vel, :] |
|
487 | yy = jspectra[ich, ind_vel, :] | |
486 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
488 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) | |
487 |
|
489 | |||
488 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
490 | junkid = jspectra[ich, freq_dc, :] <= 0 | |
489 | cjunkid = sum(junkid) |
|
491 | cjunkid = sum(junkid) | |
490 |
|
492 | |||
491 | if cjunkid.any(): |
|
493 | if cjunkid.any(): | |
492 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
494 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
493 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
495 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |
494 |
|
496 | |||
495 | if jcspectraExist: |
|
497 | if jcspectraExist: | |
496 | for ip in range(num_pairs): |
|
498 | for ip in range(num_pairs): | |
497 | yy = jcspectra[ip, ind_vel, :] |
|
499 | yy = jcspectra[ip, ind_vel, :] | |
498 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
500 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) | |
499 |
|
501 | |||
500 | self.dataOut.data_spc = jspectra |
|
502 | self.dataOut.data_spc = jspectra | |
501 | self.dataOut.data_cspc = jcspectra |
|
503 | self.dataOut.data_cspc = jcspectra | |
502 |
|
504 | |||
503 | return 1 |
|
505 | return 1 | |
504 |
|
506 | |||
505 | def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None): |
|
507 | def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None): | |
506 |
|
508 | |||
507 | jspectra = self.dataOut.data_spc |
|
509 | jspectra = self.dataOut.data_spc | |
508 | jcspectra = self.dataOut.data_cspc |
|
510 | jcspectra = self.dataOut.data_cspc | |
509 | jnoise = self.dataOut.getNoise() |
|
511 | jnoise = self.dataOut.getNoise() | |
510 | num_incoh = self.dataOut.nIncohInt |
|
512 | num_incoh = self.dataOut.nIncohInt | |
511 |
|
513 | |||
512 | num_channel = jspectra.shape[0] |
|
514 | num_channel = jspectra.shape[0] | |
513 | num_prof = jspectra.shape[1] |
|
515 | num_prof = jspectra.shape[1] | |
514 | num_hei = jspectra.shape[2] |
|
516 | num_hei = jspectra.shape[2] | |
515 |
|
517 | |||
516 | # hei_interf |
|
518 | # hei_interf | |
517 | if hei_interf is None: |
|
519 | if hei_interf is None: | |
518 | count_hei = num_hei / 2 # Como es entero no importa |
|
520 | count_hei = num_hei / 2 # Como es entero no importa | |
519 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
521 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |
520 | hei_interf = numpy.asarray(hei_interf)[0] |
|
522 | hei_interf = numpy.asarray(hei_interf)[0] | |
521 | # nhei_interf |
|
523 | # nhei_interf | |
522 | if (nhei_interf == None): |
|
524 | if (nhei_interf == None): | |
523 | nhei_interf = 5 |
|
525 | nhei_interf = 5 | |
524 | if (nhei_interf < 1): |
|
526 | if (nhei_interf < 1): | |
525 | nhei_interf = 1 |
|
527 | nhei_interf = 1 | |
526 | if (nhei_interf > count_hei): |
|
528 | if (nhei_interf > count_hei): | |
527 | nhei_interf = count_hei |
|
529 | nhei_interf = count_hei | |
528 | if (offhei_interf == None): |
|
530 | if (offhei_interf == None): | |
529 | offhei_interf = 0 |
|
531 | offhei_interf = 0 | |
530 |
|
532 | |||
531 | ind_hei = range(num_hei) |
|
533 | ind_hei = range(num_hei) | |
532 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
534 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
533 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
535 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
534 | mask_prof = numpy.asarray(range(num_prof)) |
|
536 | mask_prof = numpy.asarray(range(num_prof)) | |
535 | num_mask_prof = mask_prof.size |
|
537 | num_mask_prof = mask_prof.size | |
536 | comp_mask_prof = [0, num_prof / 2] |
|
538 | comp_mask_prof = [0, num_prof / 2] | |
537 |
|
539 | |||
538 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
540 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
539 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
541 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
540 | jnoise = numpy.nan |
|
542 | jnoise = numpy.nan | |
541 | noise_exist = jnoise[0] < numpy.Inf |
|
543 | noise_exist = jnoise[0] < numpy.Inf | |
542 |
|
544 | |||
543 | # Subrutina de Remocion de la Interferencia |
|
545 | # Subrutina de Remocion de la Interferencia | |
544 | for ich in range(num_channel): |
|
546 | for ich in range(num_channel): | |
545 | # Se ordena los espectros segun su potencia (menor a mayor) |
|
547 | # Se ordena los espectros segun su potencia (menor a mayor) | |
546 | power = jspectra[ich, mask_prof, :] |
|
548 | power = jspectra[ich, mask_prof, :] | |
547 | power = power[:, hei_interf] |
|
549 | power = power[:, hei_interf] | |
548 | power = power.sum(axis=0) |
|
550 | power = power.sum(axis=0) | |
549 | psort = power.ravel().argsort() |
|
551 | psort = power.ravel().argsort() | |
550 |
|
552 | |||
551 | # Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
553 | # Se estima la interferencia promedio en los Espectros de Potencia empleando | |
552 | junkspc_interf = jspectra[ich, :, hei_interf[psort[range( |
|
554 | junkspc_interf = jspectra[ich, :, hei_interf[psort[range( | |
553 | offhei_interf, nhei_interf + offhei_interf)]]] |
|
555 | offhei_interf, nhei_interf + offhei_interf)]]] | |
554 |
|
556 | |||
555 | if noise_exist: |
|
557 | if noise_exist: | |
556 | # tmp_noise = jnoise[ich] / num_prof |
|
558 | # tmp_noise = jnoise[ich] / num_prof | |
557 | tmp_noise = jnoise[ich] |
|
559 | tmp_noise = jnoise[ich] | |
558 | junkspc_interf = junkspc_interf - tmp_noise |
|
560 | junkspc_interf = junkspc_interf - tmp_noise | |
559 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
561 | #junkspc_interf[:,comp_mask_prof] = 0 | |
560 |
|
562 | |||
561 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf |
|
563 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf | |
562 | jspc_interf = jspc_interf.transpose() |
|
564 | jspc_interf = jspc_interf.transpose() | |
563 | # Calculando el espectro de interferencia promedio |
|
565 | # Calculando el espectro de interferencia promedio | |
564 | noiseid = numpy.where( |
|
566 | noiseid = numpy.where( | |
565 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) |
|
567 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) | |
566 | noiseid = noiseid[0] |
|
568 | noiseid = noiseid[0] | |
567 | cnoiseid = noiseid.size |
|
569 | cnoiseid = noiseid.size | |
568 | interfid = numpy.where( |
|
570 | interfid = numpy.where( | |
569 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) |
|
571 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) | |
570 | interfid = interfid[0] |
|
572 | interfid = interfid[0] | |
571 | cinterfid = interfid.size |
|
573 | cinterfid = interfid.size | |
572 |
|
574 | |||
573 | if (cnoiseid > 0): |
|
575 | if (cnoiseid > 0): | |
574 | jspc_interf[noiseid] = 0 |
|
576 | jspc_interf[noiseid] = 0 | |
575 |
|
577 | |||
576 | # Expandiendo los perfiles a limpiar |
|
578 | # Expandiendo los perfiles a limpiar | |
577 | if (cinterfid > 0): |
|
579 | if (cinterfid > 0): | |
578 | new_interfid = ( |
|
580 | new_interfid = ( | |
579 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof |
|
581 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof | |
580 | new_interfid = numpy.asarray(new_interfid) |
|
582 | new_interfid = numpy.asarray(new_interfid) | |
581 | new_interfid = {x for x in new_interfid} |
|
583 | new_interfid = {x for x in new_interfid} | |
582 | new_interfid = numpy.array(list(new_interfid)) |
|
584 | new_interfid = numpy.array(list(new_interfid)) | |
583 | new_cinterfid = new_interfid.size |
|
585 | new_cinterfid = new_interfid.size | |
584 | else: |
|
586 | else: | |
585 | new_cinterfid = 0 |
|
587 | new_cinterfid = 0 | |
586 |
|
588 | |||
587 | for ip in range(new_cinterfid): |
|
589 | for ip in range(new_cinterfid): | |
588 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() |
|
590 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() | |
589 | jspc_interf[new_interfid[ip] |
|
591 | jspc_interf[new_interfid[ip] | |
590 | ] = junkspc_interf[ind[nhei_interf / 2], new_interfid[ip]] |
|
592 | ] = junkspc_interf[ind[nhei_interf / 2], new_interfid[ip]] | |
591 |
|
593 | |||
592 | jspectra[ich, :, ind_hei] = jspectra[ich, :, |
|
594 | jspectra[ich, :, ind_hei] = jspectra[ich, :, | |
593 | ind_hei] - jspc_interf # Corregir indices |
|
595 | ind_hei] - jspc_interf # Corregir indices | |
594 |
|
596 | |||
595 | # Removiendo la interferencia del punto de mayor interferencia |
|
597 | # Removiendo la interferencia del punto de mayor interferencia | |
596 | ListAux = jspc_interf[mask_prof].tolist() |
|
598 | ListAux = jspc_interf[mask_prof].tolist() | |
597 | maxid = ListAux.index(max(ListAux)) |
|
599 | maxid = ListAux.index(max(ListAux)) | |
598 |
|
600 | |||
599 | if cinterfid > 0: |
|
601 | if cinterfid > 0: | |
600 | for ip in range(cinterfid * (interf == 2) - 1): |
|
602 | for ip in range(cinterfid * (interf == 2) - 1): | |
601 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * |
|
603 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * | |
602 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() |
|
604 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() | |
603 | cind = len(ind) |
|
605 | cind = len(ind) | |
604 |
|
606 | |||
605 | if (cind > 0): |
|
607 | if (cind > 0): | |
606 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ |
|
608 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ | |
607 | (1 + (numpy.random.uniform(cind) - 0.5) / |
|
609 | (1 + (numpy.random.uniform(cind) - 0.5) / | |
608 | numpy.sqrt(num_incoh)) |
|
610 | numpy.sqrt(num_incoh)) | |
609 |
|
611 | |||
610 | ind = numpy.array([-2, -1, 1, 2]) |
|
612 | ind = numpy.array([-2, -1, 1, 2]) | |
611 | xx = numpy.zeros([4, 4]) |
|
613 | xx = numpy.zeros([4, 4]) | |
612 |
|
614 | |||
613 | for id1 in range(4): |
|
615 | for id1 in range(4): | |
614 | xx[:, id1] = ind[id1]**numpy.asarray(range(4)) |
|
616 | xx[:, id1] = ind[id1]**numpy.asarray(range(4)) | |
615 |
|
617 | |||
616 | xx_inv = numpy.linalg.inv(xx) |
|
618 | xx_inv = numpy.linalg.inv(xx) | |
617 | xx = xx_inv[:, 0] |
|
619 | xx = xx_inv[:, 0] | |
618 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
620 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
619 | yy = jspectra[ich, mask_prof[ind], :] |
|
621 | yy = jspectra[ich, mask_prof[ind], :] | |
620 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( |
|
622 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( | |
621 | yy.transpose(), xx) |
|
623 | yy.transpose(), xx) | |
622 |
|
624 | |||
623 | indAux = (jspectra[ich, :, :] < tmp_noise * |
|
625 | indAux = (jspectra[ich, :, :] < tmp_noise * | |
624 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() |
|
626 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() | |
625 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ |
|
627 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ | |
626 | (1 - 1 / numpy.sqrt(num_incoh)) |
|
628 | (1 - 1 / numpy.sqrt(num_incoh)) | |
627 |
|
629 | |||
628 | # Remocion de Interferencia en el Cross Spectra |
|
630 | # Remocion de Interferencia en el Cross Spectra | |
629 | if jcspectra is None: |
|
631 | if jcspectra is None: | |
630 | return jspectra, jcspectra |
|
632 | return jspectra, jcspectra | |
631 | num_pairs = jcspectra.size / (num_prof * num_hei) |
|
633 | num_pairs = jcspectra.size / (num_prof * num_hei) | |
632 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
634 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
633 |
|
635 | |||
634 | for ip in range(num_pairs): |
|
636 | for ip in range(num_pairs): | |
635 |
|
637 | |||
636 | #------------------------------------------- |
|
638 | #------------------------------------------- | |
637 |
|
639 | |||
638 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) |
|
640 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) | |
639 | cspower = cspower[:, hei_interf] |
|
641 | cspower = cspower[:, hei_interf] | |
640 | cspower = cspower.sum(axis=0) |
|
642 | cspower = cspower.sum(axis=0) | |
641 |
|
643 | |||
642 | cspsort = cspower.ravel().argsort() |
|
644 | cspsort = cspower.ravel().argsort() | |
643 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[range( |
|
645 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[range( | |
644 | offhei_interf, nhei_interf + offhei_interf)]]] |
|
646 | offhei_interf, nhei_interf + offhei_interf)]]] | |
645 | junkcspc_interf = junkcspc_interf.transpose() |
|
647 | junkcspc_interf = junkcspc_interf.transpose() | |
646 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf |
|
648 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf | |
647 |
|
649 | |||
648 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
650 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
649 |
|
651 | |||
650 | median_real = numpy.median(numpy.real( |
|
652 | median_real = numpy.median(numpy.real( | |
651 | junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) |
|
653 | junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) | |
652 | median_imag = numpy.median(numpy.imag( |
|
654 | median_imag = numpy.median(numpy.imag( | |
653 | junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) |
|
655 | junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) | |
654 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( |
|
656 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( | |
655 | median_real, median_imag) |
|
657 | median_real, median_imag) | |
656 |
|
658 | |||
657 | for iprof in range(num_prof): |
|
659 | for iprof in range(num_prof): | |
658 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() |
|
660 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() | |
659 | jcspc_interf[iprof] = junkcspc_interf[iprof, |
|
661 | jcspc_interf[iprof] = junkcspc_interf[iprof, | |
660 | ind[nhei_interf / 2]] |
|
662 | ind[nhei_interf / 2]] | |
661 |
|
663 | |||
662 | # Removiendo la Interferencia |
|
664 | # Removiendo la Interferencia | |
663 | jcspectra[ip, :, ind_hei] = jcspectra[ip, |
|
665 | jcspectra[ip, :, ind_hei] = jcspectra[ip, | |
664 | :, ind_hei] - jcspc_interf |
|
666 | :, ind_hei] - jcspc_interf | |
665 |
|
667 | |||
666 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
668 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
667 | maxid = ListAux.index(max(ListAux)) |
|
669 | maxid = ListAux.index(max(ListAux)) | |
668 |
|
670 | |||
669 | ind = numpy.array([-2, -1, 1, 2]) |
|
671 | ind = numpy.array([-2, -1, 1, 2]) | |
670 | xx = numpy.zeros([4, 4]) |
|
672 | xx = numpy.zeros([4, 4]) | |
671 |
|
673 | |||
672 | for id1 in range(4): |
|
674 | for id1 in range(4): | |
673 | xx[:, id1] = ind[id1]**numpy.asarray(range(4)) |
|
675 | xx[:, id1] = ind[id1]**numpy.asarray(range(4)) | |
674 |
|
676 | |||
675 | xx_inv = numpy.linalg.inv(xx) |
|
677 | xx_inv = numpy.linalg.inv(xx) | |
676 | xx = xx_inv[:, 0] |
|
678 | xx = xx_inv[:, 0] | |
677 |
|
679 | |||
678 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
680 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
679 | yy = jcspectra[ip, mask_prof[ind], :] |
|
681 | yy = jcspectra[ip, mask_prof[ind], :] | |
680 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) |
|
682 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) | |
681 |
|
683 | |||
682 | # Guardar Resultados |
|
684 | # Guardar Resultados | |
683 | self.dataOut.data_spc = jspectra |
|
685 | self.dataOut.data_spc = jspectra | |
684 | self.dataOut.data_cspc = jcspectra |
|
686 | self.dataOut.data_cspc = jcspectra | |
685 |
|
687 | |||
686 | return 1 |
|
688 | return 1 | |
687 |
|
689 | |||
688 | def setRadarFrequency(self, frequency=None): |
|
690 | def setRadarFrequency(self, frequency=None): | |
689 |
|
691 | |||
690 | if frequency != None: |
|
692 | if frequency != None: | |
691 | self.dataOut.frequency = frequency |
|
693 | self.dataOut.frequency = frequency | |
692 |
|
694 | |||
693 | return 1 |
|
695 | return 1 | |
694 |
|
696 | |||
695 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
697 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
696 | # validacion de rango |
|
698 | # validacion de rango | |
697 | if minHei == None: |
|
699 | if minHei == None: | |
698 | minHei = self.dataOut.heightList[0] |
|
700 | minHei = self.dataOut.heightList[0] | |
699 |
|
701 | |||
700 | if maxHei == None: |
|
702 | if maxHei == None: | |
701 | maxHei = self.dataOut.heightList[-1] |
|
703 | maxHei = self.dataOut.heightList[-1] | |
702 |
|
704 | |||
703 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
705 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
704 | print 'minHei: %.2f is out of the heights range' % (minHei) |
|
706 | print 'minHei: %.2f is out of the heights range' % (minHei) | |
705 | print 'minHei is setting to %.2f' % (self.dataOut.heightList[0]) |
|
707 | print 'minHei is setting to %.2f' % (self.dataOut.heightList[0]) | |
706 | minHei = self.dataOut.heightList[0] |
|
708 | minHei = self.dataOut.heightList[0] | |
707 |
|
709 | |||
708 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
710 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
709 | print 'maxHei: %.2f is out of the heights range' % (maxHei) |
|
711 | print 'maxHei: %.2f is out of the heights range' % (maxHei) | |
710 | print 'maxHei is setting to %.2f' % (self.dataOut.heightList[-1]) |
|
712 | print 'maxHei is setting to %.2f' % (self.dataOut.heightList[-1]) | |
711 | maxHei = self.dataOut.heightList[-1] |
|
713 | maxHei = self.dataOut.heightList[-1] | |
712 |
|
714 | |||
713 | # validacion de velocidades |
|
715 | # validacion de velocidades | |
714 | velrange = self.dataOut.getVelRange(1) |
|
716 | velrange = self.dataOut.getVelRange(1) | |
715 |
|
717 | |||
716 | if minVel == None: |
|
718 | if minVel == None: | |
717 | minVel = velrange[0] |
|
719 | minVel = velrange[0] | |
718 |
|
720 | |||
719 | if maxVel == None: |
|
721 | if maxVel == None: | |
720 | maxVel = velrange[-1] |
|
722 | maxVel = velrange[-1] | |
721 |
|
723 | |||
722 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
724 | if (minVel < velrange[0]) or (minVel > maxVel): | |
723 | print 'minVel: %.2f is out of the velocity range' % (minVel) |
|
725 | print 'minVel: %.2f is out of the velocity range' % (minVel) | |
724 | print 'minVel is setting to %.2f' % (velrange[0]) |
|
726 | print 'minVel is setting to %.2f' % (velrange[0]) | |
725 | minVel = velrange[0] |
|
727 | minVel = velrange[0] | |
726 |
|
728 | |||
727 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
729 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
728 | print 'maxVel: %.2f is out of the velocity range' % (maxVel) |
|
730 | print 'maxVel: %.2f is out of the velocity range' % (maxVel) | |
729 | print 'maxVel is setting to %.2f' % (velrange[-1]) |
|
731 | print 'maxVel is setting to %.2f' % (velrange[-1]) | |
730 | maxVel = velrange[-1] |
|
732 | maxVel = velrange[-1] | |
731 |
|
733 | |||
732 | # seleccion de indices para rango |
|
734 | # seleccion de indices para rango | |
733 | minIndex = 0 |
|
735 | minIndex = 0 | |
734 | maxIndex = 0 |
|
736 | maxIndex = 0 | |
735 | heights = self.dataOut.heightList |
|
737 | heights = self.dataOut.heightList | |
736 |
|
738 | |||
737 | inda = numpy.where(heights >= minHei) |
|
739 | inda = numpy.where(heights >= minHei) | |
738 | indb = numpy.where(heights <= maxHei) |
|
740 | indb = numpy.where(heights <= maxHei) | |
739 |
|
741 | |||
740 | try: |
|
742 | try: | |
741 | minIndex = inda[0][0] |
|
743 | minIndex = inda[0][0] | |
742 | except: |
|
744 | except: | |
743 | minIndex = 0 |
|
745 | minIndex = 0 | |
744 |
|
746 | |||
745 | try: |
|
747 | try: | |
746 | maxIndex = indb[0][-1] |
|
748 | maxIndex = indb[0][-1] | |
747 | except: |
|
749 | except: | |
748 | maxIndex = len(heights) |
|
750 | maxIndex = len(heights) | |
749 |
|
751 | |||
750 | if (minIndex < 0) or (minIndex > maxIndex): |
|
752 | if (minIndex < 0) or (minIndex > maxIndex): | |
751 | raise ValueError, "some value in (%d,%d) is not valid" % ( |
|
753 | raise ValueError, "some value in (%d,%d) is not valid" % ( | |
752 | minIndex, maxIndex) |
|
754 | minIndex, maxIndex) | |
753 |
|
755 | |||
754 | if (maxIndex >= self.dataOut.nHeights): |
|
756 | if (maxIndex >= self.dataOut.nHeights): | |
755 | maxIndex = self.dataOut.nHeights - 1 |
|
757 | maxIndex = self.dataOut.nHeights - 1 | |
756 |
|
758 | |||
757 | # seleccion de indices para velocidades |
|
759 | # seleccion de indices para velocidades | |
758 | indminvel = numpy.where(velrange >= minVel) |
|
760 | indminvel = numpy.where(velrange >= minVel) | |
759 | indmaxvel = numpy.where(velrange <= maxVel) |
|
761 | indmaxvel = numpy.where(velrange <= maxVel) | |
760 | try: |
|
762 | try: | |
761 | minIndexVel = indminvel[0][0] |
|
763 | minIndexVel = indminvel[0][0] | |
762 | except: |
|
764 | except: | |
763 | minIndexVel = 0 |
|
765 | minIndexVel = 0 | |
764 |
|
766 | |||
765 | try: |
|
767 | try: | |
766 | maxIndexVel = indmaxvel[0][-1] |
|
768 | maxIndexVel = indmaxvel[0][-1] | |
767 | except: |
|
769 | except: | |
768 | maxIndexVel = len(velrange) |
|
770 | maxIndexVel = len(velrange) | |
769 |
|
771 | |||
770 | # seleccion del espectro |
|
772 | # seleccion del espectro | |
771 | data_spc = self.dataOut.data_spc[:, |
|
773 | data_spc = self.dataOut.data_spc[:, | |
772 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] |
|
774 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] | |
773 | # estimacion de ruido |
|
775 | # estimacion de ruido | |
774 | noise = numpy.zeros(self.dataOut.nChannels) |
|
776 | noise = numpy.zeros(self.dataOut.nChannels) | |
775 |
|
777 | |||
776 | for channel in range(self.dataOut.nChannels): |
|
778 | for channel in range(self.dataOut.nChannels): | |
777 | daux = data_spc[channel, :, :] |
|
779 | daux = data_spc[channel, :, :] | |
778 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
780 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
779 |
|
781 | |||
780 | self.dataOut.noise_estimation = noise.copy() |
|
782 | self.dataOut.noise_estimation = noise.copy() | |
781 |
|
783 | |||
782 | return 1 |
|
784 | return 1 | |
783 |
|
785 | |||
784 |
|
786 | |||
785 | class IncohInt(Operation): |
|
787 | class IncohInt(Operation): | |
786 |
|
788 | |||
787 | __profIndex = 0 |
|
789 | __profIndex = 0 | |
788 | __withOverapping = False |
|
790 | __withOverapping = False | |
789 |
|
791 | |||
790 | __byTime = False |
|
792 | __byTime = False | |
791 | __initime = None |
|
793 | __initime = None | |
792 | __lastdatatime = None |
|
794 | __lastdatatime = None | |
793 | __integrationtime = None |
|
795 | __integrationtime = None | |
794 |
|
796 | |||
795 | __buffer_spc = None |
|
797 | __buffer_spc = None | |
796 | __buffer_cspc = None |
|
798 | __buffer_cspc = None | |
797 | __buffer_dc = None |
|
799 | __buffer_dc = None | |
798 |
|
800 | |||
799 | __dataReady = False |
|
801 | __dataReady = False | |
800 |
|
802 | |||
801 | __timeInterval = None |
|
803 | __timeInterval = None | |
802 |
|
804 | |||
803 | n = None |
|
805 | n = None | |
804 |
|
806 | |||
805 | def __init__(self, **kwargs): |
|
807 | def __init__(self, **kwargs): | |
806 |
|
808 | |||
807 | Operation.__init__(self, **kwargs) |
|
809 | Operation.__init__(self, **kwargs) | |
808 | # self.isConfig = False |
|
810 | # self.isConfig = False | |
809 |
|
811 | |||
810 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
812 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
811 | """ |
|
813 | """ | |
812 | Set the parameters of the integration class. |
|
814 | Set the parameters of the integration class. | |
813 |
|
815 | |||
814 | Inputs: |
|
816 | Inputs: | |
815 |
|
817 | |||
816 | n : Number of coherent integrations |
|
818 | n : Number of coherent integrations | |
817 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
819 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
818 | overlapping : |
|
820 | overlapping : | |
819 |
|
821 | |||
820 | """ |
|
822 | """ | |
821 |
|
823 | |||
822 | self.__initime = None |
|
824 | self.__initime = None | |
823 | self.__lastdatatime = 0 |
|
825 | self.__lastdatatime = 0 | |
824 |
|
826 | |||
825 | self.__buffer_spc = 0 |
|
827 | self.__buffer_spc = 0 | |
826 | self.__buffer_cspc = 0 |
|
828 | self.__buffer_cspc = 0 | |
827 | self.__buffer_dc = 0 |
|
829 | self.__buffer_dc = 0 | |
828 |
|
830 | |||
829 | self.__profIndex = 0 |
|
831 | self.__profIndex = 0 | |
830 | self.__dataReady = False |
|
832 | self.__dataReady = False | |
831 | self.__byTime = False |
|
833 | self.__byTime = False | |
832 |
|
834 | |||
833 | if n is None and timeInterval is None: |
|
835 | if n is None and timeInterval is None: | |
834 | raise ValueError, "n or timeInterval should be specified ..." |
|
836 | raise ValueError, "n or timeInterval should be specified ..." | |
835 |
|
837 | |||
836 | if n is not None: |
|
838 | if n is not None: | |
837 | self.n = int(n) |
|
839 | self.n = int(n) | |
838 | else: |
|
840 | else: | |
839 | # if (type(timeInterval)!=integer) -> change this line |
|
841 | # if (type(timeInterval)!=integer) -> change this line | |
840 | self.__integrationtime = int(timeInterval) |
|
842 | self.__integrationtime = int(timeInterval) | |
841 | self.n = None |
|
843 | self.n = None | |
842 | self.__byTime = True |
|
844 | self.__byTime = True | |
843 |
|
845 | |||
844 | def putData(self, data_spc, data_cspc, data_dc): |
|
846 | def putData(self, data_spc, data_cspc, data_dc): | |
845 | """ |
|
847 | """ | |
846 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
848 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
847 |
|
849 | |||
848 | """ |
|
850 | """ | |
849 |
|
851 | |||
850 | self.__buffer_spc += data_spc |
|
852 | self.__buffer_spc += data_spc | |
851 |
|
853 | |||
852 | if data_cspc is None: |
|
854 | if data_cspc is None: | |
853 | self.__buffer_cspc = None |
|
855 | self.__buffer_cspc = None | |
854 | else: |
|
856 | else: | |
855 | self.__buffer_cspc += data_cspc |
|
857 | self.__buffer_cspc += data_cspc | |
856 |
|
858 | |||
857 | if data_dc is None: |
|
859 | if data_dc is None: | |
858 | self.__buffer_dc = None |
|
860 | self.__buffer_dc = None | |
859 | else: |
|
861 | else: | |
860 | self.__buffer_dc += data_dc |
|
862 | self.__buffer_dc += data_dc | |
861 |
|
863 | |||
862 | self.__profIndex += 1 |
|
864 | self.__profIndex += 1 | |
863 |
|
865 | |||
864 | return |
|
866 | return | |
865 |
|
867 | |||
866 | def pushData(self): |
|
868 | def pushData(self): | |
867 | """ |
|
869 | """ | |
868 | Return the sum of the last profiles and the profiles used in the sum. |
|
870 | Return the sum of the last profiles and the profiles used in the sum. | |
869 |
|
871 | |||
870 | Affected: |
|
872 | Affected: | |
871 |
|
873 | |||
872 | self.__profileIndex |
|
874 | self.__profileIndex | |
873 |
|
875 | |||
874 | """ |
|
876 | """ | |
875 |
|
877 | |||
876 | data_spc = self.__buffer_spc |
|
878 | data_spc = self.__buffer_spc | |
877 | data_cspc = self.__buffer_cspc |
|
879 | data_cspc = self.__buffer_cspc | |
878 | data_dc = self.__buffer_dc |
|
880 | data_dc = self.__buffer_dc | |
879 | n = self.__profIndex |
|
881 | n = self.__profIndex | |
880 |
|
882 | |||
881 | self.__buffer_spc = 0 |
|
883 | self.__buffer_spc = 0 | |
882 | self.__buffer_cspc = 0 |
|
884 | self.__buffer_cspc = 0 | |
883 | self.__buffer_dc = 0 |
|
885 | self.__buffer_dc = 0 | |
884 | self.__profIndex = 0 |
|
886 | self.__profIndex = 0 | |
885 |
|
887 | |||
886 | return data_spc, data_cspc, data_dc, n |
|
888 | return data_spc, data_cspc, data_dc, n | |
887 |
|
889 | |||
888 | def byProfiles(self, *args): |
|
890 | def byProfiles(self, *args): | |
889 |
|
891 | |||
890 | self.__dataReady = False |
|
892 | self.__dataReady = False | |
891 | avgdata_spc = None |
|
893 | avgdata_spc = None | |
892 | avgdata_cspc = None |
|
894 | avgdata_cspc = None | |
893 | avgdata_dc = None |
|
895 | avgdata_dc = None | |
894 |
|
896 | |||
895 | self.putData(*args) |
|
897 | self.putData(*args) | |
896 |
|
898 | |||
897 | if self.__profIndex == self.n: |
|
899 | if self.__profIndex == self.n: | |
898 |
|
900 | |||
899 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
901 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
900 | self.n = n |
|
902 | self.n = n | |
901 | self.__dataReady = True |
|
903 | self.__dataReady = True | |
902 |
|
904 | |||
903 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
905 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
904 |
|
906 | |||
905 | def byTime(self, datatime, *args): |
|
907 | def byTime(self, datatime, *args): | |
906 |
|
908 | |||
907 | self.__dataReady = False |
|
909 | self.__dataReady = False | |
908 | avgdata_spc = None |
|
910 | avgdata_spc = None | |
909 | avgdata_cspc = None |
|
911 | avgdata_cspc = None | |
910 | avgdata_dc = None |
|
912 | avgdata_dc = None | |
911 |
|
913 | |||
912 | self.putData(*args) |
|
914 | self.putData(*args) | |
913 |
|
915 | |||
914 | if (datatime - self.__initime) >= self.__integrationtime: |
|
916 | if (datatime - self.__initime) >= self.__integrationtime: | |
915 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
917 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
916 | self.n = n |
|
918 | self.n = n | |
917 | self.__dataReady = True |
|
919 | self.__dataReady = True | |
918 |
|
920 | |||
919 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
921 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
920 |
|
922 | |||
921 | def integrate(self, datatime, *args): |
|
923 | def integrate(self, datatime, *args): | |
922 |
|
924 | |||
923 | if self.__profIndex == 0: |
|
925 | if self.__profIndex == 0: | |
924 | self.__initime = datatime |
|
926 | self.__initime = datatime | |
925 |
|
927 | |||
926 | if self.__byTime: |
|
928 | if self.__byTime: | |
927 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( |
|
929 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( | |
928 | datatime, *args) |
|
930 | datatime, *args) | |
929 | else: |
|
931 | else: | |
930 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
932 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
931 |
|
933 | |||
932 | if not self.__dataReady: |
|
934 | if not self.__dataReady: | |
933 | return None, None, None, None |
|
935 | return None, None, None, None | |
934 |
|
936 | |||
935 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
937 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc | |
936 |
|
938 | |||
937 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
939 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
938 | if n == 1: |
|
940 | if n == 1: | |
939 | return |
|
941 | return | |
940 |
|
942 | |||
941 | dataOut.flagNoData = True |
|
943 | dataOut.flagNoData = True | |
942 |
|
944 | |||
943 | if not self.isConfig: |
|
945 | if not self.isConfig: | |
944 | self.setup(n, timeInterval, overlapping) |
|
946 | self.setup(n, timeInterval, overlapping) | |
945 | self.isConfig = True |
|
947 | self.isConfig = True | |
946 |
|
948 | |||
947 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
949 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
948 | dataOut.data_spc, |
|
950 | dataOut.data_spc, | |
949 | dataOut.data_cspc, |
|
951 | dataOut.data_cspc, | |
950 | dataOut.data_dc) |
|
952 | dataOut.data_dc) | |
951 |
|
953 | |||
952 | if self.__dataReady: |
|
954 | if self.__dataReady: | |
953 |
|
955 | |||
954 | dataOut.data_spc = avgdata_spc |
|
956 | dataOut.data_spc = avgdata_spc | |
955 | dataOut.data_cspc = avgdata_cspc |
|
957 | dataOut.data_cspc = avgdata_cspc | |
956 | dataOut.data_dc = avgdata_dc |
|
958 | dataOut.data_dc = avgdata_dc | |
957 |
|
959 | |||
958 | dataOut.nIncohInt *= self.n |
|
960 | dataOut.nIncohInt *= self.n | |
959 | dataOut.utctime = avgdatatime |
|
961 | dataOut.utctime = avgdatatime | |
960 | dataOut.flagNoData = False |
|
962 | dataOut.flagNoData = False |
@@ -1,757 +1,764 | |||||
1 | import numpy |
|
1 | import numpy | |
2 |
|
2 | |||
3 | from jroproc_base import ProcessingUnit, Operation |
|
3 | from jroproc_base import ProcessingUnit, Operation | |
4 | from schainpy.model.data.jrodata import Spectra |
|
4 | from schainpy.model.data.jrodata import Spectra | |
5 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
5 | from schainpy.model.data.jrodata import hildebrand_sekhon | |
6 |
|
6 | |||
7 | class SpectraAFCProc(ProcessingUnit): |
|
7 | class SpectraAFCProc(ProcessingUnit): | |
8 |
|
8 | |||
9 | def __init__(self, **kwargs): |
|
9 | def __init__(self, **kwargs): | |
10 |
|
10 | |||
11 | ProcessingUnit.__init__(self, **kwargs) |
|
11 | ProcessingUnit.__init__(self, **kwargs) | |
12 |
|
12 | |||
13 | self.buffer = None |
|
13 | self.buffer = None | |
14 | self.firstdatatime = None |
|
14 | self.firstdatatime = None | |
15 | self.profIndex = 0 |
|
15 | self.profIndex = 0 | |
16 | self.dataOut = Spectra() |
|
16 | self.dataOut = Spectra() | |
17 | self.id_min = None |
|
17 | self.id_min = None | |
18 | self.id_max = None |
|
18 | self.id_max = None | |
19 |
|
19 | |||
20 | def __updateSpecFromVoltage(self): |
|
20 | def __updateSpecFromVoltage(self): | |
21 |
|
21 | |||
22 | self.dataOut.plotting = "spectra_acf" |
|
22 | self.dataOut.plotting = "spectra_acf" | |
23 |
|
23 | |||
24 | self.dataOut.timeZone = self.dataIn.timeZone |
|
24 | self.dataOut.timeZone = self.dataIn.timeZone | |
25 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
25 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
26 | self.dataOut.errorCount = self.dataIn.errorCount |
|
26 | self.dataOut.errorCount = self.dataIn.errorCount | |
27 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
27 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
28 |
|
28 | |||
29 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
29 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
30 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
30 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
31 | self.dataOut.ippSeconds = self.dataIn.getDeltaH()*(10**-6)/0.15 |
|
31 | self.dataOut.ippSeconds = self.dataIn.getDeltaH()*(10**-6)/0.15 | |
32 |
|
32 | |||
33 | self.dataOut.channelList = self.dataIn.channelList |
|
33 | self.dataOut.channelList = self.dataIn.channelList | |
34 | self.dataOut.heightList = self.dataIn.heightList |
|
34 | self.dataOut.heightList = self.dataIn.heightList | |
35 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
35 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
36 |
|
36 | |||
37 | self.dataOut.nBaud = self.dataIn.nBaud |
|
37 | self.dataOut.nBaud = self.dataIn.nBaud | |
38 | self.dataOut.nCode = self.dataIn.nCode |
|
38 | self.dataOut.nCode = self.dataIn.nCode | |
39 | self.dataOut.code = self.dataIn.code |
|
39 | self.dataOut.code = self.dataIn.code | |
40 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
40 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
41 |
|
41 | |||
42 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
42 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
43 | self.dataOut.utctime = self.firstdatatime |
|
43 | self.dataOut.utctime = self.firstdatatime | |
44 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
44 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
45 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
45 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
46 | self.dataOut.flagShiftFFT = False |
|
46 | self.dataOut.flagShiftFFT = False | |
47 |
|
47 | |||
48 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
48 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
49 | self.dataOut.nIncohInt = 1 |
|
49 | self.dataOut.nIncohInt = 1 | |
50 |
|
50 | |||
51 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
51 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
52 |
|
52 | |||
53 | self.dataOut.frequency = self.dataIn.frequency |
|
53 | self.dataOut.frequency = self.dataIn.frequency | |
54 | self.dataOut.realtime = self.dataIn.realtime |
|
54 | self.dataOut.realtime = self.dataIn.realtime | |
55 |
|
55 | |||
56 | self.dataOut.azimuth = self.dataIn.azimuth |
|
56 | self.dataOut.azimuth = self.dataIn.azimuth | |
57 | self.dataOut.zenith = self.dataIn.zenith |
|
57 | self.dataOut.zenith = self.dataIn.zenith | |
58 |
|
58 | |||
59 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
59 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
60 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
60 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
61 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
61 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
62 |
|
62 | |||
63 | def __decodeData(self, nProfiles, code): |
|
63 | def __decodeData(self, nProfiles, code): | |
64 |
|
64 | |||
65 | if code is None: |
|
65 | if code is None: | |
66 | return |
|
66 | return | |
67 |
|
67 | |||
68 | for i in range(nProfiles): |
|
68 | for i in range(nProfiles): | |
69 | self.buffer[:,i,:] = self.buffer[:,i,:]*code[0][i] |
|
69 | self.buffer[:,i,:] = self.buffer[:,i,:]*code[0][i] | |
70 |
|
70 | |||
71 | def __getFft(self): |
|
71 | def __getFft(self): | |
72 | """ |
|
72 | """ | |
73 | Convierte valores de Voltaje a Spectra |
|
73 | Convierte valores de Voltaje a Spectra | |
74 |
|
74 | |||
75 | Affected: |
|
75 | Affected: | |
76 | self.dataOut.data_spc |
|
76 | self.dataOut.data_spc | |
77 | self.dataOut.data_cspc |
|
77 | self.dataOut.data_cspc | |
78 | self.dataOut.data_dc |
|
78 | self.dataOut.data_dc | |
79 | self.dataOut.heightList |
|
79 | self.dataOut.heightList | |
80 | self.profIndex |
|
80 | self.profIndex | |
81 | self.buffer |
|
81 | self.buffer | |
82 | self.dataOut.flagNoData |
|
82 | self.dataOut.flagNoData | |
83 | """ |
|
83 | """ | |
84 | nsegments = self.dataOut.nHeights |
|
84 | nsegments = self.dataOut.nHeights | |
85 |
|
85 | |||
86 | _fft_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, nsegments), dtype='complex') |
|
86 | _fft_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, nsegments), dtype='complex') | |
87 |
|
87 | |||
88 | for i in range(nsegments): |
|
88 | for i in range(nsegments): | |
89 | try: |
|
89 | try: | |
90 | _fft_buffer[:,:,i] = self.buffer[:,i:i+self.dataOut.nProfiles] |
|
90 | _fft_buffer[:,:,i] = self.buffer[:,i:i+self.dataOut.nProfiles] | |
91 |
|
91 | |||
92 | if self.code is not None: |
|
92 | if self.code is not None: | |
93 | _fft_buffer[:,:,i] = _fft_buffer[:,:,i]*self.code[0] |
|
93 | _fft_buffer[:,:,i] = _fft_buffer[:,:,i]*self.code[0] | |
94 | except: |
|
94 | except: | |
95 | pass |
|
95 | pass | |
96 |
|
96 | |||
97 | fft_volt = numpy.fft.fft(_fft_buffer, n=self.dataOut.nFFTPoints, axis=1) |
|
97 | fft_volt = numpy.fft.fft(_fft_buffer, n=self.dataOut.nFFTPoints, axis=1) | |
98 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
98 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
99 | dc = fft_volt[:,0,:] |
|
99 | dc = fft_volt[:,0,:] | |
100 |
|
100 | |||
101 | #calculo de self-spectra |
|
101 | #calculo de self-spectra | |
102 | # fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) |
|
102 | # fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) | |
103 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
103 | spc = fft_volt * numpy.conjugate(fft_volt) | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | data = numpy.fft.ifft(spc, axis=1) |
|
106 | data = numpy.fft.ifft(spc, axis=1) | |
107 | data = numpy.fft.fftshift(data, axes=(1,)) |
|
107 | data = numpy.fft.fftshift(data, axes=(1,)) | |
108 |
|
108 | |||
109 | spc = data.real |
|
109 | spc = data.real | |
110 |
|
110 | |||
111 |
|
111 | |||
112 |
|
112 | |||
113 | blocksize = 0 |
|
113 | blocksize = 0 | |
114 | blocksize += dc.size |
|
114 | blocksize += dc.size | |
115 | blocksize += spc.size |
|
115 | blocksize += spc.size | |
116 |
|
116 | |||
117 | cspc = None |
|
117 | cspc = None | |
118 | pairIndex = 0 |
|
118 | pairIndex = 0 | |
119 |
|
119 | |||
120 | if self.dataOut.pairsList != None: |
|
120 | if self.dataOut.pairsList != None: | |
121 | #calculo de cross-spectra |
|
121 | #calculo de cross-spectra | |
122 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
122 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
123 | for pair in self.dataOut.pairsList: |
|
123 | for pair in self.dataOut.pairsList: | |
124 | if pair[0] not in self.dataOut.channelList: |
|
124 | if pair[0] not in self.dataOut.channelList: | |
125 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
125 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) | |
126 | if pair[1] not in self.dataOut.channelList: |
|
126 | if pair[1] not in self.dataOut.channelList: | |
127 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
127 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) | |
128 |
|
128 | |||
129 | chan_index0 = self.dataOut.channelList.index(pair[0]) |
|
129 | chan_index0 = self.dataOut.channelList.index(pair[0]) | |
130 | chan_index1 = self.dataOut.channelList.index(pair[1]) |
|
130 | chan_index1 = self.dataOut.channelList.index(pair[1]) | |
131 |
|
131 | |||
132 | cspc[pairIndex,:,:] = fft_volt[chan_index0,:,:] * numpy.conjugate(fft_volt[chan_index1,:,:]) |
|
132 | cspc[pairIndex,:,:] = fft_volt[chan_index0,:,:] * numpy.conjugate(fft_volt[chan_index1,:,:]) | |
133 | pairIndex += 1 |
|
133 | pairIndex += 1 | |
134 | blocksize += cspc.size |
|
134 | blocksize += cspc.size | |
135 |
|
135 | |||
136 | self.dataOut.data_spc = spc |
|
136 | self.dataOut.data_spc = spc | |
137 | self.dataOut.data_cspc = cspc |
|
137 | self.dataOut.data_cspc = cspc | |
138 | self.dataOut.data_dc = dc |
|
138 | self.dataOut.data_dc = dc | |
139 | self.dataOut.blockSize = blocksize |
|
139 | self.dataOut.blockSize = blocksize | |
140 | self.dataOut.flagShiftFFT = True |
|
140 | self.dataOut.flagShiftFFT = True | |
141 |
|
141 | |||
142 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=1, nBaud=1): |
|
142 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=1, nBaud=1): | |
143 |
|
143 | |||
144 | self.dataOut.flagNoData = True |
|
144 | self.dataOut.flagNoData = True | |
145 |
|
145 | |||
146 | if self.dataIn.type == "Spectra": |
|
146 | if self.dataIn.type == "Spectra": | |
147 | self.dataOut.copy(self.dataIn) |
|
147 | self.dataOut.copy(self.dataIn) | |
148 | spc= self.dataOut.data_spc |
|
148 | spc= self.dataOut.data_spc | |
149 | data = numpy.fft.ifft(spc, axis=1) |
|
149 | data = numpy.fft.ifft(spc, axis=1) | |
150 | data = numpy.fft.fftshift(data, axes=(1,)) |
|
150 | data = numpy.fft.fftshift(data, axes=(1,)) | |
151 | spc = data.real |
|
151 | spc = data.real | |
152 | spc = spc[0,:,0] / numpy.max(numpy.abs(spc[0,:,0])) |
|
152 | shape = spc.shape #nchannels, nprofiles, nsamples | |
153 | print spc |
|
153 | ||
154 | import matplotlib.pyplot as plt |
|
154 | #print spc.shape | |
155 | #plt.plot(spc[10:]) |
|
155 | for i in range(shape[0]): | |
156 | plt.show() |
|
156 | for j in range(shape[2]): | |
|
157 | spc[i,:,j]= spc[i,:,j] / numpy.max(numpy.abs(spc[i,:,j])) | |||
|
158 | #spc = spc[0,:,250] / numpy.max(numpy.abs(spc[0,:,250])) | |||
|
159 | #print spc.shape | |||
|
160 | #import matplotlib.pyplot as plt | |||
|
161 | #print spc[0:10] | |||
|
162 | #plt.plot(spc[0,:,350]) | |||
|
163 | #plt.show() | |||
157 |
|
164 | |||
158 |
|
165 | |||
159 | self.dataOut.data_spc = spc |
|
166 | self.dataOut.data_spc = spc | |
160 |
|
167 | |||
161 | return True |
|
168 | return True | |
162 |
|
169 | |||
163 |
|
170 | |||
164 | if code is not None: |
|
171 | if code is not None: | |
165 | self.code = numpy.array(code).reshape(nCode,nBaud) |
|
172 | self.code = numpy.array(code).reshape(nCode,nBaud) | |
166 | else: |
|
173 | else: | |
167 | self.code = None |
|
174 | self.code = None | |
168 |
|
175 | |||
169 | if self.dataIn.type == "Voltage": |
|
176 | if self.dataIn.type == "Voltage": | |
170 |
|
177 | |||
171 | if nFFTPoints == None: |
|
178 | if nFFTPoints == None: | |
172 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
179 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" | |
173 |
|
180 | |||
174 | if nProfiles == None: |
|
181 | if nProfiles == None: | |
175 | nProfiles = nFFTPoints |
|
182 | nProfiles = nFFTPoints | |
176 |
|
183 | |||
177 | self.dataOut.ippFactor = 1 |
|
184 | self.dataOut.ippFactor = 1 | |
178 |
|
185 | |||
179 | self.dataOut.nFFTPoints = nFFTPoints |
|
186 | self.dataOut.nFFTPoints = nFFTPoints | |
180 | self.dataOut.nProfiles = nProfiles |
|
187 | self.dataOut.nProfiles = nProfiles | |
181 | self.dataOut.pairsList = pairsList |
|
188 | self.dataOut.pairsList = pairsList | |
182 |
|
189 | |||
183 | # if self.buffer is None: |
|
190 | # if self.buffer is None: | |
184 | # self.buffer = numpy.zeros( (self.dataIn.nChannels, nProfiles, self.dataIn.nHeights), |
|
191 | # self.buffer = numpy.zeros( (self.dataIn.nChannels, nProfiles, self.dataIn.nHeights), | |
185 | # dtype='complex') |
|
192 | # dtype='complex') | |
186 |
|
193 | |||
187 | if not self.dataIn.flagDataAsBlock: |
|
194 | if not self.dataIn.flagDataAsBlock: | |
188 | self.buffer = self.dataIn.data.copy() |
|
195 | self.buffer = self.dataIn.data.copy() | |
189 |
|
196 | |||
190 | # for i in range(self.dataIn.nHeights): |
|
197 | # for i in range(self.dataIn.nHeights): | |
191 | # self.buffer[:, self.profIndex, self.profIndex:] = voltage_data[:,:self.dataIn.nHeights - self.profIndex] |
|
198 | # self.buffer[:, self.profIndex, self.profIndex:] = voltage_data[:,:self.dataIn.nHeights - self.profIndex] | |
192 | # |
|
199 | # | |
193 | # self.profIndex += 1 |
|
200 | # self.profIndex += 1 | |
194 |
|
201 | |||
195 | else: |
|
202 | else: | |
196 | raise ValueError, "" |
|
203 | raise ValueError, "" | |
197 |
|
204 | |||
198 | self.firstdatatime = self.dataIn.utctime |
|
205 | self.firstdatatime = self.dataIn.utctime | |
199 |
|
206 | |||
200 | self.profIndex == nProfiles |
|
207 | self.profIndex == nProfiles | |
201 |
|
208 | |||
202 | self.__updateSpecFromVoltage() |
|
209 | self.__updateSpecFromVoltage() | |
203 |
|
210 | |||
204 | self.__getFft() |
|
211 | self.__getFft() | |
205 |
|
212 | |||
206 | self.dataOut.flagNoData = False |
|
213 | self.dataOut.flagNoData = False | |
207 |
|
214 | |||
208 | return True |
|
215 | return True | |
209 |
|
216 | |||
210 | raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) |
|
217 | raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) | |
211 |
|
218 | |||
212 | def __selectPairs(self, pairsList): |
|
219 | def __selectPairs(self, pairsList): | |
213 |
|
220 | |||
214 | if channelList == None: |
|
221 | if channelList == None: | |
215 | return |
|
222 | return | |
216 |
|
223 | |||
217 | pairsIndexListSelected = [] |
|
224 | pairsIndexListSelected = [] | |
218 |
|
225 | |||
219 | for thisPair in pairsList: |
|
226 | for thisPair in pairsList: | |
220 |
|
227 | |||
221 | if thisPair not in self.dataOut.pairsList: |
|
228 | if thisPair not in self.dataOut.pairsList: | |
222 | continue |
|
229 | continue | |
223 |
|
230 | |||
224 | pairIndex = self.dataOut.pairsList.index(thisPair) |
|
231 | pairIndex = self.dataOut.pairsList.index(thisPair) | |
225 |
|
232 | |||
226 | pairsIndexListSelected.append(pairIndex) |
|
233 | pairsIndexListSelected.append(pairIndex) | |
227 |
|
234 | |||
228 | if not pairsIndexListSelected: |
|
235 | if not pairsIndexListSelected: | |
229 | self.dataOut.data_cspc = None |
|
236 | self.dataOut.data_cspc = None | |
230 | self.dataOut.pairsList = [] |
|
237 | self.dataOut.pairsList = [] | |
231 | return |
|
238 | return | |
232 |
|
239 | |||
233 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
240 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
234 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] |
|
241 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |
235 |
|
242 | |||
236 | return |
|
243 | return | |
237 |
|
244 | |||
238 | def __selectPairsByChannel(self, channelList=None): |
|
245 | def __selectPairsByChannel(self, channelList=None): | |
239 |
|
246 | |||
240 | if channelList == None: |
|
247 | if channelList == None: | |
241 | return |
|
248 | return | |
242 |
|
249 | |||
243 | pairsIndexListSelected = [] |
|
250 | pairsIndexListSelected = [] | |
244 | for pairIndex in self.dataOut.pairsIndexList: |
|
251 | for pairIndex in self.dataOut.pairsIndexList: | |
245 | #First pair |
|
252 | #First pair | |
246 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
253 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
247 | continue |
|
254 | continue | |
248 | #Second pair |
|
255 | #Second pair | |
249 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
256 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
250 | continue |
|
257 | continue | |
251 |
|
258 | |||
252 | pairsIndexListSelected.append(pairIndex) |
|
259 | pairsIndexListSelected.append(pairIndex) | |
253 |
|
260 | |||
254 | if not pairsIndexListSelected: |
|
261 | if not pairsIndexListSelected: | |
255 | self.dataOut.data_cspc = None |
|
262 | self.dataOut.data_cspc = None | |
256 | self.dataOut.pairsList = [] |
|
263 | self.dataOut.pairsList = [] | |
257 | return |
|
264 | return | |
258 |
|
265 | |||
259 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
266 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
260 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] |
|
267 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |
261 |
|
268 | |||
262 | return |
|
269 | return | |
263 |
|
270 | |||
264 | def selectChannels(self, channelList): |
|
271 | def selectChannels(self, channelList): | |
265 |
|
272 | |||
266 | channelIndexList = [] |
|
273 | channelIndexList = [] | |
267 |
|
274 | |||
268 | for channel in channelList: |
|
275 | for channel in channelList: | |
269 | if channel not in self.dataOut.channelList: |
|
276 | if channel not in self.dataOut.channelList: | |
270 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) |
|
277 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) | |
271 |
|
278 | |||
272 | index = self.dataOut.channelList.index(channel) |
|
279 | index = self.dataOut.channelList.index(channel) | |
273 | channelIndexList.append(index) |
|
280 | channelIndexList.append(index) | |
274 |
|
281 | |||
275 | self.selectChannelsByIndex(channelIndexList) |
|
282 | self.selectChannelsByIndex(channelIndexList) | |
276 |
|
283 | |||
277 | def selectChannelsByIndex(self, channelIndexList): |
|
284 | def selectChannelsByIndex(self, channelIndexList): | |
278 | """ |
|
285 | """ | |
279 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
286 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
280 |
|
287 | |||
281 | Input: |
|
288 | Input: | |
282 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
289 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
283 |
|
290 | |||
284 | Affected: |
|
291 | Affected: | |
285 | self.dataOut.data_spc |
|
292 | self.dataOut.data_spc | |
286 | self.dataOut.channelIndexList |
|
293 | self.dataOut.channelIndexList | |
287 | self.dataOut.nChannels |
|
294 | self.dataOut.nChannels | |
288 |
|
295 | |||
289 | Return: |
|
296 | Return: | |
290 | None |
|
297 | None | |
291 | """ |
|
298 | """ | |
292 |
|
299 | |||
293 | for channelIndex in channelIndexList: |
|
300 | for channelIndex in channelIndexList: | |
294 | if channelIndex not in self.dataOut.channelIndexList: |
|
301 | if channelIndex not in self.dataOut.channelIndexList: | |
295 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) |
|
302 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) | |
296 |
|
303 | |||
297 | # nChannels = len(channelIndexList) |
|
304 | # nChannels = len(channelIndexList) | |
298 |
|
305 | |||
299 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
306 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
300 | data_dc = self.dataOut.data_dc[channelIndexList,:] |
|
307 | data_dc = self.dataOut.data_dc[channelIndexList,:] | |
301 |
|
308 | |||
302 | self.dataOut.data_spc = data_spc |
|
309 | self.dataOut.data_spc = data_spc | |
303 | self.dataOut.data_dc = data_dc |
|
310 | self.dataOut.data_dc = data_dc | |
304 |
|
311 | |||
305 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
312 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
306 | # self.dataOut.nChannels = nChannels |
|
313 | # self.dataOut.nChannels = nChannels | |
307 |
|
314 | |||
308 | self.__selectPairsByChannel(self.dataOut.channelList) |
|
315 | self.__selectPairsByChannel(self.dataOut.channelList) | |
309 |
|
316 | |||
310 | return 1 |
|
317 | return 1 | |
311 |
|
318 | |||
312 | def selectHeights(self, minHei, maxHei): |
|
319 | def selectHeights(self, minHei, maxHei): | |
313 | """ |
|
320 | """ | |
314 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
321 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
315 | minHei <= height <= maxHei |
|
322 | minHei <= height <= maxHei | |
316 |
|
323 | |||
317 | Input: |
|
324 | Input: | |
318 | minHei : valor minimo de altura a considerar |
|
325 | minHei : valor minimo de altura a considerar | |
319 | maxHei : valor maximo de altura a considerar |
|
326 | maxHei : valor maximo de altura a considerar | |
320 |
|
327 | |||
321 | Affected: |
|
328 | Affected: | |
322 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
329 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
323 |
|
330 | |||
324 | Return: |
|
331 | Return: | |
325 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
332 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
326 | """ |
|
333 | """ | |
327 |
|
334 | |||
328 | if (minHei > maxHei): |
|
335 | if (minHei > maxHei): | |
329 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) |
|
336 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) | |
330 |
|
337 | |||
331 | if (minHei < self.dataOut.heightList[0]): |
|
338 | if (minHei < self.dataOut.heightList[0]): | |
332 | minHei = self.dataOut.heightList[0] |
|
339 | minHei = self.dataOut.heightList[0] | |
333 |
|
340 | |||
334 | if (maxHei > self.dataOut.heightList[-1]): |
|
341 | if (maxHei > self.dataOut.heightList[-1]): | |
335 | maxHei = self.dataOut.heightList[-1] |
|
342 | maxHei = self.dataOut.heightList[-1] | |
336 |
|
343 | |||
337 | minIndex = 0 |
|
344 | minIndex = 0 | |
338 | maxIndex = 0 |
|
345 | maxIndex = 0 | |
339 | heights = self.dataOut.heightList |
|
346 | heights = self.dataOut.heightList | |
340 |
|
347 | |||
341 | inda = numpy.where(heights >= minHei) |
|
348 | inda = numpy.where(heights >= minHei) | |
342 | indb = numpy.where(heights <= maxHei) |
|
349 | indb = numpy.where(heights <= maxHei) | |
343 |
|
350 | |||
344 | try: |
|
351 | try: | |
345 | minIndex = inda[0][0] |
|
352 | minIndex = inda[0][0] | |
346 | except: |
|
353 | except: | |
347 | minIndex = 0 |
|
354 | minIndex = 0 | |
348 |
|
355 | |||
349 | try: |
|
356 | try: | |
350 | maxIndex = indb[0][-1] |
|
357 | maxIndex = indb[0][-1] | |
351 | except: |
|
358 | except: | |
352 | maxIndex = len(heights) |
|
359 | maxIndex = len(heights) | |
353 |
|
360 | |||
354 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
361 | self.selectHeightsByIndex(minIndex, maxIndex) | |
355 |
|
362 | |||
356 | return 1 |
|
363 | return 1 | |
357 |
|
364 | |||
358 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
365 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): | |
359 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
366 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
360 |
|
367 | |||
361 | if hei_ref != None: |
|
368 | if hei_ref != None: | |
362 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
369 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
363 |
|
370 | |||
364 | minIndex = min(newheis[0]) |
|
371 | minIndex = min(newheis[0]) | |
365 | maxIndex = max(newheis[0]) |
|
372 | maxIndex = max(newheis[0]) | |
366 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
373 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
367 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
374 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
368 |
|
375 | |||
369 | # determina indices |
|
376 | # determina indices | |
370 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
377 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) | |
371 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
378 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) | |
372 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
379 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
373 | beacon_heiIndexList = [] |
|
380 | beacon_heiIndexList = [] | |
374 | for val in avg_dB.tolist(): |
|
381 | for val in avg_dB.tolist(): | |
375 | if val >= beacon_dB[0]: |
|
382 | if val >= beacon_dB[0]: | |
376 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
383 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
377 |
|
384 | |||
378 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
385 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
379 | data_cspc = None |
|
386 | data_cspc = None | |
380 | if self.dataOut.data_cspc is not None: |
|
387 | if self.dataOut.data_cspc is not None: | |
381 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
388 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
382 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
389 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
383 |
|
390 | |||
384 | data_dc = None |
|
391 | data_dc = None | |
385 | if self.dataOut.data_dc is not None: |
|
392 | if self.dataOut.data_dc is not None: | |
386 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
393 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
387 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
394 | #data_dc = data_dc[:,beacon_heiIndexList] | |
388 |
|
395 | |||
389 | self.dataOut.data_spc = data_spc |
|
396 | self.dataOut.data_spc = data_spc | |
390 | self.dataOut.data_cspc = data_cspc |
|
397 | self.dataOut.data_cspc = data_cspc | |
391 | self.dataOut.data_dc = data_dc |
|
398 | self.dataOut.data_dc = data_dc | |
392 | self.dataOut.heightList = heightList |
|
399 | self.dataOut.heightList = heightList | |
393 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
400 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
394 |
|
401 | |||
395 | return 1 |
|
402 | return 1 | |
396 |
|
403 | |||
397 |
|
404 | |||
398 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
405 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
399 | """ |
|
406 | """ | |
400 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
407 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
401 | minIndex <= index <= maxIndex |
|
408 | minIndex <= index <= maxIndex | |
402 |
|
409 | |||
403 | Input: |
|
410 | Input: | |
404 | minIndex : valor de indice minimo de altura a considerar |
|
411 | minIndex : valor de indice minimo de altura a considerar | |
405 | maxIndex : valor de indice maximo de altura a considerar |
|
412 | maxIndex : valor de indice maximo de altura a considerar | |
406 |
|
413 | |||
407 | Affected: |
|
414 | Affected: | |
408 | self.dataOut.data_spc |
|
415 | self.dataOut.data_spc | |
409 | self.dataOut.data_cspc |
|
416 | self.dataOut.data_cspc | |
410 | self.dataOut.data_dc |
|
417 | self.dataOut.data_dc | |
411 | self.dataOut.heightList |
|
418 | self.dataOut.heightList | |
412 |
|
419 | |||
413 | Return: |
|
420 | Return: | |
414 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
421 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
415 | """ |
|
422 | """ | |
416 |
|
423 | |||
417 | if (minIndex < 0) or (minIndex > maxIndex): |
|
424 | if (minIndex < 0) or (minIndex > maxIndex): | |
418 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
425 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) | |
419 |
|
426 | |||
420 | if (maxIndex >= self.dataOut.nHeights): |
|
427 | if (maxIndex >= self.dataOut.nHeights): | |
421 | maxIndex = self.dataOut.nHeights-1 |
|
428 | maxIndex = self.dataOut.nHeights-1 | |
422 |
|
429 | |||
423 | #Spectra |
|
430 | #Spectra | |
424 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
431 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
425 |
|
432 | |||
426 | data_cspc = None |
|
433 | data_cspc = None | |
427 | if self.dataOut.data_cspc is not None: |
|
434 | if self.dataOut.data_cspc is not None: | |
428 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
435 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
429 |
|
436 | |||
430 | data_dc = None |
|
437 | data_dc = None | |
431 | if self.dataOut.data_dc is not None: |
|
438 | if self.dataOut.data_dc is not None: | |
432 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
439 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
433 |
|
440 | |||
434 | self.dataOut.data_spc = data_spc |
|
441 | self.dataOut.data_spc = data_spc | |
435 | self.dataOut.data_cspc = data_cspc |
|
442 | self.dataOut.data_cspc = data_cspc | |
436 | self.dataOut.data_dc = data_dc |
|
443 | self.dataOut.data_dc = data_dc | |
437 |
|
444 | |||
438 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
445 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
439 |
|
446 | |||
440 | return 1 |
|
447 | return 1 | |
441 |
|
448 | |||
442 | def removeDC(self, mode = 2): |
|
449 | def removeDC(self, mode = 2): | |
443 | jspectra = self.dataOut.data_spc |
|
450 | jspectra = self.dataOut.data_spc | |
444 | jcspectra = self.dataOut.data_cspc |
|
451 | jcspectra = self.dataOut.data_cspc | |
445 |
|
452 | |||
446 |
|
453 | |||
447 | num_chan = jspectra.shape[0] |
|
454 | num_chan = jspectra.shape[0] | |
448 | num_hei = jspectra.shape[2] |
|
455 | num_hei = jspectra.shape[2] | |
449 |
|
456 | |||
450 | if jcspectra is not None: |
|
457 | if jcspectra is not None: | |
451 | jcspectraExist = True |
|
458 | jcspectraExist = True | |
452 | num_pairs = jcspectra.shape[0] |
|
459 | num_pairs = jcspectra.shape[0] | |
453 | else: jcspectraExist = False |
|
460 | else: jcspectraExist = False | |
454 |
|
461 | |||
455 | freq_dc = jspectra.shape[1]/2 |
|
462 | freq_dc = jspectra.shape[1]/2 | |
456 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
463 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
457 |
|
464 | |||
458 | if ind_vel[0]<0: |
|
465 | if ind_vel[0]<0: | |
459 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
466 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
460 |
|
467 | |||
461 | if mode == 1: |
|
468 | if mode == 1: | |
462 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
469 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
463 |
|
470 | |||
464 | if jcspectraExist: |
|
471 | if jcspectraExist: | |
465 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
472 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 | |
466 |
|
473 | |||
467 | if mode == 2: |
|
474 | if mode == 2: | |
468 |
|
475 | |||
469 | vel = numpy.array([-2,-1,1,2]) |
|
476 | vel = numpy.array([-2,-1,1,2]) | |
470 | xx = numpy.zeros([4,4]) |
|
477 | xx = numpy.zeros([4,4]) | |
471 |
|
478 | |||
472 | for fil in range(4): |
|
479 | for fil in range(4): | |
473 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
480 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
474 |
|
481 | |||
475 | xx_inv = numpy.linalg.inv(xx) |
|
482 | xx_inv = numpy.linalg.inv(xx) | |
476 | xx_aux = xx_inv[0,:] |
|
483 | xx_aux = xx_inv[0,:] | |
477 |
|
484 | |||
478 | for ich in range(num_chan): |
|
485 | for ich in range(num_chan): | |
479 | yy = jspectra[ich,ind_vel,:] |
|
486 | yy = jspectra[ich,ind_vel,:] | |
480 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
487 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
481 |
|
488 | |||
482 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
489 | junkid = jspectra[ich,freq_dc,:]<=0 | |
483 | cjunkid = sum(junkid) |
|
490 | cjunkid = sum(junkid) | |
484 |
|
491 | |||
485 | if cjunkid.any(): |
|
492 | if cjunkid.any(): | |
486 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
493 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
487 |
|
494 | |||
488 | if jcspectraExist: |
|
495 | if jcspectraExist: | |
489 | for ip in range(num_pairs): |
|
496 | for ip in range(num_pairs): | |
490 | yy = jcspectra[ip,ind_vel,:] |
|
497 | yy = jcspectra[ip,ind_vel,:] | |
491 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
498 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) | |
492 |
|
499 | |||
493 |
|
500 | |||
494 | self.dataOut.data_spc = jspectra |
|
501 | self.dataOut.data_spc = jspectra | |
495 | self.dataOut.data_cspc = jcspectra |
|
502 | self.dataOut.data_cspc = jcspectra | |
496 |
|
503 | |||
497 | return 1 |
|
504 | return 1 | |
498 |
|
505 | |||
499 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
506 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
500 |
|
507 | |||
501 | jspectra = self.dataOut.data_spc |
|
508 | jspectra = self.dataOut.data_spc | |
502 | jcspectra = self.dataOut.data_cspc |
|
509 | jcspectra = self.dataOut.data_cspc | |
503 | jnoise = self.dataOut.getNoise() |
|
510 | jnoise = self.dataOut.getNoise() | |
504 | num_incoh = self.dataOut.nIncohInt |
|
511 | num_incoh = self.dataOut.nIncohInt | |
505 |
|
512 | |||
506 | num_channel = jspectra.shape[0] |
|
513 | num_channel = jspectra.shape[0] | |
507 | num_prof = jspectra.shape[1] |
|
514 | num_prof = jspectra.shape[1] | |
508 | num_hei = jspectra.shape[2] |
|
515 | num_hei = jspectra.shape[2] | |
509 |
|
516 | |||
510 | #hei_interf |
|
517 | #hei_interf | |
511 | if hei_interf is None: |
|
518 | if hei_interf is None: | |
512 | count_hei = num_hei/2 #Como es entero no importa |
|
519 | count_hei = num_hei/2 #Como es entero no importa | |
513 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
520 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |
514 | hei_interf = numpy.asarray(hei_interf)[0] |
|
521 | hei_interf = numpy.asarray(hei_interf)[0] | |
515 | #nhei_interf |
|
522 | #nhei_interf | |
516 | if (nhei_interf == None): |
|
523 | if (nhei_interf == None): | |
517 | nhei_interf = 5 |
|
524 | nhei_interf = 5 | |
518 | if (nhei_interf < 1): |
|
525 | if (nhei_interf < 1): | |
519 | nhei_interf = 1 |
|
526 | nhei_interf = 1 | |
520 | if (nhei_interf > count_hei): |
|
527 | if (nhei_interf > count_hei): | |
521 | nhei_interf = count_hei |
|
528 | nhei_interf = count_hei | |
522 | if (offhei_interf == None): |
|
529 | if (offhei_interf == None): | |
523 | offhei_interf = 0 |
|
530 | offhei_interf = 0 | |
524 |
|
531 | |||
525 | ind_hei = range(num_hei) |
|
532 | ind_hei = range(num_hei) | |
526 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
533 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
527 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
534 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
528 | mask_prof = numpy.asarray(range(num_prof)) |
|
535 | mask_prof = numpy.asarray(range(num_prof)) | |
529 | num_mask_prof = mask_prof.size |
|
536 | num_mask_prof = mask_prof.size | |
530 | comp_mask_prof = [0, num_prof/2] |
|
537 | comp_mask_prof = [0, num_prof/2] | |
531 |
|
538 | |||
532 |
|
539 | |||
533 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
540 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
534 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
541 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
535 | jnoise = numpy.nan |
|
542 | jnoise = numpy.nan | |
536 | noise_exist = jnoise[0] < numpy.Inf |
|
543 | noise_exist = jnoise[0] < numpy.Inf | |
537 |
|
544 | |||
538 | #Subrutina de Remocion de la Interferencia |
|
545 | #Subrutina de Remocion de la Interferencia | |
539 | for ich in range(num_channel): |
|
546 | for ich in range(num_channel): | |
540 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
547 | #Se ordena los espectros segun su potencia (menor a mayor) | |
541 | power = jspectra[ich,mask_prof,:] |
|
548 | power = jspectra[ich,mask_prof,:] | |
542 | power = power[:,hei_interf] |
|
549 | power = power[:,hei_interf] | |
543 | power = power.sum(axis = 0) |
|
550 | power = power.sum(axis = 0) | |
544 | psort = power.ravel().argsort() |
|
551 | psort = power.ravel().argsort() | |
545 |
|
552 | |||
546 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
553 | #Se estima la interferencia promedio en los Espectros de Potencia empleando | |
547 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
554 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
548 |
|
555 | |||
549 | if noise_exist: |
|
556 | if noise_exist: | |
550 | # tmp_noise = jnoise[ich] / num_prof |
|
557 | # tmp_noise = jnoise[ich] / num_prof | |
551 | tmp_noise = jnoise[ich] |
|
558 | tmp_noise = jnoise[ich] | |
552 | junkspc_interf = junkspc_interf - tmp_noise |
|
559 | junkspc_interf = junkspc_interf - tmp_noise | |
553 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
560 | #junkspc_interf[:,comp_mask_prof] = 0 | |
554 |
|
561 | |||
555 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
562 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf | |
556 | jspc_interf = jspc_interf.transpose() |
|
563 | jspc_interf = jspc_interf.transpose() | |
557 | #Calculando el espectro de interferencia promedio |
|
564 | #Calculando el espectro de interferencia promedio | |
558 | noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) |
|
565 | noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) | |
559 | noiseid = noiseid[0] |
|
566 | noiseid = noiseid[0] | |
560 | cnoiseid = noiseid.size |
|
567 | cnoiseid = noiseid.size | |
561 | interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) |
|
568 | interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) | |
562 | interfid = interfid[0] |
|
569 | interfid = interfid[0] | |
563 | cinterfid = interfid.size |
|
570 | cinterfid = interfid.size | |
564 |
|
571 | |||
565 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
572 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 | |
566 |
|
573 | |||
567 | #Expandiendo los perfiles a limpiar |
|
574 | #Expandiendo los perfiles a limpiar | |
568 | if (cinterfid > 0): |
|
575 | if (cinterfid > 0): | |
569 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
576 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof | |
570 | new_interfid = numpy.asarray(new_interfid) |
|
577 | new_interfid = numpy.asarray(new_interfid) | |
571 | new_interfid = {x for x in new_interfid} |
|
578 | new_interfid = {x for x in new_interfid} | |
572 | new_interfid = numpy.array(list(new_interfid)) |
|
579 | new_interfid = numpy.array(list(new_interfid)) | |
573 | new_cinterfid = new_interfid.size |
|
580 | new_cinterfid = new_interfid.size | |
574 | else: new_cinterfid = 0 |
|
581 | else: new_cinterfid = 0 | |
575 |
|
582 | |||
576 | for ip in range(new_cinterfid): |
|
583 | for ip in range(new_cinterfid): | |
577 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
584 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() | |
578 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
585 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] | |
579 |
|
586 | |||
580 |
|
587 | |||
581 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
588 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices | |
582 |
|
589 | |||
583 | #Removiendo la interferencia del punto de mayor interferencia |
|
590 | #Removiendo la interferencia del punto de mayor interferencia | |
584 | ListAux = jspc_interf[mask_prof].tolist() |
|
591 | ListAux = jspc_interf[mask_prof].tolist() | |
585 | maxid = ListAux.index(max(ListAux)) |
|
592 | maxid = ListAux.index(max(ListAux)) | |
586 |
|
593 | |||
587 |
|
594 | |||
588 | if cinterfid > 0: |
|
595 | if cinterfid > 0: | |
589 | for ip in range(cinterfid*(interf == 2) - 1): |
|
596 | for ip in range(cinterfid*(interf == 2) - 1): | |
590 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero() |
|
597 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero() | |
591 | cind = len(ind) |
|
598 | cind = len(ind) | |
592 |
|
599 | |||
593 | if (cind > 0): |
|
600 | if (cind > 0): | |
594 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh)) |
|
601 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh)) | |
595 |
|
602 | |||
596 | ind = numpy.array([-2,-1,1,2]) |
|
603 | ind = numpy.array([-2,-1,1,2]) | |
597 | xx = numpy.zeros([4,4]) |
|
604 | xx = numpy.zeros([4,4]) | |
598 |
|
605 | |||
599 | for id1 in range(4): |
|
606 | for id1 in range(4): | |
600 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
607 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
601 |
|
608 | |||
602 | xx_inv = numpy.linalg.inv(xx) |
|
609 | xx_inv = numpy.linalg.inv(xx) | |
603 | xx = xx_inv[:,0] |
|
610 | xx = xx_inv[:,0] | |
604 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
611 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
605 | yy = jspectra[ich,mask_prof[ind],:] |
|
612 | yy = jspectra[ich,mask_prof[ind],:] | |
606 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
613 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
607 |
|
614 | |||
608 |
|
615 | |||
609 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero() |
|
616 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero() | |
610 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh)) |
|
617 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh)) | |
611 |
|
618 | |||
612 | #Remocion de Interferencia en el Cross Spectra |
|
619 | #Remocion de Interferencia en el Cross Spectra | |
613 | if jcspectra is None: return jspectra, jcspectra |
|
620 | if jcspectra is None: return jspectra, jcspectra | |
614 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
621 | num_pairs = jcspectra.size/(num_prof*num_hei) | |
615 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
622 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
616 |
|
623 | |||
617 | for ip in range(num_pairs): |
|
624 | for ip in range(num_pairs): | |
618 |
|
625 | |||
619 | #------------------------------------------- |
|
626 | #------------------------------------------- | |
620 |
|
627 | |||
621 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
628 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) | |
622 | cspower = cspower[:,hei_interf] |
|
629 | cspower = cspower[:,hei_interf] | |
623 | cspower = cspower.sum(axis = 0) |
|
630 | cspower = cspower.sum(axis = 0) | |
624 |
|
631 | |||
625 | cspsort = cspower.ravel().argsort() |
|
632 | cspsort = cspower.ravel().argsort() | |
626 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
633 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
627 | junkcspc_interf = junkcspc_interf.transpose() |
|
634 | junkcspc_interf = junkcspc_interf.transpose() | |
628 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
635 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf | |
629 |
|
636 | |||
630 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
637 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
631 |
|
638 | |||
632 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
639 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
633 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
640 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
634 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
641 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) | |
635 |
|
642 | |||
636 | for iprof in range(num_prof): |
|
643 | for iprof in range(num_prof): | |
637 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
644 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() | |
638 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
645 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] | |
639 |
|
646 | |||
640 | #Removiendo la Interferencia |
|
647 | #Removiendo la Interferencia | |
641 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
648 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf | |
642 |
|
649 | |||
643 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
650 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
644 | maxid = ListAux.index(max(ListAux)) |
|
651 | maxid = ListAux.index(max(ListAux)) | |
645 |
|
652 | |||
646 | ind = numpy.array([-2,-1,1,2]) |
|
653 | ind = numpy.array([-2,-1,1,2]) | |
647 | xx = numpy.zeros([4,4]) |
|
654 | xx = numpy.zeros([4,4]) | |
648 |
|
655 | |||
649 | for id1 in range(4): |
|
656 | for id1 in range(4): | |
650 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
657 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
651 |
|
658 | |||
652 | xx_inv = numpy.linalg.inv(xx) |
|
659 | xx_inv = numpy.linalg.inv(xx) | |
653 | xx = xx_inv[:,0] |
|
660 | xx = xx_inv[:,0] | |
654 |
|
661 | |||
655 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
662 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
656 | yy = jcspectra[ip,mask_prof[ind],:] |
|
663 | yy = jcspectra[ip,mask_prof[ind],:] | |
657 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
664 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
658 |
|
665 | |||
659 | #Guardar Resultados |
|
666 | #Guardar Resultados | |
660 | self.dataOut.data_spc = jspectra |
|
667 | self.dataOut.data_spc = jspectra | |
661 | self.dataOut.data_cspc = jcspectra |
|
668 | self.dataOut.data_cspc = jcspectra | |
662 |
|
669 | |||
663 | return 1 |
|
670 | return 1 | |
664 |
|
671 | |||
665 | def setRadarFrequency(self, frequency=None): |
|
672 | def setRadarFrequency(self, frequency=None): | |
666 |
|
673 | |||
667 | if frequency != None: |
|
674 | if frequency != None: | |
668 | self.dataOut.frequency = frequency |
|
675 | self.dataOut.frequency = frequency | |
669 |
|
676 | |||
670 | return 1 |
|
677 | return 1 | |
671 |
|
678 | |||
672 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
679 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
673 | #validacion de rango |
|
680 | #validacion de rango | |
674 | if minHei == None: |
|
681 | if minHei == None: | |
675 | minHei = self.dataOut.heightList[0] |
|
682 | minHei = self.dataOut.heightList[0] | |
676 |
|
683 | |||
677 | if maxHei == None: |
|
684 | if maxHei == None: | |
678 | maxHei = self.dataOut.heightList[-1] |
|
685 | maxHei = self.dataOut.heightList[-1] | |
679 |
|
686 | |||
680 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
687 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
681 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
688 | print 'minHei: %.2f is out of the heights range'%(minHei) | |
682 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
689 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) | |
683 | minHei = self.dataOut.heightList[0] |
|
690 | minHei = self.dataOut.heightList[0] | |
684 |
|
691 | |||
685 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
692 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
686 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
693 | print 'maxHei: %.2f is out of the heights range'%(maxHei) | |
687 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
694 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) | |
688 | maxHei = self.dataOut.heightList[-1] |
|
695 | maxHei = self.dataOut.heightList[-1] | |
689 |
|
696 | |||
690 | # validacion de velocidades |
|
697 | # validacion de velocidades | |
691 | velrange = self.dataOut.getVelRange(1) |
|
698 | velrange = self.dataOut.getVelRange(1) | |
692 |
|
699 | |||
693 | if minVel == None: |
|
700 | if minVel == None: | |
694 | minVel = velrange[0] |
|
701 | minVel = velrange[0] | |
695 |
|
702 | |||
696 | if maxVel == None: |
|
703 | if maxVel == None: | |
697 | maxVel = velrange[-1] |
|
704 | maxVel = velrange[-1] | |
698 |
|
705 | |||
699 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
706 | if (minVel < velrange[0]) or (minVel > maxVel): | |
700 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
707 | print 'minVel: %.2f is out of the velocity range'%(minVel) | |
701 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
708 | print 'minVel is setting to %.2f'%(velrange[0]) | |
702 | minVel = velrange[0] |
|
709 | minVel = velrange[0] | |
703 |
|
710 | |||
704 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
711 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
705 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
712 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) | |
706 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
713 | print 'maxVel is setting to %.2f'%(velrange[-1]) | |
707 | maxVel = velrange[-1] |
|
714 | maxVel = velrange[-1] | |
708 |
|
715 | |||
709 | # seleccion de indices para rango |
|
716 | # seleccion de indices para rango | |
710 | minIndex = 0 |
|
717 | minIndex = 0 | |
711 | maxIndex = 0 |
|
718 | maxIndex = 0 | |
712 | heights = self.dataOut.heightList |
|
719 | heights = self.dataOut.heightList | |
713 |
|
720 | |||
714 | inda = numpy.where(heights >= minHei) |
|
721 | inda = numpy.where(heights >= minHei) | |
715 | indb = numpy.where(heights <= maxHei) |
|
722 | indb = numpy.where(heights <= maxHei) | |
716 |
|
723 | |||
717 | try: |
|
724 | try: | |
718 | minIndex = inda[0][0] |
|
725 | minIndex = inda[0][0] | |
719 | except: |
|
726 | except: | |
720 | minIndex = 0 |
|
727 | minIndex = 0 | |
721 |
|
728 | |||
722 | try: |
|
729 | try: | |
723 | maxIndex = indb[0][-1] |
|
730 | maxIndex = indb[0][-1] | |
724 | except: |
|
731 | except: | |
725 | maxIndex = len(heights) |
|
732 | maxIndex = len(heights) | |
726 |
|
733 | |||
727 | if (minIndex < 0) or (minIndex > maxIndex): |
|
734 | if (minIndex < 0) or (minIndex > maxIndex): | |
728 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
735 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
729 |
|
736 | |||
730 | if (maxIndex >= self.dataOut.nHeights): |
|
737 | if (maxIndex >= self.dataOut.nHeights): | |
731 | maxIndex = self.dataOut.nHeights-1 |
|
738 | maxIndex = self.dataOut.nHeights-1 | |
732 |
|
739 | |||
733 | # seleccion de indices para velocidades |
|
740 | # seleccion de indices para velocidades | |
734 | indminvel = numpy.where(velrange >= minVel) |
|
741 | indminvel = numpy.where(velrange >= minVel) | |
735 | indmaxvel = numpy.where(velrange <= maxVel) |
|
742 | indmaxvel = numpy.where(velrange <= maxVel) | |
736 | try: |
|
743 | try: | |
737 | minIndexVel = indminvel[0][0] |
|
744 | minIndexVel = indminvel[0][0] | |
738 | except: |
|
745 | except: | |
739 | minIndexVel = 0 |
|
746 | minIndexVel = 0 | |
740 |
|
747 | |||
741 | try: |
|
748 | try: | |
742 | maxIndexVel = indmaxvel[0][-1] |
|
749 | maxIndexVel = indmaxvel[0][-1] | |
743 | except: |
|
750 | except: | |
744 | maxIndexVel = len(velrange) |
|
751 | maxIndexVel = len(velrange) | |
745 |
|
752 | |||
746 | #seleccion del espectro |
|
753 | #seleccion del espectro | |
747 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
754 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] | |
748 | #estimacion de ruido |
|
755 | #estimacion de ruido | |
749 | noise = numpy.zeros(self.dataOut.nChannels) |
|
756 | noise = numpy.zeros(self.dataOut.nChannels) | |
750 |
|
757 | |||
751 | for channel in range(self.dataOut.nChannels): |
|
758 | for channel in range(self.dataOut.nChannels): | |
752 | daux = data_spc[channel,:,:] |
|
759 | daux = data_spc[channel,:,:] | |
753 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
760 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
754 |
|
761 | |||
755 | self.dataOut.noise_estimation = noise.copy() |
|
762 | self.dataOut.noise_estimation = noise.copy() | |
756 |
|
763 | |||
757 | return 1 |
|
764 | return 1 |
@@ -1,1395 +1,1397 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy |
|
2 | import numpy | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy import cSchain |
|
4 | from schainpy import cSchain | |
5 | from jroproc_base import ProcessingUnit, Operation |
|
5 | from jroproc_base import ProcessingUnit, Operation | |
6 | from schainpy.model.data.jrodata import Voltage |
|
6 | from schainpy.model.data.jrodata import Voltage | |
7 | from time import time |
|
7 | from time import time | |
8 |
|
8 | |||
9 | class VoltageProc(ProcessingUnit): |
|
9 | class VoltageProc(ProcessingUnit): | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def __init__(self, **kwargs): |
|
12 | def __init__(self, **kwargs): | |
13 |
|
13 | |||
14 | ProcessingUnit.__init__(self, **kwargs) |
|
14 | ProcessingUnit.__init__(self, **kwargs) | |
15 |
|
15 | |||
16 | # self.objectDict = {} |
|
16 | # self.objectDict = {} | |
17 | self.dataOut = Voltage() |
|
17 | self.dataOut = Voltage() | |
18 | self.flip = 1 |
|
18 | self.flip = 1 | |
19 |
|
19 | |||
20 | def run(self): |
|
20 | def run(self): | |
21 | if self.dataIn.type == 'AMISR': |
|
21 | if self.dataIn.type == 'AMISR': | |
22 | self.__updateObjFromAmisrInput() |
|
22 | self.__updateObjFromAmisrInput() | |
23 |
|
23 | |||
24 | if self.dataIn.type == 'Voltage': |
|
24 | if self.dataIn.type == 'Voltage': | |
25 | self.dataOut.copy(self.dataIn) |
|
25 | self.dataOut.copy(self.dataIn) | |
26 |
|
26 | |||
27 | # self.dataOut.copy(self.dataIn) |
|
27 | # self.dataOut.copy(self.dataIn) | |
28 |
|
28 | |||
29 | def __updateObjFromAmisrInput(self): |
|
29 | def __updateObjFromAmisrInput(self): | |
30 |
|
30 | |||
31 | self.dataOut.timeZone = self.dataIn.timeZone |
|
31 | self.dataOut.timeZone = self.dataIn.timeZone | |
32 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
32 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
33 | self.dataOut.errorCount = self.dataIn.errorCount |
|
33 | self.dataOut.errorCount = self.dataIn.errorCount | |
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
34 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
35 |
|
35 | |||
36 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
36 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
37 | self.dataOut.data = self.dataIn.data |
|
37 | self.dataOut.data = self.dataIn.data | |
38 | self.dataOut.utctime = self.dataIn.utctime |
|
38 | self.dataOut.utctime = self.dataIn.utctime | |
39 | self.dataOut.channelList = self.dataIn.channelList |
|
39 | self.dataOut.channelList = self.dataIn.channelList | |
40 | # self.dataOut.timeInterval = self.dataIn.timeInterval |
|
40 | # self.dataOut.timeInterval = self.dataIn.timeInterval | |
41 | self.dataOut.heightList = self.dataIn.heightList |
|
41 | self.dataOut.heightList = self.dataIn.heightList | |
42 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
42 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
43 |
|
43 | |||
44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
44 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
45 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
46 | self.dataOut.frequency = self.dataIn.frequency |
|
46 | self.dataOut.frequency = self.dataIn.frequency | |
47 |
|
47 | |||
48 | self.dataOut.azimuth = self.dataIn.azimuth |
|
48 | self.dataOut.azimuth = self.dataIn.azimuth | |
49 | self.dataOut.zenith = self.dataIn.zenith |
|
49 | self.dataOut.zenith = self.dataIn.zenith | |
50 |
|
50 | |||
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
51 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
52 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
53 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
54 | # |
|
54 | # | |
55 | # pass# |
|
55 | # pass# | |
56 | # |
|
56 | # | |
57 | # def init(self): |
|
57 | # def init(self): | |
58 | # |
|
58 | # | |
59 | # |
|
59 | # | |
60 | # if self.dataIn.type == 'AMISR': |
|
60 | # if self.dataIn.type == 'AMISR': | |
61 | # self.__updateObjFromAmisrInput() |
|
61 | # self.__updateObjFromAmisrInput() | |
62 | # |
|
62 | # | |
63 | # if self.dataIn.type == 'Voltage': |
|
63 | # if self.dataIn.type == 'Voltage': | |
64 | # self.dataOut.copy(self.dataIn) |
|
64 | # self.dataOut.copy(self.dataIn) | |
65 | # # No necesita copiar en cada init() los atributos de dataIn |
|
65 | # # No necesita copiar en cada init() los atributos de dataIn | |
66 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
66 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
67 |
|
67 | |||
68 | def selectChannels(self, channelList): |
|
68 | def selectChannels(self, channelList): | |
69 |
|
69 | |||
70 | channelIndexList = [] |
|
70 | channelIndexList = [] | |
71 |
|
71 | |||
72 | for channel in channelList: |
|
72 | for channel in channelList: | |
73 | if channel not in self.dataOut.channelList: |
|
73 | if channel not in self.dataOut.channelList: | |
74 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) |
|
74 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) | |
75 |
|
75 | |||
76 | index = self.dataOut.channelList.index(channel) |
|
76 | index = self.dataOut.channelList.index(channel) | |
77 | channelIndexList.append(index) |
|
77 | channelIndexList.append(index) | |
78 |
|
78 | |||
79 | self.selectChannelsByIndex(channelIndexList) |
|
79 | self.selectChannelsByIndex(channelIndexList) | |
80 |
|
80 | |||
81 | def selectChannelsByIndex(self, channelIndexList): |
|
81 | def selectChannelsByIndex(self, channelIndexList): | |
82 | """ |
|
82 | """ | |
83 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
83 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
86 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
87 |
|
87 | |||
88 | Affected: |
|
88 | Affected: | |
89 | self.dataOut.data |
|
89 | self.dataOut.data | |
90 | self.dataOut.channelIndexList |
|
90 | self.dataOut.channelIndexList | |
91 | self.dataOut.nChannels |
|
91 | self.dataOut.nChannels | |
92 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
92 | self.dataOut.m_ProcessingHeader.totalSpectra | |
93 | self.dataOut.systemHeaderObj.numChannels |
|
93 | self.dataOut.systemHeaderObj.numChannels | |
94 | self.dataOut.m_ProcessingHeader.blockSize |
|
94 | self.dataOut.m_ProcessingHeader.blockSize | |
95 |
|
95 | |||
96 | Return: |
|
96 | Return: | |
97 | None |
|
97 | None | |
98 | """ |
|
98 | """ | |
99 |
|
99 | |||
100 | for channelIndex in channelIndexList: |
|
100 | for channelIndex in channelIndexList: | |
101 | if channelIndex not in self.dataOut.channelIndexList: |
|
101 | if channelIndex not in self.dataOut.channelIndexList: | |
102 | print channelIndexList |
|
102 | print channelIndexList | |
103 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
103 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
104 |
|
104 | |||
105 | if self.dataOut.flagDataAsBlock: |
|
105 | if self.dataOut.flagDataAsBlock: | |
106 | """ |
|
106 | """ | |
107 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
107 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
108 | """ |
|
108 | """ | |
109 | data = self.dataOut.data[channelIndexList,:,:] |
|
109 | data = self.dataOut.data[channelIndexList,:,:] | |
110 | else: |
|
110 | else: | |
111 | data = self.dataOut.data[channelIndexList,:] |
|
111 | data = self.dataOut.data[channelIndexList,:] | |
112 |
|
112 | |||
113 | self.dataOut.data = data |
|
113 | self.dataOut.data = data | |
114 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
114 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
115 | # self.dataOut.nChannels = nChannels |
|
115 | # self.dataOut.nChannels = nChannels | |
116 |
|
116 | |||
117 | return 1 |
|
117 | return 1 | |
118 |
|
118 | |||
119 | def selectHeights(self, minHei=None, maxHei=None): |
|
119 | def selectHeights(self, minHei=None, maxHei=None): | |
120 | """ |
|
120 | """ | |
121 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
121 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
122 | minHei <= height <= maxHei |
|
122 | minHei <= height <= maxHei | |
123 |
|
123 | |||
124 | Input: |
|
124 | Input: | |
125 | minHei : valor minimo de altura a considerar |
|
125 | minHei : valor minimo de altura a considerar | |
126 | maxHei : valor maximo de altura a considerar |
|
126 | maxHei : valor maximo de altura a considerar | |
127 |
|
127 | |||
128 | Affected: |
|
128 | Affected: | |
129 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
129 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
130 |
|
130 | |||
131 | Return: |
|
131 | Return: | |
132 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
132 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
133 | """ |
|
133 | """ | |
134 |
|
134 | |||
135 | if minHei == None: |
|
135 | if minHei == None: | |
136 | minHei = self.dataOut.heightList[0] |
|
136 | minHei = self.dataOut.heightList[0] | |
137 |
|
137 | |||
138 | if maxHei == None: |
|
138 | if maxHei == None: | |
139 | maxHei = self.dataOut.heightList[-1] |
|
139 | maxHei = self.dataOut.heightList[-1] | |
140 |
|
140 | |||
141 | if (minHei < self.dataOut.heightList[0]): |
|
141 | if (minHei < self.dataOut.heightList[0]): | |
142 | minHei = self.dataOut.heightList[0] |
|
142 | minHei = self.dataOut.heightList[0] | |
143 |
|
143 | |||
144 | if (maxHei > self.dataOut.heightList[-1]): |
|
144 | if (maxHei > self.dataOut.heightList[-1]): | |
145 | maxHei = self.dataOut.heightList[-1] |
|
145 | maxHei = self.dataOut.heightList[-1] | |
146 |
|
146 | |||
147 | minIndex = 0 |
|
147 | minIndex = 0 | |
148 | maxIndex = 0 |
|
148 | maxIndex = 0 | |
149 | heights = self.dataOut.heightList |
|
149 | heights = self.dataOut.heightList | |
150 |
|
150 | |||
151 | inda = numpy.where(heights >= minHei) |
|
151 | inda = numpy.where(heights >= minHei) | |
152 | indb = numpy.where(heights <= maxHei) |
|
152 | indb = numpy.where(heights <= maxHei) | |
153 |
|
153 | |||
154 | try: |
|
154 | try: | |
155 | minIndex = inda[0][0] |
|
155 | minIndex = inda[0][0] | |
156 | except: |
|
156 | except: | |
157 | minIndex = 0 |
|
157 | minIndex = 0 | |
158 |
|
158 | |||
159 | try: |
|
159 | try: | |
160 | maxIndex = indb[0][-1] |
|
160 | maxIndex = indb[0][-1] | |
161 | except: |
|
161 | except: | |
162 | maxIndex = len(heights) |
|
162 | maxIndex = len(heights) | |
163 |
|
163 | |||
164 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
164 | self.selectHeightsByIndex(minIndex, maxIndex) | |
165 |
|
165 | |||
166 | return 1 |
|
166 | return 1 | |
167 |
|
167 | |||
168 |
|
168 | |||
169 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
169 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
170 | """ |
|
170 | """ | |
171 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
171 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
172 | minIndex <= index <= maxIndex |
|
172 | minIndex <= index <= maxIndex | |
173 |
|
173 | |||
174 | Input: |
|
174 | Input: | |
175 | minIndex : valor de indice minimo de altura a considerar |
|
175 | minIndex : valor de indice minimo de altura a considerar | |
176 | maxIndex : valor de indice maximo de altura a considerar |
|
176 | maxIndex : valor de indice maximo de altura a considerar | |
177 |
|
177 | |||
178 | Affected: |
|
178 | Affected: | |
179 | self.dataOut.data |
|
179 | self.dataOut.data | |
180 | self.dataOut.heightList |
|
180 | self.dataOut.heightList | |
181 |
|
181 | |||
182 | Return: |
|
182 | Return: | |
183 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
183 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
184 | """ |
|
184 | """ | |
185 |
|
185 | |||
186 | if (minIndex < 0) or (minIndex > maxIndex): |
|
186 | if (minIndex < 0) or (minIndex > maxIndex): | |
187 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
187 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) | |
188 |
|
188 | |||
189 | if (maxIndex >= self.dataOut.nHeights): |
|
189 | if (maxIndex >= self.dataOut.nHeights): | |
190 | maxIndex = self.dataOut.nHeights |
|
190 | maxIndex = self.dataOut.nHeights | |
191 |
|
191 | |||
192 | #voltage |
|
192 | #voltage | |
193 | if self.dataOut.flagDataAsBlock: |
|
193 | if self.dataOut.flagDataAsBlock: | |
194 | """ |
|
194 | """ | |
195 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
195 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
196 | """ |
|
196 | """ | |
197 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
197 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
198 | else: |
|
198 | else: | |
199 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
199 | data = self.dataOut.data[:, minIndex:maxIndex] | |
200 |
|
200 | |||
201 | # firstHeight = self.dataOut.heightList[minIndex] |
|
201 | # firstHeight = self.dataOut.heightList[minIndex] | |
202 |
|
202 | |||
203 | self.dataOut.data = data |
|
203 | self.dataOut.data = data | |
204 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
204 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
205 |
|
205 | |||
206 | if self.dataOut.nHeights <= 1: |
|
206 | if self.dataOut.nHeights <= 1: | |
207 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) |
|
207 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) | |
208 |
|
208 | |||
209 | return 1 |
|
209 | return 1 | |
210 |
|
210 | |||
211 |
|
211 | |||
212 | def filterByHeights(self, window): |
|
212 | def filterByHeights(self, window): | |
213 |
|
213 | |||
214 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
214 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
215 |
|
215 | |||
216 | if window == None: |
|
216 | if window == None: | |
217 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
217 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
218 |
|
218 | |||
219 | newdelta = deltaHeight * window |
|
219 | newdelta = deltaHeight * window | |
220 | r = self.dataOut.nHeights % window |
|
220 | r = self.dataOut.nHeights % window | |
221 | newheights = (self.dataOut.nHeights-r)/window |
|
221 | newheights = (self.dataOut.nHeights-r)/window | |
222 |
|
222 | |||
223 | if newheights <= 1: |
|
223 | if newheights <= 1: | |
224 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) |
|
224 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) | |
225 |
|
225 | |||
226 | if self.dataOut.flagDataAsBlock: |
|
226 | if self.dataOut.flagDataAsBlock: | |
227 | """ |
|
227 | """ | |
228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
228 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
229 | """ |
|
229 | """ | |
230 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] |
|
230 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] | |
231 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) |
|
231 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) | |
232 | buffer = numpy.sum(buffer,3) |
|
232 | buffer = numpy.sum(buffer,3) | |
233 |
|
233 | |||
234 | else: |
|
234 | else: | |
235 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] |
|
235 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] | |
236 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) |
|
236 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) | |
237 | buffer = numpy.sum(buffer,2) |
|
237 | buffer = numpy.sum(buffer,2) | |
238 |
|
238 | |||
239 | self.dataOut.data = buffer |
|
239 | self.dataOut.data = buffer | |
240 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
240 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
241 | self.dataOut.windowOfFilter = window |
|
241 | self.dataOut.windowOfFilter = window | |
242 |
|
242 | |||
243 | def setH0(self, h0, deltaHeight = None): |
|
243 | def setH0(self, h0, deltaHeight = None): | |
244 |
|
244 | |||
245 | if not deltaHeight: |
|
245 | if not deltaHeight: | |
246 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
246 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
247 |
|
247 | |||
248 | nHeights = self.dataOut.nHeights |
|
248 | nHeights = self.dataOut.nHeights | |
249 |
|
249 | |||
250 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
250 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
251 |
|
251 | |||
252 | self.dataOut.heightList = newHeiRange |
|
252 | self.dataOut.heightList = newHeiRange | |
253 |
|
253 | |||
254 | def deFlip(self, channelList = []): |
|
254 | def deFlip(self, channelList = []): | |
255 |
|
255 | |||
256 | data = self.dataOut.data.copy() |
|
256 | data = self.dataOut.data.copy() | |
257 |
|
257 | |||
258 | if self.dataOut.flagDataAsBlock: |
|
258 | if self.dataOut.flagDataAsBlock: | |
259 | flip = self.flip |
|
259 | flip = self.flip | |
260 | profileList = range(self.dataOut.nProfiles) |
|
260 | profileList = range(self.dataOut.nProfiles) | |
261 |
|
261 | |||
262 | if not channelList: |
|
262 | if not channelList: | |
263 | for thisProfile in profileList: |
|
263 | for thisProfile in profileList: | |
264 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
264 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
265 | flip *= -1.0 |
|
265 | flip *= -1.0 | |
266 | else: |
|
266 | else: | |
267 | for thisChannel in channelList: |
|
267 | for thisChannel in channelList: | |
268 | if thisChannel not in self.dataOut.channelList: |
|
268 | if thisChannel not in self.dataOut.channelList: | |
269 | continue |
|
269 | continue | |
270 |
|
270 | |||
271 | for thisProfile in profileList: |
|
271 | for thisProfile in profileList: | |
272 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
272 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
273 | flip *= -1.0 |
|
273 | flip *= -1.0 | |
274 |
|
274 | |||
275 | self.flip = flip |
|
275 | self.flip = flip | |
276 |
|
276 | |||
277 | else: |
|
277 | else: | |
278 | if not channelList: |
|
278 | if not channelList: | |
279 | data[:,:] = data[:,:]*self.flip |
|
279 | data[:,:] = data[:,:]*self.flip | |
280 | else: |
|
280 | else: | |
281 | for thisChannel in channelList: |
|
281 | for thisChannel in channelList: | |
282 | if thisChannel not in self.dataOut.channelList: |
|
282 | if thisChannel not in self.dataOut.channelList: | |
283 | continue |
|
283 | continue | |
284 |
|
284 | |||
285 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
285 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
286 |
|
286 | |||
287 | self.flip *= -1. |
|
287 | self.flip *= -1. | |
288 |
|
288 | |||
289 | self.dataOut.data = data |
|
289 | self.dataOut.data = data | |
290 |
|
290 | |||
291 | def setRadarFrequency(self, frequency=None): |
|
291 | def setRadarFrequency(self, frequency=None): | |
292 |
|
292 | |||
293 | if frequency != None: |
|
293 | if frequency != None: | |
294 | self.dataOut.frequency = frequency |
|
294 | self.dataOut.frequency = frequency | |
295 |
|
295 | |||
296 | return 1 |
|
296 | return 1 | |
297 |
|
297 | |||
298 | def interpolateHeights(self, topLim, botLim): |
|
298 | def interpolateHeights(self, topLim, botLim): | |
299 | #69 al 72 para julia |
|
299 | #69 al 72 para julia | |
300 | #82-84 para meteoros |
|
300 | #82-84 para meteoros | |
301 | if len(numpy.shape(self.dataOut.data))==2: |
|
301 | if len(numpy.shape(self.dataOut.data))==2: | |
302 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 |
|
302 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 | |
303 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
303 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
304 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp |
|
304 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp | |
305 | self.dataOut.data[:,botLim:topLim+1] = sampInterp |
|
305 | self.dataOut.data[:,botLim:topLim+1] = sampInterp | |
306 | else: |
|
306 | else: | |
307 | nHeights = self.dataOut.data.shape[2] |
|
307 | nHeights = self.dataOut.data.shape[2] | |
308 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
308 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
309 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] |
|
309 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] | |
310 | f = interpolate.interp1d(x, y, axis = 2) |
|
310 | f = interpolate.interp1d(x, y, axis = 2) | |
311 | xnew = numpy.arange(botLim,topLim+1) |
|
311 | xnew = numpy.arange(botLim,topLim+1) | |
312 | ynew = f(xnew) |
|
312 | ynew = f(xnew) | |
313 |
|
313 | |||
314 | self.dataOut.data[:,:,botLim:topLim+1] = ynew |
|
314 | self.dataOut.data[:,:,botLim:topLim+1] = ynew | |
315 |
|
315 | |||
316 | # import collections |
|
316 | # import collections | |
317 |
|
317 | |||
318 | class CohInt(Operation): |
|
318 | class CohInt(Operation): | |
319 |
|
319 | |||
320 | isConfig = False |
|
320 | isConfig = False | |
321 | __profIndex = 0 |
|
321 | __profIndex = 0 | |
322 | __byTime = False |
|
322 | __byTime = False | |
323 | __initime = None |
|
323 | __initime = None | |
324 | __lastdatatime = None |
|
324 | __lastdatatime = None | |
325 | __integrationtime = None |
|
325 | __integrationtime = None | |
326 | __buffer = None |
|
326 | __buffer = None | |
327 | __bufferStride = [] |
|
327 | __bufferStride = [] | |
328 | __dataReady = False |
|
328 | __dataReady = False | |
329 | __profIndexStride = 0 |
|
329 | __profIndexStride = 0 | |
330 | __dataToPutStride = False |
|
330 | __dataToPutStride = False | |
331 | n = None |
|
331 | n = None | |
332 |
|
332 | |||
333 | def __init__(self, **kwargs): |
|
333 | def __init__(self, **kwargs): | |
334 |
|
334 | |||
335 | Operation.__init__(self, **kwargs) |
|
335 | Operation.__init__(self, **kwargs) | |
336 |
|
336 | |||
337 | # self.isConfig = False |
|
337 | # self.isConfig = False | |
338 |
|
338 | |||
339 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
339 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
340 | """ |
|
340 | """ | |
341 | Set the parameters of the integration class. |
|
341 | Set the parameters of the integration class. | |
342 |
|
342 | |||
343 | Inputs: |
|
343 | Inputs: | |
344 |
|
344 | |||
345 | n : Number of coherent integrations |
|
345 | n : Number of coherent integrations | |
346 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
346 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
347 | overlapping : |
|
347 | overlapping : | |
348 | """ |
|
348 | """ | |
349 |
|
349 | |||
350 | self.__initime = None |
|
350 | self.__initime = None | |
351 | self.__lastdatatime = 0 |
|
351 | self.__lastdatatime = 0 | |
352 | self.__buffer = None |
|
352 | self.__buffer = None | |
353 | self.__dataReady = False |
|
353 | self.__dataReady = False | |
354 | self.byblock = byblock |
|
354 | self.byblock = byblock | |
355 | self.stride = stride |
|
355 | self.stride = stride | |
356 |
|
356 | |||
357 | if n == None and timeInterval == None: |
|
357 | if n == None and timeInterval == None: | |
358 | raise ValueError, "n or timeInterval should be specified ..." |
|
358 | raise ValueError, "n or timeInterval should be specified ..." | |
359 |
|
359 | |||
360 | if n != None: |
|
360 | if n != None: | |
361 | self.n = n |
|
361 | self.n = n | |
362 | self.__byTime = False |
|
362 | self.__byTime = False | |
363 | else: |
|
363 | else: | |
364 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
364 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
365 | self.n = 9999 |
|
365 | self.n = 9999 | |
366 | self.__byTime = True |
|
366 | self.__byTime = True | |
367 |
|
367 | |||
368 | if overlapping: |
|
368 | if overlapping: | |
369 | self.__withOverlapping = True |
|
369 | self.__withOverlapping = True | |
370 | self.__buffer = None |
|
370 | self.__buffer = None | |
371 | else: |
|
371 | else: | |
372 | self.__withOverlapping = False |
|
372 | self.__withOverlapping = False | |
373 | self.__buffer = 0 |
|
373 | self.__buffer = 0 | |
374 |
|
374 | |||
375 | self.__profIndex = 0 |
|
375 | self.__profIndex = 0 | |
376 |
|
376 | |||
377 | def putData(self, data): |
|
377 | def putData(self, data): | |
378 |
|
378 | |||
379 | """ |
|
379 | """ | |
380 | Add a profile to the __buffer and increase in one the __profileIndex |
|
380 | Add a profile to the __buffer and increase in one the __profileIndex | |
381 |
|
381 | |||
382 | """ |
|
382 | """ | |
383 |
|
383 | |||
384 | if not self.__withOverlapping: |
|
384 | if not self.__withOverlapping: | |
385 | self.__buffer += data.copy() |
|
385 | self.__buffer += data.copy() | |
386 | self.__profIndex += 1 |
|
386 | self.__profIndex += 1 | |
387 | return |
|
387 | return | |
388 |
|
388 | |||
389 | #Overlapping data |
|
389 | #Overlapping data | |
390 | nChannels, nHeis = data.shape |
|
390 | nChannels, nHeis = data.shape | |
391 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
391 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
392 |
|
392 | |||
393 | #If the buffer is empty then it takes the data value |
|
393 | #If the buffer is empty then it takes the data value | |
394 | if self.__buffer is None: |
|
394 | if self.__buffer is None: | |
395 | self.__buffer = data |
|
395 | self.__buffer = data | |
396 | self.__profIndex += 1 |
|
396 | self.__profIndex += 1 | |
397 | return |
|
397 | return | |
398 |
|
398 | |||
399 | #If the buffer length is lower than n then stakcing the data value |
|
399 | #If the buffer length is lower than n then stakcing the data value | |
400 | if self.__profIndex < self.n: |
|
400 | if self.__profIndex < self.n: | |
401 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
401 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
402 | self.__profIndex += 1 |
|
402 | self.__profIndex += 1 | |
403 | return |
|
403 | return | |
404 |
|
404 | |||
405 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
405 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
406 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
406 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
407 | self.__buffer[self.n-1] = data |
|
407 | self.__buffer[self.n-1] = data | |
408 | self.__profIndex = self.n |
|
408 | self.__profIndex = self.n | |
409 | return |
|
409 | return | |
410 |
|
410 | |||
411 |
|
411 | |||
412 | def pushData(self): |
|
412 | def pushData(self): | |
413 | """ |
|
413 | """ | |
414 | Return the sum of the last profiles and the profiles used in the sum. |
|
414 | Return the sum of the last profiles and the profiles used in the sum. | |
415 |
|
415 | |||
416 | Affected: |
|
416 | Affected: | |
417 |
|
417 | |||
418 | self.__profileIndex |
|
418 | self.__profileIndex | |
419 |
|
419 | |||
420 | """ |
|
420 | """ | |
421 |
|
421 | |||
422 | if not self.__withOverlapping: |
|
422 | if not self.__withOverlapping: | |
423 | data = self.__buffer |
|
423 | data = self.__buffer | |
424 | n = self.__profIndex |
|
424 | n = self.__profIndex | |
425 |
|
425 | |||
426 | self.__buffer = 0 |
|
426 | self.__buffer = 0 | |
427 | self.__profIndex = 0 |
|
427 | self.__profIndex = 0 | |
428 |
|
428 | |||
429 | return data, n |
|
429 | return data, n | |
430 |
|
430 | |||
431 | #Integration with Overlapping |
|
431 | #Integration with Overlapping | |
432 | data = numpy.sum(self.__buffer, axis=0) |
|
432 | data = numpy.sum(self.__buffer, axis=0) | |
433 | # print data |
|
433 | # print data | |
434 | # raise |
|
434 | # raise | |
435 | n = self.__profIndex |
|
435 | n = self.__profIndex | |
436 |
|
436 | |||
437 | return data, n |
|
437 | return data, n | |
438 |
|
438 | |||
439 | def byProfiles(self, data): |
|
439 | def byProfiles(self, data): | |
440 |
|
440 | |||
441 | self.__dataReady = False |
|
441 | self.__dataReady = False | |
442 | avgdata = None |
|
442 | avgdata = None | |
443 | # n = None |
|
443 | # n = None | |
444 | # print data |
|
444 | # print data | |
445 | # raise |
|
445 | # raise | |
446 | self.putData(data) |
|
446 | self.putData(data) | |
447 |
|
447 | |||
448 | if self.__profIndex == self.n: |
|
448 | if self.__profIndex == self.n: | |
449 | avgdata, n = self.pushData() |
|
449 | avgdata, n = self.pushData() | |
450 | self.__dataReady = True |
|
450 | self.__dataReady = True | |
451 |
|
451 | |||
452 | return avgdata |
|
452 | return avgdata | |
453 |
|
453 | |||
454 | def byTime(self, data, datatime): |
|
454 | def byTime(self, data, datatime): | |
455 |
|
455 | |||
456 | self.__dataReady = False |
|
456 | self.__dataReady = False | |
457 | avgdata = None |
|
457 | avgdata = None | |
458 | n = None |
|
458 | n = None | |
459 |
|
459 | |||
460 | self.putData(data) |
|
460 | self.putData(data) | |
461 |
|
461 | |||
462 | if (datatime - self.__initime) >= self.__integrationtime: |
|
462 | if (datatime - self.__initime) >= self.__integrationtime: | |
463 | avgdata, n = self.pushData() |
|
463 | avgdata, n = self.pushData() | |
464 | self.n = n |
|
464 | self.n = n | |
465 | self.__dataReady = True |
|
465 | self.__dataReady = True | |
466 |
|
466 | |||
467 | return avgdata |
|
467 | return avgdata | |
468 |
|
468 | |||
469 | def integrateByStride(self, data, datatime): |
|
469 | def integrateByStride(self, data, datatime): | |
470 | # print data |
|
470 | # print data | |
471 | if self.__profIndex == 0: |
|
471 | if self.__profIndex == 0: | |
472 | self.__buffer = [[data.copy(), datatime]] |
|
472 | self.__buffer = [[data.copy(), datatime]] | |
473 | else: |
|
473 | else: | |
474 | self.__buffer.append([data.copy(),datatime]) |
|
474 | self.__buffer.append([data.copy(),datatime]) | |
475 | self.__profIndex += 1 |
|
475 | self.__profIndex += 1 | |
476 | self.__dataReady = False |
|
476 | self.__dataReady = False | |
477 |
|
477 | |||
478 | if self.__profIndex == self.n * self.stride : |
|
478 | if self.__profIndex == self.n * self.stride : | |
479 | self.__dataToPutStride = True |
|
479 | self.__dataToPutStride = True | |
480 | self.__profIndexStride = 0 |
|
480 | self.__profIndexStride = 0 | |
481 | self.__profIndex = 0 |
|
481 | self.__profIndex = 0 | |
482 | self.__bufferStride = [] |
|
482 | self.__bufferStride = [] | |
483 | for i in range(self.stride): |
|
483 | for i in range(self.stride): | |
484 | current = self.__buffer[i::self.stride] |
|
484 | current = self.__buffer[i::self.stride] | |
485 | data = numpy.sum([t[0] for t in current], axis=0) |
|
485 | data = numpy.sum([t[0] for t in current], axis=0) | |
486 | avgdatatime = numpy.average([t[1] for t in current]) |
|
486 | avgdatatime = numpy.average([t[1] for t in current]) | |
487 | # print data |
|
487 | # print data | |
488 | self.__bufferStride.append((data, avgdatatime)) |
|
488 | self.__bufferStride.append((data, avgdatatime)) | |
489 |
|
489 | |||
490 | if self.__dataToPutStride: |
|
490 | if self.__dataToPutStride: | |
491 | self.__dataReady = True |
|
491 | self.__dataReady = True | |
492 | self.__profIndexStride += 1 |
|
492 | self.__profIndexStride += 1 | |
493 | if self.__profIndexStride == self.stride: |
|
493 | if self.__profIndexStride == self.stride: | |
494 | self.__dataToPutStride = False |
|
494 | self.__dataToPutStride = False | |
495 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
495 | # print self.__bufferStride[self.__profIndexStride - 1] | |
496 | # raise |
|
496 | # raise | |
497 | return self.__bufferStride[self.__profIndexStride - 1] |
|
497 | return self.__bufferStride[self.__profIndexStride - 1] | |
498 |
|
498 | |||
499 |
|
499 | |||
500 | return None, None |
|
500 | return None, None | |
501 |
|
501 | |||
502 | def integrate(self, data, datatime=None): |
|
502 | def integrate(self, data, datatime=None): | |
503 |
|
503 | |||
504 | if self.__initime == None: |
|
504 | if self.__initime == None: | |
505 | self.__initime = datatime |
|
505 | self.__initime = datatime | |
506 |
|
506 | |||
507 | if self.__byTime: |
|
507 | if self.__byTime: | |
508 | avgdata = self.byTime(data, datatime) |
|
508 | avgdata = self.byTime(data, datatime) | |
509 | else: |
|
509 | else: | |
510 | avgdata = self.byProfiles(data) |
|
510 | avgdata = self.byProfiles(data) | |
511 |
|
511 | |||
512 |
|
512 | |||
513 | self.__lastdatatime = datatime |
|
513 | self.__lastdatatime = datatime | |
514 |
|
514 | |||
515 | if avgdata is None: |
|
515 | if avgdata is None: | |
516 | return None, None |
|
516 | return None, None | |
517 |
|
517 | |||
518 | avgdatatime = self.__initime |
|
518 | avgdatatime = self.__initime | |
519 |
|
519 | |||
520 | deltatime = datatime - self.__lastdatatime |
|
520 | deltatime = datatime - self.__lastdatatime | |
521 |
|
521 | |||
522 | if not self.__withOverlapping: |
|
522 | if not self.__withOverlapping: | |
523 | self.__initime = datatime |
|
523 | self.__initime = datatime | |
524 | else: |
|
524 | else: | |
525 | self.__initime += deltatime |
|
525 | self.__initime += deltatime | |
526 |
|
526 | |||
527 | return avgdata, avgdatatime |
|
527 | return avgdata, avgdatatime | |
528 |
|
528 | |||
529 | def integrateByBlock(self, dataOut): |
|
529 | def integrateByBlock(self, dataOut): | |
530 |
|
530 | |||
531 | times = int(dataOut.data.shape[1]/self.n) |
|
531 | times = int(dataOut.data.shape[1]/self.n) | |
532 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
532 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
533 |
|
533 | |||
534 | id_min = 0 |
|
534 | id_min = 0 | |
535 | id_max = self.n |
|
535 | id_max = self.n | |
536 |
|
536 | |||
537 | for i in range(times): |
|
537 | for i in range(times): | |
538 | junk = dataOut.data[:,id_min:id_max,:] |
|
538 | junk = dataOut.data[:,id_min:id_max,:] | |
539 | avgdata[:,i,:] = junk.sum(axis=1) |
|
539 | avgdata[:,i,:] = junk.sum(axis=1) | |
540 | id_min += self.n |
|
540 | id_min += self.n | |
541 | id_max += self.n |
|
541 | id_max += self.n | |
542 |
|
542 | |||
543 | timeInterval = dataOut.ippSeconds*self.n |
|
543 | timeInterval = dataOut.ippSeconds*self.n | |
544 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
544 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
545 | self.__dataReady = True |
|
545 | self.__dataReady = True | |
546 | return avgdata, avgdatatime |
|
546 | return avgdata, avgdatatime | |
547 |
|
547 | |||
548 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
548 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
549 | if not self.isConfig: |
|
549 | if not self.isConfig: | |
550 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
550 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
551 | self.isConfig = True |
|
551 | self.isConfig = True | |
552 |
|
552 | |||
553 | if dataOut.flagDataAsBlock: |
|
553 | if dataOut.flagDataAsBlock: | |
554 | """ |
|
554 | """ | |
555 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
555 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
556 | """ |
|
556 | """ | |
557 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
557 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
558 | dataOut.nProfiles /= self.n |
|
558 | dataOut.nProfiles /= self.n | |
559 | else: |
|
559 | else: | |
560 | if stride is None: |
|
560 | if stride is None: | |
561 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
561 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
562 | else: |
|
562 | else: | |
563 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
563 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
564 |
|
564 | |||
565 |
|
565 | |||
566 | # dataOut.timeInterval *= n |
|
566 | # dataOut.timeInterval *= n | |
567 | dataOut.flagNoData = True |
|
567 | dataOut.flagNoData = True | |
568 |
|
568 | |||
569 | if self.__dataReady: |
|
569 | if self.__dataReady: | |
570 | dataOut.data = avgdata |
|
570 | dataOut.data = avgdata | |
571 | dataOut.nCohInt *= self.n |
|
571 | dataOut.nCohInt *= self.n | |
572 | dataOut.utctime = avgdatatime |
|
572 | dataOut.utctime = avgdatatime | |
573 | # print avgdata, avgdatatime |
|
573 | # print avgdata, avgdatatime | |
574 | # raise |
|
574 | # raise | |
575 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
575 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
576 | dataOut.flagNoData = False |
|
576 | dataOut.flagNoData = False | |
577 |
|
577 | |||
578 | class Decoder(Operation): |
|
578 | class Decoder(Operation): | |
579 |
|
579 | |||
580 | isConfig = False |
|
580 | isConfig = False | |
581 | __profIndex = 0 |
|
581 | __profIndex = 0 | |
582 |
|
582 | |||
583 | code = None |
|
583 | code = None | |
584 |
|
584 | |||
585 | nCode = None |
|
585 | nCode = None | |
586 | nBaud = None |
|
586 | nBaud = None | |
587 |
|
587 | |||
588 | def __init__(self, **kwargs): |
|
588 | def __init__(self, **kwargs): | |
589 |
|
589 | |||
590 | Operation.__init__(self, **kwargs) |
|
590 | Operation.__init__(self, **kwargs) | |
591 |
|
591 | |||
592 | self.times = None |
|
592 | self.times = None | |
593 | self.osamp = None |
|
593 | self.osamp = None | |
594 | # self.__setValues = False |
|
594 | # self.__setValues = False | |
595 | self.isConfig = False |
|
595 | self.isConfig = False | |
596 |
|
596 | |||
597 | def setup(self, code, osamp, dataOut): |
|
597 | def setup(self, code, osamp, dataOut): | |
598 |
|
598 | |||
599 | self.__profIndex = 0 |
|
599 | self.__profIndex = 0 | |
600 |
|
600 | |||
601 | self.code = code |
|
601 | self.code = code | |
602 |
|
602 | |||
603 | self.nCode = len(code) |
|
603 | self.nCode = len(code) | |
604 | self.nBaud = len(code[0]) |
|
604 | self.nBaud = len(code[0]) | |
605 |
|
605 | |||
606 | if (osamp != None) and (osamp >1): |
|
606 | if (osamp != None) and (osamp >1): | |
607 | self.osamp = osamp |
|
607 | self.osamp = osamp | |
608 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
608 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
609 | self.nBaud = self.nBaud*self.osamp |
|
609 | self.nBaud = self.nBaud*self.osamp | |
610 |
|
610 | |||
611 | self.__nChannels = dataOut.nChannels |
|
611 | self.__nChannels = dataOut.nChannels | |
612 | self.__nProfiles = dataOut.nProfiles |
|
612 | self.__nProfiles = dataOut.nProfiles | |
613 | self.__nHeis = dataOut.nHeights |
|
613 | self.__nHeis = dataOut.nHeights | |
614 |
|
614 | |||
615 | if self.__nHeis < self.nBaud: |
|
615 | if self.__nHeis < self.nBaud: | |
616 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) |
|
616 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) | |
617 |
|
617 | |||
618 | #Frequency |
|
618 | #Frequency | |
619 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
619 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
620 |
|
620 | |||
621 | __codeBuffer[:,0:self.nBaud] = self.code |
|
621 | __codeBuffer[:,0:self.nBaud] = self.code | |
622 |
|
622 | |||
623 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
623 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
624 |
|
624 | |||
625 | if dataOut.flagDataAsBlock: |
|
625 | if dataOut.flagDataAsBlock: | |
626 |
|
626 | |||
627 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
627 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
628 |
|
628 | |||
629 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
629 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
630 |
|
630 | |||
631 | else: |
|
631 | else: | |
632 |
|
632 | |||
633 | #Time |
|
633 | #Time | |
634 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
634 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
635 |
|
635 | |||
636 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
636 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
637 |
|
637 | |||
638 | def __convolutionInFreq(self, data): |
|
638 | def __convolutionInFreq(self, data): | |
639 |
|
639 | |||
640 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
640 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
641 |
|
641 | |||
642 | fft_data = numpy.fft.fft(data, axis=1) |
|
642 | fft_data = numpy.fft.fft(data, axis=1) | |
643 |
|
643 | |||
644 | conv = fft_data*fft_code |
|
644 | conv = fft_data*fft_code | |
645 |
|
645 | |||
646 | data = numpy.fft.ifft(conv,axis=1) |
|
646 | data = numpy.fft.ifft(conv,axis=1) | |
647 |
|
647 | |||
648 | return data |
|
648 | return data | |
649 |
|
649 | |||
650 | def __convolutionInFreqOpt(self, data): |
|
650 | def __convolutionInFreqOpt(self, data): | |
651 |
|
651 | |||
652 | raise NotImplementedError |
|
652 | raise NotImplementedError | |
653 |
|
653 | |||
654 | def __convolutionInTime(self, data): |
|
654 | def __convolutionInTime(self, data): | |
655 |
|
655 | |||
656 | code = self.code[self.__profIndex] |
|
656 | code = self.code[self.__profIndex] | |
657 | for i in range(self.__nChannels): |
|
657 | for i in range(self.__nChannels): | |
658 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
658 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
659 |
|
659 | |||
660 | return self.datadecTime |
|
660 | return self.datadecTime | |
661 |
|
661 | |||
662 | def __convolutionByBlockInTime(self, data): |
|
662 | def __convolutionByBlockInTime(self, data): | |
663 |
|
663 | |||
664 | repetitions = self.__nProfiles / self.nCode |
|
664 | repetitions = self.__nProfiles / self.nCode | |
665 |
|
665 | |||
666 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
666 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
667 | junk = junk.flatten() |
|
667 | junk = junk.flatten() | |
668 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
668 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
669 | profilesList = xrange(self.__nProfiles) |
|
669 | profilesList = xrange(self.__nProfiles) | |
670 |
|
670 | |||
671 | for i in range(self.__nChannels): |
|
671 | for i in range(self.__nChannels): | |
672 | for j in profilesList: |
|
672 | for j in profilesList: | |
673 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
673 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
674 | return self.datadecTime |
|
674 | return self.datadecTime | |
675 |
|
675 | |||
676 | def __convolutionByBlockInFreq(self, data): |
|
676 | def __convolutionByBlockInFreq(self, data): | |
677 |
|
677 | |||
678 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" |
|
678 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" | |
679 |
|
679 | |||
680 |
|
680 | |||
681 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
681 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
682 |
|
682 | |||
683 | fft_data = numpy.fft.fft(data, axis=2) |
|
683 | fft_data = numpy.fft.fft(data, axis=2) | |
684 |
|
684 | |||
685 | conv = fft_data*fft_code |
|
685 | conv = fft_data*fft_code | |
686 |
|
686 | |||
687 | data = numpy.fft.ifft(conv,axis=2) |
|
687 | data = numpy.fft.ifft(conv,axis=2) | |
688 |
|
688 | |||
689 | return data |
|
689 | return data | |
690 |
|
690 | |||
691 |
|
691 | |||
692 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
692 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
693 |
|
693 | |||
694 | if dataOut.flagDecodeData: |
|
694 | if dataOut.flagDecodeData: | |
695 | print "This data is already decoded, recoding again ..." |
|
695 | print "This data is already decoded, recoding again ..." | |
696 |
|
696 | |||
697 | if not self.isConfig: |
|
697 | if not self.isConfig: | |
698 |
|
698 | |||
699 | if code is None: |
|
699 | if code is None: | |
700 | if dataOut.code is None: |
|
700 | if dataOut.code is None: | |
701 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type |
|
701 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type | |
702 |
|
702 | |||
703 | code = dataOut.code |
|
703 | code = dataOut.code | |
704 | else: |
|
704 | else: | |
705 | code = numpy.array(code).reshape(nCode,nBaud) |
|
705 | code = numpy.array(code).reshape(nCode,nBaud) | |
706 | self.setup(code, osamp, dataOut) |
|
706 | self.setup(code, osamp, dataOut) | |
707 |
|
707 | |||
708 | self.isConfig = True |
|
708 | self.isConfig = True | |
709 |
|
709 | |||
710 | if mode == 3: |
|
710 | if mode == 3: | |
711 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
711 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
712 |
|
712 | |||
713 | if times != None: |
|
713 | if times != None: | |
714 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
714 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
715 |
|
715 | |||
716 | if self.code is None: |
|
716 | if self.code is None: | |
717 | print "Fail decoding: Code is not defined." |
|
717 | print "Fail decoding: Code is not defined." | |
718 | return |
|
718 | return | |
719 |
|
719 | |||
720 | self.__nProfiles = dataOut.nProfiles |
|
720 | self.__nProfiles = dataOut.nProfiles | |
721 | datadec = None |
|
721 | datadec = None | |
722 |
|
722 | |||
723 | if mode == 3: |
|
723 | if mode == 3: | |
724 | mode = 0 |
|
724 | mode = 0 | |
725 |
|
725 | |||
726 | if dataOut.flagDataAsBlock: |
|
726 | if dataOut.flagDataAsBlock: | |
727 | """ |
|
727 | """ | |
728 | Decoding when data have been read as block, |
|
728 | Decoding when data have been read as block, | |
729 | """ |
|
729 | """ | |
730 |
|
730 | |||
731 | if mode == 0: |
|
731 | if mode == 0: | |
732 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
732 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
733 | if mode == 1: |
|
733 | if mode == 1: | |
734 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
734 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
735 | else: |
|
735 | else: | |
736 | """ |
|
736 | """ | |
737 | Decoding when data have been read profile by profile |
|
737 | Decoding when data have been read profile by profile | |
738 | """ |
|
738 | """ | |
739 | if mode == 0: |
|
739 | if mode == 0: | |
740 | datadec = self.__convolutionInTime(dataOut.data) |
|
740 | datadec = self.__convolutionInTime(dataOut.data) | |
741 |
|
741 | |||
742 | if mode == 1: |
|
742 | if mode == 1: | |
743 | datadec = self.__convolutionInFreq(dataOut.data) |
|
743 | datadec = self.__convolutionInFreq(dataOut.data) | |
744 |
|
744 | |||
745 | if mode == 2: |
|
745 | if mode == 2: | |
746 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
746 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
747 |
|
747 | |||
748 | if datadec is None: |
|
748 | if datadec is None: | |
749 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode |
|
749 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode | |
750 |
|
750 | |||
751 | dataOut.code = self.code |
|
751 | dataOut.code = self.code | |
752 | dataOut.nCode = self.nCode |
|
752 | dataOut.nCode = self.nCode | |
753 | dataOut.nBaud = self.nBaud |
|
753 | dataOut.nBaud = self.nBaud | |
754 |
|
754 | |||
755 | dataOut.data = datadec |
|
755 | dataOut.data = datadec | |
756 |
|
756 | |||
757 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
757 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
758 |
|
758 | |||
759 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
759 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
760 |
|
760 | |||
761 | if self.__profIndex == self.nCode-1: |
|
761 | if self.__profIndex == self.nCode-1: | |
762 | self.__profIndex = 0 |
|
762 | self.__profIndex = 0 | |
763 | return 1 |
|
763 | return 1 | |
764 |
|
764 | |||
765 | self.__profIndex += 1 |
|
765 | self.__profIndex += 1 | |
766 |
|
766 | |||
767 | return 1 |
|
767 | return 1 | |
768 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
768 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
769 |
|
769 | |||
770 |
|
770 | |||
771 | class ProfileConcat(Operation): |
|
771 | class ProfileConcat(Operation): | |
772 |
|
772 | |||
773 | isConfig = False |
|
773 | isConfig = False | |
774 | buffer = None |
|
774 | buffer = None | |
775 |
|
775 | |||
776 | def __init__(self, **kwargs): |
|
776 | def __init__(self, **kwargs): | |
777 |
|
777 | |||
778 | Operation.__init__(self, **kwargs) |
|
778 | Operation.__init__(self, **kwargs) | |
779 | self.profileIndex = 0 |
|
779 | self.profileIndex = 0 | |
780 |
|
780 | |||
781 | def reset(self): |
|
781 | def reset(self): | |
782 | self.buffer = numpy.zeros_like(self.buffer) |
|
782 | self.buffer = numpy.zeros_like(self.buffer) | |
783 | self.start_index = 0 |
|
783 | self.start_index = 0 | |
784 | self.times = 1 |
|
784 | self.times = 1 | |
785 |
|
785 | |||
786 | def setup(self, data, m, n=1): |
|
786 | def setup(self, data, m, n=1): | |
787 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
787 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
788 | self.nHeights = data.shape[1]#.nHeights |
|
788 | self.nHeights = data.shape[1]#.nHeights | |
789 | self.start_index = 0 |
|
789 | self.start_index = 0 | |
790 | self.times = 1 |
|
790 | self.times = 1 | |
791 |
|
791 | |||
792 | def concat(self, data): |
|
792 | def concat(self, data): | |
793 |
|
793 | |||
794 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
794 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
795 | self.start_index = self.start_index + self.nHeights |
|
795 | self.start_index = self.start_index + self.nHeights | |
796 |
|
796 | |||
797 | def run(self, dataOut, m): |
|
797 | def run(self, dataOut, m): | |
798 |
|
798 | |||
799 | dataOut.flagNoData = True |
|
799 | dataOut.flagNoData = True | |
800 |
|
800 | |||
801 | if not self.isConfig: |
|
801 | if not self.isConfig: | |
802 | self.setup(dataOut.data, m, 1) |
|
802 | self.setup(dataOut.data, m, 1) | |
803 | self.isConfig = True |
|
803 | self.isConfig = True | |
804 |
|
804 | |||
805 | if dataOut.flagDataAsBlock: |
|
805 | if dataOut.flagDataAsBlock: | |
806 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" |
|
806 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" | |
807 |
|
807 | |||
808 | else: |
|
808 | else: | |
809 | self.concat(dataOut.data) |
|
809 | self.concat(dataOut.data) | |
810 | self.times += 1 |
|
810 | self.times += 1 | |
811 | if self.times > m: |
|
811 | if self.times > m: | |
812 | dataOut.data = self.buffer |
|
812 | dataOut.data = self.buffer | |
813 | self.reset() |
|
813 | self.reset() | |
814 | dataOut.flagNoData = False |
|
814 | dataOut.flagNoData = False | |
815 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
815 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
816 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
816 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
817 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
817 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
818 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
818 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
819 | dataOut.ippSeconds *= m |
|
819 | dataOut.ippSeconds *= m | |
820 |
|
820 | |||
821 | class ProfileSelector(Operation): |
|
821 | class ProfileSelector(Operation): | |
822 |
|
822 | |||
823 | profileIndex = None |
|
823 | profileIndex = None | |
824 | # Tamanho total de los perfiles |
|
824 | # Tamanho total de los perfiles | |
825 | nProfiles = None |
|
825 | nProfiles = None | |
826 |
|
826 | |||
827 | def __init__(self, **kwargs): |
|
827 | def __init__(self, **kwargs): | |
828 |
|
828 | |||
829 | Operation.__init__(self, **kwargs) |
|
829 | Operation.__init__(self, **kwargs) | |
830 | self.profileIndex = 0 |
|
830 | self.profileIndex = 0 | |
831 |
|
831 | |||
832 | def incProfileIndex(self): |
|
832 | def incProfileIndex(self): | |
833 |
|
833 | |||
834 | self.profileIndex += 1 |
|
834 | self.profileIndex += 1 | |
835 |
|
835 | |||
836 | if self.profileIndex >= self.nProfiles: |
|
836 | if self.profileIndex >= self.nProfiles: | |
837 | self.profileIndex = 0 |
|
837 | self.profileIndex = 0 | |
838 |
|
838 | |||
839 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
839 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
840 |
|
840 | |||
841 | if profileIndex < minIndex: |
|
841 | if profileIndex < minIndex: | |
842 | return False |
|
842 | return False | |
843 |
|
843 | |||
844 | if profileIndex > maxIndex: |
|
844 | if profileIndex > maxIndex: | |
845 | return False |
|
845 | return False | |
846 |
|
846 | |||
847 | return True |
|
847 | return True | |
848 |
|
848 | |||
849 | def isThisProfileInList(self, profileIndex, profileList): |
|
849 | def isThisProfileInList(self, profileIndex, profileList): | |
850 |
|
850 | |||
851 | if profileIndex not in profileList: |
|
851 | if profileIndex not in profileList: | |
852 | return False |
|
852 | return False | |
853 |
|
853 | |||
854 | return True |
|
854 | return True | |
855 |
|
855 | |||
856 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
856 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
857 |
|
857 | |||
858 | """ |
|
858 | """ | |
859 | ProfileSelector: |
|
859 | ProfileSelector: | |
860 |
|
860 | |||
861 | Inputs: |
|
861 | Inputs: | |
862 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
862 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
863 |
|
863 | |||
864 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
864 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
865 |
|
865 | |||
866 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
866 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
867 |
|
867 | |||
868 | """ |
|
868 | """ | |
869 |
|
869 | |||
870 | if rangeList is not None: |
|
870 | if rangeList is not None: | |
871 | if type(rangeList[0]) not in (tuple, list): |
|
871 | if type(rangeList[0]) not in (tuple, list): | |
872 | rangeList = [rangeList] |
|
872 | rangeList = [rangeList] | |
873 |
|
873 | |||
874 | dataOut.flagNoData = True |
|
874 | dataOut.flagNoData = True | |
875 |
|
875 | |||
876 | if dataOut.flagDataAsBlock: |
|
876 | if dataOut.flagDataAsBlock: | |
877 | """ |
|
877 | """ | |
878 | data dimension = [nChannels, nProfiles, nHeis] |
|
878 | data dimension = [nChannels, nProfiles, nHeis] | |
879 | """ |
|
879 | """ | |
880 | if profileList != None: |
|
880 | if profileList != None: | |
881 | dataOut.data = dataOut.data[:,profileList,:] |
|
881 | dataOut.data = dataOut.data[:,profileList,:] | |
882 |
|
882 | |||
883 | if profileRangeList != None: |
|
883 | if profileRangeList != None: | |
884 | minIndex = profileRangeList[0] |
|
884 | minIndex = profileRangeList[0] | |
885 | maxIndex = profileRangeList[1] |
|
885 | maxIndex = profileRangeList[1] | |
886 | profileList = range(minIndex, maxIndex+1) |
|
886 | profileList = range(minIndex, maxIndex+1) | |
887 |
|
887 | |||
888 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
888 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
889 |
|
889 | |||
890 | if rangeList != None: |
|
890 | if rangeList != None: | |
891 |
|
891 | |||
892 | profileList = [] |
|
892 | profileList = [] | |
893 |
|
893 | |||
894 | for thisRange in rangeList: |
|
894 | for thisRange in rangeList: | |
895 | minIndex = thisRange[0] |
|
895 | minIndex = thisRange[0] | |
896 | maxIndex = thisRange[1] |
|
896 | maxIndex = thisRange[1] | |
897 |
|
897 | |||
898 | profileList.extend(range(minIndex, maxIndex+1)) |
|
898 | profileList.extend(range(minIndex, maxIndex+1)) | |
899 |
|
899 | |||
900 | dataOut.data = dataOut.data[:,profileList,:] |
|
900 | dataOut.data = dataOut.data[:,profileList,:] | |
901 |
|
901 | |||
902 | dataOut.nProfiles = len(profileList) |
|
902 | dataOut.nProfiles = len(profileList) | |
903 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
903 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
904 | dataOut.flagNoData = False |
|
904 | dataOut.flagNoData = False | |
905 |
|
905 | |||
906 | return True |
|
906 | return True | |
907 |
|
907 | |||
908 | """ |
|
908 | """ | |
909 | data dimension = [nChannels, nHeis] |
|
909 | data dimension = [nChannels, nHeis] | |
910 | """ |
|
910 | """ | |
911 |
|
911 | |||
912 | if profileList != None: |
|
912 | if profileList != None: | |
913 |
|
913 | |||
914 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
914 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
915 |
|
915 | |||
916 | self.nProfiles = len(profileList) |
|
916 | self.nProfiles = len(profileList) | |
917 | dataOut.nProfiles = self.nProfiles |
|
917 | dataOut.nProfiles = self.nProfiles | |
918 | dataOut.profileIndex = self.profileIndex |
|
918 | dataOut.profileIndex = self.profileIndex | |
919 | dataOut.flagNoData = False |
|
919 | dataOut.flagNoData = False | |
920 |
|
920 | |||
921 | self.incProfileIndex() |
|
921 | self.incProfileIndex() | |
922 | return True |
|
922 | return True | |
923 |
|
923 | |||
924 | if profileRangeList != None: |
|
924 | if profileRangeList != None: | |
925 |
|
925 | |||
926 | minIndex = profileRangeList[0] |
|
926 | minIndex = profileRangeList[0] | |
927 | maxIndex = profileRangeList[1] |
|
927 | maxIndex = profileRangeList[1] | |
928 |
|
928 | |||
929 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
929 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
930 |
|
930 | |||
931 | self.nProfiles = maxIndex - minIndex + 1 |
|
931 | self.nProfiles = maxIndex - minIndex + 1 | |
932 | dataOut.nProfiles = self.nProfiles |
|
932 | dataOut.nProfiles = self.nProfiles | |
933 | dataOut.profileIndex = self.profileIndex |
|
933 | dataOut.profileIndex = self.profileIndex | |
934 | dataOut.flagNoData = False |
|
934 | dataOut.flagNoData = False | |
935 |
|
935 | |||
936 | self.incProfileIndex() |
|
936 | self.incProfileIndex() | |
937 | return True |
|
937 | return True | |
938 |
|
938 | |||
939 | if rangeList != None: |
|
939 | if rangeList != None: | |
940 |
|
940 | |||
941 | nProfiles = 0 |
|
941 | nProfiles = 0 | |
942 |
|
942 | |||
943 | for thisRange in rangeList: |
|
943 | for thisRange in rangeList: | |
944 | minIndex = thisRange[0] |
|
944 | minIndex = thisRange[0] | |
945 | maxIndex = thisRange[1] |
|
945 | maxIndex = thisRange[1] | |
946 |
|
946 | |||
947 | nProfiles += maxIndex - minIndex + 1 |
|
947 | nProfiles += maxIndex - minIndex + 1 | |
948 |
|
948 | |||
949 | for thisRange in rangeList: |
|
949 | for thisRange in rangeList: | |
950 |
|
950 | |||
951 | minIndex = thisRange[0] |
|
951 | minIndex = thisRange[0] | |
952 | maxIndex = thisRange[1] |
|
952 | maxIndex = thisRange[1] | |
953 |
|
953 | |||
954 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
954 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
955 |
|
955 | |||
956 | self.nProfiles = nProfiles |
|
956 | self.nProfiles = nProfiles | |
957 | dataOut.nProfiles = self.nProfiles |
|
957 | dataOut.nProfiles = self.nProfiles | |
958 | dataOut.profileIndex = self.profileIndex |
|
958 | dataOut.profileIndex = self.profileIndex | |
959 | dataOut.flagNoData = False |
|
959 | dataOut.flagNoData = False | |
960 |
|
960 | |||
961 | self.incProfileIndex() |
|
961 | self.incProfileIndex() | |
962 |
|
962 | |||
963 | break |
|
963 | break | |
964 |
|
964 | |||
965 | return True |
|
965 | return True | |
966 |
|
966 | |||
967 |
|
967 | |||
968 | if beam != None: #beam is only for AMISR data |
|
968 | if beam != None: #beam is only for AMISR data | |
969 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
969 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
970 | dataOut.flagNoData = False |
|
970 | dataOut.flagNoData = False | |
971 | dataOut.profileIndex = self.profileIndex |
|
971 | dataOut.profileIndex = self.profileIndex | |
972 |
|
972 | |||
973 | self.incProfileIndex() |
|
973 | self.incProfileIndex() | |
974 |
|
974 | |||
975 | return True |
|
975 | return True | |
976 |
|
976 | |||
977 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" |
|
977 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" | |
978 |
|
978 | |||
979 | return False |
|
979 | return False | |
980 |
|
980 | |||
981 | class Reshaper(Operation): |
|
981 | class Reshaper(Operation): | |
982 |
|
982 | |||
983 | def __init__(self, **kwargs): |
|
983 | def __init__(self, **kwargs): | |
984 |
|
984 | |||
985 | Operation.__init__(self, **kwargs) |
|
985 | Operation.__init__(self, **kwargs) | |
986 |
|
986 | |||
987 | self.__buffer = None |
|
987 | self.__buffer = None | |
988 | self.__nitems = 0 |
|
988 | self.__nitems = 0 | |
989 |
|
989 | |||
990 | def __appendProfile(self, dataOut, nTxs): |
|
990 | def __appendProfile(self, dataOut, nTxs): | |
991 |
|
991 | |||
992 | if self.__buffer is None: |
|
992 | if self.__buffer is None: | |
993 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
993 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
994 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
994 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
995 |
|
995 | |||
996 | ini = dataOut.nHeights * self.__nitems |
|
996 | ini = dataOut.nHeights * self.__nitems | |
997 | end = ini + dataOut.nHeights |
|
997 | end = ini + dataOut.nHeights | |
998 |
|
998 | |||
999 | self.__buffer[:, ini:end] = dataOut.data |
|
999 | self.__buffer[:, ini:end] = dataOut.data | |
1000 |
|
1000 | |||
1001 | self.__nitems += 1 |
|
1001 | self.__nitems += 1 | |
1002 |
|
1002 | |||
1003 | return int(self.__nitems*nTxs) |
|
1003 | return int(self.__nitems*nTxs) | |
1004 |
|
1004 | |||
1005 | def __getBuffer(self): |
|
1005 | def __getBuffer(self): | |
1006 |
|
1006 | |||
1007 | if self.__nitems == int(1./self.__nTxs): |
|
1007 | if self.__nitems == int(1./self.__nTxs): | |
1008 |
|
1008 | |||
1009 | self.__nitems = 0 |
|
1009 | self.__nitems = 0 | |
1010 |
|
1010 | |||
1011 | return self.__buffer.copy() |
|
1011 | return self.__buffer.copy() | |
1012 |
|
1012 | |||
1013 | return None |
|
1013 | return None | |
1014 |
|
1014 | |||
1015 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1015 | def __checkInputs(self, dataOut, shape, nTxs): | |
1016 |
|
1016 | |||
1017 | if shape is None and nTxs is None: |
|
1017 | if shape is None and nTxs is None: | |
1018 | raise ValueError, "Reshaper: shape of factor should be defined" |
|
1018 | raise ValueError, "Reshaper: shape of factor should be defined" | |
1019 |
|
1019 | |||
1020 | if nTxs: |
|
1020 | if nTxs: | |
1021 | if nTxs < 0: |
|
1021 | if nTxs < 0: | |
1022 | raise ValueError, "nTxs should be greater than 0" |
|
1022 | raise ValueError, "nTxs should be greater than 0" | |
1023 |
|
1023 | |||
1024 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1024 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1025 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) |
|
1025 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) | |
1026 |
|
1026 | |||
1027 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1027 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1028 |
|
1028 | |||
1029 | return shape, nTxs |
|
1029 | return shape, nTxs | |
1030 |
|
1030 | |||
1031 | if len(shape) != 2 and len(shape) != 3: |
|
1031 | if len(shape) != 2 and len(shape) != 3: | |
1032 | raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights) |
|
1032 | raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights) | |
1033 |
|
1033 | |||
1034 | if len(shape) == 2: |
|
1034 | if len(shape) == 2: | |
1035 | shape_tuple = [dataOut.nChannels] |
|
1035 | shape_tuple = [dataOut.nChannels] | |
1036 | shape_tuple.extend(shape) |
|
1036 | shape_tuple.extend(shape) | |
1037 | else: |
|
1037 | else: | |
1038 | shape_tuple = list(shape) |
|
1038 | shape_tuple = list(shape) | |
1039 |
|
1039 | |||
1040 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1040 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1041 |
|
1041 | |||
1042 | return shape_tuple, nTxs |
|
1042 | return shape_tuple, nTxs | |
1043 |
|
1043 | |||
1044 | def run(self, dataOut, shape=None, nTxs=None): |
|
1044 | def run(self, dataOut, shape=None, nTxs=None): | |
1045 |
|
1045 | |||
1046 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1046 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1047 |
|
1047 | |||
1048 | dataOut.flagNoData = True |
|
1048 | dataOut.flagNoData = True | |
1049 | profileIndex = None |
|
1049 | profileIndex = None | |
1050 |
|
1050 | |||
1051 | if dataOut.flagDataAsBlock: |
|
1051 | if dataOut.flagDataAsBlock: | |
1052 |
|
1052 | |||
1053 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1053 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1054 | dataOut.flagNoData = False |
|
1054 | dataOut.flagNoData = False | |
1055 |
|
1055 | |||
1056 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1056 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1057 |
|
1057 | |||
1058 | else: |
|
1058 | else: | |
1059 |
|
1059 | |||
1060 | if self.__nTxs < 1: |
|
1060 | if self.__nTxs < 1: | |
1061 |
|
1061 | |||
1062 | self.__appendProfile(dataOut, self.__nTxs) |
|
1062 | self.__appendProfile(dataOut, self.__nTxs) | |
1063 | new_data = self.__getBuffer() |
|
1063 | new_data = self.__getBuffer() | |
1064 |
|
1064 | |||
1065 | if new_data is not None: |
|
1065 | if new_data is not None: | |
1066 | dataOut.data = new_data |
|
1066 | dataOut.data = new_data | |
1067 | dataOut.flagNoData = False |
|
1067 | dataOut.flagNoData = False | |
1068 |
|
1068 | |||
1069 | profileIndex = dataOut.profileIndex*nTxs |
|
1069 | profileIndex = dataOut.profileIndex*nTxs | |
1070 |
|
1070 | |||
1071 | else: |
|
1071 | else: | |
1072 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" |
|
1072 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" | |
1073 |
|
1073 | |||
1074 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1074 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1075 |
|
1075 | |||
1076 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1076 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1077 |
|
1077 | |||
1078 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1078 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1079 |
|
1079 | |||
1080 | dataOut.profileIndex = profileIndex |
|
1080 | dataOut.profileIndex = profileIndex | |
1081 |
|
1081 | |||
1082 | dataOut.ippSeconds /= self.__nTxs |
|
1082 | dataOut.ippSeconds /= self.__nTxs | |
1083 |
|
1083 | |||
1084 | class SplitProfiles(Operation): |
|
1084 | class SplitProfiles(Operation): | |
1085 |
|
1085 | |||
1086 | def __init__(self, **kwargs): |
|
1086 | def __init__(self, **kwargs): | |
1087 |
|
1087 | |||
1088 | Operation.__init__(self, **kwargs) |
|
1088 | Operation.__init__(self, **kwargs) | |
1089 |
|
1089 | |||
1090 | def run(self, dataOut, n): |
|
1090 | def run(self, dataOut, n): | |
1091 |
|
1091 | |||
1092 | dataOut.flagNoData = True |
|
1092 | dataOut.flagNoData = True | |
1093 | profileIndex = None |
|
1093 | profileIndex = None | |
1094 |
|
1094 | |||
1095 | if dataOut.flagDataAsBlock: |
|
1095 | if dataOut.flagDataAsBlock: | |
1096 |
|
1096 | |||
1097 | #nchannels, nprofiles, nsamples |
|
1097 | #nchannels, nprofiles, nsamples | |
1098 | shape = dataOut.data.shape |
|
1098 | shape = dataOut.data.shape | |
1099 |
|
1099 | |||
1100 | if shape[2] % n != 0: |
|
1100 | if shape[2] % n != 0: | |
1101 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) |
|
1101 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) | |
1102 |
|
1102 | |||
1103 | new_shape = shape[0], shape[1]*n, shape[2]/n |
|
1103 | new_shape = shape[0], shape[1]*n, shape[2]/n | |
1104 |
|
1104 | |||
1105 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1105 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1106 | dataOut.flagNoData = False |
|
1106 | dataOut.flagNoData = False | |
1107 |
|
1107 | |||
1108 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1108 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1109 |
|
1109 | |||
1110 | else: |
|
1110 | else: | |
1111 |
|
1111 | |||
1112 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" |
|
1112 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" | |
1113 |
|
1113 | |||
1114 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1114 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1115 |
|
1115 | |||
1116 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1116 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1117 |
|
1117 | |||
1118 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1118 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1119 |
|
1119 | |||
1120 | dataOut.profileIndex = profileIndex |
|
1120 | dataOut.profileIndex = profileIndex | |
1121 |
|
1121 | |||
1122 | dataOut.ippSeconds /= n |
|
1122 | dataOut.ippSeconds /= n | |
1123 |
|
1123 | |||
1124 | class CombineProfiles(Operation): |
|
1124 | class CombineProfiles(Operation): | |
1125 |
|
1125 | |||
1126 | def __init__(self, **kwargs): |
|
1126 | def __init__(self, **kwargs): | |
1127 |
|
1127 | |||
1128 | Operation.__init__(self, **kwargs) |
|
1128 | Operation.__init__(self, **kwargs) | |
1129 |
|
1129 | |||
1130 | self.__remData = None |
|
1130 | self.__remData = None | |
1131 | self.__profileIndex = 0 |
|
1131 | self.__profileIndex = 0 | |
1132 |
|
1132 | |||
1133 | def run(self, dataOut, n): |
|
1133 | def run(self, dataOut, n): | |
1134 |
|
1134 | |||
1135 | dataOut.flagNoData = True |
|
1135 | dataOut.flagNoData = True | |
1136 | profileIndex = None |
|
1136 | profileIndex = None | |
1137 |
|
1137 | |||
1138 | if dataOut.flagDataAsBlock: |
|
1138 | if dataOut.flagDataAsBlock: | |
1139 |
|
1139 | |||
1140 | #nchannels, nprofiles, nsamples |
|
1140 | #nchannels, nprofiles, nsamples | |
1141 | shape = dataOut.data.shape |
|
1141 | shape = dataOut.data.shape | |
1142 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1142 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1143 |
|
1143 | |||
1144 | if shape[1] % n != 0: |
|
1144 | if shape[1] % n != 0: | |
1145 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) |
|
1145 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) | |
1146 |
|
1146 | |||
1147 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1147 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1148 | dataOut.flagNoData = False |
|
1148 | dataOut.flagNoData = False | |
1149 |
|
1149 | |||
1150 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1150 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1151 |
|
1151 | |||
1152 | else: |
|
1152 | else: | |
1153 |
|
1153 | |||
1154 | #nchannels, nsamples |
|
1154 | #nchannels, nsamples | |
1155 | if self.__remData is None: |
|
1155 | if self.__remData is None: | |
1156 | newData = dataOut.data |
|
1156 | newData = dataOut.data | |
1157 | else: |
|
1157 | else: | |
1158 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1158 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1159 |
|
1159 | |||
1160 | self.__profileIndex += 1 |
|
1160 | self.__profileIndex += 1 | |
1161 |
|
1161 | |||
1162 | if self.__profileIndex < n: |
|
1162 | if self.__profileIndex < n: | |
1163 | self.__remData = newData |
|
1163 | self.__remData = newData | |
1164 | #continue |
|
1164 | #continue | |
1165 | return |
|
1165 | return | |
1166 |
|
1166 | |||
1167 | self.__profileIndex = 0 |
|
1167 | self.__profileIndex = 0 | |
1168 | self.__remData = None |
|
1168 | self.__remData = None | |
1169 |
|
1169 | |||
1170 | dataOut.data = newData |
|
1170 | dataOut.data = newData | |
1171 | dataOut.flagNoData = False |
|
1171 | dataOut.flagNoData = False | |
1172 |
|
1172 | |||
1173 | profileIndex = dataOut.profileIndex/n |
|
1173 | profileIndex = dataOut.profileIndex/n | |
1174 |
|
1174 | |||
1175 |
|
1175 | |||
1176 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1176 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1177 |
|
1177 | |||
1178 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1178 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1179 |
|
1179 | |||
1180 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1180 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1181 |
|
1181 | |||
1182 | dataOut.profileIndex = profileIndex |
|
1182 | dataOut.profileIndex = profileIndex | |
1183 |
|
1183 | |||
1184 | dataOut.ippSeconds *= n |
|
1184 | dataOut.ippSeconds *= n | |
1185 |
|
1185 | |||
1186 |
|
1186 | |||
1187 | class SSheightProfiles(Operation): |
|
1187 | class SSheightProfiles(Operation): | |
1188 |
|
1188 | |||
1189 | step = None |
|
1189 | step = None | |
1190 | nsamples = None |
|
1190 | nsamples = None | |
1191 | bufferShape = None |
|
1191 | bufferShape = None | |
1192 | profileShape= None |
|
1192 | profileShape= None | |
1193 | sshProfiles = None |
|
1193 | sshProfiles = None | |
1194 | profileIndex= None |
|
1194 | profileIndex= None | |
1195 |
|
1195 | |||
1196 | def __init__(self, **kwargs): |
|
1196 | def __init__(self, **kwargs): | |
1197 |
|
1197 | |||
1198 | Operation.__init__(self, **kwargs) |
|
1198 | Operation.__init__(self, **kwargs) | |
1199 | self.isConfig = False |
|
1199 | self.isConfig = False | |
1200 |
|
1200 | |||
1201 | def setup(self,dataOut ,step = None , nsamples = None): |
|
1201 | def setup(self,dataOut ,step = None , nsamples = None): | |
1202 |
|
1202 | |||
1203 | if step == None and nsamples == None: |
|
1203 | if step == None and nsamples == None: | |
1204 | raise ValueError, "step or nheights should be specified ..." |
|
1204 | raise ValueError, "step or nheights should be specified ..." | |
1205 |
|
1205 | |||
1206 | self.step = step |
|
1206 | self.step = step | |
1207 | self.nsamples = nsamples |
|
1207 | self.nsamples = nsamples | |
1208 | self.__nChannels = dataOut.nChannels |
|
1208 | self.__nChannels = dataOut.nChannels | |
1209 | self.__nProfiles = dataOut.nProfiles |
|
1209 | self.__nProfiles = dataOut.nProfiles | |
1210 | self.__nHeis = dataOut.nHeights |
|
1210 | self.__nHeis = dataOut.nHeights | |
1211 | shape = dataOut.data.shape #nchannels, nprofiles, nsamples |
|
1211 | shape = dataOut.data.shape #nchannels, nprofiles, nsamples | |
1212 | print "shape",shape |
|
1212 | #print "shape",shape | |
1213 | #last test |
|
1213 | #last test | |
1214 | residue = (shape[1] - self.nsamples) % self.step |
|
1214 | residue = (shape[1] - self.nsamples) % self.step | |
1215 | if residue != 0: |
|
1215 | if residue != 0: | |
1216 | print "The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue) |
|
1216 | print "The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue) | |
1217 |
|
1217 | |||
1218 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1218 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1219 | numberProfile = self.nsamples |
|
1219 | numberProfile = self.nsamples | |
1220 | numberSamples = (shape[1] - self.nsamples)/self.step |
|
1220 | numberSamples = (shape[1] - self.nsamples)/self.step | |
1221 |
|
1221 | |||
1222 | print "New number of profile: %d, number of height: %d, Resolution %d Km"%(numberProfile,numberSamples,deltaHeight*self.step) |
|
1222 | print "New number of profile: %d, number of height: %d, Resolution %d Km"%(numberProfile,numberSamples,deltaHeight*self.step) | |
1223 |
|
1223 | |||
1224 | self.bufferShape = shape[0], numberSamples, numberProfile # nchannels, nsamples , nprofiles |
|
1224 | self.bufferShape = shape[0], numberSamples, numberProfile # nchannels, nsamples , nprofiles | |
1225 | self.profileShape = shape[0], numberProfile, numberSamples # nchannels, nprofiles, nsamples |
|
1225 | self.profileShape = shape[0], numberProfile, numberSamples # nchannels, nprofiles, nsamples | |
1226 |
|
1226 | |||
1227 | self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex) |
|
1227 | self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex) | |
1228 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex) |
|
1228 | self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex) | |
1229 |
|
1229 | |||
1230 | def run(self, dataOut, step, nsamples): |
|
1230 | def run(self, dataOut, step, nsamples): | |
1231 |
|
1231 | |||
1232 | dataOut.flagNoData = True |
|
1232 | dataOut.flagNoData = True | |
1233 | dataOut.flagDataAsBlock =False |
|
1233 | dataOut.flagDataAsBlock =False | |
1234 | profileIndex = None |
|
1234 | profileIndex = None | |
1235 |
|
1235 | |||
1236 | if not self.isConfig: |
|
1236 | if not self.isConfig: | |
1237 | self.setup(dataOut, step=step , nsamples=nsamples) |
|
1237 | self.setup(dataOut, step=step , nsamples=nsamples) | |
1238 | self.isConfig = True |
|
1238 | self.isConfig = True | |
1239 |
|
1239 | |||
1240 | for i in range(self.buffer.shape[1]): |
|
1240 | for i in range(self.buffer.shape[1]): | |
1241 | self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples]) |
|
1241 | self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples]) | |
1242 | #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights]) |
|
1242 | #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights]) | |
1243 |
|
1243 | |||
1244 | for j in range(self.buffer.shape[0]): |
|
1244 | for j in range(self.buffer.shape[0]): | |
1245 | self.sshProfiles[j] = numpy.transpose(self.buffer[j]) |
|
1245 | self.sshProfiles[j] = numpy.transpose(self.buffer[j]) | |
1246 |
|
1246 | |||
1247 | profileIndex = self.nsamples |
|
1247 | profileIndex = self.nsamples | |
1248 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1248 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1249 | ippSeconds = (deltaHeight*1.0e-6)/(0.15) |
|
1249 | ippSeconds = (deltaHeight*1.0e-6)/(0.15) | |
1250 |
|
1250 | |||
|
1251 | ||||
|
1252 | ||||
1251 | dataOut.data = self.sshProfiles |
|
1253 | dataOut.data = self.sshProfiles | |
1252 | dataOut.flagNoData = False |
|
1254 | dataOut.flagNoData = False | |
1253 | dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0] |
|
1255 | dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0] | |
1254 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) |
|
1256 | dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples) | |
1255 | dataOut.profileIndex = profileIndex |
|
1257 | dataOut.profileIndex = profileIndex | |
1256 | dataOut.flagDataAsBlock = True |
|
1258 | dataOut.flagDataAsBlock = True | |
1257 | dataOut.ippSeconds = ippSeconds |
|
1259 | dataOut.ippSeconds = ippSeconds | |
1258 |
|
1260 | dataOut.step = self.step | ||
1259 |
|
1261 | |||
1260 |
|
1262 | |||
1261 | # import collections |
|
1263 | # import collections | |
1262 | # from scipy.stats import mode |
|
1264 | # from scipy.stats import mode | |
1263 | # |
|
1265 | # | |
1264 | # class Synchronize(Operation): |
|
1266 | # class Synchronize(Operation): | |
1265 | # |
|
1267 | # | |
1266 | # isConfig = False |
|
1268 | # isConfig = False | |
1267 | # __profIndex = 0 |
|
1269 | # __profIndex = 0 | |
1268 | # |
|
1270 | # | |
1269 | # def __init__(self, **kwargs): |
|
1271 | # def __init__(self, **kwargs): | |
1270 | # |
|
1272 | # | |
1271 | # Operation.__init__(self, **kwargs) |
|
1273 | # Operation.__init__(self, **kwargs) | |
1272 | # # self.isConfig = False |
|
1274 | # # self.isConfig = False | |
1273 | # self.__powBuffer = None |
|
1275 | # self.__powBuffer = None | |
1274 | # self.__startIndex = 0 |
|
1276 | # self.__startIndex = 0 | |
1275 | # self.__pulseFound = False |
|
1277 | # self.__pulseFound = False | |
1276 | # |
|
1278 | # | |
1277 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1279 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1278 | # |
|
1280 | # | |
1279 | # #Read data |
|
1281 | # #Read data | |
1280 | # |
|
1282 | # | |
1281 | # powerdB = dataOut.getPower(channel = channel) |
|
1283 | # powerdB = dataOut.getPower(channel = channel) | |
1282 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1284 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1283 | # |
|
1285 | # | |
1284 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1286 | # self.__powBuffer.extend(powerdB.flatten()) | |
1285 | # |
|
1287 | # | |
1286 | # dataArray = numpy.array(self.__powBuffer) |
|
1288 | # dataArray = numpy.array(self.__powBuffer) | |
1287 | # |
|
1289 | # | |
1288 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1290 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1289 | # |
|
1291 | # | |
1290 | # maxValue = numpy.nanmax(filteredPower) |
|
1292 | # maxValue = numpy.nanmax(filteredPower) | |
1291 | # |
|
1293 | # | |
1292 | # if maxValue < noisedB + 10: |
|
1294 | # if maxValue < noisedB + 10: | |
1293 | # #No se encuentra ningun pulso de transmision |
|
1295 | # #No se encuentra ningun pulso de transmision | |
1294 | # return None |
|
1296 | # return None | |
1295 | # |
|
1297 | # | |
1296 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1298 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1297 | # |
|
1299 | # | |
1298 | # if len(maxValuesIndex) < 2: |
|
1300 | # if len(maxValuesIndex) < 2: | |
1299 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1301 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1300 | # return None |
|
1302 | # return None | |
1301 | # |
|
1303 | # | |
1302 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1304 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1303 | # |
|
1305 | # | |
1304 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1306 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1305 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1307 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1306 | # |
|
1308 | # | |
1307 | # if len(pulseIndex) < 2: |
|
1309 | # if len(pulseIndex) < 2: | |
1308 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1310 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1309 | # return None |
|
1311 | # return None | |
1310 | # |
|
1312 | # | |
1311 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1313 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1312 | # |
|
1314 | # | |
1313 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1315 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1314 | # #(No deberian existir IPP menor a 10 unidades) |
|
1316 | # #(No deberian existir IPP menor a 10 unidades) | |
1315 | # |
|
1317 | # | |
1316 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1318 | # realIndex = numpy.where(spacing > 10 )[0] | |
1317 | # |
|
1319 | # | |
1318 | # if len(realIndex) < 2: |
|
1320 | # if len(realIndex) < 2: | |
1319 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1321 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1320 | # return None |
|
1322 | # return None | |
1321 | # |
|
1323 | # | |
1322 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1324 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1323 | # realPulseIndex = pulseIndex[realIndex] |
|
1325 | # realPulseIndex = pulseIndex[realIndex] | |
1324 | # |
|
1326 | # | |
1325 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1327 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1326 | # |
|
1328 | # | |
1327 | # print "IPP = %d samples" %period |
|
1329 | # print "IPP = %d samples" %period | |
1328 | # |
|
1330 | # | |
1329 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1331 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1330 | # self.__startIndex = int(realPulseIndex[0]) |
|
1332 | # self.__startIndex = int(realPulseIndex[0]) | |
1331 | # |
|
1333 | # | |
1332 | # return 1 |
|
1334 | # return 1 | |
1333 | # |
|
1335 | # | |
1334 | # |
|
1336 | # | |
1335 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1337 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1336 | # |
|
1338 | # | |
1337 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1339 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1338 | # maxlen = buffer_size*nSamples) |
|
1340 | # maxlen = buffer_size*nSamples) | |
1339 | # |
|
1341 | # | |
1340 | # bufferList = [] |
|
1342 | # bufferList = [] | |
1341 | # |
|
1343 | # | |
1342 | # for i in range(nChannels): |
|
1344 | # for i in range(nChannels): | |
1343 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1345 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1344 | # maxlen = buffer_size*nSamples) |
|
1346 | # maxlen = buffer_size*nSamples) | |
1345 | # |
|
1347 | # | |
1346 | # bufferList.append(bufferByChannel) |
|
1348 | # bufferList.append(bufferByChannel) | |
1347 | # |
|
1349 | # | |
1348 | # self.__nSamples = nSamples |
|
1350 | # self.__nSamples = nSamples | |
1349 | # self.__nChannels = nChannels |
|
1351 | # self.__nChannels = nChannels | |
1350 | # self.__bufferList = bufferList |
|
1352 | # self.__bufferList = bufferList | |
1351 | # |
|
1353 | # | |
1352 | # def run(self, dataOut, channel = 0): |
|
1354 | # def run(self, dataOut, channel = 0): | |
1353 | # |
|
1355 | # | |
1354 | # if not self.isConfig: |
|
1356 | # if not self.isConfig: | |
1355 | # nSamples = dataOut.nHeights |
|
1357 | # nSamples = dataOut.nHeights | |
1356 | # nChannels = dataOut.nChannels |
|
1358 | # nChannels = dataOut.nChannels | |
1357 | # self.setup(nSamples, nChannels) |
|
1359 | # self.setup(nSamples, nChannels) | |
1358 | # self.isConfig = True |
|
1360 | # self.isConfig = True | |
1359 | # |
|
1361 | # | |
1360 | # #Append new data to internal buffer |
|
1362 | # #Append new data to internal buffer | |
1361 | # for thisChannel in range(self.__nChannels): |
|
1363 | # for thisChannel in range(self.__nChannels): | |
1362 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1364 | # bufferByChannel = self.__bufferList[thisChannel] | |
1363 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1365 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1364 | # |
|
1366 | # | |
1365 | # if self.__pulseFound: |
|
1367 | # if self.__pulseFound: | |
1366 | # self.__startIndex -= self.__nSamples |
|
1368 | # self.__startIndex -= self.__nSamples | |
1367 | # |
|
1369 | # | |
1368 | # #Finding Tx Pulse |
|
1370 | # #Finding Tx Pulse | |
1369 | # if not self.__pulseFound: |
|
1371 | # if not self.__pulseFound: | |
1370 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1372 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1371 | # |
|
1373 | # | |
1372 | # if indexFound == None: |
|
1374 | # if indexFound == None: | |
1373 | # dataOut.flagNoData = True |
|
1375 | # dataOut.flagNoData = True | |
1374 | # return |
|
1376 | # return | |
1375 | # |
|
1377 | # | |
1376 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1378 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1377 | # self.__pulseFound = True |
|
1379 | # self.__pulseFound = True | |
1378 | # self.__startIndex = indexFound |
|
1380 | # self.__startIndex = indexFound | |
1379 | # |
|
1381 | # | |
1380 | # #If pulse was found ... |
|
1382 | # #If pulse was found ... | |
1381 | # for thisChannel in range(self.__nChannels): |
|
1383 | # for thisChannel in range(self.__nChannels): | |
1382 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1384 | # bufferByChannel = self.__bufferList[thisChannel] | |
1383 | # #print self.__startIndex |
|
1385 | # #print self.__startIndex | |
1384 | # x = numpy.array(bufferByChannel) |
|
1386 | # x = numpy.array(bufferByChannel) | |
1385 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1387 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1386 | # |
|
1388 | # | |
1387 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1389 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1388 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1390 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1389 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1391 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1390 | # |
|
1392 | # | |
1391 | # dataOut.data = self.__arrayBuffer |
|
1393 | # dataOut.data = self.__arrayBuffer | |
1392 | # |
|
1394 | # | |
1393 | # self.__startIndex += self.__newNSamples |
|
1395 | # self.__startIndex += self.__newNSamples | |
1394 | # |
|
1396 | # | |
1395 | # return |
|
1397 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now