From abb62041a98c5fd2fa3cb96d6f81dfaf49204e69 2012-02-07 20:44:14 From: Miguel Valdez Date: 2012-02-07 20:44:14 Subject: [PATCH] Estructura de directorios del modelo agregada. --- diff --git a/schainpy/IO/Correlation.py b/schainpy/IO/Correlation.py index 6320c92..1895fc2 100644 --- a/schainpy/IO/Correlation.py +++ b/schainpy/IO/Correlation.py @@ -1,16 +1,16 @@ -''' -Created on 23/01/2012 - -@author: danielangelsuarezmunoz -''' - -from Data import DataReader -from Data import DataWriter - -class CorrelationReader(DataReader): - def __init__(self): - pass - -class CorrelationWriter(DataWriter): - def __init__(self): +''' +Created on 23/01/2012 + +@author: danielangelsuarezmunoz +''' + +from Data import DataReader +from Data import DataWriter + +class CorrelationReader(DataReader): + def __init__(self): + pass + +class CorrelationWriter(DataWriter): + def __init__(self): pass \ No newline at end of file diff --git a/schainpy/IO/Data.py b/schainpy/IO/Data.py index 1ef31e1..33ffabd 100644 --- a/schainpy/IO/Data.py +++ b/schainpy/IO/Data.py @@ -1,18 +1,18 @@ -''' -Created on 23/01/2012 - -@author: danielangelsuarezmunoz -''' - - -class DataReader: - __buffer = 0 - __buffer_count = 0 - def __init__(self): - pass - -class DataWriter: - __buffer = 0 - __buffer_count = 0 - def __init__(self): +''' +Created on 23/01/2012 + +@author: danielangelsuarezmunoz +''' + + +class DataReader: + __buffer = 0 + __buffer_count = 0 + def __init__(self): + pass + +class DataWriter: + __buffer = 0 + __buffer_count = 0 + def __init__(self): pass \ No newline at end of file diff --git a/schainpy/IO/Header.py b/schainpy/IO/Header.py index 0b3009a..2ddb512 100644 --- a/schainpy/IO/Header.py +++ b/schainpy/IO/Header.py @@ -1,237 +1,245 @@ -import numpy - -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 BasicHeader: - - size = 0 - version = 0 - dataBlock = 0 - utc = 0 - miliSecond = 0 - timeZone = 0 - dstFlag = 0 - errorCount = 0 - struct = numpy.dtype([ - ('nSize','= basicHeaderObj.utc)): - return 0 - - return 1 - - def __readBasicHeader(self, fp=None): - - if fp == None: - fp = self.__fp - - self.basicHeaderObj.read(fp) - - def __readFirstHeader(self): - - self.__readBasicHeader() - self.__rdSystemHeader() - self.__rdRadarControllerHeader() - self.__rdProcessingHeader() - self.firstHeaderSize = self.basicHeaderObj.size - - data_type=int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) - if data_type == 0: - tmp=numpy.dtype([('real','= neededSize): - self.__readBasicHeader() - return 1 - - if not(self.__setNextFile()): - return 0 - - self.__readFirstHeader() - - deltaTime = self.basicHeaderObj.utc - self.__lastUTTime # check this - - self.flagResetProcessing = 0 - 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.processingHeaderObj.profilesPerBlock*self.processingHeaderObj.numHeights*self.systemHeaderObj.numChannels - - data = numpy.fromfile(self.__fp,self.__dataType,pts2read) - - data = data.reshape((self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.numHeights, self.systemHeaderObj.numChannels)) - - self.__flagIsNewFile = 0 - - self.__buffer = data - - self.__buffer_id = 0 - - def readNextBlock(self): - - if not(self.__setNewBlock()): - return 0 - - self.__readBlock() - - self.__lastUTTime = self.basicHeaderObj.utc - - return 1 - - def __hasNotDataInBuffer(self): - if self.__buffer_id >= self.processingHeaderObj.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" - """ - self.flagResetProcessing = 0 - - if self.__hasNotDataInBuffer(): - self.readNextBlock() - - if self.noMoreFiles == 1: - print 'read finished' - return None - - data = self.__buffer[self.__buffer_id,:,:] - #time = timeblock + n*ipp - #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.__pathList = pathList - self.filenameList = filenameList - self.online = online - -class VoltageWriter(DataWriter): - - def __init__(self): - pass +''' +Created on 23/01/2012 + +@author: danielangelsuarezmunoz +''' + + +import os, sys +import numpy +import glob +import fnmatch +import time +import datetime + +from Header import * +from Data import DataReader +from Data import DataWriter + +path = os.path.split(os.getcwd())[0] +sys.path.append(os.path.join(path,"Model")) + +from Voltage import Voltage + +class VoltageReader(DataReader): + + __idFile = 0 + + __fp = 0 + + __startDateTime = 0 + + __endDateTime = 0 + + __dataType = 0 + + __sizeOfFileByHeader = 0 + + __pathList = [] + + filenameList = [] + + __lastUTTime = 0 + + __maxTimeStep = 5 + + flagResetProcessing = 0 + + __flagIsNewFile = 0 + + noMoreFiles = 0 + + online = 0 + + filename = '' + + fileSize = 0 + + firstHeaderSize = 0 + + basicHeaderSize = 24 + + m_BasicHeader = BasicHeader() + + m_SystemHeader = SystemHeader() + + m_RadarControllerHeader = RadarControllerHeader() + + m_ProcessingHeader = ProcessingHeader() + + m_Voltage = None + + __buffer = 0 + + __buffer_id = 9999 + + def __init__(self, m_Voltage): + + self.m_Voltage = m_Voltage + + def __rdSystemHeader(self,fp=None): + if fp == None: + fp = self.__fp + + self.m_SystemHeader.read(fp) + + def __rdRadarControllerHeader(self,fp=None): + if fp == None: + fp = self.__fp + + self.m_RadarControllerHeader.read(fp) + + def __rdProcessingHeader(self,fp=None): + if fp == None: + fp = self.__fp + + self.m_ProcessingHeader.read(fp) + + def __searchFiles(self,path, startDateTime, endDateTime, set=None, expLabel = "", ext = "*.r"): + + startUtSeconds = time.mktime(startDateTime.timetuple()) + endUtSeconds = time.mktime(endDateTime.timetuple()) + + startYear = startDateTime.timetuple().tm_year + endYear = endDateTime.timetuple().tm_year + + startDoy = startDateTime.timetuple().tm_yday + endDoy = endDateTime.timetuple().tm_yday + + rangeOfYears = range(startYear,endYear+1) + + listOfListDoys = [] + if startYear == endYear: + doyList = range(startDoy,endDoy+1) + else: + for year in rangeOfYears: + if (year == startYear): + listOfListDoys.append(range(startDoy,365+1)) + elif (year == endYear): + listOfListDoys.append(range(1,endDoy+1)) + else: + listOfListDoys.append(range(1,365+1)) + doyList = [] + for list in listOfListDoys: + doyList = doyList + list + + folders = [] + for thisPath in os.listdir(path): + if os.path.isdir(os.path.join(path,thisPath)): + #folders.append(os.path.join(path,thisPath)) + folders.append(thisPath) + + pathList = [] + dicOfPath = {} + for year in rangeOfYears: + for doy in doyList: + tmp = fnmatch.filter(folders, 'D' + '%4.4d%3.3d' % (year,doy)) + if len(tmp) == 0: + continue + if expLabel == '': + pathList.append(os.path.join(path,tmp[0])) + dicOfPath.setdefault(os.path.join(path,tmp[0])) + dicOfPath[os.path.join(path,tmp[0])] = [] + else: + pathList.append(os.path.join(path,os.path.join(tmp[0],expLabel))) + dicOfPath.setdefault(os.path.join(path,os.path.join(tmp[0],expLabel))) + dicOfPath[os.path.join(path,os.path.join(tmp[0],expLabel))] = [] + + + filenameList = [] + for thisPath in pathList: + fileList = glob.glob1(thisPath, ext) + #dicOfPath[thisPath].append(fileList) + fileList.sort() + for file in fileList: + filename = os.path.join(thisPath,file) + if self.isThisFileinRange(filename, startUtSeconds, endUtSeconds): + filenameList.append(filename) + + self.filenameList = filenameList + + return pathList, filenameList + + def isThisFileinRange(self, filename, startUTSeconds=None, endUTSeconds=None): + + try: + fp = open(filename,'rb') + except: + raise IOError, "The file %s can't be opened" %(filename) + + if startUTSeconds==None: + startUTSeconds = self.startUTCSeconds + + if endUTSeconds==None: + endUTSeconds = self.endUTCSeconds + + m_BasicHeader = BasicHeader() + + if not(m_BasicHeader.read(fp)): + return 0 + + fp.close() + + if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): + return 0 + + return 1 + + def __readBasicHeader(self, fp=None): + + if fp == None: + fp = self.__fp + + self.m_BasicHeader.read(fp) + + def __readFirstHeader(self): + + self.__readBasicHeader() + self.__rdSystemHeader() + self.__rdRadarControllerHeader() + self.__rdProcessingHeader() + self.firstHeaderSize = self.m_BasicHeader.size + + data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) + if data_type == 0: + tmp=numpy.dtype([('real','= neededSize): + self.__readBasicHeader() + return 1 + + if not(self.__setNextFile()): + return 0 + + self.__readFirstHeader() + + deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this + + self.flagResetProcessing = 0 + 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.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels + + data = numpy.fromfile(self.__fp,self.__dataType,pts2read) + + data = data.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) + + self.__flagIsNewFile = 0 + + self.__buffer = data + + self.__buffer_id = 0 + + def readNextBlock(self): + + if not(self.__setNewBlock()): + return 0 + + self.__readBlock() + + self.__lastUTTime = self.m_BasicHeader.utc + + return 1 + + def __hasNotDataInBuffer(self): + if self.__buffer_id >= self.m_ProcessingHeader.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" + """ + self.flagResetProcessing = 0 + + if self.__hasNotDataInBuffer(): + self.readNextBlock() + + if self.noMoreFiles == 1: + print 'read finished' + return None + + data = self.__buffer[self.__buffer_id,:,:] + time = 111 + + self.m_Voltage.data = data + self.m_Voltage.timeProfile = time + self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() + self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() + self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() + self.m_Voltage.m_SystemHeader = self.m_systemHeader.copy() + + 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.__pathList = pathList + self.filenameList = filenameList + self.online = online + +class VoltageWriter(DataWriter): + + m_BasicHeader= BasicHeader() + + + m_SystemHeader = SystemHeader() + + + m_RadarControllerHeader = RadarControllerHeader() + + + m_ProcessingHeader = ProcessingHeader() + + m_Voltage = None + + def __init__(self, m_Voltage): + + self.m_Voltage = m_Voltage + + \ No newline at end of file diff --git a/schainpy/Model/Correlation.py b/schainpy/Model/Correlation.py new file mode 100644 index 0000000..3b74204 --- /dev/null +++ b/schainpy/Model/Correlation.py @@ -0,0 +1,17 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class Correlation(Data): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass \ No newline at end of file diff --git a/schainpy/Model/Data.py b/schainpy/Model/Data.py new file mode 100644 index 0000000..833706d --- /dev/null +++ b/schainpy/Model/Data.py @@ -0,0 +1,18 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class Data: + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass + \ No newline at end of file diff --git a/schainpy/Model/Noise.py b/schainpy/Model/Noise.py new file mode 100644 index 0000000..143f8bd --- /dev/null +++ b/schainpy/Model/Noise.py @@ -0,0 +1,18 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class Noise: + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass + \ No newline at end of file diff --git a/schainpy/Model/Spectra.py b/schainpy/Model/Spectra.py new file mode 100644 index 0000000..4b5d9b7 --- /dev/null +++ b/schainpy/Model/Spectra.py @@ -0,0 +1,18 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class Spectra(Data): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass + \ No newline at end of file diff --git a/schainpy/Model/Voltage.py b/schainpy/Model/Voltage.py new file mode 100644 index 0000000..888ee5c --- /dev/null +++ b/schainpy/Model/Voltage.py @@ -0,0 +1,18 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class Voltage(Data): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass + \ No newline at end of file diff --git a/schainpy/Model/__init__.py b/schainpy/Model/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schainpy/Model/__init__.py diff --git a/schainpy/Processing/CorrelationProcessor.py b/schainpy/Processing/CorrelationProcessor.py new file mode 100644 index 0000000..4707495 --- /dev/null +++ b/schainpy/Processing/CorrelationProcessor.py @@ -0,0 +1,17 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class CorrelationProcessor(): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass \ No newline at end of file diff --git a/schainpy/Processing/SpectraProcessor.py b/schainpy/Processing/SpectraProcessor.py new file mode 100644 index 0000000..baf7904 --- /dev/null +++ b/schainpy/Processing/SpectraProcessor.py @@ -0,0 +1,17 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class SpectraProcessor(): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass \ No newline at end of file diff --git a/schainpy/Processing/VoltageProcessor.py b/schainpy/Processing/VoltageProcessor.py new file mode 100644 index 0000000..35fab97 --- /dev/null +++ b/schainpy/Processing/VoltageProcessor.py @@ -0,0 +1,17 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class VoltageProcessor(): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass \ No newline at end of file diff --git a/schainpy/Processing/__init__.py b/schainpy/Processing/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schainpy/Processing/__init__.py diff --git a/schainpy/Utilities/FtpServer.py b/schainpy/Utilities/FtpServer.py new file mode 100644 index 0000000..f9c3949 --- /dev/null +++ b/schainpy/Utilities/FtpServer.py @@ -0,0 +1,18 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class FtpServer(): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass + \ No newline at end of file diff --git a/schainpy/Utilities/FtpServerList.py b/schainpy/Utilities/FtpServerList.py new file mode 100644 index 0000000..c5c8110 --- /dev/null +++ b/schainpy/Utilities/FtpServerList.py @@ -0,0 +1,17 @@ +''' +Created on Feb 7, 2012 + +@author: roj-idl71 +''' + +class FtpServerList(): + ''' + classdocs + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass \ No newline at end of file diff --git a/schainpy/Utilities/__init__.py b/schainpy/Utilities/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/schainpy/Utilities/__init__.py