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