@@ -6,6 +6,8 $Id$ | |||
|
6 | 6 | |
|
7 | 7 | import os, sys |
|
8 | 8 | import numpy |
|
9 | ||
|
10 | import pyfits | |
|
9 | 11 | import glob |
|
10 | 12 | import fnmatch |
|
11 | 13 | import time, datetime |
@@ -19,6 +21,8 from JRODataIO import JRODataWriter | |||
|
19 | 21 | |
|
20 | 22 | from Data.JROData import Spectra |
|
21 | 23 | |
|
24 | from Data.JROData import SpectraHeis | |
|
25 | ||
|
22 | 26 | class SpectraReader(JRODataReader): |
|
23 | 27 | """ |
|
24 | 28 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
@@ -449,10 +453,6 class SpectraWriter(JRODataWriter): | |||
|
449 | 453 | |
|
450 | 454 | self.nWrPairs = self.dataOutObj.nPairs |
|
451 | 455 | |
|
452 | ||
|
453 | ||
|
454 | ||
|
455 | ||
|
456 | 456 | # self.data_spc = None |
|
457 | 457 | # self.data_cspc = None |
|
458 | 458 | # self.data_dc = None |
@@ -779,3 +779,127 class SpectraWriter(JRODataWriter): | |||
|
779 | 779 | self.processingHeaderObj.size = processingHeaderSize |
|
780 | 780 | |
|
781 | 781 | |
|
782 | ||
|
783 | class FITS: | |
|
784 | name=None | |
|
785 | format=None | |
|
786 | array =None | |
|
787 | data =None | |
|
788 | thdulist=None | |
|
789 | ||
|
790 | def __init__(self): | |
|
791 | ||
|
792 | pass | |
|
793 | ||
|
794 | def setColF(self,name,format,array): | |
|
795 | self.name=name | |
|
796 | self.format=format | |
|
797 | self.array=array | |
|
798 | a1=numpy.array([self.array],dtype=numpy.float32) | |
|
799 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
|
800 | return self.col1 | |
|
801 | ||
|
802 | # def setColP(self,name,format,data): | |
|
803 | # self.name=name | |
|
804 | # self.format=format | |
|
805 | # self.data=data | |
|
806 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
|
807 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
|
808 | # return self.col2 | |
|
809 | ||
|
810 | def writeHeader(self,): | |
|
811 | pass | |
|
812 | ||
|
813 | def writeData(self,name,format,data): | |
|
814 | self.name=name | |
|
815 | self.format=format | |
|
816 | self.data=data | |
|
817 | a2=numpy.array([self.data],dtype=numpy.float32) | |
|
818 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
|
819 | return self.col2 | |
|
820 | ||
|
821 | def cFImage(self,n): | |
|
822 | self.hdu= pyfits.PrimaryHDU(n) | |
|
823 | return self.hdu | |
|
824 | ||
|
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]) | |
|
827 | self.tbhdu = pyfits.new_table(self.cols) | |
|
828 | return self.tbhdu | |
|
829 | ||
|
830 | def CFile(self,hdu,tbhdu): | |
|
831 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
|
832 | ||
|
833 | def wFile(self,filename): | |
|
834 | self.thdulist.writeto(filename) | |
|
835 | ||
|
836 | class SpectraHeisWriter(): | |
|
837 | i=0 | |
|
838 | def __init__(self, dataOutObj): | |
|
839 | self.wrObj = FITS() | |
|
840 | self.dataOutObj = dataOutObj | |
|
841 | ||
|
842 | def isNumber(str): | |
|
843 | """ | |
|
844 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
|
845 | ||
|
846 | Excepciones: | |
|
847 | Si un determinado string no puede ser convertido a numero | |
|
848 | Input: | |
|
849 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
|
850 | ||
|
851 | Return: | |
|
852 | True : si el string es uno numerico | |
|
853 | False : no es un string numerico | |
|
854 | """ | |
|
855 | try: | |
|
856 | float( str ) | |
|
857 | return True | |
|
858 | except: | |
|
859 | return False | |
|
860 | ||
|
861 | def setup(self, wrpath,): | |
|
862 | ||
|
863 | if not(os.path.exists(wrpath)): | |
|
864 | os.mkdir(wrpath) | |
|
865 | ||
|
866 | self.wrpath = wrpath | |
|
867 | self.setFile = 0 | |
|
868 | ||
|
869 | 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) | |
|
873 | 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 | ||
|
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) | |
|
902 | self.wrObj.wFile(filename) | |
|
903 | return 1 | |
|
904 | ||
|
905 | No newline at end of file |
@@ -542,6 +542,27 class SpectraHeisProcessor: | |||
|
542 | 542 | self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip |
|
543 | 543 | self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT |
|
544 | 544 | self.dataOutObj.nIncohInt = 1 |
|
545 | self.dataOutObj.ippSeconds= self.dataInObj.ippSeconds | |
|
546 | ||
|
547 | # def addWriter(self,wrpath,blocksPerfile): | |
|
548 | def addWriter(self,wrpath): | |
|
549 | objWriter=SpectraHeisWriter(self.dataOutObj) | |
|
550 | objWriter.setup(wrpath) | |
|
551 | #objWriter.setup(wrpath,blocksPerfile) | |
|
552 | self.writerObjList.append(objWriter) | |
|
553 | ||
|
554 | # def writedata(self,wrpath,blocksPerfile): | |
|
555 | def writedata(self,wrpath): | |
|
556 | if self.dataOutObj.flagNoData: | |
|
557 | return 0 | |
|
558 | ||
|
559 | if len(self.writerObjList) <= self.writerObjIndex: | |
|
560 | #self.addWriter(wrpath, blocksPerFile) | |
|
561 | self.addWriter(wrpath) | |
|
562 | ||
|
563 | self.writerObjList[self.writerObjIndex].putData() | |
|
564 | ||
|
565 | self.writerObjIndex += 1 | |
|
545 | 566 | |
|
546 | 567 | def __getFft(self): |
|
547 | 568 | |
@@ -649,6 +670,18 class SpectraHeisProcessor: | |||
|
649 | 670 | |
|
650 | 671 | self.plotObjIndex += 1 |
|
651 | 672 | |
|
673 | def rti(self): | |
|
674 | if self.dataOutObj.flagNoData: | |
|
675 | return 0 | |
|
676 | ||
|
677 | data=numpy.average(self.dataOutObj.data_spc,axis=1) | |
|
678 | data[0] | |
|
679 | print data[0] | |
|
680 | x = numpy.arange(100000) | |
|
681 | ||
|
682 | print "test" | |
|
683 | #print self.dataOutObj.data_spc.average(axis=1) | |
|
684 | ||
|
652 | 685 | class IncoherentIntegration: |
|
653 | 686 | |
|
654 | 687 | integ_counter = None |
General Comments 0
You need to be logged in to leave comments.
Login now