diff --git a/schainpy2/Data/JROData.py b/schainpy2/Data/JROData.py index 8ba62e4..c232a9d 100644 --- a/schainpy2/Data/JROData.py +++ b/schainpy2/Data/JROData.py @@ -63,6 +63,10 @@ class JROData: ippSeconds = None timeInterval = None + + set=None + + deltaHeight = None def __init__(self): diff --git a/schainpy2/Graphics/BaseGraph_mpl.py b/schainpy2/Graphics/BaseGraph_mpl.py index 263afe1..294502a 100644 --- a/schainpy2/Graphics/BaseGraph_mpl.py +++ b/schainpy2/Graphics/BaseGraph_mpl.py @@ -209,7 +209,7 @@ class LinearPlot(): def __init__(self, indexFig,nsubplot,winTitle): self.width = 700 - self.height = 150 + self.height = 800 self.indexFig = indexFig self.ncol = 1 self.nrow = nsubplot @@ -760,12 +760,12 @@ if __name__ == '__main__': ylabel = "" indexFig = 1 - nsubplot = 2 + nsubplot = 6 winTitle = "figura" isPlotIni = False isPlotConfig = False - ntimes = 10 + ntimes = 100 # Instancia del objeto diff --git a/schainpy2/IO/JRODataIO.py b/schainpy2/IO/JRODataIO.py index 058581c..0ee3db2 100644 --- a/schainpy2/IO/JRODataIO.py +++ b/schainpy2/IO/JRODataIO.py @@ -225,6 +225,8 @@ class JRODataIO: blocksize = None + set = None + def __init__(self): pass @@ -588,7 +590,7 @@ class JRODataReader(JRODataIO): self.filename = file self.flagIsNewFile = 1 if self.fp != None: self.fp.close() - self.fp = open(file) + self.fp = open(file, 'rb') self.flagNoMoreFiles = 0 print 'Setting the file: %s' % file else: @@ -613,11 +615,11 @@ class JRODataReader(JRODataIO): if not(newFile): return 0 - + self.__readFirstHeader() self.nReadBlocks = 0 return 1 - + def __setNewBlock(self): if self.fp == None: return 0 diff --git a/schainpy2/IO/SpectraIO.py b/schainpy2/IO/SpectraIO.py index 1250896..13adaa4 100644 --- a/schainpy2/IO/SpectraIO.py +++ b/schainpy2/IO/SpectraIO.py @@ -603,8 +603,7 @@ class SpectraWriter(JRODataWriter): if self.flagNoMoreFiles: #print 'Process finished' - return 0 - + return 0 return 1 @@ -786,6 +785,8 @@ class FITS: array =None data =None thdulist=None + prihdr=None + hdu=None def __init__(self): @@ -807,9 +808,7 @@ class FITS: # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) # return self.col2 - def writeHeader(self,): - pass - + def writeData(self,name,format,data): self.name=name self.format=format @@ -818,26 +817,47 @@ class FITS: self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) return self.col2 - def cFImage(self,n): - self.hdu= pyfits.PrimaryHDU(n) - return self.hdu - - def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): - self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) + def cFImage(self,idblock,year,month,day,hour,minute,second): + self.hdu= pyfits.PrimaryHDU(idblock) + self.hdu.header.set("Year",year) + self.hdu.header.set("Month",month) + self.hdu.header.set("Day",day) + self.hdu.header.set("Hour",hour) + self.hdu.header.set("Minute",minute) + self.hdu.header.set("Second",second) + return self.hdu + + + def Ctable(self,colList): + self.cols=pyfits.ColDefs(colList) self.tbhdu = pyfits.new_table(self.cols) return self.tbhdu + def CFile(self,hdu,tbhdu): self.thdulist=pyfits.HDUList([hdu,tbhdu]) - + def wFile(self,filename): self.thdulist.writeto(filename) -class SpectraHeisWriter(): - i=0 +class SpectraHeisWriter(JRODataWriter): + set = None + setFile = None + idblock = None + doypath = None + subfolder = None + def __init__(self, dataOutObj): self.wrObj = FITS() self.dataOutObj = dataOutObj + self.nTotalBlocks=0 + self.set = None + self.setFile = 0 + self.idblock = 0 + self.wrpath = None + self.doypath = None + self.subfolder = None + def isNumber(str): """ @@ -858,7 +878,7 @@ class SpectraHeisWriter(): except: return False - def setup(self, wrpath,): + def setup(self, wrpath): if not(os.path.exists(wrpath)): os.mkdir(wrpath) @@ -867,39 +887,63 @@ class SpectraHeisWriter(): self.setFile = 0 def putData(self): - # self.wrObj.writeHeader(nChannels=self.dataOutObj.nChannels, nFFTPoints=self.dataOutObj.nFFTPoints) - #name = self.dataOutObj.utctime name= time.localtime( self.dataOutObj.utctime) - ext=".fits" - #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) - subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) + ext=".fits" + + if self.doypath == None: + self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) + self.doypath = os.path.join( self.wrpath, self.subfolder ) + os.mkdir(self.doypath) + + if self.set == None: + self.set = self.dataOutObj.set + self.setFile = 0 + if self.set != self.dataOutObj.set: + self.set = self.dataOutObj.set + self.setFile = 0 + + #make the filename + file = 'D%4.4d%3.3d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.set,self.setFile,ext) - doypath = os.path.join( self.wrpath, subfolder ) - if not( os.path.exists(doypath) ): - os.mkdir(doypath) + filename = os.path.join(self.wrpath,self.subfolder, file) + + idblock = numpy.array([self.idblock],dtype="int64") + header=self.wrObj.cFImage(idblock=idblock, + year=time.gmtime(self.dataOutObj.utctime).tm_year, + month=time.gmtime(self.dataOutObj.utctime).tm_mon, + day=time.gmtime(self.dataOutObj.utctime).tm_mday, + hour=time.gmtime(self.dataOutObj.utctime).tm_hour, + minute=time.gmtime(self.dataOutObj.utctime).tm_min, + second=time.gmtime(self.dataOutObj.utctime).tm_sec) + + c=3E8 + freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*1000)) + + colList = [] + + colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq) + + colList.append(colFreq) + + nchannel=self.dataOutObj.nChannels + + for i in range(nchannel): + col = self.wrObj.writeData(name="PCh"+str(i+1), + format=str(self.dataOutObj.nFFTPoints)+'E', + data=10*numpy.log10(self.dataOutObj.data_spc[i,:])) + + colList.append(col) + + data=self.wrObj.Ctable(colList=colList) + + self.wrObj.CFile(header,data) + + self.wrObj.wFile(filename) + + #update the setFile self.setFile += 1 - file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) - - filename = os.path.join(self.wrpath,subfolder, file) - - # print self.dataOutObj.ippSeconds - freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)/(2*self.dataOutObj.ippSeconds) - - col1=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq) - col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[0,:])) - col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[1,:])) - col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[2,:])) - col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[3,:])) - col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[4,:])) - col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[5,:])) - col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[6,:])) - col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[7,:])) - #n=numpy.arange((100)) - n=self.dataOutObj.data_spc[6,:] - a=self.wrObj.cFImage(n) - b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) - self.wrObj.CFile(a,b) - self.wrObj.wFile(filename) + self.idblock += 1 + return 1 \ No newline at end of file diff --git a/schainpy2/IO/VoltageIO.py b/schainpy2/IO/VoltageIO.py index 6ce38ae..c69be3e 100644 --- a/schainpy2/IO/VoltageIO.py +++ b/schainpy2/IO/VoltageIO.py @@ -228,6 +228,12 @@ class VoltageReader(JRODataReader): return 1 + + def __getset(self,filename): + name = os.path.basename(filename) + basename,ext = os.path.splitext(name) + set = int(basename[8:]) + return set def getData(self): """ @@ -273,6 +279,8 @@ class VoltageReader(JRODataReader): self.dataOutObj.flagNoData = True return 0 + self.dataOutObj.set = self.__getset(self.filename) + self.dataOutObj.data = self.datablock[:,self.profileIndex,:] self.dataOutObj.dtype = self.dtype @@ -297,6 +305,8 @@ class VoltageReader(JRODataReader): self.dataOutObj.ippSeconds = self.ippSeconds + self.dataOutObj.deltaHeight = self.processingHeaderObj.deltaHeight + self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt diff --git a/schainpy2/Processing/SpectraProcessor.py b/schainpy2/Processing/SpectraProcessor.py index 8231830..bed41bc 100644 --- a/schainpy2/Processing/SpectraProcessor.py +++ b/schainpy2/Processing/SpectraProcessor.py @@ -12,8 +12,9 @@ path = os.path.split(os.getcwd())[0] sys.path.append(path) from Data.JROData import Spectra, SpectraHeis -from IO.SpectraIO import SpectraWriter +from IO.SpectraIO import SpectraWriter,SpectraHeisWriter from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure +from Graphics.BaseGraph_mpl import LinearPlot #from JRONoise import Noise class SpectraProcessor: @@ -551,7 +552,9 @@ class SpectraHeisProcessor: self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT self.dataOutObj.nIncohInt = 1 self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds - + self.dataOutObj.set=self.dataInObj.set + self.dataOutObj.deltaHeight=self.dataInObj.deltaHeight + # def addWriter(self,wrpath,blocksPerfile): def addWriter(self,wrpath): objWriter=SpectraHeisWriter(self.dataOutObj) @@ -605,7 +608,7 @@ class SpectraHeisProcessor: self.addIntegrator(N,timeInterval) myIncohIntObj = self.integratorObjList[self.integratorObjIndex] - myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime) + myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime) if myIncohIntObj.isReady: self.dataOutObj.data_spc = myIncohIntObj.data @@ -677,6 +680,84 @@ class SpectraHeisProcessor: gpath) self.plotObjIndex += 1 + + + def addPlotMatScope(self, indexPlot,nsubplot,winTitle): + linearObj = LinearPlot(indexPlot,nsubplot,winTitle) + self.plotObjList.append(linearObj) + + def plotMatScope(self, idfigure, + channelList=None, + wintitle="", + save=None, + gpath=None): + + if self.dataOutObj.flagNoData: + return 0 + + if channelList == None: + channelList = self.dataOutObj.channelList + + nchannels = len(channelList) + + thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) + dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) + winTitle = "Spectra Profile" #+ dateTime + + if len(self.plotObjList) <= self.plotObjIndex: + self.addPlotMatScope(idfigure,nchannels,winTitle) + c = 3E8 + x=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*self.dataOutObj.nHeights*1000)) + x= x/(10000.0) + + data = 10*numpy.log10(self.dataOutObj.data_spc) + + subplotTitle = "Channel No." + xlabel = "Frecuencias(hz)*10K" + ylabel = "Potencia(dB)" + + isPlotIni=False + isPlotConfig=False + + ntimes=2 + nsubplot= nchannels + + plotObj = self.plotObjList[self.plotObjIndex] + +# for i in range(ntimes): + #Creacion de Subplots + if not(plotObj.isPlotIni): + for index in range(nsubplot): + indexplot = index + 1 + title = subplotTitle + '%d'%indexplot + xmin = numpy.min(x) + xmax = numpy.max(x) + ymin = numpy.min(data[index,:]) + ymax = numpy.max(data[index,:]) + plotObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel) + plotObj.isPlotIni =True + + # Inicializa el grafico en cada itearcion + plotObj.setFigure(idfigure) + plotObj.setFigure("") + + for index in range(nsubplot): + subplot = index + plotObj.iniPlot(subplot+1) + #Ploteo de datos + + for channel in range(nsubplot): + y=data[channel,:] + plotObj.plot(channel+1,x,y,type='simple') + + plotObj.refresh() + + #time.sleep(0.05) + +# plotObj.show() + + self.plotObjIndex += 1 + #print "Ploteo Finalizado" def rti(self): if self.dataOutObj.flagNoData: diff --git a/schainpy2/TestSpectraHeis.py b/schainpy2/TestSpectraHeis.py index 7cf1eff..40c45d8 100644 --- a/schainpy2/TestSpectraHeis.py +++ b/schainpy2/TestSpectraHeis.py @@ -21,30 +21,51 @@ from Processing.SpectraProcessor import * #from Graphics.BaseGraph_mpl import LinearPlot class TestHeis(): - i=None + def __init__(self): self.setValues() self.createObjects() self.testSChain() self.i=0 + + + def VerifyArguments(self): + pass + + + + def setValues(self): + - def setValues( self ): - self.path="/home/roj-idl71/data" + self.path="D:\\te" #self.path = "" - self.startDate = datetime.date(2012,4,1) - self.endDate = datetime.date(2012,6,30) +# self.startDate = datetime.date(2012,10,1) +# self.endDate = datetime.date(2012,12,30) +# +# self.startTime = datetime.time(0,0,0) +# self.endTime = datetime.time(23,0,0) +# - self.startTime = datetime.time(0,0,0) - self.endTime = datetime.time(23,0,0) - - + + + self.N=1000 + + self.wrpath = "D:\\te\\FITS" + + self.online + + self.startDate = None + self.endDate = None + self.startTime = None + self.endTime = None + + # self.blocksPerFile = 1 def createObjects( self ): self.readerObj = VoltageReader() self.specProcObj = SpectraHeisProcessor() - self.voltObj1 = self.readerObj.setup( path = self.path, startDate = self.startDate, @@ -52,41 +73,29 @@ class TestHeis(): startTime = self.startTime, endTime = self.endTime, expLabel = '', - online = 0) + online = self.online) if not(self.voltObj1): sys.exit(0) self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights) - - -# - -# - +# def testSChain( self ): ini = time.time() counter = 0 while(True): self.readerObj.getData() + self.specProcObj.init() - self.specProcObj.integrator(N=32) ## return self.dataOutObj + self.specProcObj.integrator(self.N) ## return self.dataOutObj - - - - self.specProcObj.plotScope(idfigure=1, - wintitle='test plot library', - driver='plplot', - minvalue = 30000.0, - maxvalue = 5000000.0, - save=True, - gpath="/home/roj-idl71/PlotImage") - + self.specProcObj.writedata(self.wrpath) - if self.readerObj.flagNoMoreFiles: + self.specProcObj.plotMatScope(idfigure=1) + + if self.readerObj.flagNoMoreFiles: break @@ -94,7 +103,7 @@ class TestHeis(): if self.readerObj.flagIsNewBlock: print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks, datetime.datetime.fromtimestamp(self.readerObj.basicHeaderObj.utc),) - + if __name__ == '__main__':