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