##// END OF EJS Templates
actualizacion para SpectraHeis
Alexander Valdez -
r171:51b2ad4fcfc8
parent child
Show More
@@ -64,6 +64,10 class JROData:
64 64
65 65 timeInterval = None
66 66
67 set=None
68
69 deltaHeight = None
70
67 71 def __init__(self):
68 72
69 73 raise ValueError, "This class has not been implemented"
@@ -209,7 +209,7 class LinearPlot():
209 209
210 210 def __init__(self, indexFig,nsubplot,winTitle):
211 211 self.width = 700
212 self.height = 150
212 self.height = 800
213 213 self.indexFig = indexFig
214 214 self.ncol = 1
215 215 self.nrow = nsubplot
@@ -760,12 +760,12 if __name__ == '__main__':
760 760 ylabel = ""
761 761
762 762 indexFig = 1
763 nsubplot = 2
763 nsubplot = 6
764 764 winTitle = "figura"
765 765
766 766 isPlotIni = False
767 767 isPlotConfig = False
768 ntimes = 10
768 ntimes = 100
769 769
770 770
771 771 # Instancia del objeto
@@ -225,6 +225,8 class JRODataIO:
225 225
226 226 blocksize = None
227 227
228 set = None
229
228 230 def __init__(self):
229 231 pass
230 232
@@ -588,7 +590,7 class JRODataReader(JRODataIO):
588 590 self.filename = file
589 591 self.flagIsNewFile = 1
590 592 if self.fp != None: self.fp.close()
591 self.fp = open(file)
593 self.fp = open(file, 'rb')
592 594 self.flagNoMoreFiles = 0
593 595 print 'Setting the file: %s' % file
594 596 else:
@@ -604,7 +604,6 class SpectraWriter(JRODataWriter):
604 604 if self.flagNoMoreFiles:
605 605 #print 'Process finished'
606 606 return 0
607
608 607 return 1
609 608
610 609
@@ -786,6 +785,8 class FITS:
786 785 array =None
787 786 data =None
788 787 thdulist=None
788 prihdr=None
789 hdu=None
789 790
790 791 def __init__(self):
791 792
@@ -807,8 +808,6 class FITS:
807 808 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
808 809 # return self.col2
809 810
810 def writeHeader(self,):
811 pass
812 811
813 812 def writeData(self,name,format,data):
814 813 self.name=name
@@ -818,26 +817,47 class FITS:
818 817 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
819 818 return self.col2
820 819
821 def cFImage(self,n):
822 self.hdu= pyfits.PrimaryHDU(n)
820 def cFImage(self,idblock,year,month,day,hour,minute,second):
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 828 return self.hdu
824 829
825 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
826 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
830
831 def Ctable(self,colList):
832 self.cols=pyfits.ColDefs(colList)
827 833 self.tbhdu = pyfits.new_table(self.cols)
828 834 return self.tbhdu
829 835
836
830 837 def CFile(self,hdu,tbhdu):
831 838 self.thdulist=pyfits.HDUList([hdu,tbhdu])
832 839
833 840 def wFile(self,filename):
834 841 self.thdulist.writeto(filename)
835 842
836 class SpectraHeisWriter():
837 i=0
843 class SpectraHeisWriter(JRODataWriter):
844 set = None
845 setFile = None
846 idblock = None
847 doypath = None
848 subfolder = None
849
838 850 def __init__(self, dataOutObj):
839 851 self.wrObj = FITS()
840 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 862 def isNumber(str):
843 863 """
@@ -858,7 +878,7 class SpectraHeisWriter():
858 878 except:
859 879 return False
860 880
861 def setup(self, wrpath,):
881 def setup(self, wrpath):
862 882
863 883 if not(os.path.exists(wrpath)):
864 884 os.mkdir(wrpath)
@@ -867,39 +887,63 class SpectraHeisWriter():
867 887 self.setFile = 0
868 888
869 889 def putData(self):
870 # self.wrObj.writeHeader(nChannels=self.dataOutObj.nChannels, nFFTPoints=self.dataOutObj.nFFTPoints)
871 #name = self.dataOutObj.utctime
872 890 name= time.localtime( self.dataOutObj.utctime)
873 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 )
878 if not( os.path.exists(doypath) ):
879 os.mkdir(doypath)
880 self.setFile += 1
881 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
882
883 filename = os.path.join(self.wrpath,subfolder, file)
884
885 # print self.dataOutObj.ippSeconds
886 freq=numpy.arange(-1*self.dataOutObj.nHeights/2.,self.dataOutObj.nHeights/2.)/(2*self.dataOutObj.ippSeconds)
887
888 col1=self.wrObj.setColF(name="freq", format=str(self.dataOutObj.nFFTPoints)+'E', array=freq)
889 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[0,:]))
890 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[1,:]))
891 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[2,:]))
892 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[3,:]))
893 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[4,:]))
894 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[5,:]))
895 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[6,:]))
896 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOutObj.nFFTPoints)+'E',data=10*numpy.log10(self.dataOutObj.data_spc[7,:]))
897 #n=numpy.arange((100))
898 n=self.dataOutObj.data_spc[6,:]
899 a=self.wrObj.cFImage(n)
900 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
901 self.wrObj.CFile(a,b)
893 if self.doypath == None:
894 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
895 self.doypath = os.path.join( self.wrpath, self.subfolder )
896 os.mkdir(self.doypath)
897
898 if self.set == None:
899 self.set = self.dataOutObj.set
900 self.setFile = 0
901 if self.set != self.dataOutObj.set:
902 self.set = self.dataOutObj.set
903 self.setFile = 0
904
905 #make the filename
906 file = 'D%4.4d%3.3d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.set,self.setFile,ext)
907
908 filename = os.path.join(self.wrpath,self.subfolder, file)
909
910 idblock = numpy.array([self.idblock],dtype="int64")
911 header=self.wrObj.cFImage(idblock=idblock,
912 year=time.gmtime(self.dataOutObj.utctime).tm_year,
913 month=time.gmtime(self.dataOutObj.utctime).tm_mon,
914 day=time.gmtime(self.dataOutObj.utctime).tm_mday,
915 hour=time.gmtime(self.dataOutObj.utctime).tm_hour,
916 minute=time.gmtime(self.dataOutObj.utctime).tm_min,
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 941 self.wrObj.wFile(filename)
942
943 #update the setFile
944 self.setFile += 1
945 self.idblock += 1
946
903 947 return 1
904 948
905 949 No newline at end of file
@@ -229,6 +229,12 class VoltageReader(JRODataReader):
229 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 238 def getData(self):
233 239 """
234 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 279 self.dataOutObj.flagNoData = True
274 280 return 0
275 281
282 self.dataOutObj.set = self.__getset(self.filename)
283
276 284 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
277 285
278 286 self.dataOutObj.dtype = self.dtype
@@ -297,6 +305,8 class VoltageReader(JRODataReader):
297 305
298 306 self.dataOutObj.ippSeconds = self.ippSeconds
299 307
308 self.dataOutObj.deltaHeight = self.processingHeaderObj.deltaHeight
309
300 310 self.dataOutObj.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
301 311
302 312 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
@@ -12,8 +12,9 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from Data.JROData import Spectra, SpectraHeis
15 from IO.SpectraIO import SpectraWriter
15 from IO.SpectraIO import SpectraWriter,SpectraHeisWriter
16 16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure, RTIFigure
17 from Graphics.BaseGraph_mpl import LinearPlot
17 18 #from JRONoise import Noise
18 19
19 20 class SpectraProcessor:
@@ -551,6 +552,8 class SpectraHeisProcessor:
551 552 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
552 553 self.dataOutObj.nIncohInt = 1
553 554 self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds
555 self.dataOutObj.set=self.dataInObj.set
556 self.dataOutObj.deltaHeight=self.dataInObj.deltaHeight
554 557
555 558 # def addWriter(self,wrpath,blocksPerfile):
556 559 def addWriter(self,wrpath):
@@ -605,7 +608,7 class SpectraHeisProcessor:
605 608 self.addIntegrator(N,timeInterval)
606 609
607 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 613 if myIncohIntObj.isReady:
611 614 self.dataOutObj.data_spc = myIncohIntObj.data
@@ -678,6 +681,84 class SpectraHeisProcessor:
678 681
679 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 762 def rti(self):
682 763 if self.dataOutObj.flagNoData:
683 764 return 0
@@ -21,30 +21,51 from Processing.SpectraProcessor import *
21 21 #from Graphics.BaseGraph_mpl import LinearPlot
22 22
23 23 class TestHeis():
24 i=None
24
25 25 def __init__(self):
26 26 self.setValues()
27 27 self.createObjects()
28 28 self.testSChain()
29 29 self.i=0
30 30
31
32 def VerifyArguments(self):
33 pass
34
35
36
31 37 def setValues( self ):
32 38
33 self.path="/home/roj-idl71/data"
39
40
41 self.path="D:\\te"
34 42
35 43 #self.path = ""
36 self.startDate = datetime.date(2012,4,1)
37 self.endDate = datetime.date(2012,6,30)
44 # self.startDate = datetime.date(2012,10,1)
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)
40 self.endTime = datetime.time(23,0,0)
55 self.wrpath = "D:\\te\\FITS"
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 65 def createObjects( self ):
44 66
45 67 self.readerObj = VoltageReader()
46 68 self.specProcObj = SpectraHeisProcessor()
47
48 69 self.voltObj1 = self.readerObj.setup(
49 70 path = self.path,
50 71 startDate = self.startDate,
@@ -52,39 +73,27 class TestHeis():
52 73 startTime = self.startTime,
53 74 endTime = self.endTime,
54 75 expLabel = '',
55 online = 0)
76 online = self.online)
56 77
57 78 if not(self.voltObj1):
58 79 sys.exit(0)
59 80
60 81 self.specObj1 = self.specProcObj.setup(dataInObj = self.voltObj1,nFFTPoints=self.voltObj1.nHeights)
61
62
63 #
64
65 82 #
66
67 83 def testSChain( self ):
68 84
69 85 ini = time.time()
70 86 counter = 0
71 87 while(True):
72 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,
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")
94 self.specProcObj.writedata(self.wrpath)
87 95
96 self.specProcObj.plotMatScope(idfigure=1)
88 97
89 98 if self.readerObj.flagNoMoreFiles:
90 99 break
General Comments 0
You need to be logged in to leave comments. Login now