|
@@
-10,6
+10,7
import time
|
|
10
|
import numpy
|
|
10
|
import numpy
|
|
11
|
import fnmatch
|
|
11
|
import fnmatch
|
|
12
|
import time, datetime
|
|
12
|
import time, datetime
|
|
|
|
|
13
|
import pyfits
|
|
13
|
|
|
14
|
|
|
14
|
from jrodata import *
|
|
15
|
from jrodata import *
|
|
15
|
from jroheaderIO import *
|
|
16
|
from jroheaderIO import *
|
|
@@
-2533,14
+2534,24
class SpectraWriter(JRODataWriter):
|
|
2533
|
|
|
2534
|
|
|
2534
|
self.processingHeaderObj.size = processingHeaderSize
|
|
2535
|
self.processingHeaderObj.size = processingHeaderSize
|
|
2535
|
|
|
2536
|
|
|
2536
|
class SpectraHeisWriter():
|
|
2537
|
class SpectraHeisWriter(Operation):
|
|
2537
|
|
|
2538
|
# set = None
|
|
2538
|
i=0
|
|
2539
|
setFile = None
|
|
|
|
|
2540
|
idblock = None
|
|
|
|
|
2541
|
doypath = None
|
|
|
|
|
2542
|
subfolder = None
|
|
2539
|
|
|
2543
|
|
|
2540
|
def __init__(self, dataOut):
|
|
2544
|
def __init__(self):
|
|
2541
|
|
|
|
|
|
2542
|
self.wrObj = FITS()
|
|
2545
|
self.wrObj = FITS()
|
|
2543
|
self.dataOut = dataOut
|
|
2546
|
# self.dataOut = dataOut
|
|
|
|
|
2547
|
self.nTotalBlocks=0
|
|
|
|
|
2548
|
# self.set = None
|
|
|
|
|
2549
|
self.setFile = None
|
|
|
|
|
2550
|
self.idblock = 0
|
|
|
|
|
2551
|
self.wrpath = None
|
|
|
|
|
2552
|
self.doypath = None
|
|
|
|
|
2553
|
self.subfolder = None
|
|
|
|
|
2554
|
self.isConfig = False
|
|
2544
|
|
|
2555
|
|
|
2545
|
def isNumber(str):
|
|
2556
|
def isNumber(str):
|
|
2546
|
"""
|
|
2557
|
"""
|
|
@@
-2559,59
+2570,96
class SpectraHeisWriter():
|
|
2559
|
float( str )
|
|
2570
|
float( str )
|
|
2560
|
return True
|
|
2571
|
return True
|
|
2561
|
except:
|
|
2572
|
except:
|
|
2562
|
return False
|
|
2573
|
return False
|
|
2563
|
|
|
2574
|
|
|
2564
|
def setup(self, wrpath,):
|
|
2575
|
def setup(self, dataOut, wrpath):
|
|
2565
|
|
|
2576
|
|
|
2566
|
if not(os.path.exists(wrpath)):
|
|
2577
|
if not(os.path.exists(wrpath)):
|
|
2567
|
os.mkdir(wrpath)
|
|
2578
|
os.mkdir(wrpath)
|
|
2568
|
|
|
2579
|
|
|
2569
|
self.wrpath = wrpath
|
|
2580
|
self.wrpath = wrpath
|
|
2570
|
self.setFile = 0
|
|
2581
|
# self.setFile = 0
|
|
|
|
|
2582
|
self.dataOut = dataOut
|
|
2571
|
|
|
2583
|
|
|
2572
|
def putData(self):
|
|
2584
|
def putData(self):
|
|
2573
|
# self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints)
|
|
|
|
|
2574
|
#name = self.dataOut.utctime
|
|
|
|
|
2575
|
name= time.localtime( self.dataOut.utctime)
|
|
2585
|
name= time.localtime( self.dataOut.utctime)
|
|
2576
|
ext=".fits"
|
|
2586
|
ext=".fits"
|
|
2577
|
#folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
|
|
2587
|
|
|
2578
|
subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
|
|
2588
|
if self.doypath == None:
|
|
|
|
|
2589
|
self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
|
|
|
|
|
2590
|
self.doypath = os.path.join( self.wrpath, self.subfolder )
|
|
|
|
|
2591
|
os.mkdir(self.doypath)
|
|
|
|
|
2592
|
|
|
|
|
|
2593
|
if self.setFile == None:
|
|
|
|
|
2594
|
# self.set = self.dataOut.set
|
|
|
|
|
2595
|
self.setFile = 0
|
|
|
|
|
2596
|
# if self.set != self.dataOut.set:
|
|
|
|
|
2597
|
## self.set = self.dataOut.set
|
|
|
|
|
2598
|
# self.setFile = 0
|
|
|
|
|
2599
|
|
|
|
|
|
2600
|
#make the filename
|
|
|
|
|
2601
|
file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
|
|
2579
|
|
|
2602
|
|
|
2580
|
fullpath = os.path.join( self.wrpath, subfolder )
|
|
2603
|
filename = os.path.join(self.wrpath,self.subfolder, file)
|
|
2581
|
if not( os.path.exists(fullpath) ):
|
|
2604
|
|
|
2582
|
os.mkdir(fullpath)
|
|
2605
|
idblock = numpy.array([self.idblock],dtype="int64")
|
|
|
|
|
2606
|
header=self.wrObj.cFImage(idblock=idblock,
|
|
|
|
|
2607
|
year=time.gmtime(self.dataOut.utctime).tm_year,
|
|
|
|
|
2608
|
month=time.gmtime(self.dataOut.utctime).tm_mon,
|
|
|
|
|
2609
|
day=time.gmtime(self.dataOut.utctime).tm_mday,
|
|
|
|
|
2610
|
hour=time.gmtime(self.dataOut.utctime).tm_hour,
|
|
|
|
|
2611
|
minute=time.gmtime(self.dataOut.utctime).tm_min,
|
|
|
|
|
2612
|
second=time.gmtime(self.dataOut.utctime).tm_sec)
|
|
|
|
|
2613
|
|
|
|
|
|
2614
|
c=3E8
|
|
|
|
|
2615
|
deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
|
|
|
|
|
2616
|
freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
|
|
|
|
|
2617
|
|
|
|
|
|
2618
|
colList = []
|
|
|
|
|
2619
|
|
|
|
|
|
2620
|
colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
|
|
|
|
|
2621
|
|
|
|
|
|
2622
|
colList.append(colFreq)
|
|
|
|
|
2623
|
|
|
|
|
|
2624
|
nchannel=self.dataOut.nChannels
|
|
|
|
|
2625
|
|
|
|
|
|
2626
|
for i in range(nchannel):
|
|
|
|
|
2627
|
col = self.wrObj.writeData(name="PCh"+str(i+1),
|
|
|
|
|
2628
|
format=str(self.dataOut.nFFTPoints)+'E',
|
|
|
|
|
2629
|
data=10*numpy.log10(self.dataOut.data_spc[i,:]))
|
|
|
|
|
2630
|
|
|
|
|
|
2631
|
colList.append(col)
|
|
|
|
|
2632
|
|
|
|
|
|
2633
|
data=self.wrObj.Ctable(colList=colList)
|
|
|
|
|
2634
|
|
|
|
|
|
2635
|
self.wrObj.CFile(header,data)
|
|
|
|
|
2636
|
|
|
|
|
|
2637
|
self.wrObj.wFile(filename)
|
|
|
|
|
2638
|
|
|
|
|
|
2639
|
#update the setFile
|
|
2583
|
self.setFile += 1
|
|
2640
|
self.setFile += 1
|
|
2584
|
file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
|
|
2641
|
self.idblock += 1
|
|
2585
|
|
|
2642
|
|
|
2586
|
filename = os.path.join(self.wrpath,subfolder, file)
|
|
|
|
|
2587
|
|
|
|
|
|
2588
|
# print self.dataOut.ippSeconds
|
|
|
|
|
2589
|
freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds)
|
|
|
|
|
2590
|
|
|
|
|
|
2591
|
col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
|
|
|
|
|
2592
|
col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:]))
|
|
|
|
|
2593
|
col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:]))
|
|
|
|
|
2594
|
col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:]))
|
|
|
|
|
2595
|
col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:]))
|
|
|
|
|
2596
|
col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:]))
|
|
|
|
|
2597
|
col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:]))
|
|
|
|
|
2598
|
col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:]))
|
|
|
|
|
2599
|
col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:]))
|
|
|
|
|
2600
|
#n=numpy.arange((100))
|
|
|
|
|
2601
|
n=self.dataOut.data_spc[6,:]
|
|
|
|
|
2602
|
a=self.wrObj.cFImage(n)
|
|
|
|
|
2603
|
b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
|
|
|
|
|
2604
|
self.wrObj.CFile(a,b)
|
|
|
|
|
2605
|
self.wrObj.wFile(filename)
|
|
|
|
|
2606
|
return 1
|
|
2643
|
return 1
|
|
|
|
|
2644
|
|
|
|
|
|
2645
|
def run(self, dataOut, **kwargs):
|
|
|
|
|
2646
|
|
|
|
|
|
2647
|
if not(self.isConfig):
|
|
|
|
|
2648
|
|
|
|
|
|
2649
|
self.setup(dataOut, **kwargs)
|
|
|
|
|
2650
|
self.isConfig = True
|
|
|
|
|
2651
|
|
|
|
|
|
2652
|
self.putData()
|
|
|
|
|
2653
|
|
|
2607
|
|
|
2654
|
|
|
2608
|
class FITS:
|
|
2655
|
class FITS:
|
|
2609
|
|
|
|
|
|
2610
|
name=None
|
|
2656
|
name=None
|
|
2611
|
format=None
|
|
2657
|
format=None
|
|
2612
|
array =None
|
|
2658
|
array =None
|
|
2613
|
data =None
|
|
2659
|
data =None
|
|
2614
|
thdulist=None
|
|
2660
|
thdulist=None
|
|
|
|
|
2661
|
prihdr=None
|
|
|
|
|
2662
|
hdu=None
|
|
2615
|
|
|
2663
|
|
|
2616
|
def __init__(self):
|
|
2664
|
def __init__(self):
|
|
2617
|
|
|
2665
|
|
|
@@
-2633,9
+2681,7
class FITS:
|
|
2633
|
# self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
|
|
2681
|
# self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
|
|
2634
|
# return self.col2
|
|
2682
|
# return self.col2
|
|
2635
|
|
|
2683
|
|
|
2636
|
def writeHeader(self,):
|
|
2684
|
|
|
2637
|
pass
|
|
|
|
|
2638
|
|
|
|
|
|
2639
|
def writeData(self,name,format,data):
|
|
2685
|
def writeData(self,name,format,data):
|
|
2640
|
self.name=name
|
|
2686
|
self.name=name
|
|
2641
|
self.format=format
|
|
2687
|
self.format=format
|
|
@@
-2644,17
+2690,27
class FITS:
|
|
2644
|
self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
|
|
2690
|
self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
|
|
2645
|
return self.col2
|
|
2691
|
return self.col2
|
|
2646
|
|
|
2692
|
|
|
2647
|
def cFImage(self,n):
|
|
2693
|
def cFImage(self,idblock,year,month,day,hour,minute,second):
|
|
2648
|
self.hdu= pyfits.PrimaryHDU(n)
|
|
2694
|
self.hdu= pyfits.PrimaryHDU(idblock)
|
|
2649
|
return self.hdu
|
|
2695
|
self.hdu.header.set("Year",year)
|
|
2650
|
|
|
2696
|
self.hdu.header.set("Month",month)
|
|
2651
|
def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
|
|
2697
|
self.hdu.header.set("Day",day)
|
|
2652
|
self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
|
|
2698
|
self.hdu.header.set("Hour",hour)
|
|
|
|
|
2699
|
self.hdu.header.set("Minute",minute)
|
|
|
|
|
2700
|
self.hdu.header.set("Second",second)
|
|
|
|
|
2701
|
return self.hdu
|
|
|
|
|
2702
|
|
|
|
|
|
2703
|
|
|
|
|
|
2704
|
def Ctable(self,colList):
|
|
|
|
|
2705
|
self.cols=pyfits.ColDefs(colList)
|
|
2653
|
self.tbhdu = pyfits.new_table(self.cols)
|
|
2706
|
self.tbhdu = pyfits.new_table(self.cols)
|
|
2654
|
return self.tbhdu
|
|
2707
|
return self.tbhdu
|
|
2655
|
|
|
2708
|
|
|
|
|
|
2709
|
|
|
2656
|
def CFile(self,hdu,tbhdu):
|
|
2710
|
def CFile(self,hdu,tbhdu):
|
|
2657
|
self.thdulist=pyfits.HDUList([hdu,tbhdu])
|
|
2711
|
self.thdulist=pyfits.HDUList([hdu,tbhdu])
|
|
2658
|
|
|
2712
|
|
|
2659
|
def wFile(self,filename):
|
|
2713
|
def wFile(self,filename):
|
|
2660
|
self.thdulist.writeto(filename)
No newline at end of file
|
|
2714
|
if os.path.isfile(filename):
|
|
|
|
|
2715
|
os.remove(filename)
|
|
|
|
|
2716
|
self.thdulist.writeto(filename)
|