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