##// END OF EJS Templates
actualizacion para SpectraHeis
Alexander Valdez -
r171:51b2ad4fcfc8
parent child
Show More
@@ -64,6 +64,10 class JROData:
64
64
65 timeInterval = None
65 timeInterval = None
66
66
67 set=None
68
69 deltaHeight = None
70
67 def __init__(self):
71 def __init__(self):
68
72
69 raise ValueError, "This class has not been implemented"
73 raise ValueError, "This class has not been implemented"
@@ -209,7 +209,7 class LinearPlot():
209
209
210 def __init__(self, indexFig,nsubplot,winTitle):
210 def __init__(self, indexFig,nsubplot,winTitle):
211 self.width = 700
211 self.width = 700
212 self.height = 150
212 self.height = 800
213 self.indexFig = indexFig
213 self.indexFig = indexFig
214 self.ncol = 1
214 self.ncol = 1
215 self.nrow = nsubplot
215 self.nrow = nsubplot
@@ -760,12 +760,12 if __name__ == '__main__':
760 ylabel = ""
760 ylabel = ""
761
761
762 indexFig = 1
762 indexFig = 1
763 nsubplot = 2
763 nsubplot = 6
764 winTitle = "figura"
764 winTitle = "figura"
765
765
766 isPlotIni = False
766 isPlotIni = False
767 isPlotConfig = False
767 isPlotConfig = False
768 ntimes = 10
768 ntimes = 100
769
769
770
770
771 # Instancia del objeto
771 # Instancia del objeto
@@ -225,6 +225,8 class JRODataIO:
225
225
226 blocksize = None
226 blocksize = None
227
227
228 set = None
229
228 def __init__(self):
230 def __init__(self):
229 pass
231 pass
230
232
@@ -588,7 +590,7 class JRODataReader(JRODataIO):
588 self.filename = file
590 self.filename = file
589 self.flagIsNewFile = 1
591 self.flagIsNewFile = 1
590 if self.fp != None: self.fp.close()
592 if self.fp != None: self.fp.close()
591 self.fp = open(file)
593 self.fp = open(file, 'rb')
592 self.flagNoMoreFiles = 0
594 self.flagNoMoreFiles = 0
593 print 'Setting the file: %s' % file
595 print 'Setting the file: %s' % file
594 else:
596 else:
@@ -604,7 +604,6 class SpectraWriter(JRODataWriter):
604 if self.flagNoMoreFiles:
604 if self.flagNoMoreFiles:
605 #print 'Process finished'
605 #print 'Process finished'
606 return 0
606 return 0
607
608 return 1
607 return 1
609
608
610
609
@@ -786,6 +785,8 class FITS:
786 array =None
785 array =None
787 data =None
786 data =None
788 thdulist=None
787 thdulist=None
788 prihdr=None
789 hdu=None
789
790
790 def __init__(self):
791 def __init__(self):
791
792
@@ -807,8 +808,6 class FITS:
807 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
808 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
808 # return self.col2
809 # return self.col2
809
810
810 def writeHeader(self,):
811 pass
812
811
813 def writeData(self,name,format,data):
812 def writeData(self,name,format,data):
814 self.name=name
813 self.name=name
@@ -818,26 +817,47 class FITS:
818 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
817 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
819 return self.col2
818 return self.col2
820
819
821 def cFImage(self,n):
820 def cFImage(self,idblock,year,month,day,hour,minute,second):
822 self.hdu= pyfits.PrimaryHDU(n)
821 self.hdu= pyfits.PrimaryHDU(idblock)
822 self.hdu.header.set("Year",year)
823 self.hdu.header.set("Month",month)
824 self.hdu.header.set("Day",day)
825 self.hdu.header.set("Hour",hour)
826 self.hdu.header.set("Minute",minute)
827 self.hdu.header.set("Second",second)
823 return self.hdu
828 return self.hdu
824
829
825 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
830
826 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
831 def Ctable(self,colList):
832 self.cols=pyfits.ColDefs(colList)
827 self.tbhdu = pyfits.new_table(self.cols)
833 self.tbhdu = pyfits.new_table(self.cols)
828 return self.tbhdu
834 return self.tbhdu
829
835
836
830 def CFile(self,hdu,tbhdu):
837 def CFile(self,hdu,tbhdu):
831 self.thdulist=pyfits.HDUList([hdu,tbhdu])
838 self.thdulist=pyfits.HDUList([hdu,tbhdu])
832
839
833 def wFile(self,filename):
840 def wFile(self,filename):
834 self.thdulist.writeto(filename)
841 self.thdulist.writeto(filename)
835
842
836 class SpectraHeisWriter():
843 class SpectraHeisWriter(JRODataWriter):
837 i=0
844 set = None
845 setFile = None
846 idblock = None
847 doypath = None
848 subfolder = None
849
838 def __init__(self, dataOutObj):
850 def __init__(self, dataOutObj):
839 self.wrObj = FITS()
851 self.wrObj = FITS()
840 self.dataOutObj = dataOutObj
852 self.dataOutObj = dataOutObj
853 self.nTotalBlocks=0
854 self.set = None
855 self.setFile = 0
856 self.idblock = 0
857 self.wrpath = None
858 self.doypath = None
859 self.subfolder = None
860
841
861
842 def isNumber(str):
862 def isNumber(str):
843 """
863 """
@@ -858,7 +878,7 class SpectraHeisWriter():
858 except:
878 except:
859 return False
879 return False
860
880
861 def setup(self, wrpath,):
881 def setup(self, wrpath):
862
882
863 if not(os.path.exists(wrpath)):
883 if not(os.path.exists(wrpath)):
864 os.mkdir(wrpath)
884 os.mkdir(wrpath)
@@ -867,39 +887,63 class SpectraHeisWriter():
867 self.setFile = 0
887 self.setFile = 0
868
888
869 def putData(self):
889 def putData(self):
870 # self.wrObj.writeHeader(nChannels=self.dataOutObj.nChannels, nFFTPoints=self.dataOutObj.nFFTPoints)
871 #name = self.dataOutObj.utctime
872 name= time.localtime( self.dataOutObj.utctime)
890 name= time.localtime( self.dataOutObj.utctime)
873 ext=".fits"
891 ext=".fits"
874 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
875 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
876
892
877 doypath = os.path.join( self.wrpath, subfolder )
893 if self.doypath == None:
878 if not( os.path.exists(doypath) ):
894 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
879 os.mkdir(doypath)
895 self.doypath = os.path.join( self.wrpath, self.subfolder )
880 self.setFile += 1
896 os.mkdir(self.doypath)
881 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
897
882
898 if self.set == None:
883 filename = os.path.join(self.wrpath,subfolder, file)
899 self.set = self.dataOutObj.set
884
900 self.setFile = 0
885 # print self.dataOutObj.ippSeconds
901 if self.set != self.dataOutObj.set:
886 freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)/(2*self.dataOutObj.ippSeconds)
902 self.set = self.dataOutObj.set
887
903 self.setFile = 0
888 col1=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq)
904
889 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[0,:]))
905 #make the filename
890 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[1,:]))
906 file = 'D%4.4d%3.3d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.set,self.setFile,ext)
891 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[2,:]))
907
892 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[3,:]))
908 filename = os.path.join(self.wrpath,self.subfolder, file)
893 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[4,:]))
909
894 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[5,:]))
910 idblock = numpy.array([self.idblock],dtype="int64")
895 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[6,:]))
911 header=self.wrObj.cFImage(idblock=idblock,
896 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[7,:]))
912 year=time.gmtime(self.dataOutObj.utctime).tm_year,
897 #n=numpy.arange((100))
913 month=time.gmtime(self.dataOutObj.utctime).tm_mon,
898 n=self.dataOutObj.data_spc[6,:]
914 day=time.gmtime(self.dataOutObj.utctime).tm_mday,
899 a=self.wrObj.cFImage(n)
915 hour=time.gmtime(self.dataOutObj.utctime).tm_hour,
900 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
916 minute=time.gmtime(self.dataOutObj.utctime).tm_min,
901 self.wrObj.CFile(a,b)
917 second=time.gmtime(self.dataOutObj.utctime).tm_sec)
918
919 c=3E8
920 freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*1000))
921
922 colList = []
923
924 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq)
925
926 colList.append(colFreq)
927
928 nchannel=self.dataOutObj.nChannels
929
930 for i in range(nchannel):
931 col = self.wrObj.writeData(name="PCh"+str(i+1),
932 format=str(self.dataOutObj.nFFTPoints)+'E',
933 data=10*numpy.log10(self.dataOutObj.data_spc[i,:]))
934
935 colList.append(col)
936
937 data=self.wrObj.Ctable(colList=colList)
938
939 self.wrObj.CFile(header,data)
940
902 self.wrObj.wFile(filename)
941 self.wrObj.wFile(filename)
942
943 #update the setFile
944 self.setFile += 1
945 self.idblock += 1
946
903 return 1
947 return 1
904
948
905 No newline at end of file
949
@@ -229,6 +229,12 class VoltageReader(JRODataReader):
229 return 1
229 return 1
230
230
231
231
232 def __getset(self,filename):
233 name = os.path.basename(filename)
234 basename,ext = os.path.splitext(name)
235 set = int(basename[8:])
236 return set
237
232 def getData(self):
238 def getData(self):
233 """
239 """
234 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
240 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
@@ -273,6 +279,8 class VoltageReader(JRODataReader):
273 self.dataOutObj.flagNoData = True
279 self.dataOutObj.flagNoData = True
274 return 0
280 return 0
275
281
282 self.dataOutObj.set = self.__getset(self.filename)
283
276 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
284 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
277
285
278 self.dataOutObj.dtype = self.dtype
286 self.dataOutObj.dtype = self.dtype
@@ -297,6 +305,8 class VoltageReader(JRODataReader):
297
305
298 self.dataOutObj.ippSeconds = self.ippSeconds
306 self.dataOutObj.ippSeconds = self.ippSeconds
299
307
308 self.dataOutObj.deltaHeight = self.processingHeaderObj.deltaHeight
309
300 self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
310 self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
301
311
302 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
312 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
@@ -12,8 +12,9 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Data.JROData import Spectra, SpectraHeis
14 from Data.JROData import Spectra, SpectraHeis
15 from IO.SpectraIO import SpectraWriter
15 from IO.SpectraIO import SpectraWriter,SpectraHeisWriter
16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure
16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure
17 from Graphics.BaseGraph_mpl import LinearPlot
17 #from JRONoise import Noise
18 #from JRONoise import Noise
18
19
19 class SpectraProcessor:
20 class SpectraProcessor:
@@ -551,6 +552,8 class SpectraHeisProcessor:
551 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
552 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
552 self.dataOutObj.nIncohInt = 1
553 self.dataOutObj.nIncohInt = 1
553 self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds
554 self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds
555 self.dataOutObj.set=self.dataInObj.set
556 self.dataOutObj.deltaHeight=self.dataInObj.deltaHeight
554
557
555 # def addWriter(self,wrpath,blocksPerfile):
558 # def addWriter(self,wrpath,blocksPerfile):
556 def addWriter(self,wrpath):
559 def addWriter(self,wrpath):
@@ -605,7 +608,7 class SpectraHeisProcessor:
605 self.addIntegrator(N,timeInterval)
608 self.addIntegrator(N,timeInterval)
606
609
607 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
610 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
608 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
611 myIncohIntObj.exe(data=self.dataOutObj.data_spc,datatime=self.dataOutObj.utctime)
609
612
610 if myIncohIntObj.isReady:
613 if myIncohIntObj.isReady:
611 self.dataOutObj.data_spc = myIncohIntObj.data
614 self.dataOutObj.data_spc = myIncohIntObj.data
@@ -678,6 +681,84 class SpectraHeisProcessor:
678
681
679 self.plotObjIndex += 1
682 self.plotObjIndex += 1
680
683
684
685 def addPlotMatScope(self, indexPlot,nsubplot,winTitle):
686 linearObj = LinearPlot(indexPlot,nsubplot,winTitle)
687 self.plotObjList.append(linearObj)
688
689 def plotMatScope(self, idfigure,
690 channelList=None,
691 wintitle="",
692 save=None,
693 gpath=None):
694
695 if self.dataOutObj.flagNoData:
696 return 0
697
698 if channelList == None:
699 channelList = self.dataOutObj.channelList
700
701 nchannels = len(channelList)
702
703 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
704 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
705 winTitle = "Spectra Profile" #+ dateTime
706
707 if len(self.plotObjList) <= self.plotObjIndex:
708 self.addPlotMatScope(idfigure,nchannels,winTitle)
709 c = 3E8
710 x=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)*(c/(2*self.dataOutObj.deltaHeight*self.dataOutObj.nHeights*1000))
711 x= x/(10000.0)
712
713 data = 10*numpy.log10(self.dataOutObj.data_spc)
714
715 subplotTitle = "Channel No."
716 xlabel = "Frecuencias(hz)*10K"
717 ylabel = "Potencia(dB)"
718
719 isPlotIni=False
720 isPlotConfig=False
721
722 ntimes=2
723 nsubplot= nchannels
724
725 plotObj = self.plotObjList[self.plotObjIndex]
726
727 # for i in range(ntimes):
728 #Creacion de Subplots
729 if not(plotObj.isPlotIni):
730 for index in range(nsubplot):
731 indexplot = index + 1
732 title = subplotTitle + '%d'%indexplot
733 xmin = numpy.min(x)
734 xmax = numpy.max(x)
735 ymin = numpy.min(data[index,:])
736 ymax = numpy.max(data[index,:])
737 plotObj.createObjects(indexplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel)
738 plotObj.isPlotIni =True
739
740 # Inicializa el grafico en cada itearcion
741 plotObj.setFigure(idfigure)
742 plotObj.setFigure("")
743
744 for index in range(nsubplot):
745 subplot = index
746 plotObj.iniPlot(subplot+1)
747 #Ploteo de datos
748
749 for channel in range(nsubplot):
750 y=data[channel,:]
751 plotObj.plot(channel+1,x,y,type='simple')
752
753 plotObj.refresh()
754
755 #time.sleep(0.05)
756
757 # plotObj.show()
758
759 self.plotObjIndex += 1
760 #print "Ploteo Finalizado"
761
681 def rti(self):
762 def rti(self):
682 if self.dataOutObj.flagNoData:
763 if self.dataOutObj.flagNoData:
683 return 0
764 return 0
@@ -21,30 +21,51 from Processing.SpectraProcessor import *
21 #from Graphics.BaseGraph_mpl import LinearPlot
21 #from Graphics.BaseGraph_mpl import LinearPlot
22
22
23 class TestHeis():
23 class TestHeis():
24 i=None
24
25 def __init__(self):
25 def __init__(self):
26 self.setValues()
26 self.setValues()
27 self.createObjects()
27 self.createObjects()
28 self.testSChain()
28 self.testSChain()
29 self.i=0
29 self.i=0
30
30
31
32 def VerifyArguments(self):
33 pass
34
35
36
31 def setValues( self ):
37 def setValues(self):
32
38
33 self.path="/home/roj-idl71/data"
39
40
41 self.path="D:\\te"
34
42
35 #self.path = ""
43 #self.path = ""
36 self.startDate = datetime.date(2012,4,1)
44 # self.startDate = datetime.date(2012,10,1)
37 self.endDate = datetime.date(2012,6,30)
45 # self.endDate = datetime.date(2012,12,30)
46 #
47 # self.startTime = datetime.time(0,0,0)
48 # self.endTime = datetime.time(23,0,0)
49 #
50
51
52
53 self.N=1000
38
54
39 self.startTime = datetime.time(0,0,0)
55 self.wrpath = "D:\\te\\FITS"
40 self.endTime = datetime.time(23,0,0)
41
56
57 self.online
42
58
59 self.startDate = None
60 self.endDate = None
61 self.startTime = None
62 self.endTime = None
63
64 # self.blocksPerFile = 1
43 def createObjects( self ):
65 def createObjects( self ):
44
66
45 self.readerObj = VoltageReader()
67 self.readerObj = VoltageReader()
46 self.specProcObj = SpectraHeisProcessor()
68 self.specProcObj = SpectraHeisProcessor()
47
48 self.voltObj1 = self.readerObj.setup(
69 self.voltObj1 = self.readerObj.setup(
49 path = self.path,
70 path = self.path,
50 startDate = self.startDate,
71 startDate = self.startDate,
@@ -52,39 +73,27 class TestHeis():
52 startTime = self.startTime,
73 startTime = self.startTime,
53 endTime = self.endTime,
74 endTime = self.endTime,
54 expLabel = '',
75 expLabel = '',
55 online = 0)
76 online = self.online)
56
77
57 if not(self.voltObj1):
78 if not(self.voltObj1):
58 sys.exit(0)
79 sys.exit(0)
59
80
60 self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights)
81 self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights)
61
62
63 #
64
65 #
82 #
66
67 def testSChain( self ):
83 def testSChain( self ):
68
84
69 ini = time.time()
85 ini = time.time()
70 counter = 0
86 counter = 0
71 while(True):
87 while(True):
72 self.readerObj.getData()
88 self.readerObj.getData()
73 self.specProcObj.init()
74
75 self.specProcObj.integrator(N=32) ## return self.dataOutObj
76
77
89
90 self.specProcObj.init()
78
91
92 self.specProcObj.integrator(self.N) ## return self.dataOutObj
79
93
80 self.specProcObj.plotScope(idfigure=1,
94 self.specProcObj.writedata(self.wrpath)
81 wintitle='test plot library',
82 driver='plplot',
83 minvalue = 30000.0,
84 maxvalue = 5000000.0,
85 save=True,
86 gpath="/home/roj-idl71/PlotImage")
87
95
96 self.specProcObj.plotMatScope(idfigure=1)
88
97
89 if self.readerObj.flagNoMoreFiles:
98 if self.readerObj.flagNoMoreFiles:
90 break
99 break
General Comments 0
You need to be logged in to leave comments. Login now