@@ -10,9 +10,6 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter | |||||
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
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 |
|
|||
14 | import tempfile |
|
|||
15 | from StringIO import StringIO |
|
|||
16 | # from _sha import blocksize |
|
13 | # from _sha import blocksize | |
17 |
|
14 | |||
18 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
15 | class VoltageReader(JRODataReader, ProcessingUnit): | |
@@ -61,7 +58,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
61 | optchar = "D" |
|
58 | optchar = "D" | |
62 | dataOut = None |
|
59 | dataOut = None | |
63 |
|
60 | |||
64 |
def __init__(self |
|
61 | def __init__(self): | |
65 | """ |
|
62 | """ | |
66 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
63 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
67 |
|
64 | |||
@@ -80,8 +77,8 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
80 | None |
|
77 | None | |
81 | """ |
|
78 | """ | |
82 |
|
79 | |||
83 |
ProcessingUnit.__init__(self |
|
80 | ProcessingUnit.__init__(self) | |
84 |
|
|
81 | ||
85 | self.isConfig = False |
|
82 | self.isConfig = False | |
86 |
|
83 | |||
87 | self.datablock = None |
|
84 | self.datablock = None | |
@@ -192,7 +189,6 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
192 | self.blocksize = pts2read |
|
189 | self.blocksize = pts2read | |
193 |
|
190 | |||
194 |
|
191 | |||
195 |
|
||||
196 | def readBlock(self): |
|
192 | def readBlock(self): | |
197 | """ |
|
193 | """ | |
198 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
194 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
@@ -216,16 +212,6 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
216 | Exceptions: |
|
212 | Exceptions: | |
217 | Si un bloque leido no es un bloque valido |
|
213 | Si un bloque leido no es un bloque valido | |
218 | """ |
|
214 | """ | |
219 |
|
||||
220 | # if self.server is not None: |
|
|||
221 | # self.zBlock = self.receiver.recv() |
|
|||
222 | # self.zHeader = self.zBlock[:24] |
|
|||
223 | # self.zDataBlock = self.zBlock[24:] |
|
|||
224 | # junk = numpy.fromstring(self.zDataBlock, numpy.dtype([('real','<i4'),('imag','<i4')])) |
|
|||
225 | # self.processingHeaderObj.profilesPerBlock = 240 |
|
|||
226 | # self.processingHeaderObj.nHeights = 248 |
|
|||
227 | # self.systemHeaderObj.nChannels |
|
|||
228 | # else: |
|
|||
229 | current_pointer_location = self.fp.tell() |
|
215 | current_pointer_location = self.fp.tell() | |
230 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
216 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
231 |
|
217 | |||
@@ -262,8 +248,6 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
262 |
|
248 | |||
263 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
249 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
264 |
|
250 | |||
265 | self.dataOut.processingHeaderObj = self.processingHeaderObj.copy() |
|
|||
266 |
|
||||
267 | if self.nTxs > 1: |
|
251 | if self.nTxs > 1: | |
268 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
252 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
269 |
|
253 | |||
@@ -317,97 +301,6 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
317 |
|
301 | |||
318 | return |
|
302 | return | |
319 |
|
303 | |||
320 | def readFirstHeaderFromServer(self): |
|
|||
321 |
|
||||
322 | self.getFirstHeader() |
|
|||
323 |
|
||||
324 | self.firstHeaderSize = self.basicHeaderObj.size |
|
|||
325 |
|
||||
326 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
|||
327 | if datatype == 0: |
|
|||
328 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
|||
329 | elif datatype == 1: |
|
|||
330 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
|||
331 | elif datatype == 2: |
|
|||
332 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
|||
333 | elif datatype == 3: |
|
|||
334 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
|||
335 | elif datatype == 4: |
|
|||
336 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
|||
337 | elif datatype == 5: |
|
|||
338 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
|||
339 | else: |
|
|||
340 | raise ValueError, 'Data type was not defined' |
|
|||
341 |
|
||||
342 | self.dtype = datatype_str |
|
|||
343 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
|||
344 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
|||
345 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
|||
346 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
|||
347 | self.getBlockDimension() |
|
|||
348 |
|
||||
349 |
|
||||
350 | def getFromServer(self): |
|
|||
351 | self.flagDiscontinuousBlock = 0 |
|
|||
352 | self.profileIndex = 0 |
|
|||
353 | self.flagIsNewBlock = 1 |
|
|||
354 | self.dataOut.flagNoData = False |
|
|||
355 | self.nTotalBlocks += 1 |
|
|||
356 | self.nReadBlocks += 1 |
|
|||
357 | self.blockPointer = 0 |
|
|||
358 |
|
||||
359 | block = self.receiver.recv() |
|
|||
360 |
|
||||
361 | self.basicHeaderObj.read(block[self.blockPointer:]) |
|
|||
362 | self.blockPointer += self.basicHeaderObj.length |
|
|||
363 | self.systemHeaderObj.read(block[self.blockPointer:]) |
|
|||
364 | self.blockPointer += self.systemHeaderObj.length |
|
|||
365 | self.radarControllerHeaderObj.read(block[self.blockPointer:]) |
|
|||
366 | self.blockPointer += self.radarControllerHeaderObj.length |
|
|||
367 | self.processingHeaderObj.read(block[self.blockPointer:]) |
|
|||
368 | self.blockPointer += self.processingHeaderObj.length |
|
|||
369 | self.readFirstHeaderFromServer() |
|
|||
370 |
|
||||
371 | timestamp = self.basicHeaderObj.get_datatime() |
|
|||
372 | print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp) |
|
|||
373 | current_pointer_location = self.blockPointer |
|
|||
374 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) |
|
|||
375 |
|
||||
376 | try: |
|
|||
377 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
|||
378 | except: |
|
|||
379 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
|||
380 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
|||
381 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) |
|
|||
382 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
|||
383 | # return 0 |
|
|||
384 |
|
||||
385 | #Dimensions : nChannels, nProfiles, nSamples |
|
|||
386 |
|
||||
387 | junk = numpy.transpose(junk, (2,0,1)) |
|
|||
388 | self.datablock = junk['real'] + junk['imag'] * 1j |
|
|||
389 | self.profileIndex = 0 |
|
|||
390 | if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles |
|
|||
391 | if self.selBlocktime != None: |
|
|||
392 | if self.dataOut.nCohInt is not None: |
|
|||
393 | nCohInt = self.dataOut.nCohInt |
|
|||
394 | else: |
|
|||
395 | nCohInt = 1 |
|
|||
396 | self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles))) |
|
|||
397 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] |
|
|||
398 | datasize = self.dataOut.data.shape[1] |
|
|||
399 | if datasize < self.selBlocksize: |
|
|||
400 | buffer = numpy.zeros((self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype = 'complex') |
|
|||
401 | buffer[:,:datasize,:] = self.dataOut.data |
|
|||
402 | self.dataOut.data = buffer |
|
|||
403 | self.profileIndex = blockIndex |
|
|||
404 |
|
||||
405 | self.dataOut.flagDataAsBlock = True |
|
|||
406 | self.flagIsNewBlock = 1 |
|
|||
407 | self.dataOut.realtime = self.online |
|
|||
408 |
|
||||
409 | return self.dataOut.data |
|
|||
410 |
|
||||
411 | def getData(self): |
|
304 | def getData(self): | |
412 | """ |
|
305 | """ | |
413 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut |
|
306 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut | |
@@ -444,19 +337,24 class VoltageReader(JRODataReader, ProcessingUnit): | |||||
444 | self.flagDiscontinuousBlock |
|
337 | self.flagDiscontinuousBlock | |
445 | self.flagIsNewBlock |
|
338 | self.flagIsNewBlock | |
446 | """ |
|
339 | """ | |
|
340 | ||||
447 | if self.flagNoMoreFiles: |
|
341 | if self.flagNoMoreFiles: | |
448 | self.dataOut.flagNoData = True |
|
342 | self.dataOut.flagNoData = True | |
449 | print 'Process finished' |
|
343 | print 'Process finished' | |
450 | return 0 |
|
344 | return 0 | |
|
345 | ||||
451 | self.flagDiscontinuousBlock = 0 |
|
346 | self.flagDiscontinuousBlock = 0 | |
452 | self.flagIsNewBlock = 0 |
|
347 | self.flagIsNewBlock = 0 | |
|
348 | ||||
453 | if self.__hasNotDataInBuffer(): |
|
349 | if self.__hasNotDataInBuffer(): | |
|
350 | ||||
454 | if not( self.readNextBlock() ): |
|
351 | if not( self.readNextBlock() ): | |
455 | return 0 |
|
352 | return 0 | |
456 |
|
353 | |||
457 | self.getFirstHeader() |
|
354 | self.getFirstHeader() | |
458 |
|
355 | |||
459 | self.reshapeData() |
|
356 | self.reshapeData() | |
|
357 | ||||
460 | if self.datablock is None: |
|
358 | if self.datablock is None: | |
461 | self.dataOut.flagNoData = True |
|
359 | self.dataOut.flagNoData = True | |
462 | return 0 |
|
360 | return 0 | |
@@ -547,7 +445,7 class VoltageWriter(JRODataWriter, Operation): | |||||
547 | shapeBuffer = None |
|
445 | shapeBuffer = None | |
548 |
|
446 | |||
549 |
|
447 | |||
550 |
def __init__(self |
|
448 | def __init__(self): | |
551 | """ |
|
449 | """ | |
552 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
450 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
553 |
|
451 | |||
@@ -556,7 +454,7 class VoltageWriter(JRODataWriter, Operation): | |||||
556 |
|
454 | |||
557 | Return: None |
|
455 | Return: None | |
558 | """ |
|
456 | """ | |
559 |
Operation.__init__(self |
|
457 | Operation.__init__(self) | |
560 |
|
458 | |||
561 | self.nTotalBlocks = 0 |
|
459 | self.nTotalBlocks = 0 | |
562 |
|
460 |
General Comments 0
You need to be logged in to leave comments.
Login now