Commit 1aa397b8 authored by Monica Rainer's avatar Monica Rainer
Browse files

Change headers of ms1d files and IMANAME keywords

parent 249b6a9b
......@@ -138,7 +138,7 @@ class GBNodding():
h[mjdB] = (nodB.header[CONFIG['KEYS']['MJD']],CONFIG['SPEC_MJD'][1])
nodAB.header[CONFIG['KEYS']['FILENAME']] = ABnome
#nodAB.header[CONFIG['KEYS']['IMANAME']] = ABnome
nodAB.header[CONFIG['KEYS']['IMANAME']] = ABnome
ABtmpnome = os.path.join(CONFIG['TMP_DIR'],ABnome)
......@@ -462,6 +462,7 @@ class GBNodding():
heaspe = fits.Header(hea_ima)
heaspe[CONFIG['KEYS']['FILENAME']] = calname
heaspe[CONFIG['KEYS']['IMANAME']] = calname
drs_mjd = float(heaspe[CONFIG['KEYS']['MJD']]) + (float(heaspe[CONFIG['KEYS']['EXPTIME']])/(2*86400))
heaspe[CONFIG['DRS_MJD'][0]] = (drs_mjd,CONFIG['DRS_MJD'][1])
......@@ -520,10 +521,14 @@ class GBNodding():
c3 = fits.Column(name='FLUX', format=''.join((str(CONFIG['YCCD']),'D')), array=optSpectrum)
c4 = fits.Column(name='SNR', format=''.join((str(CONFIG['YCCD']),'D')), array=snr)
tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4],header=heaspe)
#tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4],header=heaspe)
tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4])
prihdu = fits.PrimaryHDU(data=None, header=heaspe)
hdulist = fits.HDUList([prihdu, tbhdu])
calname = os.path.join(CONFIG['RED_DIR'],calname)
tbhdu.writeto(calname,clobber=True)
#tbhdu.writeto(calname,clobber=True)
hdulist.writeto(calname,clobber=True)
#t1 = time.time()
......@@ -536,6 +541,7 @@ class GBNodding():
#s1d = varie.create_s1d(optSpectrum,snr,heaspe)
s1d, startval = varie.create_s1d(optSpectrum,heaspe)
heaspe[CONFIG['KEYS']['FILENAME']] = calname1d
heaspe[CONFIG['KEYS']['IMANAME']] = calname1d
heaspe['CRPIX1'] = (1.,'Reference pixel')
heaspe['CRVAL1'] = (startval,'Coordinates at reference pixel')
heaspe['CDELT1'] = (CONFIG['S1D_STEP'],'Coordinates increment per pixel')
......@@ -590,18 +596,15 @@ class GBNodding():
acal = fits.open(acalib)
#afluxes = acal[0].data
#awaves = acal[0].header
#roneff = math.sqrt(2)*acal[0].header[CONFIG['RON_EFF'][0]]
#gaineff = 2*acal[0].header[CONFIG['GAIN_EFF'][0]]
adata = acal[1].data
#print adata.shape
afluxes = adata.field(2)
#print afluxes
#print afluxes.shape
awaves = acal[1].header
roneff = math.sqrt(2)*acal[1].header[CONFIG['RON_EFF'][0]]
gaineff = 2*acal[1].header[CONFIG['GAIN_EFF'][0]]
#awaves = acal[1].header
abhea = acal[0].header
#roneff = math.sqrt(2)*acal[1].header[CONFIG['RON_EFF'][0]]
#gaineff = 2*acal[1].header[CONFIG['GAIN_EFF'][0]]
roneff = math.sqrt(2)*abhea[CONFIG['RON_EFF'][0]]
gaineff = 2*abhea[CONFIG['GAIN_EFF'][0]]
bcal = fits.open(bcalib)
......@@ -609,14 +612,16 @@ class GBNodding():
#bwaves = bcal[0].header
bdata = bcal[1].data
bfluxes = bdata.field(2)
bwaves = bcal[1].header
#bwaves = bcal[1].header
bwaves = bcal[0].header
abcalib = np.zeros((CONFIG['N_ORD'],CONFIG['YCCD']))
snr = np.zeros((CONFIG['N_ORD'],CONFIG['YCCD']))
for o in xrange(CONFIG['N_ORD']):
bshift = varie.rebin(awaves,bfluxes[o],bwaves,o)
#bshift = varie.rebin(awaves,bfluxes[o],bwaves,o)
bshift = varie.rebin(abhea,bfluxes[o],bwaves,o)
abcalib[o] = (afluxes[o]+bshift)/2.0
#snr.append(max(np.mean(abcalib[o][1000:1050])/np.std(abcalib[o][1000:1050]),0))
with np.errstate(divide='ignore', invalid='ignore'):
......@@ -626,7 +631,7 @@ class GBNodding():
abcalib = np.asarray(abcalib, dtype='float32')
#abhea = acal[0].header
abhea = acal[1].header
#abhea = acal[1].header
abhea[CONFIG['RON_EFF'][0]] = (roneff,CONFIG['RON_EFF'][1])
abhea[CONFIG['GAIN_EFF'][0]] = (gaineff,CONFIG['GAIN_EFF'][1])
#abhea[CONFIG['TEXP_EFF'][0]] = (,CONFIG['TEXP_EFF'][1])
......@@ -658,13 +663,15 @@ class GBNodding():
try:
#am_a = acal[0].header[CONFIG['AIRMASS'][0]]
#am_b = bcal[0].header[CONFIG['AIRMASS'][0]]
am_a = acal[1].header[CONFIG['AIRMASS'][0]]
am_b = bcal[1].header[CONFIG['AIRMASS'][0]]
#am_a = acal[1].header[CONFIG['AIRMASS'][0]]
#am_b = bcal[1].header[CONFIG['AIRMASS'][0]]
am_a = abhea[CONFIG['AIRMASS'][0]]
am_b = bwaves[CONFIG['AIRMASS'][0]]
except:
#am_a = acal[0].header[CONFIG['KEYS']['AM']]
#am_b = bcal[0].header[CONFIG['KEYS']['AM']]
am_a = acal[1].header[CONFIG['KEYS']['AM']]
am_b = bcal[1].header[CONFIG['KEYS']['AM']]
am_a = abhea[CONFIG['KEYS']['AM']]
am_b = bwaves[CONFIG['KEYS']['AM']]
am = (am_a+am_b)/2.0
......@@ -705,9 +712,13 @@ class GBNodding():
c3 = fits.Column(name='FLUX', format=''.join((str(CONFIG['YCCD']),'D')), array=abcalib)
c4 = fits.Column(name='SNR', format=''.join((str(CONFIG['YCCD']),'D')), array=snr)
tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4],header=heaspe)
#tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4],header=heaspe)
tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4])
prihdu = fits.PrimaryHDU(data=None, header=heaspe)
hdulist = fits.HDUList([prihdu, tbhdu])
tbhdu.writeto(abnome,clobber=True)
#tbhdu.writeto(abnome,clobber=True)
hdulist.writeto(abnome,clobber=True)
try: obj_name = heaspe[CONFIG['KEYS']['OBJECT']]
......@@ -765,6 +776,7 @@ class GBNodding():
ABnome = str(os.path.basename(self.group['noddings'][0])).replace('_AB.fits','_ABgrp.fits')
nodA.header[CONFIG['KEYS']['FILENAME']] = ABnome
nodA.header[CONFIG['KEYS']['IMANAME']] = ABnome
nodA.header[CONFIG['GAIN_EFF'][0]] = (len(self.group['noddings'])*headers[0][CONFIG['GAIN_EFF'][0]],CONFIG['GAIN_EFF'][1])
nodA.header[CONFIG['RON_EFF'][0]] = (headers[0][CONFIG['RON_EFF'][0]]*math.sqrt(len(self.group['noddings'])),CONFIG['RON_EFF'][1])
......@@ -802,8 +814,10 @@ class GBNodding():
heaB = nodA.header
heaA[CONFIG['KEYS']['SLIT']] = CONFIG['A']
heaA[CONFIG['KEYS']['FILENAME']] = heaA[''.join((CONFIG['SPEC_USED'][0],'1','A'))]
heaA[CONFIG['KEYS']['IMANAME']] = heaA[''.join((CONFIG['SPEC_USED'][0],'1','A'))]
heaB[CONFIG['KEYS']['SLIT']] = CONFIG['B']
heaB[CONFIG['KEYS']['FILENAME']] = heaA[''.join((CONFIG['SPEC_USED'][0],'1','B'))]
heaB[CONFIG['KEYS']['IMANAME']] = heaA[''.join((CONFIG['SPEC_USED'][0],'1','B'))]
Atmpnome = os.path.join(CONFIG['TMP_DIR'],ABnome)
......
......@@ -559,6 +559,8 @@ class GBStare():
#calname1d = redname.replace('.fits','_s1d.fits')
heaspe = fits.Header(imstr.header)
heaspe[CONFIG['KEYS']['FILENAME']] = str(os.path.basename(calname))
heaspe[CONFIG['KEYS']['IMANAME']] = str(os.path.basename(calname))
try:
heaspe[CONFIG['MASTERFLAT'][0]] = (os.path.basename(masterflat),CONFIG['MASTERFLAT'][1])
......@@ -613,16 +615,22 @@ class GBStare():
c3 = fits.Column(name='FLUX', format=''.join((str(CONFIG['YCCD']),'D')), array=optSpectrum)
c4 = fits.Column(name='SNR', format=''.join((str(CONFIG['YCCD']),'D')), array=snr)
tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4],header=heaspe)
#tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4],header=heaspe)
tbhdu = fits.BinTableHDU.from_columns([c1, c2, c3, c4])
prihdu = fits.PrimaryHDU(data=None, header=heaspe)
hdulist = fits.HDUList([prihdu, tbhdu])
calname = os.path.join(CONFIG['RED_DIR'],calname)
tbhdu.writeto(calname,clobber=True)
#tbhdu.writeto(calname,clobber=True)
hdulist.writeto(calname,clobber=True)
try: obj_name = heaspe[CONFIG['KEYS']['OBJECT']]
except: obj_name = 'NONE'
if CONFIG['S1D']:
heaspe[CONFIG['KEYS']['FILENAME']] = str(os.path.basename(calname1d))
heaspe[CONFIG['KEYS']['IMANAME']] = str(os.path.basename(calname1d))
#s1d = varie.create_s1d(optSpectrum,snr,heaspe)
s1d, startval = varie.create_s1d(optSpectrum,heaspe)
heaspe['CRPIX1'] = (1.,'Reference pixel')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment