Commit 21dea867 authored by Monica Rainer's avatar Monica Rainer
Browse files

Merge branch 'develop'

parents 73b16bb5 e6b9485e
backup
compute_vrad.py
fringing
git_howto.txt
gofioDRS.py
......@@ -20,4 +21,7 @@ webuidatabases
gofio/calibrations
gofio/resources/straight_giano_2D
gofio/resources/straight_giano_2D_v1_1_old.f
gofio/resources/*MASKC*.fits
gofio/vradlib
......@@ -236,6 +236,7 @@ CONFIG['S1D_STEP'] = 0.001 # constant step to use in s1d spectra
CONFIG['WAVE_SELECT'] = os.path.join(CONFIG['RES_DIR'], 'UNe_lines_GIANO_selected.txt')
CONFIG['WAVE_ALL'] = os.path.join(CONFIG['RES_DIR'], 'UNe_observed_lines_GIANOB_18nov2016.txt')
CONFIG['WAVE_FIT'] = {'drift':0.0, 'low_fwhm':1.7, 'high_fwhm':4.0, 'wrange1':10, 'confidence1':3, 'wrange2':5, 'confidence2':1.5, 'xc_range':10}
#CONFIG['WAVE_FIT'] = {'drift':0.0, 'low_fwhm':0.5, 'high_fwhm':4.0, 'wrange1':10, 'confidence1':3, 'wrange2':5, 'confidence2':2.5, 'xc_range':10}
CONFIG['XC_GUESS'] = {32:987, 33:984, 34:982, 35:980, 36:978, 37:976, 38:974, 39:972, 40:970, 41:968, 42:965, 43:963, 44:960, 45:957, 46:955, 47:952, 48:949, 49:946, 50:943, 51:940, 52:937, 53:933, 54:930, 55:927, 56:924, 57:921, 58:918, 59:914, 60:910, 61:907, 62:904, 63:901, 64:898, 65:895, 66:892, 67:889, 68:886, 69:883, 70:880, 71:877, 72:874, 73:871, 74:868, 75:865, 76:862, 77:859, 78:857, 79:855, 80:853, 81:851}
CONFIG['L0_GUESS'] = {32:2398.32, 33:2325.63, 34:2257.24, 35:2192.68, 36:2131.75, 37:2074.09, 38:2019.53, 39:1967.73, 40:1918.56, 41:1871.75, 42:1827.18, 43:1784.70, 44:1744.14, 45:1705.38, 46:1668.31, 47:1632.82, 48:1598.81, 49:1566.20, 50:1534.86, 51:1504.78, 52:1475.85, 53:1448.03, 54:1421.20, 55:1395.38, 56:1370.45, 57:1346.41, 58:1323.22, 59:1300.78, 60:1279.12, 61:1258.15, 62:1237.85, 63:1218.21, 64:1199.17, 65:1180.72, 66:1162.83, 67:1145.47, 68:1128.62, 69:1112.26, 70:1096.36, 71:1080.91, 72:1065.89, 73:1051.28, 74:1037.06, 75:1023.22, 76:1003.74, 77:996.61, 78:983.81, 79:971.34, 80:959.17, 81:947.30}
......@@ -276,6 +277,10 @@ CONFIG['SCIENCECHECK'] = [500,540,140,160] # region x1:x2,y1:y2 for images' qual
CONFIG['NODSIGNAL'] = 0.0 # lowest image signal expected to pass quality check
# radial velocity computation configuration
CONFIG['RV_STEP'] = 0.2 # km/s step
CONFIG['RV_EXTEND'] = 16
if USRCONFIG['OFFLINE']:
for key in USRCONFIG.keys():
......
......@@ -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])
......@@ -650,6 +655,9 @@ class GBNodding():
heaspe = fits.Header(abhea)
heaspe[CONFIG['KEYS']['FILENAME']] = os.path.basename(abnome)
heaspe[CONFIG['KEYS']['IMANAME']] = os.path.basename(abnome)
barycorr, hjd = varie.berv_corr(heaspe)
heaspe[CONFIG['BERV'][0]] = (barycorr,CONFIG['BERV'][1])
heaspe[CONFIG['HJD'][0]] = (hjd,CONFIG['HJD'][1])
......@@ -658,13 +666,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,16 +715,21 @@ 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']]
except: obj_name = 'NONE'
if CONFIG['S1D']:
heaspe[CONFIG['KEYS']['FILENAME']] = os.path.basename(abnome1d)
heaspe[CONFIG['KEYS']['IMANAME']] = os.path.basename(abnome1d)
#s1d = varie.create_s1d(abcalib,snr,heaspe)
s1d, startval = varie.create_s1d(abcalib,heaspe)
heaspe['CRPIX1'] = (1.,'Reference pixel')
......@@ -765,6 +780,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 +818,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')
......
......@@ -547,7 +547,10 @@ def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']
peak = wline[wrange]
x0 = pix
cont = np.median(np.sort(wline)[0:3])
#cont = min(wline) # fare mediana dei tre punti piu' bassi
#if cont < 0:
# wline = wline - cont
# cont = 0
sigmagauss = 2.0
try:
......@@ -563,6 +566,8 @@ def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']
except:
#print 'gauss 1 failed'
#print select_lines[pixel]['wave']
true_pixel = 0.0
fwhm = 0.0
......@@ -645,6 +650,11 @@ def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']
x0 = wpos
#cont = min(wline)
cont = np.median(np.sort(wline)[0:3])
#if cont < 0:
# wline = wline - cont
# cont = 0
sigmagauss = 2.0
try:
......@@ -788,9 +798,9 @@ def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']
else:
print ' **** WARNING **** Order %s: not enough lines for the calibration!' % (str(order))
#print ' **** WARNING **** Order %s: not enough lines for the calibration!' % (str(order))
#calib = np.zeros(len(lamp))
messages.append('Calibration failed for order %s, not enough lines.' % (str(order),))
messages.append(' **** WARNING **** Calibration failed for order %s, not enough lines.' % (str(order),))
if use_oliva:
#coeffs = OrderedDict({'k1':None,'k2':None,'k3':None,'l0':None,'xc':None,'rms':None})
coeffs.update({'k1':None,'k2':None,'k3':None,'l0':None,'xc':None,'rms':None})
......
......@@ -48,30 +48,28 @@ from watchdog.events import PatternMatchingEventHandler
# --------------------------------
docopt_args = docopt(__doc__)
# watchdog append fits files to the raw list
class UpdateRawList(PatternMatchingEventHandler):
def process(self, event):
raws.append(event.src_path)
drslogger.log('File %s has arrived.' % (event.src_path))
def on_created(self, event):
ext = os.path.splitext(event.src_path)[1]
if ext == '.fts':
self.process(event)
def run_gofio(CONFIG, rawlists, dbcalib, working, group, stop, drslogger, dbnight, dbramps):
do_calib = CONFIG['DO_CALIB']
rawdir = CONFIG['RAW_DIR']
# check if there are already files in RAW_DIR, create list raws in temporal order
fits = os.path.join(rawdir,"*.fts")
#global raws
raws = glob.glob(fits)
raws.sort()
# watchdog append fits files to the raw list
class UpdateRawList(PatternMatchingEventHandler):
def process(self, event):
#global raws
raws.append(event.src_path)
drslogger.log('File %s has arrived.' % (event.src_path))
def on_created(self, event):
ext = os.path.splitext(event.src_path)[1]
if ext == '.fts':
self.process(event)
# use watchdog to check when new files are created
observer = Observer()
observer.schedule(UpdateRawList(),rawdir)
......@@ -112,7 +110,6 @@ def run_gofio(CONFIG, rawlists, dbcalib, working, group, stop, drslogger, dbnigh
sys.exit(0)
except KeyboardInterrupt:
observer.stop()
# reduce any file still pending!
if working:
......
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