@@ -1,890 +1,890 | |||||
1 | import numpy |
|
1 | import numpy | |
2 |
|
2 | |||
3 | from jroproc_base import ProcessingUnit, Operation |
|
3 | from jroproc_base import ProcessingUnit, Operation | |
4 | from model.data.jrodata import Voltage |
|
4 | from model.data.jrodata import Voltage | |
5 |
|
5 | |||
6 |
|
6 | |||
7 | class VoltageProc(ProcessingUnit): |
|
7 | class VoltageProc(ProcessingUnit): | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | def __init__(self): |
|
10 | def __init__(self): | |
11 |
|
11 | |||
12 | ProcessingUnit.__init__(self) |
|
12 | ProcessingUnit.__init__(self) | |
13 |
|
13 | |||
14 | # self.objectDict = {} |
|
14 | # self.objectDict = {} | |
15 | self.dataOut = Voltage() |
|
15 | self.dataOut = Voltage() | |
16 | self.flip = 1 |
|
16 | self.flip = 1 | |
17 |
|
17 | |||
18 | def run(self): |
|
18 | def run(self): | |
19 | if self.dataIn.type == 'AMISR': |
|
19 | if self.dataIn.type == 'AMISR': | |
20 | self.__updateObjFromAmisrInput() |
|
20 | self.__updateObjFromAmisrInput() | |
21 |
|
21 | |||
22 | if self.dataIn.type == 'Voltage': |
|
22 | if self.dataIn.type == 'Voltage': | |
23 | self.dataOut.copy(self.dataIn) |
|
23 | self.dataOut.copy(self.dataIn) | |
24 |
|
24 | |||
25 | # self.dataOut.copy(self.dataIn) |
|
25 | # self.dataOut.copy(self.dataIn) | |
26 |
|
26 | |||
27 | def __updateObjFromAmisrInput(self): |
|
27 | def __updateObjFromAmisrInput(self): | |
28 |
|
28 | |||
29 | self.dataOut.timeZone = self.dataIn.timeZone |
|
29 | self.dataOut.timeZone = self.dataIn.timeZone | |
30 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
30 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
31 | self.dataOut.errorCount = self.dataIn.errorCount |
|
31 | self.dataOut.errorCount = self.dataIn.errorCount | |
32 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
32 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
33 |
|
33 | |||
34 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
34 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
35 | self.dataOut.data = self.dataIn.data |
|
35 | self.dataOut.data = self.dataIn.data | |
36 | self.dataOut.utctime = self.dataIn.utctime |
|
36 | self.dataOut.utctime = self.dataIn.utctime | |
37 | self.dataOut.channelList = self.dataIn.channelList |
|
37 | self.dataOut.channelList = self.dataIn.channelList | |
38 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
38 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
39 | self.dataOut.heightList = self.dataIn.heightList |
|
39 | self.dataOut.heightList = self.dataIn.heightList | |
40 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
40 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
41 |
|
41 | |||
42 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
42 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
43 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
43 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
44 | self.dataOut.frequency = self.dataIn.frequency |
|
44 | self.dataOut.frequency = self.dataIn.frequency | |
45 |
|
45 | |||
46 | self.dataOut.azimuth = self.dataIn.azimuth |
|
46 | self.dataOut.azimuth = self.dataIn.azimuth | |
47 | self.dataOut.zenith = self.dataIn.zenith |
|
47 | self.dataOut.zenith = self.dataIn.zenith | |
48 |
|
48 | |||
49 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
49 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
50 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
50 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
51 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
51 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
52 | # |
|
52 | # | |
53 | # pass# |
|
53 | # pass# | |
54 | # |
|
54 | # | |
55 | # def init(self): |
|
55 | # def init(self): | |
56 | # |
|
56 | # | |
57 | # |
|
57 | # | |
58 | # if self.dataIn.type == 'AMISR': |
|
58 | # if self.dataIn.type == 'AMISR': | |
59 | # self.__updateObjFromAmisrInput() |
|
59 | # self.__updateObjFromAmisrInput() | |
60 | # |
|
60 | # | |
61 | # if self.dataIn.type == 'Voltage': |
|
61 | # if self.dataIn.type == 'Voltage': | |
62 | # self.dataOut.copy(self.dataIn) |
|
62 | # self.dataOut.copy(self.dataIn) | |
63 | # # No necesita copiar en cada init() los atributos de dataIn |
|
63 | # # No necesita copiar en cada init() los atributos de dataIn | |
64 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
64 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
65 |
|
65 | |||
66 | def selectChannels(self, channelList): |
|
66 | def selectChannels(self, channelList): | |
67 |
|
67 | |||
68 | channelIndexList = [] |
|
68 | channelIndexList = [] | |
69 |
|
69 | |||
70 | for channel in channelList: |
|
70 | for channel in channelList: | |
71 | index = self.dataOut.channelList.index(channel) |
|
71 | index = self.dataOut.channelList.index(channel) | |
72 | channelIndexList.append(index) |
|
72 | channelIndexList.append(index) | |
73 |
|
73 | |||
74 | self.selectChannelsByIndex(channelIndexList) |
|
74 | self.selectChannelsByIndex(channelIndexList) | |
75 |
|
75 | |||
76 | def selectChannelsByIndex(self, channelIndexList): |
|
76 | def selectChannelsByIndex(self, channelIndexList): | |
77 | """ |
|
77 | """ | |
78 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
78 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
79 |
|
79 | |||
80 | Input: |
|
80 | Input: | |
81 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
81 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
82 |
|
82 | |||
83 | Affected: |
|
83 | Affected: | |
84 | self.dataOut.data |
|
84 | self.dataOut.data | |
85 | self.dataOut.channelIndexList |
|
85 | self.dataOut.channelIndexList | |
86 | self.dataOut.nChannels |
|
86 | self.dataOut.nChannels | |
87 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
87 | self.dataOut.m_ProcessingHeader.totalSpectra | |
88 | self.dataOut.systemHeaderObj.numChannels |
|
88 | self.dataOut.systemHeaderObj.numChannels | |
89 | self.dataOut.m_ProcessingHeader.blockSize |
|
89 | self.dataOut.m_ProcessingHeader.blockSize | |
90 |
|
90 | |||
91 | Return: |
|
91 | Return: | |
92 | None |
|
92 | None | |
93 | """ |
|
93 | """ | |
94 |
|
94 | |||
95 | for channelIndex in channelIndexList: |
|
95 | for channelIndex in channelIndexList: | |
96 | if channelIndex not in self.dataOut.channelIndexList: |
|
96 | if channelIndex not in self.dataOut.channelIndexList: | |
97 | print channelIndexList |
|
97 | print channelIndexList | |
98 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
98 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
99 |
|
99 | |||
100 | # nChannels = len(channelIndexList) |
|
100 | # nChannels = len(channelIndexList) | |
101 | if self.dataOut.flagDataAsBlock: |
|
101 | if self.dataOut.flagDataAsBlock: | |
102 | """ |
|
102 | """ | |
103 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
103 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
104 | """ |
|
104 | """ | |
105 | data = self.dataOut.data[channelIndexList,:,:] |
|
105 | data = self.dataOut.data[channelIndexList,:,:] | |
106 | else: |
|
106 | else: | |
107 | data = self.dataOut.data[channelIndexList,:] |
|
107 | data = self.dataOut.data[channelIndexList,:] | |
108 |
|
108 | |||
109 | self.dataOut.data = data |
|
109 | self.dataOut.data = data | |
110 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
110 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
111 | # self.dataOut.nChannels = nChannels |
|
111 | # self.dataOut.nChannels = nChannels | |
112 |
|
112 | |||
113 | return 1 |
|
113 | return 1 | |
114 |
|
114 | |||
115 | def selectHeights(self, minHei=None, maxHei=None): |
|
115 | def selectHeights(self, minHei=None, maxHei=None): | |
116 | """ |
|
116 | """ | |
117 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
117 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
118 | minHei <= height <= maxHei |
|
118 | minHei <= height <= maxHei | |
119 |
|
119 | |||
120 | Input: |
|
120 | Input: | |
121 | minHei : valor minimo de altura a considerar |
|
121 | minHei : valor minimo de altura a considerar | |
122 | maxHei : valor maximo de altura a considerar |
|
122 | maxHei : valor maximo de altura a considerar | |
123 |
|
123 | |||
124 | Affected: |
|
124 | Affected: | |
125 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
125 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
126 |
|
126 | |||
127 | Return: |
|
127 | Return: | |
128 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
128 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
129 | """ |
|
129 | """ | |
130 |
|
130 | |||
131 | if minHei == None: |
|
131 | if minHei == None: | |
132 | minHei = self.dataOut.heightList[0] |
|
132 | minHei = self.dataOut.heightList[0] | |
133 |
|
133 | |||
134 | if maxHei == None: |
|
134 | if maxHei == None: | |
135 | maxHei = self.dataOut.heightList[-1] |
|
135 | maxHei = self.dataOut.heightList[-1] | |
136 |
|
136 | |||
137 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
137 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
138 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
138 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
139 |
|
139 | |||
140 |
|
140 | |||
141 | if (maxHei > self.dataOut.heightList[-1]): |
|
141 | if (maxHei > self.dataOut.heightList[-1]): | |
142 | maxHei = self.dataOut.heightList[-1] |
|
142 | maxHei = self.dataOut.heightList[-1] | |
143 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
143 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
144 |
|
144 | |||
145 | minIndex = 0 |
|
145 | minIndex = 0 | |
146 | maxIndex = 0 |
|
146 | maxIndex = 0 | |
147 | heights = self.dataOut.heightList |
|
147 | heights = self.dataOut.heightList | |
148 |
|
148 | |||
149 | inda = numpy.where(heights >= minHei) |
|
149 | inda = numpy.where(heights >= minHei) | |
150 | indb = numpy.where(heights <= maxHei) |
|
150 | indb = numpy.where(heights <= maxHei) | |
151 |
|
151 | |||
152 | try: |
|
152 | try: | |
153 | minIndex = inda[0][0] |
|
153 | minIndex = inda[0][0] | |
154 | except: |
|
154 | except: | |
155 | minIndex = 0 |
|
155 | minIndex = 0 | |
156 |
|
156 | |||
157 | try: |
|
157 | try: | |
158 | maxIndex = indb[0][-1] |
|
158 | maxIndex = indb[0][-1] | |
159 | except: |
|
159 | except: | |
160 | maxIndex = len(heights) |
|
160 | maxIndex = len(heights) | |
161 |
|
161 | |||
162 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
162 | self.selectHeightsByIndex(minIndex, maxIndex) | |
163 |
|
163 | |||
164 | return 1 |
|
164 | return 1 | |
165 |
|
165 | |||
166 |
|
166 | |||
167 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
167 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
168 | """ |
|
168 | """ | |
169 | 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 | |
170 | minIndex <= index <= maxIndex |
|
170 | minIndex <= index <= maxIndex | |
171 |
|
171 | |||
172 | Input: |
|
172 | Input: | |
173 | minIndex : valor de indice minimo de altura a considerar |
|
173 | minIndex : valor de indice minimo de altura a considerar | |
174 | maxIndex : valor de indice maximo de altura a considerar |
|
174 | maxIndex : valor de indice maximo de altura a considerar | |
175 |
|
175 | |||
176 | Affected: |
|
176 | Affected: | |
177 | self.dataOut.data |
|
177 | self.dataOut.data | |
178 | self.dataOut.heightList |
|
178 | self.dataOut.heightList | |
179 |
|
179 | |||
180 | Return: |
|
180 | Return: | |
181 | 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 | |
182 | """ |
|
182 | """ | |
183 |
|
183 | |||
184 | if (minIndex < 0) or (minIndex > maxIndex): |
|
184 | if (minIndex < 0) or (minIndex > maxIndex): | |
185 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
185 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
186 |
|
186 | |||
187 | if (maxIndex >= self.dataOut.nHeights): |
|
187 | if (maxIndex >= self.dataOut.nHeights): | |
188 | maxIndex = self.dataOut.nHeights |
|
188 | maxIndex = self.dataOut.nHeights | |
189 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
189 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
190 |
|
190 | |||
191 | # nHeights = maxIndex - minIndex + 1 |
|
191 | # nHeights = maxIndex - minIndex + 1 | |
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 | return 1 |
|
207 | return 1 | |
208 |
|
208 | |||
209 |
|
209 | |||
210 |
def filterByHeights(self, window, axis= |
|
210 | def filterByHeights(self, window, axis=2): | |
211 |
|
211 | |||
212 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
212 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
213 |
|
213 | |||
214 | if window == None: |
|
214 | if window == None: | |
215 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
215 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
216 |
|
216 | |||
217 | newdelta = deltaHeight * window |
|
217 | newdelta = deltaHeight * window | |
218 | r = self.dataOut.nHeights % window |
|
218 | r = self.dataOut.nHeights % window | |
219 |
|
219 | |||
220 | if self.dataOut.flagDataAsBlock: |
|
220 | if self.dataOut.flagDataAsBlock: | |
221 | """ |
|
221 | """ | |
222 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
222 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
223 | """ |
|
223 | """ | |
224 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] |
|
224 | buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r] | |
225 |
buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.n |
|
225 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) | |
226 | buffer = numpy.sum(buffer,3) |
|
226 | buffer = numpy.sum(buffer,3) | |
227 |
|
227 | |||
228 | else: |
|
228 | else: | |
229 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] |
|
229 | buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r] | |
230 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) |
|
230 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window) | |
231 | buffer = numpy.sum(buffer,2) |
|
231 | buffer = numpy.sum(buffer,2) | |
232 |
|
232 | |||
233 | self.dataOut.data = buffer.copy() |
|
233 | self.dataOut.data = buffer.copy() | |
234 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
234 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) | |
235 | self.dataOut.windowOfFilter = window |
|
235 | self.dataOut.windowOfFilter = window | |
236 |
|
236 | |||
237 | return 1 |
|
237 | return 1 | |
238 |
|
238 | |||
239 | def deFlip(self, channelList = []): |
|
239 | def deFlip(self, channelList = []): | |
240 |
|
240 | |||
241 | data = self.dataOut.data.copy() |
|
241 | data = self.dataOut.data.copy() | |
242 |
|
242 | |||
243 | if self.dataOut.flagDataAsBlock: |
|
243 | if self.dataOut.flagDataAsBlock: | |
244 | flip = self.flip |
|
244 | flip = self.flip | |
245 | profileList = range(self.dataOut.nProfiles) |
|
245 | profileList = range(self.dataOut.nProfiles) | |
246 |
|
246 | |||
247 | if channelList == []: |
|
247 | if channelList == []: | |
248 | for thisProfile in profileList: |
|
248 | for thisProfile in profileList: | |
249 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
249 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
250 | flip *= -1.0 |
|
250 | flip *= -1.0 | |
251 | else: |
|
251 | else: | |
252 | for thisChannel in channelList: |
|
252 | for thisChannel in channelList: | |
253 | for thisProfile in profileList: |
|
253 | for thisProfile in profileList: | |
254 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
254 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
255 | flip *= -1.0 |
|
255 | flip *= -1.0 | |
256 |
|
256 | |||
257 | self.flip = flip |
|
257 | self.flip = flip | |
258 |
|
258 | |||
259 | else: |
|
259 | else: | |
260 | if channelList == []: |
|
260 | if channelList == []: | |
261 | data[:,:] = data[:,:]*self.flip |
|
261 | data[:,:] = data[:,:]*self.flip | |
262 | else: |
|
262 | else: | |
263 | for thisChannel in channelList: |
|
263 | for thisChannel in channelList: | |
264 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
264 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
265 |
|
265 | |||
266 | self.flip *= -1. |
|
266 | self.flip *= -1. | |
267 |
|
267 | |||
268 | self.dataOut.data = data |
|
268 | self.dataOut.data = data | |
269 |
|
269 | |||
270 |
|
270 | |||
271 |
|
271 | |||
272 | def setRadarFrequency(self, frequency=None): |
|
272 | def setRadarFrequency(self, frequency=None): | |
273 |
|
273 | |||
274 | if frequency != None: |
|
274 | if frequency != None: | |
275 | self.dataOut.frequency = frequency |
|
275 | self.dataOut.frequency = frequency | |
276 |
|
276 | |||
277 | return 1 |
|
277 | return 1 | |
278 |
|
278 | |||
279 | class CohInt(Operation): |
|
279 | class CohInt(Operation): | |
280 |
|
280 | |||
281 | isConfig = False |
|
281 | isConfig = False | |
282 |
|
282 | |||
283 | __profIndex = 0 |
|
283 | __profIndex = 0 | |
284 | __withOverapping = False |
|
284 | __withOverapping = False | |
285 |
|
285 | |||
286 | __byTime = False |
|
286 | __byTime = False | |
287 | __initime = None |
|
287 | __initime = None | |
288 | __lastdatatime = None |
|
288 | __lastdatatime = None | |
289 | __integrationtime = None |
|
289 | __integrationtime = None | |
290 |
|
290 | |||
291 | __buffer = None |
|
291 | __buffer = None | |
292 |
|
292 | |||
293 | __dataReady = False |
|
293 | __dataReady = False | |
294 |
|
294 | |||
295 | n = None |
|
295 | n = None | |
296 |
|
296 | |||
297 |
|
297 | |||
298 | def __init__(self): |
|
298 | def __init__(self): | |
299 |
|
299 | |||
300 | Operation.__init__(self) |
|
300 | Operation.__init__(self) | |
301 |
|
301 | |||
302 | # self.isConfig = False |
|
302 | # self.isConfig = False | |
303 |
|
303 | |||
304 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): |
|
304 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): | |
305 | """ |
|
305 | """ | |
306 | Set the parameters of the integration class. |
|
306 | Set the parameters of the integration class. | |
307 |
|
307 | |||
308 | Inputs: |
|
308 | Inputs: | |
309 |
|
309 | |||
310 | n : Number of coherent integrations |
|
310 | n : Number of coherent integrations | |
311 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
311 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
312 | overlapping : |
|
312 | overlapping : | |
313 |
|
313 | |||
314 | """ |
|
314 | """ | |
315 |
|
315 | |||
316 | self.__initime = None |
|
316 | self.__initime = None | |
317 | self.__lastdatatime = 0 |
|
317 | self.__lastdatatime = 0 | |
318 | self.__buffer = None |
|
318 | self.__buffer = None | |
319 | self.__dataReady = False |
|
319 | self.__dataReady = False | |
320 | self.byblock = byblock |
|
320 | self.byblock = byblock | |
321 |
|
321 | |||
322 | if n == None and timeInterval == None: |
|
322 | if n == None and timeInterval == None: | |
323 | raise ValueError, "n or timeInterval should be specified ..." |
|
323 | raise ValueError, "n or timeInterval should be specified ..." | |
324 |
|
324 | |||
325 | if n != None: |
|
325 | if n != None: | |
326 | self.n = n |
|
326 | self.n = n | |
327 | self.__byTime = False |
|
327 | self.__byTime = False | |
328 | else: |
|
328 | else: | |
329 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
329 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
330 | self.n = 9999 |
|
330 | self.n = 9999 | |
331 | self.__byTime = True |
|
331 | self.__byTime = True | |
332 |
|
332 | |||
333 | if overlapping: |
|
333 | if overlapping: | |
334 | self.__withOverapping = True |
|
334 | self.__withOverapping = True | |
335 | self.__buffer = None |
|
335 | self.__buffer = None | |
336 | else: |
|
336 | else: | |
337 | self.__withOverapping = False |
|
337 | self.__withOverapping = False | |
338 | self.__buffer = 0 |
|
338 | self.__buffer = 0 | |
339 |
|
339 | |||
340 | self.__profIndex = 0 |
|
340 | self.__profIndex = 0 | |
341 |
|
341 | |||
342 | def putData(self, data): |
|
342 | def putData(self, data): | |
343 |
|
343 | |||
344 | """ |
|
344 | """ | |
345 | Add a profile to the __buffer and increase in one the __profileIndex |
|
345 | Add a profile to the __buffer and increase in one the __profileIndex | |
346 |
|
346 | |||
347 | """ |
|
347 | """ | |
348 |
|
348 | |||
349 | if not self.__withOverapping: |
|
349 | if not self.__withOverapping: | |
350 | self.__buffer += data.copy() |
|
350 | self.__buffer += data.copy() | |
351 | self.__profIndex += 1 |
|
351 | self.__profIndex += 1 | |
352 | return |
|
352 | return | |
353 |
|
353 | |||
354 | #Overlapping data |
|
354 | #Overlapping data | |
355 | nChannels, nHeis = data.shape |
|
355 | nChannels, nHeis = data.shape | |
356 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
356 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
357 |
|
357 | |||
358 | #If the buffer is empty then it takes the data value |
|
358 | #If the buffer is empty then it takes the data value | |
359 | if self.__buffer == None: |
|
359 | if self.__buffer == None: | |
360 | self.__buffer = data |
|
360 | self.__buffer = data | |
361 | self.__profIndex += 1 |
|
361 | self.__profIndex += 1 | |
362 | return |
|
362 | return | |
363 |
|
363 | |||
364 | #If the buffer length is lower than n then stakcing the data value |
|
364 | #If the buffer length is lower than n then stakcing the data value | |
365 | if self.__profIndex < self.n: |
|
365 | if self.__profIndex < self.n: | |
366 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
366 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
367 | self.__profIndex += 1 |
|
367 | self.__profIndex += 1 | |
368 | return |
|
368 | return | |
369 |
|
369 | |||
370 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
370 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
371 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
371 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
372 | self.__buffer[self.n-1] = data |
|
372 | self.__buffer[self.n-1] = data | |
373 | self.__profIndex = self.n |
|
373 | self.__profIndex = self.n | |
374 | return |
|
374 | return | |
375 |
|
375 | |||
376 |
|
376 | |||
377 | def pushData(self): |
|
377 | def pushData(self): | |
378 | """ |
|
378 | """ | |
379 | Return the sum of the last profiles and the profiles used in the sum. |
|
379 | Return the sum of the last profiles and the profiles used in the sum. | |
380 |
|
380 | |||
381 | Affected: |
|
381 | Affected: | |
382 |
|
382 | |||
383 | self.__profileIndex |
|
383 | self.__profileIndex | |
384 |
|
384 | |||
385 | """ |
|
385 | """ | |
386 |
|
386 | |||
387 | if not self.__withOverapping: |
|
387 | if not self.__withOverapping: | |
388 | data = self.__buffer |
|
388 | data = self.__buffer | |
389 | n = self.__profIndex |
|
389 | n = self.__profIndex | |
390 |
|
390 | |||
391 | self.__buffer = 0 |
|
391 | self.__buffer = 0 | |
392 | self.__profIndex = 0 |
|
392 | self.__profIndex = 0 | |
393 |
|
393 | |||
394 | return data, n |
|
394 | return data, n | |
395 |
|
395 | |||
396 | #Integration with Overlapping |
|
396 | #Integration with Overlapping | |
397 | data = numpy.sum(self.__buffer, axis=0) |
|
397 | data = numpy.sum(self.__buffer, axis=0) | |
398 | n = self.__profIndex |
|
398 | n = self.__profIndex | |
399 |
|
399 | |||
400 | return data, n |
|
400 | return data, n | |
401 |
|
401 | |||
402 | def byProfiles(self, data): |
|
402 | def byProfiles(self, data): | |
403 |
|
403 | |||
404 | self.__dataReady = False |
|
404 | self.__dataReady = False | |
405 | avgdata = None |
|
405 | avgdata = None | |
406 | # n = None |
|
406 | # n = None | |
407 |
|
407 | |||
408 | self.putData(data) |
|
408 | self.putData(data) | |
409 |
|
409 | |||
410 | if self.__profIndex == self.n: |
|
410 | if self.__profIndex == self.n: | |
411 |
|
411 | |||
412 | avgdata, n = self.pushData() |
|
412 | avgdata, n = self.pushData() | |
413 | self.__dataReady = True |
|
413 | self.__dataReady = True | |
414 |
|
414 | |||
415 | return avgdata |
|
415 | return avgdata | |
416 |
|
416 | |||
417 | def byTime(self, data, datatime): |
|
417 | def byTime(self, data, datatime): | |
418 |
|
418 | |||
419 | self.__dataReady = False |
|
419 | self.__dataReady = False | |
420 | avgdata = None |
|
420 | avgdata = None | |
421 | n = None |
|
421 | n = None | |
422 |
|
422 | |||
423 | self.putData(data) |
|
423 | self.putData(data) | |
424 |
|
424 | |||
425 | if (datatime - self.__initime) >= self.__integrationtime: |
|
425 | if (datatime - self.__initime) >= self.__integrationtime: | |
426 | avgdata, n = self.pushData() |
|
426 | avgdata, n = self.pushData() | |
427 | self.n = n |
|
427 | self.n = n | |
428 | self.__dataReady = True |
|
428 | self.__dataReady = True | |
429 |
|
429 | |||
430 | return avgdata |
|
430 | return avgdata | |
431 |
|
431 | |||
432 | def integrate(self, data, datatime=None): |
|
432 | def integrate(self, data, datatime=None): | |
433 |
|
433 | |||
434 | if self.__initime == None: |
|
434 | if self.__initime == None: | |
435 | self.__initime = datatime |
|
435 | self.__initime = datatime | |
436 |
|
436 | |||
437 | if self.__byTime: |
|
437 | if self.__byTime: | |
438 | avgdata = self.byTime(data, datatime) |
|
438 | avgdata = self.byTime(data, datatime) | |
439 | else: |
|
439 | else: | |
440 | avgdata = self.byProfiles(data) |
|
440 | avgdata = self.byProfiles(data) | |
441 |
|
441 | |||
442 |
|
442 | |||
443 | self.__lastdatatime = datatime |
|
443 | self.__lastdatatime = datatime | |
444 |
|
444 | |||
445 | if avgdata == None: |
|
445 | if avgdata == None: | |
446 | return None, None |
|
446 | return None, None | |
447 |
|
447 | |||
448 | avgdatatime = self.__initime |
|
448 | avgdatatime = self.__initime | |
449 |
|
449 | |||
450 | deltatime = datatime -self.__lastdatatime |
|
450 | deltatime = datatime -self.__lastdatatime | |
451 |
|
451 | |||
452 | if not self.__withOverapping: |
|
452 | if not self.__withOverapping: | |
453 | self.__initime = datatime |
|
453 | self.__initime = datatime | |
454 | else: |
|
454 | else: | |
455 | self.__initime += deltatime |
|
455 | self.__initime += deltatime | |
456 |
|
456 | |||
457 | return avgdata, avgdatatime |
|
457 | return avgdata, avgdatatime | |
458 |
|
458 | |||
459 | def integrateByBlock(self, dataOut): |
|
459 | def integrateByBlock(self, dataOut): | |
460 |
|
460 | |||
461 | times = int(dataOut.data.shape[1]/self.n) |
|
461 | times = int(dataOut.data.shape[1]/self.n) | |
462 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
462 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
463 |
|
463 | |||
464 | id_min = 0 |
|
464 | id_min = 0 | |
465 | id_max = self.n |
|
465 | id_max = self.n | |
466 |
|
466 | |||
467 | for i in range(times): |
|
467 | for i in range(times): | |
468 | junk = dataOut.data[:,id_min:id_max,:] |
|
468 | junk = dataOut.data[:,id_min:id_max,:] | |
469 | avgdata[:,i,:] = junk.sum(axis=1) |
|
469 | avgdata[:,i,:] = junk.sum(axis=1) | |
470 | id_min += self.n |
|
470 | id_min += self.n | |
471 | id_max += self.n |
|
471 | id_max += self.n | |
472 |
|
472 | |||
473 | timeInterval = dataOut.ippSeconds*self.n |
|
473 | timeInterval = dataOut.ippSeconds*self.n | |
474 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
474 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
475 | self.__dataReady = True |
|
475 | self.__dataReady = True | |
476 | return avgdata, avgdatatime |
|
476 | return avgdata, avgdatatime | |
477 |
|
477 | |||
478 | def run(self, dataOut, **kwargs): |
|
478 | def run(self, dataOut, **kwargs): | |
479 |
|
479 | |||
480 | if not self.isConfig: |
|
480 | if not self.isConfig: | |
481 | self.setup(**kwargs) |
|
481 | self.setup(**kwargs) | |
482 | self.isConfig = True |
|
482 | self.isConfig = True | |
483 |
|
483 | |||
484 | if dataOut.flagDataAsBlock: |
|
484 | if dataOut.flagDataAsBlock: | |
485 | """ |
|
485 | """ | |
486 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
486 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
487 | """ |
|
487 | """ | |
488 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
488 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
489 | else: |
|
489 | else: | |
490 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
490 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
491 |
|
491 | |||
492 | # dataOut.timeInterval *= n |
|
492 | # dataOut.timeInterval *= n | |
493 | dataOut.flagNoData = True |
|
493 | dataOut.flagNoData = True | |
494 |
|
494 | |||
495 | if self.__dataReady: |
|
495 | if self.__dataReady: | |
496 | dataOut.data = avgdata |
|
496 | dataOut.data = avgdata | |
497 | dataOut.nCohInt *= self.n |
|
497 | dataOut.nCohInt *= self.n | |
498 | dataOut.utctime = avgdatatime |
|
498 | dataOut.utctime = avgdatatime | |
499 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
499 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
500 | dataOut.flagNoData = False |
|
500 | dataOut.flagNoData = False | |
501 |
|
501 | |||
502 | class Decoder(Operation): |
|
502 | class Decoder(Operation): | |
503 |
|
503 | |||
504 | isConfig = False |
|
504 | isConfig = False | |
505 | __profIndex = 0 |
|
505 | __profIndex = 0 | |
506 |
|
506 | |||
507 | code = None |
|
507 | code = None | |
508 |
|
508 | |||
509 | nCode = None |
|
509 | nCode = None | |
510 | nBaud = None |
|
510 | nBaud = None | |
511 |
|
511 | |||
512 |
|
512 | |||
513 | def __init__(self): |
|
513 | def __init__(self): | |
514 |
|
514 | |||
515 | Operation.__init__(self) |
|
515 | Operation.__init__(self) | |
516 |
|
516 | |||
517 | self.times = None |
|
517 | self.times = None | |
518 | self.osamp = None |
|
518 | self.osamp = None | |
519 | # self.__setValues = False |
|
519 | # self.__setValues = False | |
520 | self.isConfig = False |
|
520 | self.isConfig = False | |
521 |
|
521 | |||
522 | def setup(self, code, osamp, dataOut): |
|
522 | def setup(self, code, osamp, dataOut): | |
523 |
|
523 | |||
524 | self.__profIndex = 0 |
|
524 | self.__profIndex = 0 | |
525 |
|
525 | |||
526 | self.code = code |
|
526 | self.code = code | |
527 |
|
527 | |||
528 | self.nCode = len(code) |
|
528 | self.nCode = len(code) | |
529 | self.nBaud = len(code[0]) |
|
529 | self.nBaud = len(code[0]) | |
530 |
|
530 | |||
531 | if (osamp != None) and (osamp >1): |
|
531 | if (osamp != None) and (osamp >1): | |
532 | self.osamp = osamp |
|
532 | self.osamp = osamp | |
533 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
533 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
534 | self.nBaud = self.nBaud*self.osamp |
|
534 | self.nBaud = self.nBaud*self.osamp | |
535 |
|
535 | |||
536 | self.__nChannels = dataOut.nChannels |
|
536 | self.__nChannels = dataOut.nChannels | |
537 | self.__nProfiles = dataOut.nProfiles |
|
537 | self.__nProfiles = dataOut.nProfiles | |
538 | self.__nHeis = dataOut.nHeights |
|
538 | self.__nHeis = dataOut.nHeights | |
539 |
|
539 | |||
540 | if dataOut.flagDataAsBlock: |
|
540 | if dataOut.flagDataAsBlock: | |
541 |
|
541 | |||
542 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
542 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
543 |
|
543 | |||
544 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
544 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
545 |
|
545 | |||
546 | else: |
|
546 | else: | |
547 |
|
547 | |||
548 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
548 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
549 |
|
549 | |||
550 | __codeBuffer[:,0:self.nBaud] = self.code |
|
550 | __codeBuffer[:,0:self.nBaud] = self.code | |
551 |
|
551 | |||
552 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
552 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
553 |
|
553 | |||
554 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
554 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
555 |
|
555 | |||
556 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
556 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
557 |
|
557 | |||
558 | def convolutionInFreq(self, data): |
|
558 | def convolutionInFreq(self, data): | |
559 |
|
559 | |||
560 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
560 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
561 |
|
561 | |||
562 | fft_data = numpy.fft.fft(data, axis=1) |
|
562 | fft_data = numpy.fft.fft(data, axis=1) | |
563 |
|
563 | |||
564 | conv = fft_data*fft_code |
|
564 | conv = fft_data*fft_code | |
565 |
|
565 | |||
566 | data = numpy.fft.ifft(conv,axis=1) |
|
566 | data = numpy.fft.ifft(conv,axis=1) | |
567 |
|
567 | |||
568 | datadec = data#[:,:] |
|
568 | datadec = data#[:,:] | |
569 |
|
569 | |||
570 | return datadec |
|
570 | return datadec | |
571 |
|
571 | |||
572 | def convolutionInFreqOpt(self, data): |
|
572 | def convolutionInFreqOpt(self, data): | |
573 |
|
573 | |||
574 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
574 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
575 |
|
575 | |||
576 | data = cfunctions.decoder(fft_code, data) |
|
576 | data = cfunctions.decoder(fft_code, data) | |
577 |
|
577 | |||
578 | datadec = data#[:,:] |
|
578 | datadec = data#[:,:] | |
579 |
|
579 | |||
580 | return datadec |
|
580 | return datadec | |
581 |
|
581 | |||
582 | def convolutionInTime(self, data): |
|
582 | def convolutionInTime(self, data): | |
583 |
|
583 | |||
584 | code = self.code[self.__profIndex] |
|
584 | code = self.code[self.__profIndex] | |
585 |
|
585 | |||
586 | for i in range(self.__nChannels): |
|
586 | for i in range(self.__nChannels): | |
587 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='same') |
|
587 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='same') | |
588 |
|
588 | |||
589 | return self.datadecTime |
|
589 | return self.datadecTime | |
590 |
|
590 | |||
591 | def convolutionByBlockInTime(self, data): |
|
591 | def convolutionByBlockInTime(self, data): | |
592 |
|
592 | |||
593 | repetitions = self.__nProfiles / self.nCode |
|
593 | repetitions = self.__nProfiles / self.nCode | |
594 |
|
594 | |||
595 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
595 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
596 | junk = junk.flatten() |
|
596 | junk = junk.flatten() | |
597 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
597 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
598 |
|
598 | |||
599 | for i in range(self.__nChannels): |
|
599 | for i in range(self.__nChannels): | |
600 | for j in range(self.__nProfiles): |
|
600 | for j in range(self.__nProfiles): | |
601 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='same') |
|
601 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='same') | |
602 |
|
602 | |||
603 | return self.datadecTime |
|
603 | return self.datadecTime | |
604 |
|
604 | |||
605 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): |
|
605 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): | |
606 |
|
606 | |||
607 | if not self.isConfig: |
|
607 | if not self.isConfig: | |
608 |
|
608 | |||
609 | if code == None: |
|
609 | if code == None: | |
610 | code = dataOut.code |
|
610 | code = dataOut.code | |
611 | else: |
|
611 | else: | |
612 | code = numpy.array(code).reshape(nCode,nBaud) |
|
612 | code = numpy.array(code).reshape(nCode,nBaud) | |
613 |
|
613 | |||
614 | self.setup(code, osamp, dataOut) |
|
614 | self.setup(code, osamp, dataOut) | |
615 |
|
615 | |||
616 | self.isConfig = True |
|
616 | self.isConfig = True | |
617 |
|
617 | |||
618 | if dataOut.flagDataAsBlock: |
|
618 | if dataOut.flagDataAsBlock: | |
619 | """ |
|
619 | """ | |
620 | Decoding when data have been read as block, |
|
620 | Decoding when data have been read as block, | |
621 | """ |
|
621 | """ | |
622 | datadec = self.convolutionByBlockInTime(dataOut.data) |
|
622 | datadec = self.convolutionByBlockInTime(dataOut.data) | |
623 |
|
623 | |||
624 | else: |
|
624 | else: | |
625 | """ |
|
625 | """ | |
626 | Decoding when data have been read profile by profile |
|
626 | Decoding when data have been read profile by profile | |
627 | """ |
|
627 | """ | |
628 | if mode == 0: |
|
628 | if mode == 0: | |
629 | datadec = self.convolutionInTime(dataOut.data) |
|
629 | datadec = self.convolutionInTime(dataOut.data) | |
630 |
|
630 | |||
631 | if mode == 1: |
|
631 | if mode == 1: | |
632 | datadec = self.convolutionInFreq(dataOut.data) |
|
632 | datadec = self.convolutionInFreq(dataOut.data) | |
633 |
|
633 | |||
634 | if mode == 2: |
|
634 | if mode == 2: | |
635 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
635 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
636 |
|
636 | |||
637 | dataOut.code = self.code |
|
637 | dataOut.code = self.code | |
638 | dataOut.nCode = self.nCode |
|
638 | dataOut.nCode = self.nCode | |
639 | dataOut.nBaud = self.nBaud |
|
639 | dataOut.nBaud = self.nBaud | |
640 | dataOut.radarControllerHeaderObj.code = self.code |
|
640 | dataOut.radarControllerHeaderObj.code = self.code | |
641 | dataOut.radarControllerHeaderObj.nCode = self.nCode |
|
641 | dataOut.radarControllerHeaderObj.nCode = self.nCode | |
642 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud |
|
642 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud | |
643 |
|
643 | |||
644 | dataOut.data = datadec |
|
644 | dataOut.data = datadec | |
645 |
|
645 | |||
646 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
646 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] | |
647 |
|
647 | |||
648 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
648 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
649 |
|
649 | |||
650 | if self.__profIndex == self.nCode-1: |
|
650 | if self.__profIndex == self.nCode-1: | |
651 | self.__profIndex = 0 |
|
651 | self.__profIndex = 0 | |
652 | return 1 |
|
652 | return 1 | |
653 |
|
653 | |||
654 | self.__profIndex += 1 |
|
654 | self.__profIndex += 1 | |
655 |
|
655 | |||
656 | return 1 |
|
656 | return 1 | |
657 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
657 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
658 |
|
658 | |||
659 |
|
659 | |||
660 | class ProfileConcat(Operation): |
|
660 | class ProfileConcat(Operation): | |
661 |
|
661 | |||
662 | isConfig = False |
|
662 | isConfig = False | |
663 | buffer = None |
|
663 | buffer = None | |
664 |
|
664 | |||
665 | def __init__(self): |
|
665 | def __init__(self): | |
666 |
|
666 | |||
667 | Operation.__init__(self) |
|
667 | Operation.__init__(self) | |
668 | self.profileIndex = 0 |
|
668 | self.profileIndex = 0 | |
669 |
|
669 | |||
670 | def reset(self): |
|
670 | def reset(self): | |
671 | self.buffer = numpy.zeros_like(self.buffer) |
|
671 | self.buffer = numpy.zeros_like(self.buffer) | |
672 | self.start_index = 0 |
|
672 | self.start_index = 0 | |
673 | self.times = 1 |
|
673 | self.times = 1 | |
674 |
|
674 | |||
675 | def setup(self, data, m, n=1): |
|
675 | def setup(self, data, m, n=1): | |
676 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
676 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
677 | self.nHeights = data.nHeights |
|
677 | self.nHeights = data.nHeights | |
678 | self.start_index = 0 |
|
678 | self.start_index = 0 | |
679 | self.times = 1 |
|
679 | self.times = 1 | |
680 |
|
680 | |||
681 | def concat(self, data): |
|
681 | def concat(self, data): | |
682 |
|
682 | |||
683 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() |
|
683 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() | |
684 | self.start_index = self.start_index + self.nHeights |
|
684 | self.start_index = self.start_index + self.nHeights | |
685 |
|
685 | |||
686 | def run(self, dataOut, m): |
|
686 | def run(self, dataOut, m): | |
687 |
|
687 | |||
688 | dataOut.flagNoData = True |
|
688 | dataOut.flagNoData = True | |
689 |
|
689 | |||
690 | if not self.isConfig: |
|
690 | if not self.isConfig: | |
691 | self.setup(dataOut.data, m, 1) |
|
691 | self.setup(dataOut.data, m, 1) | |
692 | self.isConfig = True |
|
692 | self.isConfig = True | |
693 |
|
693 | |||
694 | if dataOut.flagDataAsBlock: |
|
694 | if dataOut.flagDataAsBlock: | |
695 |
|
695 | |||
696 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" |
|
696 | raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False" | |
697 |
|
697 | |||
698 | else: |
|
698 | else: | |
699 | self.concat(dataOut.data) |
|
699 | self.concat(dataOut.data) | |
700 | self.times += 1 |
|
700 | self.times += 1 | |
701 | if self.times > m: |
|
701 | if self.times > m: | |
702 | dataOut.data = self.buffer |
|
702 | dataOut.data = self.buffer | |
703 | self.reset() |
|
703 | self.reset() | |
704 | dataOut.flagNoData = False |
|
704 | dataOut.flagNoData = False | |
705 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
705 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
706 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
706 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
707 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
707 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
708 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
708 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
709 | dataOut.ippSeconds *= m |
|
709 | dataOut.ippSeconds *= m | |
710 |
|
710 | |||
711 | class ProfileSelector(Operation): |
|
711 | class ProfileSelector(Operation): | |
712 |
|
712 | |||
713 | profileIndex = None |
|
713 | profileIndex = None | |
714 | # Tamanho total de los perfiles |
|
714 | # Tamanho total de los perfiles | |
715 | nProfiles = None |
|
715 | nProfiles = None | |
716 |
|
716 | |||
717 | def __init__(self): |
|
717 | def __init__(self): | |
718 |
|
718 | |||
719 | Operation.__init__(self) |
|
719 | Operation.__init__(self) | |
720 | self.profileIndex = 0 |
|
720 | self.profileIndex = 0 | |
721 |
|
721 | |||
722 | def incIndex(self): |
|
722 | def incIndex(self): | |
723 |
|
723 | |||
724 | self.profileIndex += 1 |
|
724 | self.profileIndex += 1 | |
725 |
|
725 | |||
726 | if self.profileIndex >= self.nProfiles: |
|
726 | if self.profileIndex >= self.nProfiles: | |
727 | self.profileIndex = 0 |
|
727 | self.profileIndex = 0 | |
728 |
|
728 | |||
729 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
729 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
730 |
|
730 | |||
731 | if profileIndex < minIndex: |
|
731 | if profileIndex < minIndex: | |
732 | return False |
|
732 | return False | |
733 |
|
733 | |||
734 | if profileIndex > maxIndex: |
|
734 | if profileIndex > maxIndex: | |
735 | return False |
|
735 | return False | |
736 |
|
736 | |||
737 | return True |
|
737 | return True | |
738 |
|
738 | |||
739 | def isThisProfileInList(self, profileIndex, profileList): |
|
739 | def isThisProfileInList(self, profileIndex, profileList): | |
740 |
|
740 | |||
741 | if profileIndex not in profileList: |
|
741 | if profileIndex not in profileList: | |
742 | return False |
|
742 | return False | |
743 |
|
743 | |||
744 | return True |
|
744 | return True | |
745 |
|
745 | |||
746 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None): |
|
746 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None): | |
747 |
|
747 | |||
748 | """ |
|
748 | """ | |
749 | ProfileSelector: |
|
749 | ProfileSelector: | |
750 |
|
750 | |||
751 | Inputs: |
|
751 | Inputs: | |
752 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
752 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
753 |
|
753 | |||
754 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
754 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
755 |
|
755 | |||
756 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
756 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
757 |
|
757 | |||
758 | """ |
|
758 | """ | |
759 |
|
759 | |||
760 | dataOut.flagNoData = True |
|
760 | dataOut.flagNoData = True | |
761 | self.nProfiles = dataOut.nProfiles |
|
761 | self.nProfiles = dataOut.nProfiles | |
762 |
|
762 | |||
763 | if dataOut.flagDataAsBlock: |
|
763 | if dataOut.flagDataAsBlock: | |
764 | """ |
|
764 | """ | |
765 | data dimension = [nChannels, nProfiles, nHeis] |
|
765 | data dimension = [nChannels, nProfiles, nHeis] | |
766 | """ |
|
766 | """ | |
767 | if profileList != None: |
|
767 | if profileList != None: | |
768 | dataOut.data = dataOut.data[:,profileList,:] |
|
768 | dataOut.data = dataOut.data[:,profileList,:] | |
769 | dataOut.nProfiles = len(profileList) |
|
769 | dataOut.nProfiles = len(profileList) | |
770 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
770 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
771 | else: |
|
771 | else: | |
772 | minIndex = profileRangeList[0] |
|
772 | minIndex = profileRangeList[0] | |
773 | maxIndex = profileRangeList[1] |
|
773 | maxIndex = profileRangeList[1] | |
774 |
|
774 | |||
775 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
775 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
776 | dataOut.nProfiles = maxIndex - minIndex + 1 |
|
776 | dataOut.nProfiles = maxIndex - minIndex + 1 | |
777 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
777 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
778 |
|
778 | |||
779 | dataOut.flagNoData = False |
|
779 | dataOut.flagNoData = False | |
780 |
|
780 | |||
781 | return True |
|
781 | return True | |
782 |
|
782 | |||
783 | else: |
|
783 | else: | |
784 | """ |
|
784 | """ | |
785 | data dimension = [nChannels, nHeis] |
|
785 | data dimension = [nChannels, nHeis] | |
786 |
|
786 | |||
787 | """ |
|
787 | """ | |
788 | if profileList != None: |
|
788 | if profileList != None: | |
789 |
|
789 | |||
790 | dataOut.nProfiles = len(profileList) |
|
790 | dataOut.nProfiles = len(profileList) | |
791 |
|
791 | |||
792 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
792 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
793 | dataOut.flagNoData = False |
|
793 | dataOut.flagNoData = False | |
794 | dataOut.profileIndex = self.profileIndex |
|
794 | dataOut.profileIndex = self.profileIndex | |
795 |
|
795 | |||
796 | self.incIndex() |
|
796 | self.incIndex() | |
797 | return True |
|
797 | return True | |
798 |
|
798 | |||
799 |
|
799 | |||
800 | if profileRangeList != None: |
|
800 | if profileRangeList != None: | |
801 |
|
801 | |||
802 | minIndex = profileRangeList[0] |
|
802 | minIndex = profileRangeList[0] | |
803 | maxIndex = profileRangeList[1] |
|
803 | maxIndex = profileRangeList[1] | |
804 |
|
804 | |||
805 | dataOut.nProfiles = maxIndex - minIndex + 1 |
|
805 | dataOut.nProfiles = maxIndex - minIndex + 1 | |
806 |
|
806 | |||
807 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
807 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
808 | dataOut.flagNoData = False |
|
808 | dataOut.flagNoData = False | |
809 | dataOut.profileIndex = self.profileIndex |
|
809 | dataOut.profileIndex = self.profileIndex | |
810 |
|
810 | |||
811 | self.incIndex() |
|
811 | self.incIndex() | |
812 | return True |
|
812 | return True | |
813 |
|
813 | |||
814 | if rangeList != None: |
|
814 | if rangeList != None: | |
815 |
|
815 | |||
816 | nProfiles = 0 |
|
816 | nProfiles = 0 | |
817 |
|
817 | |||
818 | for thisRange in rangeList: |
|
818 | for thisRange in rangeList: | |
819 | minIndex = thisRange[0] |
|
819 | minIndex = thisRange[0] | |
820 | maxIndex = thisRange[1] |
|
820 | maxIndex = thisRange[1] | |
821 |
|
821 | |||
822 | nProfiles += maxIndex - minIndex + 1 |
|
822 | nProfiles += maxIndex - minIndex + 1 | |
823 |
|
823 | |||
824 | dataOut.nProfiles = nProfiles |
|
824 | dataOut.nProfiles = nProfiles | |
825 |
|
825 | |||
826 | for thisRange in rangeList: |
|
826 | for thisRange in rangeList: | |
827 |
|
827 | |||
828 | minIndex = thisRange[0] |
|
828 | minIndex = thisRange[0] | |
829 | maxIndex = thisRange[1] |
|
829 | maxIndex = thisRange[1] | |
830 |
|
830 | |||
831 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
831 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
832 |
|
832 | |||
833 | # print "profileIndex = ", dataOut.profileIndex |
|
833 | # print "profileIndex = ", dataOut.profileIndex | |
834 |
|
834 | |||
835 | dataOut.flagNoData = False |
|
835 | dataOut.flagNoData = False | |
836 | dataOut.profileIndex = self.profileIndex |
|
836 | dataOut.profileIndex = self.profileIndex | |
837 |
|
837 | |||
838 | self.incIndex() |
|
838 | self.incIndex() | |
839 | break |
|
839 | break | |
840 | return True |
|
840 | return True | |
841 |
|
841 | |||
842 |
|
842 | |||
843 | if beam != None: #beam is only for AMISR data |
|
843 | if beam != None: #beam is only for AMISR data | |
844 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
844 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
845 | dataOut.flagNoData = False |
|
845 | dataOut.flagNoData = False | |
846 | dataOut.profileIndex = self.profileIndex |
|
846 | dataOut.profileIndex = self.profileIndex | |
847 |
|
847 | |||
848 | self.incIndex() |
|
848 | self.incIndex() | |
849 | return 1 |
|
849 | return 1 | |
850 |
|
850 | |||
851 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
851 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
852 |
|
852 | |||
853 | return 0 |
|
853 | return 0 | |
854 |
|
854 | |||
855 |
|
855 | |||
856 |
|
856 | |||
857 | class Reshaper(Operation): |
|
857 | class Reshaper(Operation): | |
858 |
|
858 | |||
859 | def __init__(self): |
|
859 | def __init__(self): | |
860 |
|
860 | |||
861 | Operation.__init__(self) |
|
861 | Operation.__init__(self) | |
862 | self.updateNewHeights = True |
|
862 | self.updateNewHeights = True | |
863 |
|
863 | |||
864 | def run(self, dataOut, shape): |
|
864 | def run(self, dataOut, shape): | |
865 |
|
865 | |||
866 | if not dataOut.flagDataAsBlock: |
|
866 | if not dataOut.flagDataAsBlock: | |
867 | raise ValueError, "Reshaper can only be used when voltage have been read as Block, getBlock = True" |
|
867 | raise ValueError, "Reshaper can only be used when voltage have been read as Block, getBlock = True" | |
868 |
|
868 | |||
869 | if len(shape) != 3: |
|
869 | if len(shape) != 3: | |
870 | raise ValueError, "shape len should be equal to 3, (nChannels, nProfiles, nHeis)" |
|
870 | raise ValueError, "shape len should be equal to 3, (nChannels, nProfiles, nHeis)" | |
871 |
|
871 | |||
872 | shape_tuple = tuple(shape) |
|
872 | shape_tuple = tuple(shape) | |
873 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
873 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
874 | dataOut.flagNoData = False |
|
874 | dataOut.flagNoData = False | |
875 |
|
875 | |||
876 | if self.updateNewHeights: |
|
876 | if self.updateNewHeights: | |
877 |
|
877 | |||
878 | old_nheights = dataOut.nHeights |
|
878 | old_nheights = dataOut.nHeights | |
879 | new_nheights = dataOut.data.shape[2] |
|
879 | new_nheights = dataOut.data.shape[2] | |
880 | factor = 1.0*new_nheights / old_nheights |
|
880 | factor = 1.0*new_nheights / old_nheights | |
881 |
|
881 | |||
882 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
882 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
883 |
|
883 | |||
884 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor |
|
884 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor | |
885 |
|
885 | |||
886 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
886 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
887 |
|
887 | |||
888 | dataOut.nProfiles = dataOut.data.shape[1] |
|
888 | dataOut.nProfiles = dataOut.data.shape[1] | |
889 |
|
889 | |||
890 | dataOut.ippSeconds *= factor No newline at end of file |
|
890 | dataOut.ippSeconds *= factor |
General Comments 0
You need to be logged in to leave comments.
Login now