@@ -1,1312 +1,1310 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy |
|
2 | import numpy | |
3 | from profilehooks import profile |
|
3 | from profilehooks import profile | |
4 | from scipy import interpolate |
|
4 | from scipy import interpolate | |
5 | from schainpy import cSchain |
|
5 | from schainpy import cSchain | |
6 | from jroproc_base import ProcessingUnit, Operation |
|
6 | from jroproc_base import ProcessingUnit, Operation | |
7 | from schainpy.model.data.jrodata import Voltage |
|
7 | from schainpy.model.data.jrodata import Voltage | |
8 | from time import time |
|
8 | from time import time | |
9 |
|
9 | |||
10 | class VoltageProc(ProcessingUnit): |
|
10 | class VoltageProc(ProcessingUnit): | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | def __init__(self, **kwargs): |
|
13 | def __init__(self, **kwargs): | |
14 |
|
14 | |||
15 | ProcessingUnit.__init__(self, **kwargs) |
|
15 | ProcessingUnit.__init__(self, **kwargs) | |
16 |
|
16 | |||
17 | # self.objectDict = {} |
|
17 | # self.objectDict = {} | |
18 | self.dataOut = Voltage() |
|
18 | self.dataOut = Voltage() | |
19 | self.flip = 1 |
|
19 | self.flip = 1 | |
20 |
|
20 | |||
21 | def run(self): |
|
21 | def run(self): | |
22 | if self.dataIn.type == 'AMISR': |
|
22 | if self.dataIn.type == 'AMISR': | |
23 | self.__updateObjFromAmisrInput() |
|
23 | self.__updateObjFromAmisrInput() | |
24 |
|
24 | |||
25 | if self.dataIn.type == 'Voltage': |
|
25 | if self.dataIn.type == 'Voltage': | |
26 | self.dataOut.copy(self.dataIn) |
|
26 | self.dataOut.copy(self.dataIn) | |
27 |
|
27 | |||
28 | # self.dataOut.copy(self.dataIn) |
|
28 | # self.dataOut.copy(self.dataIn) | |
29 |
|
29 | |||
30 | def __updateObjFromAmisrInput(self): |
|
30 | def __updateObjFromAmisrInput(self): | |
31 |
|
31 | |||
32 | self.dataOut.timeZone = self.dataIn.timeZone |
|
32 | self.dataOut.timeZone = self.dataIn.timeZone | |
33 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
33 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
34 | self.dataOut.errorCount = self.dataIn.errorCount |
|
34 | self.dataOut.errorCount = self.dataIn.errorCount | |
35 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
35 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
36 |
|
36 | |||
37 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
37 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
38 | self.dataOut.data = self.dataIn.data |
|
38 | self.dataOut.data = self.dataIn.data | |
39 | self.dataOut.utctime = self.dataIn.utctime |
|
39 | self.dataOut.utctime = self.dataIn.utctime | |
40 | self.dataOut.channelList = self.dataIn.channelList |
|
40 | self.dataOut.channelList = self.dataIn.channelList | |
41 | # self.dataOut.timeInterval = self.dataIn.timeInterval |
|
41 | # self.dataOut.timeInterval = self.dataIn.timeInterval | |
42 | self.dataOut.heightList = self.dataIn.heightList |
|
42 | self.dataOut.heightList = self.dataIn.heightList | |
43 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
43 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
44 |
|
44 | |||
45 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
45 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
46 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
46 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
47 | self.dataOut.frequency = self.dataIn.frequency |
|
47 | self.dataOut.frequency = self.dataIn.frequency | |
48 |
|
48 | |||
49 | self.dataOut.azimuth = self.dataIn.azimuth |
|
49 | self.dataOut.azimuth = self.dataIn.azimuth | |
50 | self.dataOut.zenith = self.dataIn.zenith |
|
50 | self.dataOut.zenith = self.dataIn.zenith | |
51 |
|
51 | |||
52 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
52 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
53 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
53 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
54 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
54 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
55 | # |
|
55 | # | |
56 | # pass# |
|
56 | # pass# | |
57 | # |
|
57 | # | |
58 | # def init(self): |
|
58 | # def init(self): | |
59 | # |
|
59 | # | |
60 | # |
|
60 | # | |
61 | # if self.dataIn.type == 'AMISR': |
|
61 | # if self.dataIn.type == 'AMISR': | |
62 | # self.__updateObjFromAmisrInput() |
|
62 | # self.__updateObjFromAmisrInput() | |
63 | # |
|
63 | # | |
64 | # if self.dataIn.type == 'Voltage': |
|
64 | # if self.dataIn.type == 'Voltage': | |
65 | # self.dataOut.copy(self.dataIn) |
|
65 | # self.dataOut.copy(self.dataIn) | |
66 | # # No necesita copiar en cada init() los atributos de dataIn |
|
66 | # # No necesita copiar en cada init() los atributos de dataIn | |
67 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
67 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
68 |
|
68 | |||
69 | def selectChannels(self, channelList): |
|
69 | def selectChannels(self, channelList): | |
70 |
|
70 | |||
71 | channelIndexList = [] |
|
71 | channelIndexList = [] | |
72 |
|
72 | |||
73 | for channel in channelList: |
|
73 | for channel in channelList: | |
74 | if channel not in self.dataOut.channelList: |
|
74 | if channel not in self.dataOut.channelList: | |
75 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) |
|
75 | raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList)) | |
76 |
|
76 | |||
77 | index = self.dataOut.channelList.index(channel) |
|
77 | index = self.dataOut.channelList.index(channel) | |
78 | channelIndexList.append(index) |
|
78 | channelIndexList.append(index) | |
79 |
|
79 | |||
80 | self.selectChannelsByIndex(channelIndexList) |
|
80 | self.selectChannelsByIndex(channelIndexList) | |
81 |
|
81 | |||
82 | def selectChannelsByIndex(self, channelIndexList): |
|
82 | def selectChannelsByIndex(self, channelIndexList): | |
83 | """ |
|
83 | """ | |
84 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
84 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
85 |
|
85 | |||
86 | Input: |
|
86 | Input: | |
87 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
87 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
88 |
|
88 | |||
89 | Affected: |
|
89 | Affected: | |
90 | self.dataOut.data |
|
90 | self.dataOut.data | |
91 | self.dataOut.channelIndexList |
|
91 | self.dataOut.channelIndexList | |
92 | self.dataOut.nChannels |
|
92 | self.dataOut.nChannels | |
93 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
93 | self.dataOut.m_ProcessingHeader.totalSpectra | |
94 | self.dataOut.systemHeaderObj.numChannels |
|
94 | self.dataOut.systemHeaderObj.numChannels | |
95 | self.dataOut.m_ProcessingHeader.blockSize |
|
95 | self.dataOut.m_ProcessingHeader.blockSize | |
96 |
|
96 | |||
97 | Return: |
|
97 | Return: | |
98 | None |
|
98 | None | |
99 | """ |
|
99 | """ | |
100 |
|
100 | |||
101 | for channelIndex in channelIndexList: |
|
101 | for channelIndex in channelIndexList: | |
102 | if channelIndex not in self.dataOut.channelIndexList: |
|
102 | if channelIndex not in self.dataOut.channelIndexList: | |
103 | print channelIndexList |
|
103 | print channelIndexList | |
104 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
104 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
105 |
|
105 | |||
106 | if self.dataOut.flagDataAsBlock: |
|
106 | if self.dataOut.flagDataAsBlock: | |
107 | """ |
|
107 | """ | |
108 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
108 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
109 | """ |
|
109 | """ | |
110 | data = self.dataOut.data[channelIndexList,:,:] |
|
110 | data = self.dataOut.data[channelIndexList,:,:] | |
111 | else: |
|
111 | else: | |
112 | data = self.dataOut.data[channelIndexList,:] |
|
112 | data = self.dataOut.data[channelIndexList,:] | |
113 |
|
113 | |||
114 | self.dataOut.data = data |
|
114 | self.dataOut.data = data | |
115 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
115 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
116 | # self.dataOut.nChannels = nChannels |
|
116 | # self.dataOut.nChannels = nChannels | |
117 |
|
117 | |||
118 | return 1 |
|
118 | return 1 | |
119 |
|
119 | |||
120 | def selectHeights(self, minHei=None, maxHei=None): |
|
120 | def selectHeights(self, minHei=None, maxHei=None): | |
121 | """ |
|
121 | """ | |
122 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
122 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
123 | minHei <= height <= maxHei |
|
123 | minHei <= height <= maxHei | |
124 |
|
124 | |||
125 | Input: |
|
125 | Input: | |
126 | minHei : valor minimo de altura a considerar |
|
126 | minHei : valor minimo de altura a considerar | |
127 | maxHei : valor maximo de altura a considerar |
|
127 | maxHei : valor maximo de altura a considerar | |
128 |
|
128 | |||
129 | Affected: |
|
129 | Affected: | |
130 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
130 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
131 |
|
131 | |||
132 | Return: |
|
132 | Return: | |
133 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
133 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
134 | """ |
|
134 | """ | |
135 |
|
135 | |||
136 | if minHei == None: |
|
136 | if minHei == None: | |
137 | minHei = self.dataOut.heightList[0] |
|
137 | minHei = self.dataOut.heightList[0] | |
138 |
|
138 | |||
139 | if maxHei == None: |
|
139 | if maxHei == None: | |
140 | maxHei = self.dataOut.heightList[-1] |
|
140 | maxHei = self.dataOut.heightList[-1] | |
141 |
|
141 | |||
142 | if (minHei < self.dataOut.heightList[0]): |
|
142 | if (minHei < self.dataOut.heightList[0]): | |
143 | minHei = self.dataOut.heightList[0] |
|
143 | minHei = self.dataOut.heightList[0] | |
144 |
|
144 | |||
145 | if (maxHei > self.dataOut.heightList[-1]): |
|
145 | if (maxHei > self.dataOut.heightList[-1]): | |
146 | maxHei = self.dataOut.heightList[-1] |
|
146 | maxHei = self.dataOut.heightList[-1] | |
147 |
|
147 | |||
148 | minIndex = 0 |
|
148 | minIndex = 0 | |
149 | maxIndex = 0 |
|
149 | maxIndex = 0 | |
150 | heights = self.dataOut.heightList |
|
150 | heights = self.dataOut.heightList | |
151 |
|
151 | |||
152 | inda = numpy.where(heights >= minHei) |
|
152 | inda = numpy.where(heights >= minHei) | |
153 | indb = numpy.where(heights <= maxHei) |
|
153 | indb = numpy.where(heights <= maxHei) | |
154 |
|
154 | |||
155 | try: |
|
155 | try: | |
156 | minIndex = inda[0][0] |
|
156 | minIndex = inda[0][0] | |
157 | except: |
|
157 | except: | |
158 | minIndex = 0 |
|
158 | minIndex = 0 | |
159 |
|
159 | |||
160 | try: |
|
160 | try: | |
161 | maxIndex = indb[0][-1] |
|
161 | maxIndex = indb[0][-1] | |
162 | except: |
|
162 | except: | |
163 | maxIndex = len(heights) |
|
163 | maxIndex = len(heights) | |
164 |
|
164 | |||
165 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
165 | self.selectHeightsByIndex(minIndex, maxIndex) | |
166 |
|
166 | |||
167 | return 1 |
|
167 | return 1 | |
168 |
|
168 | |||
169 |
|
169 | |||
170 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
170 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
171 | """ |
|
171 | """ | |
172 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
172 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
173 | minIndex <= index <= maxIndex |
|
173 | minIndex <= index <= maxIndex | |
174 |
|
174 | |||
175 | Input: |
|
175 | Input: | |
176 | minIndex : valor de indice minimo de altura a considerar |
|
176 | minIndex : valor de indice minimo de altura a considerar | |
177 | maxIndex : valor de indice maximo de altura a considerar |
|
177 | maxIndex : valor de indice maximo de altura a considerar | |
178 |
|
178 | |||
179 | Affected: |
|
179 | Affected: | |
180 | self.dataOut.data |
|
180 | self.dataOut.data | |
181 | self.dataOut.heightList |
|
181 | self.dataOut.heightList | |
182 |
|
182 | |||
183 | Return: |
|
183 | Return: | |
184 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
184 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
185 | """ |
|
185 | """ | |
186 |
|
186 | |||
187 | if (minIndex < 0) or (minIndex > maxIndex): |
|
187 | if (minIndex < 0) or (minIndex > maxIndex): | |
188 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
188 | raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex) | |
189 |
|
189 | |||
190 | if (maxIndex >= self.dataOut.nHeights): |
|
190 | if (maxIndex >= self.dataOut.nHeights): | |
191 | maxIndex = self.dataOut.nHeights |
|
191 | maxIndex = self.dataOut.nHeights | |
192 |
|
192 | |||
193 | #voltage |
|
193 | #voltage | |
194 | if self.dataOut.flagDataAsBlock: |
|
194 | if self.dataOut.flagDataAsBlock: | |
195 | """ |
|
195 | """ | |
196 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
196 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
197 | """ |
|
197 | """ | |
198 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
198 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
199 | else: |
|
199 | else: | |
200 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
200 | data = self.dataOut.data[:, minIndex:maxIndex] | |
201 |
|
201 | |||
202 | # firstHeight = self.dataOut.heightList[minIndex] |
|
202 | # firstHeight = self.dataOut.heightList[minIndex] | |
203 |
|
203 | |||
204 | self.dataOut.data = data |
|
204 | self.dataOut.data = data | |
205 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
205 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
206 |
|
206 | |||
207 | if self.dataOut.nHeights <= 1: |
|
207 | if self.dataOut.nHeights <= 1: | |
208 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) |
|
208 | raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights) | |
209 |
|
209 | |||
210 | return 1 |
|
210 | return 1 | |
211 |
|
211 | |||
212 |
|
212 | |||
213 | def filterByHeights(self, window): |
|
213 | def filterByHeights(self, window): | |
214 |
|
214 | |||
215 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
215 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
216 |
|
216 | |||
217 | if window == None: |
|
217 | if window == None: | |
218 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
218 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
219 |
|
219 | |||
220 | newdelta = deltaHeight * window |
|
220 | newdelta = deltaHeight * window | |
221 | r = self.dataOut.nHeights % window |
|
221 | r = self.dataOut.nHeights % window | |
222 | newheights = (self.dataOut.nHeights-r)/window |
|
222 | newheights = (self.dataOut.nHeights-r)/window | |
223 |
|
223 | |||
224 | if newheights <= 1: |
|
224 | if newheights <= 1: | |
225 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) |
|
225 | raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window) | |
226 |
|
226 | |||
227 | if self.dataOut.flagDataAsBlock: |
|
227 | if self.dataOut.flagDataAsBlock: | |
228 | """ |
|
228 | """ | |
229 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
229 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
230 | """ |
|
230 | """ | |
231 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] |
|
231 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] | |
232 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) |
|
232 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) | |
233 | buffer = numpy.sum(buffer,3) |
|
233 | buffer = numpy.sum(buffer,3) | |
234 |
|
234 | |||
235 | else: |
|
235 | else: | |
236 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] |
|
236 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] | |
237 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) |
|
237 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) | |
238 | buffer = numpy.sum(buffer,2) |
|
238 | buffer = numpy.sum(buffer,2) | |
239 |
|
239 | |||
240 | self.dataOut.data = buffer |
|
240 | self.dataOut.data = buffer | |
241 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
241 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
242 | self.dataOut.windowOfFilter = window |
|
242 | self.dataOut.windowOfFilter = window | |
243 |
|
243 | |||
244 | def setH0(self, h0, deltaHeight = None): |
|
244 | def setH0(self, h0, deltaHeight = None): | |
245 |
|
245 | |||
246 | if not deltaHeight: |
|
246 | if not deltaHeight: | |
247 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
247 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
248 |
|
248 | |||
249 | nHeights = self.dataOut.nHeights |
|
249 | nHeights = self.dataOut.nHeights | |
250 |
|
250 | |||
251 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
251 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
252 |
|
252 | |||
253 | self.dataOut.heightList = newHeiRange |
|
253 | self.dataOut.heightList = newHeiRange | |
254 |
|
254 | |||
255 | def deFlip(self, channelList = []): |
|
255 | def deFlip(self, channelList = []): | |
256 |
|
256 | |||
257 | data = self.dataOut.data.copy() |
|
257 | data = self.dataOut.data.copy() | |
258 |
|
258 | |||
259 | if self.dataOut.flagDataAsBlock: |
|
259 | if self.dataOut.flagDataAsBlock: | |
260 | flip = self.flip |
|
260 | flip = self.flip | |
261 | profileList = range(self.dataOut.nProfiles) |
|
261 | profileList = range(self.dataOut.nProfiles) | |
262 |
|
262 | |||
263 | if not channelList: |
|
263 | if not channelList: | |
264 | for thisProfile in profileList: |
|
264 | for thisProfile in profileList: | |
265 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
265 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
266 | flip *= -1.0 |
|
266 | flip *= -1.0 | |
267 | else: |
|
267 | else: | |
268 | for thisChannel in channelList: |
|
268 | for thisChannel in channelList: | |
269 | if thisChannel not in self.dataOut.channelList: |
|
269 | if thisChannel not in self.dataOut.channelList: | |
270 | continue |
|
270 | continue | |
271 |
|
271 | |||
272 | for thisProfile in profileList: |
|
272 | for thisProfile in profileList: | |
273 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
273 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
274 | flip *= -1.0 |
|
274 | flip *= -1.0 | |
275 |
|
275 | |||
276 | self.flip = flip |
|
276 | self.flip = flip | |
277 |
|
277 | |||
278 | else: |
|
278 | else: | |
279 | if not channelList: |
|
279 | if not channelList: | |
280 | data[:,:] = data[:,:]*self.flip |
|
280 | data[:,:] = data[:,:]*self.flip | |
281 | else: |
|
281 | else: | |
282 | for thisChannel in channelList: |
|
282 | for thisChannel in channelList: | |
283 | if thisChannel not in self.dataOut.channelList: |
|
283 | if thisChannel not in self.dataOut.channelList: | |
284 | continue |
|
284 | continue | |
285 |
|
285 | |||
286 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
286 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
287 |
|
287 | |||
288 | self.flip *= -1. |
|
288 | self.flip *= -1. | |
289 |
|
289 | |||
290 | self.dataOut.data = data |
|
290 | self.dataOut.data = data | |
291 |
|
291 | |||
292 | def setRadarFrequency(self, frequency=None): |
|
292 | def setRadarFrequency(self, frequency=None): | |
293 |
|
293 | |||
294 | if frequency != None: |
|
294 | if frequency != None: | |
295 | self.dataOut.frequency = frequency |
|
295 | self.dataOut.frequency = frequency | |
296 |
|
296 | |||
297 | return 1 |
|
297 | return 1 | |
298 |
|
298 | |||
299 | def interpolateHeights(self, topLim, botLim): |
|
299 | def interpolateHeights(self, topLim, botLim): | |
300 | #69 al 72 para julia |
|
300 | #69 al 72 para julia | |
301 | #82-84 para meteoros |
|
301 | #82-84 para meteoros | |
302 | if len(numpy.shape(self.dataOut.data))==2: |
|
302 | if len(numpy.shape(self.dataOut.data))==2: | |
303 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 |
|
303 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 | |
304 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
304 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
305 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp |
|
305 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp | |
306 | self.dataOut.data[:,botLim:topLim+1] = sampInterp |
|
306 | self.dataOut.data[:,botLim:topLim+1] = sampInterp | |
307 | else: |
|
307 | else: | |
308 | nHeights = self.dataOut.data.shape[2] |
|
308 | nHeights = self.dataOut.data.shape[2] | |
309 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
309 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
310 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] |
|
310 | y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)] | |
311 | f = interpolate.interp1d(x, y, axis = 2) |
|
311 | f = interpolate.interp1d(x, y, axis = 2) | |
312 | xnew = numpy.arange(botLim,topLim+1) |
|
312 | xnew = numpy.arange(botLim,topLim+1) | |
313 | ynew = f(xnew) |
|
313 | ynew = f(xnew) | |
314 |
|
314 | |||
315 | self.dataOut.data[:,:,botLim:topLim+1] = ynew |
|
315 | self.dataOut.data[:,:,botLim:topLim+1] = ynew | |
316 |
|
316 | |||
317 | # import collections |
|
317 | # import collections | |
318 |
|
318 | |||
319 | class CohInt(Operation): |
|
319 | class CohInt(Operation): | |
320 |
|
320 | |||
321 | isConfig = False |
|
321 | isConfig = False | |
322 |
|
322 | |||
323 | __profIndex = 0 |
|
323 | __profIndex = 0 | |
324 | __withOverapping = False |
|
324 | __withOverapping = False | |
325 |
|
325 | |||
326 | __byTime = False |
|
326 | __byTime = False | |
327 | __initime = None |
|
327 | __initime = None | |
328 | __lastdatatime = None |
|
328 | __lastdatatime = None | |
329 | __integrationtime = None |
|
329 | __integrationtime = None | |
330 |
|
330 | |||
331 | __buffer = None |
|
331 | __buffer = None | |
332 |
|
332 | |||
333 | __dataReady = False |
|
333 | __dataReady = False | |
334 |
|
334 | |||
335 | n = None |
|
335 | n = None | |
336 |
|
336 | |||
337 |
|
337 | |||
338 | def __init__(self, **kwargs): |
|
338 | def __init__(self, **kwargs): | |
339 |
|
339 | |||
340 | Operation.__init__(self, **kwargs) |
|
340 | Operation.__init__(self, **kwargs) | |
341 |
|
341 | |||
342 | # self.isConfig = False |
|
342 | # self.isConfig = False | |
343 |
|
343 | |||
344 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): |
|
344 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): | |
345 | """ |
|
345 | """ | |
346 | Set the parameters of the integration class. |
|
346 | Set the parameters of the integration class. | |
347 |
|
347 | |||
348 | Inputs: |
|
348 | Inputs: | |
349 |
|
349 | |||
350 | n : Number of coherent integrations |
|
350 | n : Number of coherent integrations | |
351 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
351 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
352 | overlapping : |
|
352 | overlapping : | |
353 |
|
353 | |||
354 | """ |
|
354 | """ | |
355 |
|
355 | |||
356 | self.__initime = None |
|
356 | self.__initime = None | |
357 | self.__lastdatatime = 0 |
|
357 | self.__lastdatatime = 0 | |
358 | self.__buffer = None |
|
358 | self.__buffer = None | |
359 | self.__dataReady = False |
|
359 | self.__dataReady = False | |
360 | self.byblock = byblock |
|
360 | self.byblock = byblock | |
361 |
|
361 | |||
362 | if n == None and timeInterval == None: |
|
362 | if n == None and timeInterval == None: | |
363 | raise ValueError, "n or timeInterval should be specified ..." |
|
363 | raise ValueError, "n or timeInterval should be specified ..." | |
364 |
|
364 | |||
365 | if n != None: |
|
365 | if n != None: | |
366 | self.n = n |
|
366 | self.n = n | |
367 | self.__byTime = False |
|
367 | self.__byTime = False | |
368 | else: |
|
368 | else: | |
369 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
369 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
370 | self.n = 9999 |
|
370 | self.n = 9999 | |
371 | self.__byTime = True |
|
371 | self.__byTime = True | |
372 |
|
372 | |||
373 | if overlapping: |
|
373 | if overlapping: | |
374 | self.__withOverapping = True |
|
374 | self.__withOverapping = True | |
375 | self.__buffer = None |
|
375 | self.__buffer = None | |
376 | else: |
|
376 | else: | |
377 | self.__withOverapping = False |
|
377 | self.__withOverapping = False | |
378 | self.__buffer = 0 |
|
378 | self.__buffer = 0 | |
379 |
|
379 | |||
380 | self.__profIndex = 0 |
|
380 | self.__profIndex = 0 | |
381 |
|
381 | |||
382 | def putData(self, data): |
|
382 | def putData(self, data): | |
383 |
|
383 | |||
384 | """ |
|
384 | """ | |
385 | Add a profile to the __buffer and increase in one the __profileIndex |
|
385 | Add a profile to the __buffer and increase in one the __profileIndex | |
386 |
|
386 | |||
387 | """ |
|
387 | """ | |
388 |
|
388 | |||
389 | if not self.__withOverapping: |
|
389 | if not self.__withOverapping: | |
390 | self.__buffer += data.copy() |
|
390 | self.__buffer += data.copy() | |
391 | self.__profIndex += 1 |
|
391 | self.__profIndex += 1 | |
392 | return |
|
392 | return | |
393 |
|
393 | |||
394 | #Overlapping data |
|
394 | #Overlapping data | |
395 | nChannels, nHeis = data.shape |
|
395 | nChannels, nHeis = data.shape | |
396 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
396 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
397 |
|
397 | |||
398 | #If the buffer is empty then it takes the data value |
|
398 | #If the buffer is empty then it takes the data value | |
399 | if self.__buffer is None: |
|
399 | if self.__buffer is None: | |
400 | self.__buffer = data |
|
400 | self.__buffer = data | |
401 | self.__profIndex += 1 |
|
401 | self.__profIndex += 1 | |
402 | return |
|
402 | return | |
403 |
|
403 | |||
404 | #If the buffer length is lower than n then stakcing the data value |
|
404 | #If the buffer length is lower than n then stakcing the data value | |
405 | if self.__profIndex < self.n: |
|
405 | if self.__profIndex < self.n: | |
406 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
406 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
407 | self.__profIndex += 1 |
|
407 | self.__profIndex += 1 | |
408 | return |
|
408 | return | |
409 |
|
409 | |||
410 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
410 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
411 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
411 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
412 | self.__buffer[self.n-1] = data |
|
412 | self.__buffer[self.n-1] = data | |
413 | self.__profIndex = self.n |
|
413 | self.__profIndex = self.n | |
414 | return |
|
414 | return | |
415 |
|
415 | |||
416 |
|
416 | |||
417 | def pushData(self): |
|
417 | def pushData(self): | |
418 | """ |
|
418 | """ | |
419 | Return the sum of the last profiles and the profiles used in the sum. |
|
419 | Return the sum of the last profiles and the profiles used in the sum. | |
420 |
|
420 | |||
421 | Affected: |
|
421 | Affected: | |
422 |
|
422 | |||
423 | self.__profileIndex |
|
423 | self.__profileIndex | |
424 |
|
424 | |||
425 | """ |
|
425 | """ | |
426 |
|
426 | |||
427 | if not self.__withOverapping: |
|
427 | if not self.__withOverapping: | |
428 | data = self.__buffer |
|
428 | data = self.__buffer | |
429 | n = self.__profIndex |
|
429 | n = self.__profIndex | |
430 |
|
430 | |||
431 | self.__buffer = 0 |
|
431 | self.__buffer = 0 | |
432 | self.__profIndex = 0 |
|
432 | self.__profIndex = 0 | |
433 |
|
433 | |||
434 | return data, n |
|
434 | return data, n | |
435 |
|
435 | |||
436 | #Integration with Overlapping |
|
436 | #Integration with Overlapping | |
437 | data = numpy.sum(self.__buffer, axis=0) |
|
437 | data = numpy.sum(self.__buffer, axis=0) | |
438 | n = self.__profIndex |
|
438 | n = self.__profIndex | |
439 |
|
439 | |||
440 | return data, n |
|
440 | return data, n | |
441 |
|
441 | |||
442 | def byProfiles(self, data): |
|
442 | def byProfiles(self, data): | |
443 |
|
443 | |||
444 | self.__dataReady = False |
|
444 | self.__dataReady = False | |
445 | avgdata = None |
|
445 | avgdata = None | |
446 | # n = None |
|
446 | # n = None | |
447 |
|
447 | |||
448 | self.putData(data) |
|
448 | self.putData(data) | |
449 |
|
449 | |||
450 | if self.__profIndex == self.n: |
|
450 | if self.__profIndex == self.n: | |
451 |
|
451 | |||
452 | avgdata, n = self.pushData() |
|
452 | avgdata, n = self.pushData() | |
453 | self.__dataReady = True |
|
453 | self.__dataReady = True | |
454 |
|
454 | |||
455 | return avgdata |
|
455 | return avgdata | |
456 |
|
456 | |||
457 | def byTime(self, data, datatime): |
|
457 | def byTime(self, data, datatime): | |
458 |
|
458 | |||
459 | self.__dataReady = False |
|
459 | self.__dataReady = False | |
460 | avgdata = None |
|
460 | avgdata = None | |
461 | n = None |
|
461 | n = None | |
462 |
|
462 | |||
463 | self.putData(data) |
|
463 | self.putData(data) | |
464 |
|
464 | |||
465 | if (datatime - self.__initime) >= self.__integrationtime: |
|
465 | if (datatime - self.__initime) >= self.__integrationtime: | |
466 | avgdata, n = self.pushData() |
|
466 | avgdata, n = self.pushData() | |
467 | self.n = n |
|
467 | self.n = n | |
468 | self.__dataReady = True |
|
468 | self.__dataReady = True | |
469 |
|
469 | |||
470 | return avgdata |
|
470 | return avgdata | |
471 |
|
471 | |||
472 | def integrate(self, data, datatime=None): |
|
472 | def integrate(self, data, datatime=None): | |
473 |
|
473 | |||
474 | if self.__initime == None: |
|
474 | if self.__initime == None: | |
475 | self.__initime = datatime |
|
475 | self.__initime = datatime | |
476 |
|
476 | |||
477 | if self.__byTime: |
|
477 | if self.__byTime: | |
478 | avgdata = self.byTime(data, datatime) |
|
478 | avgdata = self.byTime(data, datatime) | |
479 | else: |
|
479 | else: | |
480 | avgdata = self.byProfiles(data) |
|
480 | avgdata = self.byProfiles(data) | |
481 |
|
481 | |||
482 |
|
482 | |||
483 | self.__lastdatatime = datatime |
|
483 | self.__lastdatatime = datatime | |
484 |
|
484 | |||
485 | if avgdata is None: |
|
485 | if avgdata is None: | |
486 | return None, None |
|
486 | return None, None | |
487 |
|
487 | |||
488 | avgdatatime = self.__initime |
|
488 | avgdatatime = self.__initime | |
489 |
|
489 | |||
490 | deltatime = datatime -self.__lastdatatime |
|
490 | deltatime = datatime -self.__lastdatatime | |
491 |
|
491 | |||
492 | if not self.__withOverapping: |
|
492 | if not self.__withOverapping: | |
493 | self.__initime = datatime |
|
493 | self.__initime = datatime | |
494 | else: |
|
494 | else: | |
495 | self.__initime += deltatime |
|
495 | self.__initime += deltatime | |
496 |
|
496 | |||
497 | return avgdata, avgdatatime |
|
497 | return avgdata, avgdatatime | |
498 |
|
498 | |||
499 | def integrateByBlock(self, dataOut): |
|
499 | def integrateByBlock(self, dataOut): | |
500 |
|
500 | |||
501 | times = int(dataOut.data.shape[1]/self.n) |
|
501 | times = int(dataOut.data.shape[1]/self.n) | |
502 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
502 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
503 |
|
503 | |||
504 | id_min = 0 |
|
504 | id_min = 0 | |
505 | id_max = self.n |
|
505 | id_max = self.n | |
506 |
|
506 | |||
507 | for i in range(times): |
|
507 | for i in range(times): | |
508 | junk = dataOut.data[:,id_min:id_max,:] |
|
508 | junk = dataOut.data[:,id_min:id_max,:] | |
509 | avgdata[:,i,:] = junk.sum(axis=1) |
|
509 | avgdata[:,i,:] = junk.sum(axis=1) | |
510 | id_min += self.n |
|
510 | id_min += self.n | |
511 | id_max += self.n |
|
511 | id_max += self.n | |
512 |
|
512 | |||
513 | timeInterval = dataOut.ippSeconds*self.n |
|
513 | timeInterval = dataOut.ippSeconds*self.n | |
514 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
514 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
515 | self.__dataReady = True |
|
515 | self.__dataReady = True | |
516 | return avgdata, avgdatatime |
|
516 | return avgdata, avgdatatime | |
517 |
|
517 | |||
518 |
|
518 | |||
519 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs): |
|
519 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs): | |
520 | if not self.isConfig: |
|
520 | if not self.isConfig: | |
521 | self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
521 | self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
522 | self.isConfig = True |
|
522 | self.isConfig = True | |
523 |
|
523 | |||
524 | if dataOut.flagDataAsBlock: |
|
524 | if dataOut.flagDataAsBlock: | |
525 | """ |
|
525 | """ | |
526 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
526 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
527 | """ |
|
527 | """ | |
528 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
528 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
529 | dataOut.nProfiles /= self.n |
|
529 | dataOut.nProfiles /= self.n | |
530 | else: |
|
530 | else: | |
531 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
531 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
532 |
|
532 | |||
533 | # dataOut.timeInterval *= n |
|
533 | # dataOut.timeInterval *= n | |
534 | dataOut.flagNoData = True |
|
534 | dataOut.flagNoData = True | |
535 |
|
535 | |||
536 | if self.__dataReady: |
|
536 | if self.__dataReady: | |
537 | dataOut.data = avgdata |
|
537 | dataOut.data = avgdata | |
538 | dataOut.nCohInt *= self.n |
|
538 | dataOut.nCohInt *= self.n | |
539 | dataOut.utctime = avgdatatime |
|
539 | dataOut.utctime = avgdatatime | |
540 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
540 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
541 | dataOut.flagNoData = False |
|
541 | dataOut.flagNoData = False | |
542 |
|
542 | |||
543 | class Decoder(Operation): |
|
543 | class Decoder(Operation): | |
544 |
|
544 | |||
545 | isConfig = False |
|
545 | isConfig = False | |
546 | __profIndex = 0 |
|
546 | __profIndex = 0 | |
547 |
|
547 | |||
548 | code = None |
|
548 | code = None | |
549 |
|
549 | |||
550 | nCode = None |
|
550 | nCode = None | |
551 | nBaud = None |
|
551 | nBaud = None | |
552 |
|
552 | |||
553 |
|
553 | |||
554 | def __init__(self, **kwargs): |
|
554 | def __init__(self, **kwargs): | |
555 |
|
555 | |||
556 | Operation.__init__(self, **kwargs) |
|
556 | Operation.__init__(self, **kwargs) | |
557 |
|
557 | |||
558 | self.times = None |
|
558 | self.times = None | |
559 | self.osamp = None |
|
559 | self.osamp = None | |
560 | # self.__setValues = False |
|
560 | # self.__setValues = False | |
561 | self.isConfig = False |
|
561 | self.isConfig = False | |
562 |
|
562 | |||
563 | def setup(self, code, osamp, dataOut): |
|
563 | def setup(self, code, osamp, dataOut): | |
564 |
|
564 | |||
565 | self.__profIndex = 0 |
|
565 | self.__profIndex = 0 | |
566 |
|
566 | |||
567 | self.code = code |
|
567 | self.code = code | |
568 |
|
568 | |||
569 | self.nCode = len(code) |
|
569 | self.nCode = len(code) | |
570 | self.nBaud = len(code[0]) |
|
570 | self.nBaud = len(code[0]) | |
571 |
|
571 | |||
572 | if (osamp != None) and (osamp >1): |
|
572 | if (osamp != None) and (osamp >1): | |
573 | self.osamp = osamp |
|
573 | self.osamp = osamp | |
574 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
574 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
575 | self.nBaud = self.nBaud*self.osamp |
|
575 | self.nBaud = self.nBaud*self.osamp | |
576 |
|
576 | |||
577 | self.__nChannels = dataOut.nChannels |
|
577 | self.__nChannels = dataOut.nChannels | |
578 | self.__nProfiles = dataOut.nProfiles |
|
578 | self.__nProfiles = dataOut.nProfiles | |
579 | self.__nHeis = dataOut.nHeights |
|
579 | self.__nHeis = dataOut.nHeights | |
580 |
|
580 | |||
581 | if self.__nHeis < self.nBaud: |
|
581 | if self.__nHeis < self.nBaud: | |
582 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) |
|
582 | raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud) | |
583 |
|
583 | |||
584 | #Frequency |
|
584 | #Frequency | |
585 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
585 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
586 |
|
586 | |||
587 | __codeBuffer[:,0:self.nBaud] = self.code |
|
587 | __codeBuffer[:,0:self.nBaud] = self.code | |
588 |
|
588 | |||
589 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
589 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
590 |
|
590 | |||
591 | if dataOut.flagDataAsBlock: |
|
591 | if dataOut.flagDataAsBlock: | |
592 |
|
592 | |||
593 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
593 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
594 |
|
594 | |||
595 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
595 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
596 |
|
596 | |||
597 | else: |
|
597 | else: | |
598 |
|
598 | |||
599 | #Time |
|
599 | #Time | |
600 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
600 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
601 |
|
601 | |||
602 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
602 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
603 |
|
603 | |||
604 | def __convolutionInFreq(self, data): |
|
604 | def __convolutionInFreq(self, data): | |
605 |
|
605 | |||
606 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
606 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
607 |
|
607 | |||
608 | fft_data = numpy.fft.fft(data, axis=1) |
|
608 | fft_data = numpy.fft.fft(data, axis=1) | |
609 |
|
609 | |||
610 | conv = fft_data*fft_code |
|
610 | conv = fft_data*fft_code | |
611 |
|
611 | |||
612 | data = numpy.fft.ifft(conv,axis=1) |
|
612 | data = numpy.fft.ifft(conv,axis=1) | |
613 |
|
613 | |||
614 | return data |
|
614 | return data | |
615 |
|
615 | |||
616 | def __convolutionInFreqOpt(self, data): |
|
616 | def __convolutionInFreqOpt(self, data): | |
617 |
|
617 | |||
618 | raise NotImplementedError |
|
618 | raise NotImplementedError | |
619 |
|
619 | |||
620 | def __convolutionInTime(self, data): |
|
620 | def __convolutionInTime(self, data): | |
621 |
|
621 | |||
622 | code = self.code[self.__profIndex] |
|
622 | code = self.code[self.__profIndex] | |
623 |
|
623 | |||
624 | for i in range(self.__nChannels): |
|
624 | for i in range(self.__nChannels): | |
625 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
625 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
626 |
|
626 | |||
627 | return self.datadecTime |
|
627 | return self.datadecTime | |
628 |
|
628 | |||
629 | #@profile |
|
629 | #@profile | |
630 | def oldCorrelate(self, i, data, code_block): |
|
630 | def oldCorrelate(self, i, data, code_block): | |
631 | profilesList = xrange(self.__nProfiles) |
|
631 | profilesList = xrange(self.__nProfiles) | |
632 | for j in profilesList: |
|
632 | for j in profilesList: | |
633 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
633 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
634 |
|
634 | |||
635 | @profile |
|
635 | #@profile | |
636 | def __convolutionByBlockInTime(self, data): |
|
636 | def __convolutionByBlockInTime(self, data): | |
637 |
|
637 | |||
638 | repetitions = self.__nProfiles / self.nCode |
|
638 | repetitions = self.__nProfiles / self.nCode | |
639 |
|
639 | |||
640 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
640 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
641 | junk = junk.flatten() |
|
641 | junk = junk.flatten() | |
642 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
642 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
643 |
|
643 | profilesList = xrange(self.__nProfiles) | ||
644 |
|
644 | |||
645 | # def toVectorize(a,b): |
|
645 | # def toVectorize(a,b): | |
646 | # return numpy.correlate(a,b, mode='full') |
|
646 | # return numpy.correlate(a,b, mode='full') | |
647 | # vectorized = numpy.vectorize(toVectorize, signature='(n),(m)->(k)') |
|
647 | # vectorized = numpy.vectorize(toVectorize, signature='(n),(m)->(k)') | |
648 | a = time() |
|
|||
649 | for i in range(self.__nChannels): |
|
648 | for i in range(self.__nChannels): | |
650 | # self.datadecTime[i,:,:] = numpy.array([numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] for j in profilesList ]) |
|
649 | # self.datadecTime[i,:,:] = numpy.array([numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] for j in profilesList ]) | |
651 | # def func(i, j): |
|
650 | # def func(i, j): | |
652 | # self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
651 | # self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
653 | # map(lambda j: func(i, j), range(self.__nProfiles)) |
|
652 | # map(lambda j: func(i, j), range(self.__nProfiles)) | |
654 | #print data[i,:,:].shape |
|
653 | #print data[i,:,:].shape | |
655 | # self.datadecTime[i,:,:] = vectorized(data[i,:,:], code_block[:,:])[:,self.nBaud-1:] |
|
654 | # self.datadecTime[i,:,:] = vectorized(data[i,:,:], code_block[:,:])[:,self.nBaud-1:] | |
656 | self.oldCorrelate(i, data, code_block) |
|
655 | for j in profilesList: | |
657 | print self.datadecTime[i,:,:] |
|
656 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
658 | # print data[i,:,:] |
|
657 | # print data[i,:,:] | |
659 | # print cSchain.correlateByBlock(data[i,:,:], code_block, 2) |
|
658 | # print cSchain.correlateByBlock(data[i,:,:], code_block, 2) | |
660 | self.datadecTime[i,:,:] = cSchain.correlateByBlock(data[i,:,:], code_block, 2) |
|
659 | # self.datadecTime[i,:,:] = cSchain.correlateByBlock(data[i,:,:], code_block, 2) | |
661 | print self.datadecTime[i,:,:] |
|
660 | # print self.datadecTime[i,:,:] | |
662 | #print self.datadecTime[i,:,:].shape |
|
661 | #print self.datadecTime[i,:,:].shape | |
663 | print time() - a |
|
|||
664 | return self.datadecTime |
|
662 | return self.datadecTime | |
665 |
|
663 | |||
666 |
|
664 | |||
667 | def __convolutionByBlockInFreq(self, data): |
|
665 | def __convolutionByBlockInFreq(self, data): | |
668 |
|
666 | |||
669 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" |
|
667 | raise NotImplementedError, "Decoder by frequency fro Blocks not implemented" | |
670 |
|
668 | |||
671 |
|
669 | |||
672 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
670 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
673 |
|
671 | |||
674 | fft_data = numpy.fft.fft(data, axis=2) |
|
672 | fft_data = numpy.fft.fft(data, axis=2) | |
675 |
|
673 | |||
676 | conv = fft_data*fft_code |
|
674 | conv = fft_data*fft_code | |
677 |
|
675 | |||
678 | data = numpy.fft.ifft(conv,axis=2) |
|
676 | data = numpy.fft.ifft(conv,axis=2) | |
679 |
|
677 | |||
680 | return data |
|
678 | return data | |
681 |
|
679 | |||
682 |
|
680 | |||
683 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
681 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
684 |
|
682 | |||
685 | if dataOut.flagDecodeData: |
|
683 | if dataOut.flagDecodeData: | |
686 | print "This data is already decoded, recoding again ..." |
|
684 | print "This data is already decoded, recoding again ..." | |
687 |
|
685 | |||
688 | if not self.isConfig: |
|
686 | if not self.isConfig: | |
689 |
|
687 | |||
690 | if code is None: |
|
688 | if code is None: | |
691 | if dataOut.code is None: |
|
689 | if dataOut.code is None: | |
692 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type |
|
690 | raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type | |
693 |
|
691 | |||
694 | code = dataOut.code |
|
692 | code = dataOut.code | |
695 | else: |
|
693 | else: | |
696 | code = numpy.array(code).reshape(nCode,nBaud) |
|
694 | code = numpy.array(code).reshape(nCode,nBaud) | |
697 |
|
695 | |||
698 | self.setup(code, osamp, dataOut) |
|
696 | self.setup(code, osamp, dataOut) | |
699 |
|
697 | |||
700 | self.isConfig = True |
|
698 | self.isConfig = True | |
701 |
|
699 | |||
702 | if mode == 3: |
|
700 | if mode == 3: | |
703 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
701 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
704 |
|
702 | |||
705 | if times != None: |
|
703 | if times != None: | |
706 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
704 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
707 |
|
705 | |||
708 | if self.code is None: |
|
706 | if self.code is None: | |
709 | print "Fail decoding: Code is not defined." |
|
707 | print "Fail decoding: Code is not defined." | |
710 | return |
|
708 | return | |
711 |
|
709 | |||
712 | self.__nProfiles = dataOut.nProfiles |
|
710 | self.__nProfiles = dataOut.nProfiles | |
713 | datadec = None |
|
711 | datadec = None | |
714 |
|
712 | |||
715 | if mode == 3: |
|
713 | if mode == 3: | |
716 | mode = 0 |
|
714 | mode = 0 | |
717 |
|
715 | |||
718 | if dataOut.flagDataAsBlock: |
|
716 | if dataOut.flagDataAsBlock: | |
719 | """ |
|
717 | """ | |
720 | Decoding when data have been read as block, |
|
718 | Decoding when data have been read as block, | |
721 | """ |
|
719 | """ | |
722 |
|
720 | |||
723 | if mode == 0: |
|
721 | if mode == 0: | |
724 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
722 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
725 | if mode == 1: |
|
723 | if mode == 1: | |
726 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
724 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
727 | else: |
|
725 | else: | |
728 | """ |
|
726 | """ | |
729 | Decoding when data have been read profile by profile |
|
727 | Decoding when data have been read profile by profile | |
730 | """ |
|
728 | """ | |
731 | if mode == 0: |
|
729 | if mode == 0: | |
732 | datadec = self.__convolutionInTime(dataOut.data) |
|
730 | datadec = self.__convolutionInTime(dataOut.data) | |
733 |
|
731 | |||
734 | if mode == 1: |
|
732 | if mode == 1: | |
735 | datadec = self.__convolutionInFreq(dataOut.data) |
|
733 | datadec = self.__convolutionInFreq(dataOut.data) | |
736 |
|
734 | |||
737 | if mode == 2: |
|
735 | if mode == 2: | |
738 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
736 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
739 |
|
737 | |||
740 | if datadec is None: |
|
738 | if datadec is None: | |
741 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode |
|
739 | raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode | |
742 |
|
740 | |||
743 | dataOut.code = self.code |
|
741 | dataOut.code = self.code | |
744 | dataOut.nCode = self.nCode |
|
742 | dataOut.nCode = self.nCode | |
745 | dataOut.nBaud = self.nBaud |
|
743 | dataOut.nBaud = self.nBaud | |
746 |
|
744 | |||
747 | dataOut.data = datadec |
|
745 | dataOut.data = datadec | |
748 |
|
746 | |||
749 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
747 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
750 |
|
748 | |||
751 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
749 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
752 |
|
750 | |||
753 | if self.__profIndex == self.nCode-1: |
|
751 | if self.__profIndex == self.nCode-1: | |
754 | self.__profIndex = 0 |
|
752 | self.__profIndex = 0 | |
755 | return 1 |
|
753 | return 1 | |
756 |
|
754 | |||
757 | self.__profIndex += 1 |
|
755 | self.__profIndex += 1 | |
758 |
|
756 | |||
759 | return 1 |
|
757 | return 1 | |
760 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
758 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
761 |
|
759 | |||
762 |
|
760 | |||
763 | class ProfileConcat(Operation): |
|
761 | class ProfileConcat(Operation): | |
764 |
|
762 | |||
765 | isConfig = False |
|
763 | isConfig = False | |
766 | buffer = None |
|
764 | buffer = None | |
767 |
|
765 | |||
768 | def __init__(self, **kwargs): |
|
766 | def __init__(self, **kwargs): | |
769 |
|
767 | |||
770 | Operation.__init__(self, **kwargs) |
|
768 | Operation.__init__(self, **kwargs) | |
771 | self.profileIndex = 0 |
|
769 | self.profileIndex = 0 | |
772 |
|
770 | |||
773 | def reset(self): |
|
771 | def reset(self): | |
774 | self.buffer = numpy.zeros_like(self.buffer) |
|
772 | self.buffer = numpy.zeros_like(self.buffer) | |
775 | self.start_index = 0 |
|
773 | self.start_index = 0 | |
776 | self.times = 1 |
|
774 | self.times = 1 | |
777 |
|
775 | |||
778 | def setup(self, data, m, n=1): |
|
776 | def setup(self, data, m, n=1): | |
779 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
777 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
780 | self.nHeights = data.shape[1]#.nHeights |
|
778 | self.nHeights = data.shape[1]#.nHeights | |
781 | self.start_index = 0 |
|
779 | self.start_index = 0 | |
782 | self.times = 1 |
|
780 | self.times = 1 | |
783 |
|
781 | |||
784 | def concat(self, data): |
|
782 | def concat(self, data): | |
785 |
|
783 | |||
786 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
784 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
787 | self.start_index = self.start_index + self.nHeights |
|
785 | self.start_index = self.start_index + self.nHeights | |
788 |
|
786 | |||
789 | def run(self, dataOut, m): |
|
787 | def run(self, dataOut, m): | |
790 |
|
788 | |||
791 | dataOut.flagNoData = True |
|
789 | dataOut.flagNoData = True | |
792 |
|
790 | |||
793 | if not self.isConfig: |
|
791 | if not self.isConfig: | |
794 | self.setup(dataOut.data, m, 1) |
|
792 | self.setup(dataOut.data, m, 1) | |
795 | self.isConfig = True |
|
793 | self.isConfig = True | |
796 |
|
794 | |||
797 | if dataOut.flagDataAsBlock: |
|
795 | if dataOut.flagDataAsBlock: | |
798 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" |
|
796 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" | |
799 |
|
797 | |||
800 | else: |
|
798 | else: | |
801 | self.concat(dataOut.data) |
|
799 | self.concat(dataOut.data) | |
802 | self.times += 1 |
|
800 | self.times += 1 | |
803 | if self.times > m: |
|
801 | if self.times > m: | |
804 | dataOut.data = self.buffer |
|
802 | dataOut.data = self.buffer | |
805 | self.reset() |
|
803 | self.reset() | |
806 | dataOut.flagNoData = False |
|
804 | dataOut.flagNoData = False | |
807 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
805 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
808 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
806 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
809 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
807 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
810 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
808 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
811 | dataOut.ippSeconds *= m |
|
809 | dataOut.ippSeconds *= m | |
812 |
|
810 | |||
813 | class ProfileSelector(Operation): |
|
811 | class ProfileSelector(Operation): | |
814 |
|
812 | |||
815 | profileIndex = None |
|
813 | profileIndex = None | |
816 | # Tamanho total de los perfiles |
|
814 | # Tamanho total de los perfiles | |
817 | nProfiles = None |
|
815 | nProfiles = None | |
818 |
|
816 | |||
819 | def __init__(self, **kwargs): |
|
817 | def __init__(self, **kwargs): | |
820 |
|
818 | |||
821 | Operation.__init__(self, **kwargs) |
|
819 | Operation.__init__(self, **kwargs) | |
822 | self.profileIndex = 0 |
|
820 | self.profileIndex = 0 | |
823 |
|
821 | |||
824 | def incProfileIndex(self): |
|
822 | def incProfileIndex(self): | |
825 |
|
823 | |||
826 | self.profileIndex += 1 |
|
824 | self.profileIndex += 1 | |
827 |
|
825 | |||
828 | if self.profileIndex >= self.nProfiles: |
|
826 | if self.profileIndex >= self.nProfiles: | |
829 | self.profileIndex = 0 |
|
827 | self.profileIndex = 0 | |
830 |
|
828 | |||
831 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
829 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
832 |
|
830 | |||
833 | if profileIndex < minIndex: |
|
831 | if profileIndex < minIndex: | |
834 | return False |
|
832 | return False | |
835 |
|
833 | |||
836 | if profileIndex > maxIndex: |
|
834 | if profileIndex > maxIndex: | |
837 | return False |
|
835 | return False | |
838 |
|
836 | |||
839 | return True |
|
837 | return True | |
840 |
|
838 | |||
841 | def isThisProfileInList(self, profileIndex, profileList): |
|
839 | def isThisProfileInList(self, profileIndex, profileList): | |
842 |
|
840 | |||
843 | if profileIndex not in profileList: |
|
841 | if profileIndex not in profileList: | |
844 | return False |
|
842 | return False | |
845 |
|
843 | |||
846 | return True |
|
844 | return True | |
847 |
|
845 | |||
848 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
846 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
849 |
|
847 | |||
850 | """ |
|
848 | """ | |
851 | ProfileSelector: |
|
849 | ProfileSelector: | |
852 |
|
850 | |||
853 | Inputs: |
|
851 | Inputs: | |
854 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
852 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
855 |
|
853 | |||
856 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
854 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
857 |
|
855 | |||
858 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
856 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
859 |
|
857 | |||
860 | """ |
|
858 | """ | |
861 |
|
859 | |||
862 | if rangeList is not None: |
|
860 | if rangeList is not None: | |
863 | if type(rangeList[0]) not in (tuple, list): |
|
861 | if type(rangeList[0]) not in (tuple, list): | |
864 | rangeList = [rangeList] |
|
862 | rangeList = [rangeList] | |
865 |
|
863 | |||
866 | dataOut.flagNoData = True |
|
864 | dataOut.flagNoData = True | |
867 |
|
865 | |||
868 | if dataOut.flagDataAsBlock: |
|
866 | if dataOut.flagDataAsBlock: | |
869 | """ |
|
867 | """ | |
870 | data dimension = [nChannels, nProfiles, nHeis] |
|
868 | data dimension = [nChannels, nProfiles, nHeis] | |
871 | """ |
|
869 | """ | |
872 | if profileList != None: |
|
870 | if profileList != None: | |
873 | dataOut.data = dataOut.data[:,profileList,:] |
|
871 | dataOut.data = dataOut.data[:,profileList,:] | |
874 |
|
872 | |||
875 | if profileRangeList != None: |
|
873 | if profileRangeList != None: | |
876 | minIndex = profileRangeList[0] |
|
874 | minIndex = profileRangeList[0] | |
877 | maxIndex = profileRangeList[1] |
|
875 | maxIndex = profileRangeList[1] | |
878 | profileList = range(minIndex, maxIndex+1) |
|
876 | profileList = range(minIndex, maxIndex+1) | |
879 |
|
877 | |||
880 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
878 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
881 |
|
879 | |||
882 | if rangeList != None: |
|
880 | if rangeList != None: | |
883 |
|
881 | |||
884 | profileList = [] |
|
882 | profileList = [] | |
885 |
|
883 | |||
886 | for thisRange in rangeList: |
|
884 | for thisRange in rangeList: | |
887 | minIndex = thisRange[0] |
|
885 | minIndex = thisRange[0] | |
888 | maxIndex = thisRange[1] |
|
886 | maxIndex = thisRange[1] | |
889 |
|
887 | |||
890 | profileList.extend(range(minIndex, maxIndex+1)) |
|
888 | profileList.extend(range(minIndex, maxIndex+1)) | |
891 |
|
889 | |||
892 | dataOut.data = dataOut.data[:,profileList,:] |
|
890 | dataOut.data = dataOut.data[:,profileList,:] | |
893 |
|
891 | |||
894 | dataOut.nProfiles = len(profileList) |
|
892 | dataOut.nProfiles = len(profileList) | |
895 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
893 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
896 | dataOut.flagNoData = False |
|
894 | dataOut.flagNoData = False | |
897 |
|
895 | |||
898 | return True |
|
896 | return True | |
899 |
|
897 | |||
900 | """ |
|
898 | """ | |
901 | data dimension = [nChannels, nHeis] |
|
899 | data dimension = [nChannels, nHeis] | |
902 | """ |
|
900 | """ | |
903 |
|
901 | |||
904 | if profileList != None: |
|
902 | if profileList != None: | |
905 |
|
903 | |||
906 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
904 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
907 |
|
905 | |||
908 | self.nProfiles = len(profileList) |
|
906 | self.nProfiles = len(profileList) | |
909 | dataOut.nProfiles = self.nProfiles |
|
907 | dataOut.nProfiles = self.nProfiles | |
910 | dataOut.profileIndex = self.profileIndex |
|
908 | dataOut.profileIndex = self.profileIndex | |
911 | dataOut.flagNoData = False |
|
909 | dataOut.flagNoData = False | |
912 |
|
910 | |||
913 | self.incProfileIndex() |
|
911 | self.incProfileIndex() | |
914 | return True |
|
912 | return True | |
915 |
|
913 | |||
916 | if profileRangeList != None: |
|
914 | if profileRangeList != None: | |
917 |
|
915 | |||
918 | minIndex = profileRangeList[0] |
|
916 | minIndex = profileRangeList[0] | |
919 | maxIndex = profileRangeList[1] |
|
917 | maxIndex = profileRangeList[1] | |
920 |
|
918 | |||
921 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
919 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
922 |
|
920 | |||
923 | self.nProfiles = maxIndex - minIndex + 1 |
|
921 | self.nProfiles = maxIndex - minIndex + 1 | |
924 | dataOut.nProfiles = self.nProfiles |
|
922 | dataOut.nProfiles = self.nProfiles | |
925 | dataOut.profileIndex = self.profileIndex |
|
923 | dataOut.profileIndex = self.profileIndex | |
926 | dataOut.flagNoData = False |
|
924 | dataOut.flagNoData = False | |
927 |
|
925 | |||
928 | self.incProfileIndex() |
|
926 | self.incProfileIndex() | |
929 | return True |
|
927 | return True | |
930 |
|
928 | |||
931 | if rangeList != None: |
|
929 | if rangeList != None: | |
932 |
|
930 | |||
933 | nProfiles = 0 |
|
931 | nProfiles = 0 | |
934 |
|
932 | |||
935 | for thisRange in rangeList: |
|
933 | for thisRange in rangeList: | |
936 | minIndex = thisRange[0] |
|
934 | minIndex = thisRange[0] | |
937 | maxIndex = thisRange[1] |
|
935 | maxIndex = thisRange[1] | |
938 |
|
936 | |||
939 | nProfiles += maxIndex - minIndex + 1 |
|
937 | nProfiles += maxIndex - minIndex + 1 | |
940 |
|
938 | |||
941 | for thisRange in rangeList: |
|
939 | for thisRange in rangeList: | |
942 |
|
940 | |||
943 | minIndex = thisRange[0] |
|
941 | minIndex = thisRange[0] | |
944 | maxIndex = thisRange[1] |
|
942 | maxIndex = thisRange[1] | |
945 |
|
943 | |||
946 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
944 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
947 |
|
945 | |||
948 | self.nProfiles = nProfiles |
|
946 | self.nProfiles = nProfiles | |
949 | dataOut.nProfiles = self.nProfiles |
|
947 | dataOut.nProfiles = self.nProfiles | |
950 | dataOut.profileIndex = self.profileIndex |
|
948 | dataOut.profileIndex = self.profileIndex | |
951 | dataOut.flagNoData = False |
|
949 | dataOut.flagNoData = False | |
952 |
|
950 | |||
953 | self.incProfileIndex() |
|
951 | self.incProfileIndex() | |
954 |
|
952 | |||
955 | break |
|
953 | break | |
956 |
|
954 | |||
957 | return True |
|
955 | return True | |
958 |
|
956 | |||
959 |
|
957 | |||
960 | if beam != None: #beam is only for AMISR data |
|
958 | if beam != None: #beam is only for AMISR data | |
961 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
959 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
962 | dataOut.flagNoData = False |
|
960 | dataOut.flagNoData = False | |
963 | dataOut.profileIndex = self.profileIndex |
|
961 | dataOut.profileIndex = self.profileIndex | |
964 |
|
962 | |||
965 | self.incProfileIndex() |
|
963 | self.incProfileIndex() | |
966 |
|
964 | |||
967 | return True |
|
965 | return True | |
968 |
|
966 | |||
969 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" |
|
967 | raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter" | |
970 |
|
968 | |||
971 | return False |
|
969 | return False | |
972 |
|
970 | |||
973 | class Reshaper(Operation): |
|
971 | class Reshaper(Operation): | |
974 |
|
972 | |||
975 | def __init__(self, **kwargs): |
|
973 | def __init__(self, **kwargs): | |
976 |
|
974 | |||
977 | Operation.__init__(self, **kwargs) |
|
975 | Operation.__init__(self, **kwargs) | |
978 |
|
976 | |||
979 | self.__buffer = None |
|
977 | self.__buffer = None | |
980 | self.__nitems = 0 |
|
978 | self.__nitems = 0 | |
981 |
|
979 | |||
982 | def __appendProfile(self, dataOut, nTxs): |
|
980 | def __appendProfile(self, dataOut, nTxs): | |
983 |
|
981 | |||
984 | if self.__buffer is None: |
|
982 | if self.__buffer is None: | |
985 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
983 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
986 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
984 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
987 |
|
985 | |||
988 | ini = dataOut.nHeights * self.__nitems |
|
986 | ini = dataOut.nHeights * self.__nitems | |
989 | end = ini + dataOut.nHeights |
|
987 | end = ini + dataOut.nHeights | |
990 |
|
988 | |||
991 | self.__buffer[:, ini:end] = dataOut.data |
|
989 | self.__buffer[:, ini:end] = dataOut.data | |
992 |
|
990 | |||
993 | self.__nitems += 1 |
|
991 | self.__nitems += 1 | |
994 |
|
992 | |||
995 | return int(self.__nitems*nTxs) |
|
993 | return int(self.__nitems*nTxs) | |
996 |
|
994 | |||
997 | def __getBuffer(self): |
|
995 | def __getBuffer(self): | |
998 |
|
996 | |||
999 | if self.__nitems == int(1./self.__nTxs): |
|
997 | if self.__nitems == int(1./self.__nTxs): | |
1000 |
|
998 | |||
1001 | self.__nitems = 0 |
|
999 | self.__nitems = 0 | |
1002 |
|
1000 | |||
1003 | return self.__buffer.copy() |
|
1001 | return self.__buffer.copy() | |
1004 |
|
1002 | |||
1005 | return None |
|
1003 | return None | |
1006 |
|
1004 | |||
1007 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1005 | def __checkInputs(self, dataOut, shape, nTxs): | |
1008 |
|
1006 | |||
1009 | if shape is None and nTxs is None: |
|
1007 | if shape is None and nTxs is None: | |
1010 | raise ValueError, "Reshaper: shape of factor should be defined" |
|
1008 | raise ValueError, "Reshaper: shape of factor should be defined" | |
1011 |
|
1009 | |||
1012 | if nTxs: |
|
1010 | if nTxs: | |
1013 | if nTxs < 0: |
|
1011 | if nTxs < 0: | |
1014 | raise ValueError, "nTxs should be greater than 0" |
|
1012 | raise ValueError, "nTxs should be greater than 0" | |
1015 |
|
1013 | |||
1016 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1014 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1017 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) |
|
1015 | raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)) | |
1018 |
|
1016 | |||
1019 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1017 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1020 |
|
1018 | |||
1021 | return shape, nTxs |
|
1019 | return shape, nTxs | |
1022 |
|
1020 | |||
1023 | if len(shape) != 2 and len(shape) != 3: |
|
1021 | if len(shape) != 2 and len(shape) != 3: | |
1024 | 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) |
|
1022 | 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) | |
1025 |
|
1023 | |||
1026 | if len(shape) == 2: |
|
1024 | if len(shape) == 2: | |
1027 | shape_tuple = [dataOut.nChannels] |
|
1025 | shape_tuple = [dataOut.nChannels] | |
1028 | shape_tuple.extend(shape) |
|
1026 | shape_tuple.extend(shape) | |
1029 | else: |
|
1027 | else: | |
1030 | shape_tuple = list(shape) |
|
1028 | shape_tuple = list(shape) | |
1031 |
|
1029 | |||
1032 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1030 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1033 |
|
1031 | |||
1034 | return shape_tuple, nTxs |
|
1032 | return shape_tuple, nTxs | |
1035 |
|
1033 | |||
1036 | def run(self, dataOut, shape=None, nTxs=None): |
|
1034 | def run(self, dataOut, shape=None, nTxs=None): | |
1037 |
|
1035 | |||
1038 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1036 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1039 |
|
1037 | |||
1040 | dataOut.flagNoData = True |
|
1038 | dataOut.flagNoData = True | |
1041 | profileIndex = None |
|
1039 | profileIndex = None | |
1042 |
|
1040 | |||
1043 | if dataOut.flagDataAsBlock: |
|
1041 | if dataOut.flagDataAsBlock: | |
1044 |
|
1042 | |||
1045 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1043 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1046 | dataOut.flagNoData = False |
|
1044 | dataOut.flagNoData = False | |
1047 |
|
1045 | |||
1048 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1046 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1049 |
|
1047 | |||
1050 | else: |
|
1048 | else: | |
1051 |
|
1049 | |||
1052 | if self.__nTxs < 1: |
|
1050 | if self.__nTxs < 1: | |
1053 |
|
1051 | |||
1054 | self.__appendProfile(dataOut, self.__nTxs) |
|
1052 | self.__appendProfile(dataOut, self.__nTxs) | |
1055 | new_data = self.__getBuffer() |
|
1053 | new_data = self.__getBuffer() | |
1056 |
|
1054 | |||
1057 | if new_data is not None: |
|
1055 | if new_data is not None: | |
1058 | dataOut.data = new_data |
|
1056 | dataOut.data = new_data | |
1059 | dataOut.flagNoData = False |
|
1057 | dataOut.flagNoData = False | |
1060 |
|
1058 | |||
1061 | profileIndex = dataOut.profileIndex*nTxs |
|
1059 | profileIndex = dataOut.profileIndex*nTxs | |
1062 |
|
1060 | |||
1063 | else: |
|
1061 | else: | |
1064 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" |
|
1062 | raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)" | |
1065 |
|
1063 | |||
1066 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1064 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1067 |
|
1065 | |||
1068 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1066 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1069 |
|
1067 | |||
1070 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1068 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1071 |
|
1069 | |||
1072 | dataOut.profileIndex = profileIndex |
|
1070 | dataOut.profileIndex = profileIndex | |
1073 |
|
1071 | |||
1074 | dataOut.ippSeconds /= self.__nTxs |
|
1072 | dataOut.ippSeconds /= self.__nTxs | |
1075 |
|
1073 | |||
1076 | class SplitProfiles(Operation): |
|
1074 | class SplitProfiles(Operation): | |
1077 |
|
1075 | |||
1078 | def __init__(self, **kwargs): |
|
1076 | def __init__(self, **kwargs): | |
1079 |
|
1077 | |||
1080 | Operation.__init__(self, **kwargs) |
|
1078 | Operation.__init__(self, **kwargs) | |
1081 |
|
1079 | |||
1082 | def run(self, dataOut, n): |
|
1080 | def run(self, dataOut, n): | |
1083 |
|
1081 | |||
1084 | dataOut.flagNoData = True |
|
1082 | dataOut.flagNoData = True | |
1085 | profileIndex = None |
|
1083 | profileIndex = None | |
1086 |
|
1084 | |||
1087 | if dataOut.flagDataAsBlock: |
|
1085 | if dataOut.flagDataAsBlock: | |
1088 |
|
1086 | |||
1089 | #nchannels, nprofiles, nsamples |
|
1087 | #nchannels, nprofiles, nsamples | |
1090 | shape = dataOut.data.shape |
|
1088 | shape = dataOut.data.shape | |
1091 |
|
1089 | |||
1092 | if shape[2] % n != 0: |
|
1090 | if shape[2] % n != 0: | |
1093 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) |
|
1091 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]) | |
1094 |
|
1092 | |||
1095 | new_shape = shape[0], shape[1]*n, shape[2]/n |
|
1093 | new_shape = shape[0], shape[1]*n, shape[2]/n | |
1096 |
|
1094 | |||
1097 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1095 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1098 | dataOut.flagNoData = False |
|
1096 | dataOut.flagNoData = False | |
1099 |
|
1097 | |||
1100 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1098 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1101 |
|
1099 | |||
1102 | else: |
|
1100 | else: | |
1103 |
|
1101 | |||
1104 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" |
|
1102 | raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)" | |
1105 |
|
1103 | |||
1106 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1104 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1107 |
|
1105 | |||
1108 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1106 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1109 |
|
1107 | |||
1110 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1108 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1111 |
|
1109 | |||
1112 | dataOut.profileIndex = profileIndex |
|
1110 | dataOut.profileIndex = profileIndex | |
1113 |
|
1111 | |||
1114 | dataOut.ippSeconds /= n |
|
1112 | dataOut.ippSeconds /= n | |
1115 |
|
1113 | |||
1116 | class CombineProfiles(Operation): |
|
1114 | class CombineProfiles(Operation): | |
1117 |
|
1115 | |||
1118 | def __init__(self, **kwargs): |
|
1116 | def __init__(self, **kwargs): | |
1119 |
|
1117 | |||
1120 | Operation.__init__(self, **kwargs) |
|
1118 | Operation.__init__(self, **kwargs) | |
1121 |
|
1119 | |||
1122 | self.__remData = None |
|
1120 | self.__remData = None | |
1123 | self.__profileIndex = 0 |
|
1121 | self.__profileIndex = 0 | |
1124 |
|
1122 | |||
1125 | def run(self, dataOut, n): |
|
1123 | def run(self, dataOut, n): | |
1126 |
|
1124 | |||
1127 | dataOut.flagNoData = True |
|
1125 | dataOut.flagNoData = True | |
1128 | profileIndex = None |
|
1126 | profileIndex = None | |
1129 |
|
1127 | |||
1130 | if dataOut.flagDataAsBlock: |
|
1128 | if dataOut.flagDataAsBlock: | |
1131 |
|
1129 | |||
1132 | #nchannels, nprofiles, nsamples |
|
1130 | #nchannels, nprofiles, nsamples | |
1133 | shape = dataOut.data.shape |
|
1131 | shape = dataOut.data.shape | |
1134 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1132 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1135 |
|
1133 | |||
1136 | if shape[1] % n != 0: |
|
1134 | if shape[1] % n != 0: | |
1137 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) |
|
1135 | raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]) | |
1138 |
|
1136 | |||
1139 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1137 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1140 | dataOut.flagNoData = False |
|
1138 | dataOut.flagNoData = False | |
1141 |
|
1139 | |||
1142 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1140 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1143 |
|
1141 | |||
1144 | else: |
|
1142 | else: | |
1145 |
|
1143 | |||
1146 | #nchannels, nsamples |
|
1144 | #nchannels, nsamples | |
1147 | if self.__remData is None: |
|
1145 | if self.__remData is None: | |
1148 | newData = dataOut.data |
|
1146 | newData = dataOut.data | |
1149 | else: |
|
1147 | else: | |
1150 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1148 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1151 |
|
1149 | |||
1152 | self.__profileIndex += 1 |
|
1150 | self.__profileIndex += 1 | |
1153 |
|
1151 | |||
1154 | if self.__profileIndex < n: |
|
1152 | if self.__profileIndex < n: | |
1155 | self.__remData = newData |
|
1153 | self.__remData = newData | |
1156 | #continue |
|
1154 | #continue | |
1157 | return |
|
1155 | return | |
1158 |
|
1156 | |||
1159 | self.__profileIndex = 0 |
|
1157 | self.__profileIndex = 0 | |
1160 | self.__remData = None |
|
1158 | self.__remData = None | |
1161 |
|
1159 | |||
1162 | dataOut.data = newData |
|
1160 | dataOut.data = newData | |
1163 | dataOut.flagNoData = False |
|
1161 | dataOut.flagNoData = False | |
1164 |
|
1162 | |||
1165 | profileIndex = dataOut.profileIndex/n |
|
1163 | profileIndex = dataOut.profileIndex/n | |
1166 |
|
1164 | |||
1167 |
|
1165 | |||
1168 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1166 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1169 |
|
1167 | |||
1170 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1168 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1171 |
|
1169 | |||
1172 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1170 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1173 |
|
1171 | |||
1174 | dataOut.profileIndex = profileIndex |
|
1172 | dataOut.profileIndex = profileIndex | |
1175 |
|
1173 | |||
1176 | dataOut.ippSeconds *= n |
|
1174 | dataOut.ippSeconds *= n | |
1177 |
|
1175 | |||
1178 | # import collections |
|
1176 | # import collections | |
1179 | # from scipy.stats import mode |
|
1177 | # from scipy.stats import mode | |
1180 | # |
|
1178 | # | |
1181 | # class Synchronize(Operation): |
|
1179 | # class Synchronize(Operation): | |
1182 | # |
|
1180 | # | |
1183 | # isConfig = False |
|
1181 | # isConfig = False | |
1184 | # __profIndex = 0 |
|
1182 | # __profIndex = 0 | |
1185 | # |
|
1183 | # | |
1186 | # def __init__(self, **kwargs): |
|
1184 | # def __init__(self, **kwargs): | |
1187 | # |
|
1185 | # | |
1188 | # Operation.__init__(self, **kwargs) |
|
1186 | # Operation.__init__(self, **kwargs) | |
1189 | # # self.isConfig = False |
|
1187 | # # self.isConfig = False | |
1190 | # self.__powBuffer = None |
|
1188 | # self.__powBuffer = None | |
1191 | # self.__startIndex = 0 |
|
1189 | # self.__startIndex = 0 | |
1192 | # self.__pulseFound = False |
|
1190 | # self.__pulseFound = False | |
1193 | # |
|
1191 | # | |
1194 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1192 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1195 | # |
|
1193 | # | |
1196 | # #Read data |
|
1194 | # #Read data | |
1197 | # |
|
1195 | # | |
1198 | # powerdB = dataOut.getPower(channel = channel) |
|
1196 | # powerdB = dataOut.getPower(channel = channel) | |
1199 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1197 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1200 | # |
|
1198 | # | |
1201 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1199 | # self.__powBuffer.extend(powerdB.flatten()) | |
1202 | # |
|
1200 | # | |
1203 | # dataArray = numpy.array(self.__powBuffer) |
|
1201 | # dataArray = numpy.array(self.__powBuffer) | |
1204 | # |
|
1202 | # | |
1205 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1203 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1206 | # |
|
1204 | # | |
1207 | # maxValue = numpy.nanmax(filteredPower) |
|
1205 | # maxValue = numpy.nanmax(filteredPower) | |
1208 | # |
|
1206 | # | |
1209 | # if maxValue < noisedB + 10: |
|
1207 | # if maxValue < noisedB + 10: | |
1210 | # #No se encuentra ningun pulso de transmision |
|
1208 | # #No se encuentra ningun pulso de transmision | |
1211 | # return None |
|
1209 | # return None | |
1212 | # |
|
1210 | # | |
1213 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1211 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1214 | # |
|
1212 | # | |
1215 | # if len(maxValuesIndex) < 2: |
|
1213 | # if len(maxValuesIndex) < 2: | |
1216 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1214 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1217 | # return None |
|
1215 | # return None | |
1218 | # |
|
1216 | # | |
1219 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1217 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1220 | # |
|
1218 | # | |
1221 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1219 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1222 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1220 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1223 | # |
|
1221 | # | |
1224 | # if len(pulseIndex) < 2: |
|
1222 | # if len(pulseIndex) < 2: | |
1225 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1223 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1226 | # return None |
|
1224 | # return None | |
1227 | # |
|
1225 | # | |
1228 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1226 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1229 | # |
|
1227 | # | |
1230 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1228 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1231 | # #(No deberian existir IPP menor a 10 unidades) |
|
1229 | # #(No deberian existir IPP menor a 10 unidades) | |
1232 | # |
|
1230 | # | |
1233 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1231 | # realIndex = numpy.where(spacing > 10 )[0] | |
1234 | # |
|
1232 | # | |
1235 | # if len(realIndex) < 2: |
|
1233 | # if len(realIndex) < 2: | |
1236 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1234 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1237 | # return None |
|
1235 | # return None | |
1238 | # |
|
1236 | # | |
1239 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1237 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1240 | # realPulseIndex = pulseIndex[realIndex] |
|
1238 | # realPulseIndex = pulseIndex[realIndex] | |
1241 | # |
|
1239 | # | |
1242 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1240 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1243 | # |
|
1241 | # | |
1244 | # print "IPP = %d samples" %period |
|
1242 | # print "IPP = %d samples" %period | |
1245 | # |
|
1243 | # | |
1246 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1244 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1247 | # self.__startIndex = int(realPulseIndex[0]) |
|
1245 | # self.__startIndex = int(realPulseIndex[0]) | |
1248 | # |
|
1246 | # | |
1249 | # return 1 |
|
1247 | # return 1 | |
1250 | # |
|
1248 | # | |
1251 | # |
|
1249 | # | |
1252 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1250 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1253 | # |
|
1251 | # | |
1254 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1252 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1255 | # maxlen = buffer_size*nSamples) |
|
1253 | # maxlen = buffer_size*nSamples) | |
1256 | # |
|
1254 | # | |
1257 | # bufferList = [] |
|
1255 | # bufferList = [] | |
1258 | # |
|
1256 | # | |
1259 | # for i in range(nChannels): |
|
1257 | # for i in range(nChannels): | |
1260 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1258 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1261 | # maxlen = buffer_size*nSamples) |
|
1259 | # maxlen = buffer_size*nSamples) | |
1262 | # |
|
1260 | # | |
1263 | # bufferList.append(bufferByChannel) |
|
1261 | # bufferList.append(bufferByChannel) | |
1264 | # |
|
1262 | # | |
1265 | # self.__nSamples = nSamples |
|
1263 | # self.__nSamples = nSamples | |
1266 | # self.__nChannels = nChannels |
|
1264 | # self.__nChannels = nChannels | |
1267 | # self.__bufferList = bufferList |
|
1265 | # self.__bufferList = bufferList | |
1268 | # |
|
1266 | # | |
1269 | # def run(self, dataOut, channel = 0): |
|
1267 | # def run(self, dataOut, channel = 0): | |
1270 | # |
|
1268 | # | |
1271 | # if not self.isConfig: |
|
1269 | # if not self.isConfig: | |
1272 | # nSamples = dataOut.nHeights |
|
1270 | # nSamples = dataOut.nHeights | |
1273 | # nChannels = dataOut.nChannels |
|
1271 | # nChannels = dataOut.nChannels | |
1274 | # self.setup(nSamples, nChannels) |
|
1272 | # self.setup(nSamples, nChannels) | |
1275 | # self.isConfig = True |
|
1273 | # self.isConfig = True | |
1276 | # |
|
1274 | # | |
1277 | # #Append new data to internal buffer |
|
1275 | # #Append new data to internal buffer | |
1278 | # for thisChannel in range(self.__nChannels): |
|
1276 | # for thisChannel in range(self.__nChannels): | |
1279 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1277 | # bufferByChannel = self.__bufferList[thisChannel] | |
1280 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1278 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1281 | # |
|
1279 | # | |
1282 | # if self.__pulseFound: |
|
1280 | # if self.__pulseFound: | |
1283 | # self.__startIndex -= self.__nSamples |
|
1281 | # self.__startIndex -= self.__nSamples | |
1284 | # |
|
1282 | # | |
1285 | # #Finding Tx Pulse |
|
1283 | # #Finding Tx Pulse | |
1286 | # if not self.__pulseFound: |
|
1284 | # if not self.__pulseFound: | |
1287 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1285 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1288 | # |
|
1286 | # | |
1289 | # if indexFound == None: |
|
1287 | # if indexFound == None: | |
1290 | # dataOut.flagNoData = True |
|
1288 | # dataOut.flagNoData = True | |
1291 | # return |
|
1289 | # return | |
1292 | # |
|
1290 | # | |
1293 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1291 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1294 | # self.__pulseFound = True |
|
1292 | # self.__pulseFound = True | |
1295 | # self.__startIndex = indexFound |
|
1293 | # self.__startIndex = indexFound | |
1296 | # |
|
1294 | # | |
1297 | # #If pulse was found ... |
|
1295 | # #If pulse was found ... | |
1298 | # for thisChannel in range(self.__nChannels): |
|
1296 | # for thisChannel in range(self.__nChannels): | |
1299 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1297 | # bufferByChannel = self.__bufferList[thisChannel] | |
1300 | # #print self.__startIndex |
|
1298 | # #print self.__startIndex | |
1301 | # x = numpy.array(bufferByChannel) |
|
1299 | # x = numpy.array(bufferByChannel) | |
1302 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1300 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1303 | # |
|
1301 | # | |
1304 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1302 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1305 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1303 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1306 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1304 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1307 | # |
|
1305 | # | |
1308 | # dataOut.data = self.__arrayBuffer |
|
1306 | # dataOut.data = self.__arrayBuffer | |
1309 | # |
|
1307 | # | |
1310 | # self.__startIndex += self.__newNSamples |
|
1308 | # self.__startIndex += self.__newNSamples | |
1311 | # |
|
1309 | # | |
1312 | # return |
|
1310 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now