From e0918654d2e93ac6d49379f0091271e8536ad161 2012-02-02 21:58:36 From: Daniel Valdez Date: 2012-02-02 21:58:36 Subject: [PATCH] First Version of Voltage Reader Module --- diff --git a/schainpy/IO/DataReader.py b/schainpy/IO/DataReader.py new file mode 100644 index 0000000..2f2ad0c --- /dev/null +++ b/schainpy/IO/DataReader.py @@ -0,0 +1,12 @@ +''' +Created on 23/01/2012 + +@author: danielangelsuarezmunoz +''' + + +class DataReader: + __buffer = 0 + __buffer_count = 0 + def __init__(self): + pass \ No newline at end of file diff --git a/schainpy/IO/TestReader.py b/schainpy/IO/TestReader.py new file mode 100644 index 0000000..e71911b --- /dev/null +++ b/schainpy/IO/TestReader.py @@ -0,0 +1,31 @@ +''' +Created on 23/01/2012 + +@author: danielangelsuarezmunoz +''' + +import VoltageReader +import datetime +import time + +objReader = VoltageReader.VoltageReader() + +path = '/Users/danielangelsuarezmunoz/Documents/Projects' +startDateTime = datetime.datetime(2007,1,1,16,0,0) +endDateTime = datetime.datetime(2007,12,1,17,1,0) +set = None +expLabel = '' +ext = '*.r' + +t0 = time.time() +objReader.setup(path, startDateTime, endDateTime, set, expLabel, ext) +print time.time() - t0 + + +while(not(objReader.noMoreFiles)): + + objReader.getData() + #print objReader.objStructShortHeader.dataBlock + #print time.localtime(objReader.objStructShortHeader.universalTime) + + \ No newline at end of file diff --git a/schainpy/IO/VoltageReader.py b/schainpy/IO/VoltageReader.py new file mode 100644 index 0000000..78621cf --- /dev/null +++ b/schainpy/IO/VoltageReader.py @@ -0,0 +1,592 @@ +''' +Created on 23/01/2012 + +@author: danielangelsuarezmunoz +''' + +from DataReader import DataReader + +import numpy +import os.path +import glob +import fnmatch +import time +import datetime + +class PROCFLAG: + COHERENT_INTEGRATION = numpy.uint32(0x00000001) + DECODE_DATA = numpy.uint32(0x00000002) + SPECTRA_CALC = numpy.uint32(0x00000004) + INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) + POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) + SHIFT_FFT_DATA = numpy.uint32(0x00000020) + + DATATYPE_CHAR = numpy.uint32(0x00000040) + DATATYPE_SHORT = numpy.uint32(0x00000080) + DATATYPE_LONG = numpy.uint32(0x00000100) + DATATYPE_INT64 = numpy.uint32(0x00000200) + DATATYPE_FLOAT = numpy.uint32(0x00000400) + DATATYPE_DOUBLE = numpy.uint32(0x00000800) + + DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) + DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) + DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) + + SAVE_CHANNELS_DC = numpy.uint32(0x00008000) + DEFLIP_DATA = numpy.uint32(0x00010000) + DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) + + ACQ_SYS_NATALIA = numpy.uint32(0x00040000) + ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) + ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) + ACQ_SYS_JULIA = numpy.uint32(0x00100000) + ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) + + EXP_NAME_ESP = numpy.uint32(0x00200000) + CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) + + OPERATION_MASK = numpy.uint32(0x0000003F) + DATATYPE_MASK = numpy.uint32(0x00000FC0) + DATAARRANGE_MASK = numpy.uint32(0x00007000) + ACQ_SYS_MASK = numpy.uint32(0x001C0000) + +class StructShortHeader(): + + size = 0 + version = 0 + dataBlock = 0 + utc = 0 + miliSecond = 0 + timeZone = 0 + dstFlag = 0 + errorCount = 0 + struct = numpy.dtype([ + ('nSize','= objShortHeader.utc)): + return 0 + + return 1 + + def __readBasicHeader(self, fp=None): + + if fp == None: + fp = self.__fp + + self.objStructShortHeader.read(fp) + + + def __readFirstHeader(self): + + self.__readBasicHeader() + self.__rdSystemHeader() + self.__rdRadarControllerHeader() + self.__rdProcessingHeader() + self.firstHeaderSize = self.objStructShortHeader.size + + data_type=int(numpy.log2((self.objStructProcessing.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) + if data_type == 0: + tmp=numpy.dtype([('real','= neededSize): + self.__readBasicHeader() + return 1 + + self.__setNextFile() + self.__readFirstHeader() + + deltaTime = self.objStructShortHeader.utc - self.__lastUTTime # check this + if deltaTime > self.__maxTimeStep: + self.__flagResetProcessing = 1 + + return 1 + + def __readBlock(self): + """Lee el bloque de datos desde la posicion actual del puntero del archivo y + actualiza todos los parametros relacionados al bloque de datos (data, time, + etc). La data leida es almacenada en el buffer y el contador de datos leidos es + seteado a 0 + """ + + pts2read = self.objStructProcessing.profilesPerBlock*self.objStructProcessing.numHeights*self.objStructSystemHeader.numChannels + + data = numpy.fromfile(self.__fp,self.__dataType,pts2read) + + data = data.reshape((self.objStructProcessing.profilesPerBlock, self.objStructProcessing.numHeights, self.objStructSystemHeader.numChannels)) + + self.__buffer = data + + self.__buffer_id = 0 + + def readNextBlock(self): + + self.__setNewBlock() + + self.__readBlock() + + self.__lastUTTime = self.objStructShortHeader.utc + + def __hasNotDataInBuffer(self): + if self.__buffer_id >= self.objStructProcessing.profilesPerBlock: + return 1 + + return 0 + + def getData(self): + """Obtiene un unidad de datos del buffer de lectura y es copiada a la clase "Data" + con todos los parametros asociados a este. cuando no hay datos en el buffer de + lectura es necesario hacer una nueva lectura de los bloques de datos + "__readBlock" + """ + + if self.__hasNotDataInBuffer(): + self.readNextBlock() + + if self.noMoreFiles == 1: + print 'read finished' + return None + + data = self.__buffer[self.__buffer_id,:,:] + + #print self.__buffer_id + + self.__buffer_id += 1 + + #call setData - to Data Object + + return data + + + def setup(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r", online = 0): + + if online == 0: + pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) + + if len(filenameList) == 0: + print 'Do not exist files in range: %s - %s'%(startDateTime.ctime(), endDateTime.ctime()) + return 0 + +# for thisFile in filenameList: +# print thisFile + + self.__idFile = -1 + + if not(self.__setNextFile()): + print "No more files" + return 0 + + self.__readFirstHeader() + + self.startUTCSeconds = time.mktime(startDateTime.timetuple()) + self.endUTCSeconds = time.mktime(endDateTime.timetuple()) + + self.startYear = startDateTime.timetuple().tm_year + self.endYear = endDateTime.timetuple().tm_year + + self.startDoy = startDateTime.timetuple().tm_yday + self.endDoy = endDateTime.timetuple().tm_yday + #call fillHeaderValues() - to Data Object + + self.__listOfPath = pathList + self.filenameList = filenameList + self.online = online