diff --git a/schainpy/Controller/experiment.cfg b/schainpy/Controller/experiment.cfg index ca7e331..30996c1 100644 --- a/schainpy/Controller/experiment.cfg +++ b/schainpy/Controller/experiment.cfg @@ -1,23 +1,13 @@ [Read0] id = 0 type = VoltageReader -setup = str,/Users/jro/Documents/RadarData/EW_Drifts,datetime,2011-11-20-0-0-1,datetime,2011-12-31-0-0-1,int,0,str,,str,None,int,0 +setup = str,/Users/jro/Documents/RadarData/MST_ISR/MST,datetime,2009-01-01-0-0-1,datetime,2009-12-31-0-0-1,int,0,str,,str,None,int,0 getData = None,None [Processing0] id = 1 -type = Voltage -input = 0 -setup = None,None -init = None,None -integrator = int,4,None,None -plotData = float,None,float,None,float,None,float,None,str,iq,str,Test Data Voltage 2,int,1 - -[Processing1] -id = 2 type = Spectra -input = 1 -setup = int,8,None,None +input = 0 +setup = int,16,None,None init = None,None -integrator = int,4,int,3 -plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,2 +plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,1 diff --git a/schainpy/Graphics/BaseGraph.py b/schainpy/Graphics/BaseGraph.py index 3b7ce6a..9fefb7c 100644 --- a/schainpy/Graphics/BaseGraph.py +++ b/schainpy/Graphics/BaseGraph.py @@ -621,7 +621,7 @@ class ColorPlot: - def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): + def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, title = ''): """ Inputs: @@ -647,6 +647,7 @@ class ColorPlot: plplot.plschr(0.0, self.__szchar) self.__iniSubpage() + self.colorGraphObj.title = title self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax) self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) @@ -661,7 +662,7 @@ class ColorPlot: cmapObj.colorbarPlot(0., 1., zmin, zmax) if self.__showPowerProfile: - power = numpy.max(data, axis=0) + power = numpy.average(data, axis=0) step = (ymax - ymin)/(nY-1) heis = numpy.arange(ymin, ymax + step, step) diff --git a/schainpy/Graphics/SpectraPlot.py b/schainpy/Graphics/SpectraPlot.py index 20bc75d..0939108 100644 --- a/schainpy/Graphics/SpectraPlot.py +++ b/schainpy/Graphics/SpectraPlot.py @@ -154,7 +154,7 @@ class Spectrum: plplot.plsstrm(self.indexPlot) data = 10.*numpy.log10(self.spectraObj.data_spc) - + noise = 10.*numpy.log10(self.spectraObj.noise) #data.shape = Channels x Heights x Profiles # data = numpy.transpose( data, (0,2,1) ) #data.shape = Channels x Profiles x Heights @@ -186,7 +186,8 @@ class Spectrum: ymin=ymin, ymax=ymax, zmin=zmin, - zmax=zmax) + zmax=zmax, + title = "Channel: %d - Noise: %.2f" %(i, noise[i])) plplot.plssub(1,0) plplot.pladv(0) diff --git a/schainpy/IO/JRODataIO.py b/schainpy/IO/JRODataIO.py index e4dc4a0..eb905ba 100644 --- a/schainpy/IO/JRODataIO.py +++ b/schainpy/IO/JRODataIO.py @@ -179,7 +179,7 @@ class JRODataIO: m_ProcessingHeader = ProcessingHeader() - m_DataObj = None + dataOutObj = None online = 0 @@ -256,7 +256,7 @@ class JRODataReader(JRODataIO): nReadBlocks = 0 - def __init__(self, m_DataObj=None): + def __init__(self, dataOutObj=None): raise ValueError, "This class can't be instanced" @@ -280,6 +280,126 @@ class JRODataReader(JRODataIO): raise ValueError, "This method has not been implemented" + def createObjByDefault(self): + """ + Los objetos creados por defecto por cada clase (Voltaje o Espectro) difieren en el tipo + raise ValueError, "This method has not been implemented + """ + raise ValueError, "This method has not been implemented" + + def setup(self, dataOutObj=None, path=None, startDateTime=None, endDateTime=None, set=0, expLabel = "", ext = None, online = 0): + """ + setup configura los parametros de lectura de la clase DataReader. + + Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos + que coincidan con los parametros especificados; esta lista de archivos son almacenados en + self.filenameList. + + Input: + path : Directorios donde se ubican los datos a leer. Dentro de este + directorio deberia de estar subdirectorios de la forma: + + path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] + + startDateTime : Fecha inicial. Rechaza todos los archivos donde + file end time < startDatetime (obejto datetime.datetime) + + endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde + file end time < startDatetime (obejto datetime.datetime) + + set : Set del primer archivo a leer. Por defecto None + + expLabel : Nombre del subdirectorio de datos. Por defecto "" + + ext : Extension de los archivos a leer. Por defecto .r + + online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas + + Return: + 0 : Si no encuentra files que cumplan con las condiciones dadas + 1 : Si encuentra files que cumplan con las condiciones dadas + + Affected: + self.startUTCSeconds + self.endUTCSeconds + self.startYear + self.endYear + self.startDoy + self.endDoy + self.pathList + self.filenameList + self.online + """ + if path == None: + raise ValueError, "The path is not valid" + + if ext == None: + ext = self.ext + + if dataOutObj == None: + dataOutObj = self.createObjByDefault() + + self.dataOutObj = dataOutObj + + if online: + print "Searching files ..." + doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext) + + if not(doypath): + for nTries in range( self.nTries ): + print '\tWaiting %0.2f sec for valid file in %s: try %02d ...' % (self.delay, path, nTries+1) + time.sleep( self.delay ) + doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext) + if doypath: + break + + if not(doypath): + print "There 'isn't valied files in %s" % path + return None + + self.year = year + self.doy = doy + self.set = set - 1 + self.path = path + + else: # offline + pathList, filenameList = self.__searchFilesOffLine(path, startDateTime, endDateTime, set, expLabel, ext) + if not(pathList): + print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) + return None + + self.fileIndex = -1 + self.pathList = pathList + self.filenameList = filenameList + + self.online = online + self.ext = ext + + ext = ext.lower() + + if not( self.setNextFile() ): + if (startDateTime != None) and (endDateTime != None): + print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) + elif startDateTime != None: + print "No files in : %s" % startDateTime.ctime() + else: + print "No files" + return None + + if startDateTime != None: + self.startUTCSeconds = time.mktime(startDateTime.timetuple()) + self.startYear = startDateTime.timetuple().tm_year + self.startDoy = startDateTime.timetuple().tm_yday + + if endDateTime != None: + self.endUTCSeconds = time.mktime(endDateTime.timetuple()) + self.endYear = endDateTime.timetuple().tm_year + self.endDoy = endDateTime.timetuple().tm_yday + #call fillHeaderValues() - to Data Object + + self.updateDataHeader() + + return self.dataOutObj def __rdSystemHeader(self, fp=None): @@ -359,7 +479,9 @@ class JRODataReader(JRODataIO): self.ippSeconds = 2 * 1000 * self.m_RadarControllerHeader.ipp / self.c self.fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) - + self.dataOutObj.channelList = numpy.arange(self.m_SystemHeader.numChannels) + self.dataOutObj.channelIndexList = numpy.arange(self.m_SystemHeader.numChannels) + self.getBlockDimension() @@ -833,120 +955,14 @@ class JRODataReader(JRODataIO): def updateDataHeader(self): - self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy() - self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy() - self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() - self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy() - - self.m_DataObj.dataType = self.dataType - self.m_DataObj.updateObjFromHeader() - - def setup(self, path, startDateTime=None, endDateTime=None, set=0, expLabel = "", ext = None, online = 0): - """ - setup configura los parametros de lectura de la clase DataReader. - - Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos - que coincidan con los parametros especificados; esta lista de archivos son almacenados en - self.filenameList. - - Input: - path : Directorios donde se ubican los datos a leer. Dentro de este - directorio deberia de estar subdirectorios de la forma: - - path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] - - startDateTime : Fecha inicial. Rechaza todos los archivos donde - file end time < startDatetime (obejto datetime.datetime) - - endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde - file end time < startDatetime (obejto datetime.datetime) - - set : Set del primer archivo a leer. Por defecto None - - expLabel : Nombre del subdirectorio de datos. Por defecto "" - - ext : Extension de los archivos a leer. Por defecto .r - - online : Si es == a 0 entonces busca files que cumplan con las condiciones dadas - - Return: - 0 : Si no encuentra files que cumplan con las condiciones dadas - 1 : Si encuentra files que cumplan con las condiciones dadas - - Affected: - self.startUTCSeconds - self.endUTCSeconds - self.startYear - self.endYear - self.startDoy - self.endDoy - self.pathList - self.filenameList - self.online - """ + self.dataOutObj.m_BasicHeader = self.m_BasicHeader.copy() + self.dataOutObj.m_ProcessingHeader = self.m_ProcessingHeader.copy() + self.dataOutObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() + self.dataOutObj.m_SystemHeader = self.m_SystemHeader.copy() - if ext == None: - ext = self.ext - - if online: - print "Searching files ..." - doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext) + self.dataOutObj.dataType = self.dataType + self.dataOutObj.updateObjFromHeader() - if not(doypath): - for nTries in range( self.nTries ): - print '\tWaiting %0.2f sec for valid file in %s: try %02d ...' % (self.delay, path, nTries+1) - time.sleep( self.delay ) - doypath, file, year, doy, set = self.__searchFilesOnLine(path, startDateTime, endDateTime, expLabel, ext) - if doypath: - break - - if not(doypath): - print "There 'isn't valied files in %s" % path - return 0 - - self.year = year - self.doy = doy - self.set = set - 1 - self.path = path - - else: # offline - pathList, filenameList = self.__searchFilesOffLine(path, startDateTime, endDateTime, set, expLabel, ext) - if not(pathList): - print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) - return 0 - - self.fileIndex = -1 - self.pathList = pathList - self.filenameList = filenameList - - self.online = online - self.ext = ext - - ext = ext.lower() - - if not( self.setNextFile() ): - if (startDateTime != None) and (endDateTime != None): - print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) - elif startDateTime != None: - print "No files in : %s" % startDateTime.ctime() - else: - print "No files" - return 0 - - if startDateTime != None: - self.startUTCSeconds = time.mktime(startDateTime.timetuple()) - self.startYear = startDateTime.timetuple().tm_year - self.startDoy = startDateTime.timetuple().tm_yday - - if endDateTime != None: - self.endUTCSeconds = time.mktime(endDateTime.timetuple()) - self.endYear = endDateTime.timetuple().tm_year - self.endDoy = endDateTime.timetuple().tm_yday - #call fillHeaderValues() - to Data Object - - self.updateDataHeader() - - return 1 class JRODataWriter(JRODataIO): @@ -960,7 +976,7 @@ class JRODataWriter(JRODataIO): setFile = None - def __init__(self, m_DataObj=None): + def __init__(self, dataOutObj=None): raise ValueError, "Not implemented" @@ -994,7 +1010,7 @@ class JRODataWriter(JRODataIO): self.__wrSystemHeader() self.__wrRadarControllerHeader() self.__wrProcessingHeader() - self.dataType = self.m_DataObj.dataType + self.dataType = self.dataOutObj.dataType def __writeBasicHeader(self, fp=None): @@ -1007,7 +1023,7 @@ class JRODataWriter(JRODataIO): if fp == None: fp = self.fp - self.m_DataObj.m_BasicHeader.write(fp) + self.dataOutObj.m_BasicHeader.write(fp) def __wrSystemHeader(self, fp=None): @@ -1020,7 +1036,7 @@ class JRODataWriter(JRODataIO): if fp == None: fp = self.fp - self.m_DataObj.m_SystemHeader.write(fp) + self.dataOutObj.m_SystemHeader.write(fp) def __wrRadarControllerHeader(self, fp=None): @@ -1033,7 +1049,7 @@ class JRODataWriter(JRODataIO): if fp == None: fp = self.fp - self.m_DataObj.m_RadarControllerHeader.write(fp) + self.dataOutObj.m_RadarControllerHeader.write(fp) def __wrProcessingHeader(self, fp=None): @@ -1046,7 +1062,7 @@ class JRODataWriter(JRODataIO): if fp == None: fp = self.fp - self.m_DataObj.m_ProcessingHeader.write(fp) + self.dataOutObj.m_ProcessingHeader.write(fp) def setNextFile(self): @@ -1070,7 +1086,7 @@ class JRODataWriter(JRODataIO): if self.fp != None: self.fp.close() - timeTuple = time.localtime( self.m_DataObj.m_BasicHeader.utc ) + timeTuple = time.localtime( self.dataOutObj.m_BasicHeader.utc ) subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) doypath = os.path.join( path, subfolder ) @@ -1175,14 +1191,14 @@ class JRODataWriter(JRODataIO): Return: None """ - self.m_DataObj.updateHeaderFromObj() + self.dataOutObj.updateHeaderFromObj() - self.m_BasicHeader = self.m_DataObj.m_BasicHeader.copy() - self.m_SystemHeader = self.m_DataObj.m_SystemHeader.copy() - self.m_RadarControllerHeader = self.m_DataObj.m_RadarControllerHeader.copy() - self.m_ProcessingHeader = self.m_DataObj.m_ProcessingHeader.copy() + self.m_BasicHeader = self.dataOutObj.m_BasicHeader.copy() + self.m_SystemHeader = self.dataOutObj.m_SystemHeader.copy() + self.m_RadarControllerHeader = self.dataOutObj.m_RadarControllerHeader.copy() + self.m_ProcessingHeader = self.dataOutObj.m_ProcessingHeader.copy() - self.dataType = self.m_DataObj.dataType + self.dataType = self.dataOutObj.dataType def setup(self, path, set=0, ext=None): diff --git a/schainpy/IO/SpectraIO.py b/schainpy/IO/SpectraIO.py index 5625e71..a1826b3 100644 --- a/schainpy/IO/SpectraIO.py +++ b/schainpy/IO/SpectraIO.py @@ -53,13 +53,13 @@ class SpectraReader(JRODataReader): readerObj.getData() - print readerObj.m_Spectra.data + print readerObj.dataOutObj.data if readerObj.flagNoMoreFiles: break """ - m_DataObj = None + dataOutObj = None data_spc = None data_cspc = None @@ -70,19 +70,16 @@ class SpectraReader(JRODataReader): pts2read_DCchannels = 0 nChannels = 0 - nPairs = 0 - #pairList = None - - channelList = None + flag_cspc = False - def __init__(self, m_Spectra=None): + def __init__(self, dataOutObj=None): """ Inicializador de la clase SpectraReader para la lectura de datos de espectros. Inputs: - m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para + dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para almacenar un perfil de datos cada vez que se haga un requerimiento (getData). El perfil sera obtenido a partir del buffer de datos, si el buffer esta vacio se hara un nuevo proceso de lectura de un @@ -90,17 +87,10 @@ class SpectraReader(JRODataReader): Si este parametro no es pasado se creara uno internamente. Affected: - self.m_DataObj + self.dataOutObj Return : None """ - if m_Spectra == None: - m_Spectra = Spectra() - - if not( isinstance(m_Spectra, Spectra) ): - raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object" - - self.m_DataObj = m_Spectra self.data_spc = None self.data_cspc = None @@ -174,13 +164,12 @@ class SpectraReader(JRODataReader): self.blocksize = 0 - #pairList = None - - channelList = None + def createObjByDefault(self): - self.flag_cspc = False - - + dataObj = Spectra() + + return dataObj + def __hasNotDataInBuffer(self): return 1 @@ -196,8 +185,8 @@ class SpectraReader(JRODataReader): self.pts2read_CrossSpectra self.pts2read_DCchannels self.blocksize - self.m_DataObj.nChannels - self.m_DataObj.nPairs + self.dataOutObj.nChannels + self.dataOutObj.nPairs Return: None @@ -212,16 +201,13 @@ class SpectraReader(JRODataReader): else: self.nPairs = self.nPairs + 1 #par de canales diferentes self.pairList.append( (self.m_ProcessingHeader.spectraComb[i], self.m_ProcessingHeader.spectraComb[i+1]) ) - - if self.nPairs > 0: - self.flag_cspc = True pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock self.pts2read_SelfSpectra = int(self.nChannels * pts2read) self.blocksize = self.pts2read_SelfSpectra - if self.flag_cspc: + if self.m_ProcessingHeader.flag_cspc: self.pts2read_CrossSpectra = int(self.nPairs * pts2read) self.blocksize += self.pts2read_CrossSpectra @@ -230,8 +216,6 @@ class SpectraReader(JRODataReader): self.blocksize += self.pts2read_DCchannels # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels - - self.channelList = numpy.arange(self.nChannels) def readBlock(self): @@ -312,7 +296,7 @@ class SpectraReader(JRODataReader): 1 : Si hizo una buena copia del buffer Affected: - self.m_DataObj + self.dataOutObj self.datablockIndex self.flagResetProcessing self.flagIsNewBlock @@ -337,15 +321,15 @@ class SpectraReader(JRODataReader): #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) if self.data_dc == None: - self.m_DataObj.flagNoData = True + self.dataOutObj.flagNoData = True return 0 - self.m_DataObj.flagNoData = False - self.m_DataObj.flagResetProcessing = self.flagResetProcessing + self.dataOutObj.flagNoData = False + self.dataOutObj.flagResetProcessing = self.flagResetProcessing - self.m_DataObj.data_spc = self.data_spc - self.m_DataObj.data_cspc = self.data_cspc - self.m_DataObj.data_dc = self.data_dc + self.dataOutObj.data_spc = self.data_spc + self.dataOutObj.data_cspc = self.data_cspc + self.dataOutObj.data_dc = self.data_dc return 1 @@ -357,7 +341,7 @@ class SpectraWriter(JRODataWriter): de los datos siempre se realiza por bloques. """ - m_DataObj = None + dataOutObj = None shape_spc_Buffer = None shape_cspc_Buffer = None @@ -368,12 +352,12 @@ class SpectraWriter(JRODataWriter): data_dc = None - def __init__(self, m_Spectra=None): + def __init__(self, dataOutObj=None): """ Inicializador de la clase SpectraWriter para la escritura de datos de espectros. Affected: - self.m_DataObj + self.dataOutObj self.m_BasicHeader self.m_SystemHeader self.m_RadarControllerHeader @@ -381,13 +365,13 @@ class SpectraWriter(JRODataWriter): Return: None """ - if m_Spectra == None: - m_Spectra = Spectra() + if dataOutObj == None: + dataOutObj = Spectra() - if not( isinstance(m_Spectra, Spectra) ): - raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object" + if not( isinstance(dataOutObj, Spectra) ): + raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object" - self.m_DataObj = m_Spectra + self.dataOutObj = dataOutObj self.ext = ".pdata" @@ -449,11 +433,11 @@ class SpectraWriter(JRODataWriter): Return: None """ - self.shape_spc_Buffer = (self.m_DataObj.nChannels, + self.shape_spc_Buffer = (self.dataOutObj.nChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) - self.shape_cspc_Buffer = (self.m_DataObj.nPairs, + self.shape_cspc_Buffer = (self.dataOutObj.nPairs, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) @@ -526,18 +510,18 @@ class SpectraWriter(JRODataWriter): """ self.flagIsNewBlock = 0 - if self.m_DataObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 - if self.m_DataObj.flagResetProcessing: + if self.dataOutObj.flagResetProcessing: self.data_spc.fill(0) self.data_cspc.fill(0) self.data_dc.fill(0) self.setNextFile() - self.data_spc = self.m_DataObj.data_spc - self.data_cspc = self.m_DataObj.data_cspc - self.data_dc = self.m_DataObj.data_dc + self.data_spc = self.dataOutObj.data_spc + self.data_cspc = self.dataOutObj.data_cspc + self.data_dc = self.dataOutObj.data_dc # #self.m_ProcessingHeader.dataBlocksPerFile) if self.hasAllDataInBuffer(): diff --git a/schainpy/IO/VoltageIO.py b/schainpy/IO/VoltageIO.py index 049721a..e06d049 100644 --- a/schainpy/IO/VoltageIO.py +++ b/schainpy/IO/VoltageIO.py @@ -61,7 +61,7 @@ class VoltageReader(JRODataReader): break """ - m_DataObj = None + dataOutObj = None datablock = None @@ -70,12 +70,12 @@ class VoltageReader(JRODataReader): optchar = "D" - def __init__(self, m_Voltage=None): + def __init__(self, dataOutObj=None): """ Inicializador de la clase VoltageReader para la lectura de datos de voltage. Input: - m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para + dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para almacenar un perfil de datos cada vez que se haga un requerimiento (getData). El perfil sera obtenido a partir del buffer de datos, si el buffer esta vacio se hara un nuevo proceso de lectura de un @@ -83,18 +83,11 @@ class VoltageReader(JRODataReader): Si este parametro no es pasado se creara uno internamente. Variables afectadas: - self.m_DataObj + self.dataOutObj Return: None """ - if m_Voltage == None: - m_Voltage = Voltage() - - if not(isinstance(m_Voltage, Voltage)): - raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object" - - self.m_DataObj = m_Voltage self.datablock = None @@ -172,6 +165,12 @@ class VoltageReader(JRODataReader): self.blocksize = 0 + def createObjByDefault(self): + + dataObj = Voltage() + + return dataObj + def __hasNotDataInBuffer(self): if self.profileIndex >= self.m_ProcessingHeader.profilesPerBlock: return 1 @@ -251,11 +250,11 @@ class VoltageReader(JRODataReader): buffer. Si no hay mas archivos a leer retorna None. Variables afectadas: - self.m_DataObj + self.dataOutObj self.profileIndex Affected: - self.m_DataObj + self.dataOutObj self.profileIndex self.flagResetProcessing self.flagIsNewBlock @@ -279,22 +278,22 @@ class VoltageReader(JRODataReader): #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) if self.datablock == None: - self.m_DataObj.flagNoData = True + self.dataOutObj.flagNoData = True return 0 time = self.m_BasicHeader.utc + self.profileIndex * self.ippSeconds - self.m_DataObj.m_BasicHeader.utc = time + self.dataOutObj.m_BasicHeader.utc = time - self.m_DataObj.flagNoData = False - self.m_DataObj.flagResetProcessing = self.flagResetProcessing + self.dataOutObj.flagNoData = False + self.dataOutObj.flagResetProcessing = self.flagResetProcessing - self.m_DataObj.data = self.datablock[:,self.profileIndex,:] + self.dataOutObj.data = self.datablock[:,self.profileIndex,:] self.profileIndex += 1 #call setData - to Data Object - return 1 #self.m_DataObj.data + return 1 #self.dataOutObj.data class VoltageWriter(JRODataWriter): @@ -304,7 +303,7 @@ class VoltageWriter(JRODataWriter): """ __configHeaderFile = 'wrSetHeadet.txt' - m_DataObj = None + dataOutObj = None ext = ".r" @@ -317,22 +316,22 @@ class VoltageWriter(JRODataWriter): shapeBuffer = None - def __init__(self, m_Voltage=None): + def __init__(self, dataOutObj=None): """ Inicializador de la clase VoltageWriter para la escritura de datos de espectros. Affected: - self.m_DataObj + self.dataOutObj Return: None """ - if m_Voltage == None: - m_Voltage = Voltage() + if dataOutObj == None: + dataOutObj = Voltage() - if not( isinstance(m_Voltage, Voltage) ): - raise ValueError, "in VoltageReader, m_Voltage must be an Spectra class object" + if not( isinstance(dataOutObj, Voltage) ): + raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object" - self.m_DataObj = m_Voltage + self.dataOutObj = dataOutObj def hasAllDataInBuffer(self): @@ -408,16 +407,16 @@ class VoltageWriter(JRODataWriter): """ self.flagIsNewBlock = 0 - if self.m_DataObj.flagNoData: + if self.dataOutObj.flagNoData: return 0 - if self.m_DataObj.flagResetProcessing: + if self.dataOutObj.flagResetProcessing: self.datablock.fill(0) self.profileIndex = 0 self.setNextFile() - self.datablock[:,self.profileIndex,:] = self.m_DataObj.data + self.datablock[:,self.profileIndex,:] = self.dataOutObj.data self.profileIndex += 1 diff --git a/schainpy/Model/JROData.py b/schainpy/Model/JROData.py index 02d239e..3f75c87 100644 --- a/schainpy/Model/JROData.py +++ b/schainpy/Model/JROData.py @@ -32,16 +32,7 @@ class Data: return copy.deepcopy(self) -class Noise(Data): - ''' - classdocs - ''' - def __init__(self): - ''' - Constructor - ''' - pass class JROData(Data): ''' @@ -56,7 +47,7 @@ class JROData(Data): m_BasicHeader = BasicHeader() - m_NoiseObj = Noise() + noise = None type = None @@ -72,6 +63,10 @@ class JROData(Data): channelList = None + channelIndexList = None + + pairList = None + flagNoData = False flagResetProcessing = False @@ -101,6 +96,7 @@ class JROData(Data): xf = xi + self.m_ProcessingHeader.numHeights*step self.heightList = numpy.arange(xi, xf, step) + self.channelIndexList = numpy.arange(self.m_SystemHeader.numChannels) self.channelList = numpy.arange(self.m_SystemHeader.numChannels) self.nHeights = len(self.heightList) diff --git a/schainpy/Model/JROHeader.py b/schainpy/Model/JROHeader.py index dee0d03..8ec4b69 100644 --- a/schainpy/Model/JROHeader.py +++ b/schainpy/Model/JROHeader.py @@ -307,6 +307,8 @@ class ProcessingHeader(Header): incoherentInt = None totalSpectra = None struct = None + flag_dc = None + flag_cspc = None def __init__(self): self.size = 0 @@ -343,6 +345,7 @@ class ProcessingHeader(Header): self.numBaud = 0 self.shif_fft = False self.flag_dc = False + self.flag_cspc = False def read(self, fp): try: @@ -376,6 +379,22 @@ class ProcessingHeader(Header): if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): self.flag_dc = True + + nChannels = 0 + nPairs = 0 + pairList = [] + + for i in range( 0, self.totalSpectra*2, 2 ): + if self.spectraComb[i] == self.spectraComb[i+1]: + nChannels = nChannels + 1 #par de canales iguales + else: + nPairs = nPairs + 1 #par de canales diferentes + pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) + + self.flag_cspc = False + if nPairs > 0: + self.flag_cspc = True + except: return 0 diff --git a/schainpy/Model/Spectra.py b/schainpy/Model/Spectra.py index cd6bf73..f01c604 100644 --- a/schainpy/Model/Spectra.py +++ b/schainpy/Model/Spectra.py @@ -5,7 +5,7 @@ Created on Feb 7, 2012 @version $Id$ ''' -from JROData import JROData, Noise +from JROData import JROData from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader class Spectra(JROData): @@ -39,8 +39,6 @@ class Spectra(JROData): self.m_BasicHeader = BasicHeader() - self.m_NoiseObj = Noise() - self.type = "Spectra" self.dataType = None diff --git a/schainpy/Model/Voltage.py b/schainpy/Model/Voltage.py index e2d98fe..f06c2ea 100644 --- a/schainpy/Model/Voltage.py +++ b/schainpy/Model/Voltage.py @@ -5,7 +5,7 @@ Created on Feb 7, 2012 @version $Id$ ''' -from JROData import JROData, Noise +from JROData import JROData from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader class Voltage(JROData): @@ -32,8 +32,6 @@ class Voltage(JROData): self.m_BasicHeader = BasicHeader() - self.m_NoiseObj = Noise() - self.type = "Voltage" #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) diff --git a/schainpy/Processing/Noise.py b/schainpy/Processing/JRONoise.py similarity index 57% rename from schainpy/Processing/Noise.py rename to schainpy/Processing/JRONoise.py index fde1858..e1a4379 100644 --- a/schainpy/Processing/Noise.py +++ b/schainpy/Processing/JRONoise.py @@ -1,7 +1,7 @@ import numpy from Model.Spectra import Spectra -def hildebrand_sekhon(Data, navg=1): +def hildebrand_sekhon(Data, navg): """ This method is for the objective determination of de noise level in Doppler spectra. This implementation technique is based on the fact that the standard deviation of the spectral @@ -15,6 +15,7 @@ def hildebrand_sekhon(Data, navg=1): -1 : any error anoise : noise's level """ + divisor = 8 ratio = 7 / divisor data = Data.reshape(-1) @@ -63,50 +64,150 @@ def hildebrand_sekhon(Data, navg=1): return anoise; +def sorting_bruce(Data, navg): + sortdata = numpy.sort(Data) + lenOfData = len(Data) + nums_min = lenOfData/10 + + if (lenOfData/10) > 0: + nums_min = lenOfData/10 + else: + nums_min = 0 + + rtest = 1.0 + 1.0/navg + + sum = 0. + + sumq = 0. + + j = 0 + + cont = 1 + + while((cont==1)and(j nums_min: + if ((sumq*j) <= (rtest*sum**2)): + lnoise = sum / j + else: + j = j - 1 + sum = sum - sordata[j] + sumq = sumq - sordata[j]**2 + cont = 0 + + if j == nums_min: + lnoise = sum /j + + return lnoise class Noise: """ Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler """ - m_DataObj = None + data = None + noise = None + dim = None + def __init__(self, data=None): + """ + Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. - def __init__(self, m_Spectra=None): + Inputs: + data: Numpy array de la forma nChan x nHeis x nProfiles + + Affected: + self.noise + + Return: + None + """ + + self.data = data + self.dim = None + self.nChannels = None + self.noise = None + + def setNoise(self, data): """ Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. + Inputs: + data: Numpy array de la forma nChan x nHeis x nProfiles + Affected: - self.m_DataObj + self.noise Return: None """ - if m_Spectra == None: - m_Spectra = Spectra() - if not(isinstance(m_Spectra, Spectra)): - raise ValueError, "in Noise class, m_Spectra must be an Spectra class object" + if data == None: + return 0 + + shape = data.shape + self.dim = len(shape) + if self.dim == 3: + nChan, nProfiles, nHeis = shape + elif self.dim == 2: + nChan, nHeis = shape + else: + raise ValueError, "" - self.m_DataObj = m_Spectra + self.nChannels = nChan + self.data = data.copy() + self.noise = numpy.zeros(nChan) + return 1 + - def getNoiseLevelByHildebrandSekhon(self): + def byHildebrand(self, navg=1): """ Determino el nivel de ruido usando el metodo Hildebrand-Sekhon Return: - noise level + noiselevel """ - data = self.m_DataObj.data_spc + daux = None - for channel in range(self.m_DataObj.nChannels): + for channel in range(self.nChannels): + daux = self.data[channel,:,:] + self.noise[channel] = hildebrand_sekhon(daux, navg) + return self.noise + + def byWindow(self, heiIndexMin, heiIndexMax, freqIndexMin, freqIndexMax): + """ + Determina el ruido del canal utilizando la ventana indicada con las coordenadas: + (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) + + Inputs: + heiIndexMin: Limite inferior del eje de alturas + heiIndexMax: Limite superior del eje de alturas + freqIndexMin: Limite inferior del eje de frecuencia + freqIndexMax: Limite supoerior del eje de frecuencia + """ + + data = self.data[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] + + for channel in range(self.nChannels): daux = data[channel,:,:] - noiselevel = hildebrand_sekhon(daux) - print noiselevel + self.noise[channel] = numpy.average(daux) + return self.noise + + def bySort(self,navg = 1): + daux = None + + for channel in range(self.nChannels): + daux = self.data[channel,:,:] + self.noise[channel] = sorting_bruce(daux, navg) + + return self.noise - for pair in range(self.m_DataObj.nPairs): - daux = data[pair,:,:] - noiselevel = hildebrand_sekhon(daux) - print noiselevel + \ No newline at end of file diff --git a/schainpy/Processing/SpectraProcessor.py b/schainpy/Processing/SpectraProcessor.py index fd75b7d..38c076a 100644 --- a/schainpy/Processing/SpectraProcessor.py +++ b/schainpy/Processing/SpectraProcessor.py @@ -13,7 +13,7 @@ sys.path.append(path) from Model.Spectra import Spectra from IO.SpectraIO import SpectraWriter from Graphics.SpectraPlot import Spectrum - +from JRONoise import Noise class SpectraProcessor: ''' @@ -24,13 +24,7 @@ class SpectraProcessor: dataOutObj = None - integratorObjIndex = None - - decoderObjIndex = None - - writerObjIndex = None - - plotterObjIndex = None + noiseObj = None integratorObjList = [] @@ -40,26 +34,34 @@ class SpectraProcessor: plotterObjList = [] + integratorObjIndex = None + + decoderObjIndex = None + + writerObjIndex = None + + plotterObjIndex = None + buffer = None - ptsId = 0 + profIndex = 0 nFFTPoints = None + nChannels = None + + nHeights = None + + nPairs = None + pairList = None - def __init__(self, dataInObj=None, dataOutObj=None): + def __init__(self): ''' Constructor ''' - self.dataInObj = dataInObj - if dataOutObj == None: - self.dataOutObj = Spectra() - else: - self.dataOutObj = dataOutObj - self.integratorObjIndex = None self.decoderObjIndex = None self.writerObjIndex = None @@ -70,30 +72,79 @@ class SpectraProcessor: self.writerObjList = [] self.plotterObjList = [] + self.noiseObj = Noise() self.buffer = None - self.ptsId = 0 - - def setIO(self,inputObject, outputObject): - -# if not( isinstance(inputObject, Voltage) ): -# print 'InputObject must be an instance from Voltage()' -# sys.exit(0) + self.profIndex = 0 - if not( isinstance(outputObject, Spectra) ): - print 'OutputObject must be an instance from Spectra()' - sys.exit(0) + def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None): - self.dataInObj = inputObject - self.dataOutObj = outputObject + if dataInObj == None: + raise ValueError, "" - def setup(self,nFFTPoints=None, pairList=None): if nFFTPoints == None: - nFFTPoints = self.dataOutObj.nFFTPoints + raise ValueError, "" + + self.dataInObj = dataInObj + if dataOutObj == None: + dataOutObj = Spectra() + + self.dataOutObj = dataOutObj + self.noiseObj = Noise() + + ########################################## self.nFFTPoints = nFFTPoints + self.nChannels = self.dataInObj.nChannels + self.nHeights = self.dataInObj.nHeights self.pairList = pairList + if pairList != None: + self.nPairs = len(pairList) + else: + self.nPairs = 0 + + self.dataOutObj.heightList = self.dataInObj.heightList + self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList + self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() + self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() + self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() + self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() + + self.dataOutObj.dataType = self.dataInObj.dataType + self.dataOutObj.nPairs = self.nPairs + self.dataOutObj.nChannels = self.nChannels + self.dataOutObj.nProfiles = self.nFFTPoints + self.dataOutObj.nHeights = self.nHeights + self.dataOutObj.nFFTPoints = self.nFFTPoints + #self.dataOutObj.data = None + + self.dataOutObj.m_SystemHeader.numChannels = self.nChannels + self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints + + self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs + self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints + self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights + self.dataOutObj.m_ProcessingHeader.shif_fft = True + + spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1')) + k = 0 + for i in range( 0,self.nChannels*2,2 ): + spectraComb[i] = k + spectraComb[i+1] = k + k += 1 + + k *= 2 + + if self.pairList != None: + + for pair in self.pairList: + spectraComb[k] = pair[0] + spectraComb[k+1] = pair[1] + k += 2 + + self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb + + return self.dataOutObj -# def init(self, nFFTPoints, pairList=None): def init(self): self.integratorObjIndex = 0 @@ -101,18 +152,37 @@ class SpectraProcessor: self.writerObjIndex = 0 self.plotterObjIndex = 0 -# if nFFTPoints == None: -# nFFTPoints = self.dataOutObj.nFFTPoints -# -# self.nFFTPoints = nFFTPoints -# self.pairList = pairList -# - if not( isinstance(self.dataInObj, Spectra) ): - self.__getFft() - else: + if self.dataInObj.type == "Voltage": + + if self.buffer == None: + self.buffer = numpy.zeros((self.nChannels, + self.nFFTPoints, + self.nHeights), + dtype='complex') + + self.buffer[:,self.profIndex,:] = self.dataInObj.data + self.profIndex += 1 + + if self.profIndex == self.nFFTPoints: + self.__getFft() + self.dataOutObj.flagNoData = False + + self.buffer = None + self.profIndex = 0 + return + + self.dataOutObj.flagNoData = True + + return + + #Other kind of data + if self.dataInObj.type == "Spectra": self.dataOutObj.copy(self.dataInObj) - - + self.dataOutObj.flagNoData = False + return + + raise ValueError, "The datatype is not valid" + def __getFft(self): """ Convierte valores de Voltaje a Spectra @@ -126,7 +196,7 @@ class SpectraProcessor: self.dataOutObj.m_ProcessingHeader self.dataOutObj.m_RadarControllerHeader self.dataOutObj.m_SystemHeader - self.ptsId + self.profIndex self.buffer self.dataOutObj.flagNoData self.dataOutObj.dataType @@ -142,20 +212,6 @@ class SpectraProcessor: """ if self.dataInObj.flagNoData: return 0 - - blocksize = 0 - nFFTPoints = self.nFFTPoints - nChannels, nheis = self.dataInObj.data.shape - - if self.buffer == None: - self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex') - - self.buffer[:,self.ptsId,:] = self.dataInObj.data - self.ptsId += 1 - - if self.ptsId < self.nFFTPoints: - self.dataOutObj.flagNoData = True - return fft_volt = numpy.fft.fft(self.buffer,axis=1) dc = fft_volt[:,0,:] @@ -164,69 +220,24 @@ class SpectraProcessor: fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) + blocksize = 0 blocksize += dc.size blocksize += spc.size cspc = None - nPair = 0 + pairIndex = 0 if self.pairList != None: #calculo de cross-spectra - nPairs = len(self.pairList) - cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex') + cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex') for pair in self.pairList: - cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) - nPair += 1 + cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) + pairIndex += 1 blocksize += cspc.size self.dataOutObj.data_spc = spc self.dataOutObj.data_cspc = cspc self.dataOutObj.data_dc = dc - - self.ptsId = 0 - self.buffer = None - self.dataOutObj.flagNoData = False - - self.dataOutObj.heightList = self.dataInObj.heightList - self.dataOutObj.channelList = self.dataInObj.channelList - self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() - self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() - self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() - self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() - - self.dataOutObj.dataType = self.dataInObj.dataType - self.dataOutObj.nPairs = nPair - self.dataOutObj.nChannels = nChannels - self.dataOutObj.nProfiles = nFFTPoints - self.dataOutObj.nHeights = nheis - self.dataOutObj.nFFTPoints = nFFTPoints - #self.dataOutObj.data = None - - self.dataOutObj.m_SystemHeader.numChannels = nChannels - self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints - self.dataOutObj.m_ProcessingHeader.blockSize = blocksize - self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair - self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints - self.dataOutObj.m_ProcessingHeader.numHeights = nheis - self.dataOutObj.m_ProcessingHeader.shif_fft = True - - spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1')) - k = 0 - for i in range( 0,nChannels*2,2 ): - spectraComb[i] = k - spectraComb[i+1] = k - k += 1 - - k *= 2 - - if self.pairList != None: - - for pair in self.pairList: - spectraComb[k] = pair[0] - spectraComb[k+1] = pair[1] - k += 2 - - self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb def addWriter(self,wrpath): @@ -289,36 +300,93 @@ class SpectraProcessor: #print "myIncohIntObj.navg: ",myIncohIntObj.navg self.dataOutObj.flagNoData = False + self.getNoise(type="hildebrand",parm=myIncohIntObj.navg) +# self.getNoise(type="sort", parm=16) + else: self.dataOutObj.flagNoData = True self.integratorObjIndex += 1 - + + """Calcular el ruido""" +# self.getNoise(type="hildebrand", parm=1) + def removeDC(self, type): if self.dataOutObj.flagNoData: return 0 - pass def removeInterference(self): if self.dataOutObj.flagNoData: return 0 - pass def removeSatellites(self): if self.dataOutObj.flagNoData: return 0 - pass - def selectChannels(self, channelList, pairList=None): + def getNoise(self, type="hildebrand", parm=None): + + self.noiseObj.setNoise(self.dataOutObj.data_spc) + + if type == "hildebrand": + noise = self.noiseObj.byHildebrand(parm) + + if type == "window": + noise = self.noiseObj.byWindow(parm) + + if type == "sort": + noise = self.noiseObj.bySort(parm) + + self.dataOutObj.noise = noise + print 10*numpy.log10(noise) + + def selectChannels(self, channelList, pairList=[]): + + channelIndexList = [] + + for channel in channelList: + if channel in self.dataOutObj.channelList: + index = self.dataOutObj.channelList.index(channel) + channelIndexList.append(index) + + pairIndexList = [] + + for pair in pairList: + if pair in self.dataOutObj.pairList: + index = self.dataOutObj.pairList.index(pair) + pairIndexList.append(index) + + self.selectChannelsByIndex(channelIndexList, pairIndexList) + + def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]): """ - Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList + Selecciona un bloque de datos en base a canales y pares segun el + channelIndexList y el pairIndexList Input: - channelList : lista sencilla de canales a seleccionar por ej. (2,3,7) - pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) ) + channelIndexList : lista de indices de los canales a seleccionar por ej. + + Si tenemos los canales + + self.channelList = (2,3,5,7) + + y deseamos escoger los canales (3,7) + entonces colocaremos el parametro + + channelndexList = (1,3) + + pairIndexList : tupla de indice depares que se desea selecionar por ej. + + Si tenemos los pares : + + ( (0,1), (0,2), (1,3), (2,5) ) + + y deseamos seleccionar los pares ((0,2), (2,5)) + entonces colocaremos el parametro + + pairIndexList = (1,3) Affected: self.dataOutObj.data_spc @@ -329,6 +397,7 @@ class SpectraProcessor: self.dataOutObj.m_ProcessingHeader.spectraComb self.dataOutObj.m_SystemHeader.numChannels + self.dataOutObj.noise Return: None """ @@ -336,71 +405,35 @@ class SpectraProcessor: if self.dataOutObj.flagNoData: return 0 - channelIndexList = [] - for channel in channelList: - if channel in self.dataOutObj.channelList: - index = self.dataOutObj.channelList.index(channel) - channelIndexList.append(index) - continue - - raise ValueError, "The value %d in channelList is not valid" %channel - - nProfiles = self.dataOutObj.nProfiles - #dataType = self.dataOutObj.dataType - nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights - blocksize = 0 - - #self spectra + if pairIndexList == []: + pairIndexList = numpy.arange(len(self.dataOutObj.pairList)) + nChannels = len(channelIndexList) - spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] ) - - for index, channel in enumerate(channelIndexList): - spc[index,:,:] = self.dataOutObj.data_spc[index,:,:] + nPairs = len(pairIndexList) - #DC channel - dc = numpy.zeros( (nChannels,nHeights), dtype='complex' ) - for index, channel in enumerate(channelIndexList): - dc[index,:] = self.dataOutObj.data_dc[channel,:] - - blocksize += dc.size + blocksize = 0 + #self spectra + spc = self.dataOutObj.data_spc[channelIndexList,:,:] blocksize += spc.size - - nPairs = 0 - cspc = None - if pairList == None: - pairList = self.pairList - - if (pairList != None) and (self.dataOutObj.data_cspc != None): - #cross spectra - nPairs = len(pairList) - cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' ) - - spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb - totalSpectra = len(spectraComb) - nchan = self.dataOutObj.nChannels - pairIndexList = [] - - for pair in pairList: #busco el par en la lista de pares del Spectra Combinations - for index in range(0,totalSpectra,2): - if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]: - pairIndexList.append( index/2 - nchan ) - - for index, pair in enumerate(pairIndexList): - cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:] + cspc = None + if pairIndexList != []: + cspc = self.dataOutObj.data_cspc[pairIndexList,:,:] blocksize += cspc.size - - else: - pairList = self.pairList - cspc = self.dataOutObj.data_cspc - if cspc != None: - blocksize += cspc.size + #DC channel + dc = None + if self.dataOutObj.m_ProcessingHeader.flag_dc: + dc = self.dataOutObj.data_dc[channelIndexList,:] + blocksize += dc.size + + #Almacenar las combinaciones de canales y cros espectros + spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) i = 0 - for val in channelList: - spectraComb[i] = val - spectraComb[i+1] = val + for spcChannel in channelIndexList: + spectraComb[i] = spcChannel + spectraComb[i+1] = spcChannel i += 2 if pairList != None: @@ -408,21 +441,28 @@ class SpectraProcessor: spectraComb[i] = pair[0] spectraComb[i+1] = pair[1] i += 2 - + + ####### + self.dataOutObj.data_spc = spc self.dataOutObj.data_cspc = cspc self.dataOutObj.data_dc = dc self.dataOutObj.nChannels = nChannels self.dataOutObj.nPairs = nPairs - self.dataOutObj.channelList = channelList + self.dataOutObj.channelIndexList = channelIndexList self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs self.dataOutObj.m_SystemHeader.numChannels = nChannels self.dataOutObj.nChannels = nChannels self.dataOutObj.m_ProcessingHeader.blockSize = blocksize - + + if cspc == None: + self.dataOutObj.m_ProcessingHeader.flag_dc = False + if dc == None: + self.dataOutObj.m_ProcessingHeader.flag_cpsc = False + def selectHeightsByValue(self, minHei, maxHei): """ Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango diff --git a/schainpy/Processing/VoltageProcessor.py b/schainpy/Processing/VoltageProcessor.py index bb86cb1..c5be060 100644 --- a/schainpy/Processing/VoltageProcessor.py +++ b/schainpy/Processing/VoltageProcessor.py @@ -22,7 +22,7 @@ class VoltageProcessor: dataInObj = None dataOutObj = None - + integratorObjIndex = None decoderObjIndex = None profSelectorObjIndex = None @@ -37,17 +37,10 @@ class VoltageProcessor: plotterObjList = [] m_Voltage= Voltage() - def __init__(self, dataInObj=None, dataOutObj=None): + def __init__(self): ''' Constructor ''' - - self.dataInObj = dataInObj - - if dataOutObj == None: - self.dataOutObj = Voltage() - else: - self.dataOutObj = dataOutObj self.integratorObjIndex = None self.decoderObjIndex = None @@ -60,22 +53,20 @@ class VoltageProcessor: self.profileSelectorObjList = [] self.writerObjList = [] self.plotterObjList = [] - - def setIO(self,inputObject, outputObject): - if not( isinstance(inputObject, Voltage) ): - print 'InputObject must be an instance from Voltage()' - sys.exit(0) + def setup(self, dataInObj=None, dataOutObj=None): - if not( isinstance(outputObject, Voltage) ): - print 'OutputObject must be an instance from Voltage()' - sys.exit(0) + self.dataInObj = dataInObj + + if dataOutObj == None: + dataOutObj = Voltage() - self.dataInObj = inputObject - self.dataOutObj = outputObject + dataOutObj.copy(dataInObj) + + self.dataOutObj = dataOutObj + + return self.dataOutObj - def setup(self): - pass def init(self): @@ -217,15 +208,18 @@ class VoltageProcessor: self.flipIndex *= -1. def selectChannels(self, channelList): + pass + + def selectChannelsByIndex(self, channelIndexList): """ - Selecciona un bloque de datos en base a canales segun el channelList + Selecciona un bloque de datos en base a canales segun el channelIndexList Input: - channelList : lista sencilla de canales a seleccionar por ej. [2,3,7] + channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] Affected: self.dataOutObj.data - self.dataOutObj.channelList + self.dataOutObj.channelIndexList self.dataOutObj.nChannels self.dataOutObj.m_ProcessingHeader.totalSpectra self.dataOutObj.m_SystemHeader.numChannels @@ -237,19 +231,19 @@ class VoltageProcessor: if self.dataOutObj.flagNoData: return 0 - for channel in channelList: - if channel not in self.dataOutObj.channelList: - raise ValueError, "The value %d in channelList is not valid" %channel + for channel in channelIndexList: + if channel not in self.dataOutObj.channelIndexList: + raise ValueError, "The value %d in channelIndexList is not valid" %channel - nChannels = len(channelList) + nChannels = len(channelIndexList) - data = self.dataOutObj.data[channelList,:] + data = self.dataOutObj.data[channelIndexList,:] self.dataOutObj.data = data - self.dataOutObj.channelList = channelList + self.dataOutObj.channelIndexList = channelIndexList self.dataOutObj.nChannels = nChannels - self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + self.dataOutObj.m_ProcessingHeader.totalSpectra = 0 self.dataOutObj.m_SystemHeader.numChannels = nChannels self.dataOutObj.m_ProcessingHeader.blockSize = data.size return 1 diff --git a/schainpy/TestSVoltageChain.py b/schainpy/TestSVoltageChain.py index 97d98ec..5b8ecbe 100644 --- a/schainpy/TestSVoltageChain.py +++ b/schainpy/TestSVoltageChain.py @@ -30,29 +30,47 @@ class TestSChain(): self.path = "/home/dsuarez/Projects" #1 self.path = "/Users/jro/Documents/RadarData/EW_Drifts" -# self.path = "/Users/jro/Documents/RadarData/JULIA" + self.path = "/Users/jro/Documents/RadarData/MST_ISR/MST" # self.startDateTime = datetime.datetime(2007,5,1,15,49,0) # self.endDateTime = datetime.datetime(2007,5,1,23,0,0) - self.startDateTime = datetime.datetime(2011,10,1,0,0,0) - self.endDateTime = datetime.datetime(2011,12,31,0,20,0) + self.startDateTime = datetime.datetime(2009,01,1,0,0,0) + self.endDateTime = datetime.datetime(2009,01,31,0,20,0) + +# self.startDateTime = datetime.datetime(2011,11,1,0,0,0) +# self.endDateTime = datetime.datetime(2011,12,31,0,20,0) + + self.N = 4 self.npts = 8 - def createObjects( self ): + def createObjects( self ): - self.voltObj1 = Voltage() - self.voltObj2 = Voltage() - self.specObj1 = Spectra() - - self.readerObj = VoltageReader(self.voltObj1) - self.voltProcObj = VoltageProcessor(self.voltObj1, self.voltObj2) - self.specProcObj = SpectraProcessor(self.voltObj2, self.specObj1) + self.readerObj = VoltageReader() + self.voltProcObj = VoltageProcessor() + self.specProcObj = SpectraProcessor() - if not(self.readerObj.setup( self.path, self.startDateTime, self.endDateTime, expLabel='', online =0) ): + voltObj1 = self.readerObj.setup( + path = self.path, + startDateTime = self.startDateTime, + endDateTime = self.endDateTime, + expLabel = '', + online = 0) + + if not(voltObj1): sys.exit(0) - self.specProcObj.setup(nFFTPoints=8) + voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1) + + specObj1 = self.specProcObj.setup(dataInObj = voltObj2, + nFFTPoints = 16) + +# voltObj2 = self.voltProcObj.setup(dataInObj = voltObj1, +# dataOutObj = voltObj2) +# +# specObj1 = self.specProcObj.setup(dataInObj = voltObj2, +# dataOutObj =specObj1, +# nFFTPoints=16) def testSChain( self ): @@ -63,18 +81,18 @@ class TestSChain(): self.voltProcObj.init() - self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1) - - self.voltProcObj.integrator(4) - - self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2) +# self.voltProcObj.plotData(winTitle='VOLTAGE INPUT', index=1) +# +# self.voltProcObj.integrator(4) +# +# self.voltProcObj.plotData(winTitle='VOLTAGE AVG', index=2) +# - self.specProcObj.init() - self.specProcObj.integrator(N=2) + self.specProcObj.integrator(N=1) - self.specProcObj.plotData(winTitle='Spectra 1', index=3) + self.specProcObj.plotData(winTitle='Spectra 1', index=1) if self.readerObj.flagNoMoreFiles: