Commit cfe0704c authored by Monica Rainer's avatar Monica Rainer
Browse files

Python 3 version

Directory gofio3 with python3 version. Add a keyword in config.py
parent 9d2bf390
......@@ -19,6 +19,7 @@ webuidatabases
.~*
gofio/calibrations
gofio/drslib/berv
gofio/drslib/nodding_*
gofio/raw
gofio/reduced
gofio/resources/straight_giano_2D
......@@ -26,5 +27,13 @@ gofio/resources/straight_giano_2D_v1_1_old.f
gofio/resources/*MASKC*.fits
gofio/vradlib
gofio/webuidatabases
gofio3/calibrations
gofio3/drslib/berv
gofio3/raw
gofio3/reduced
gofio3/resources/straight_giano_2D
gofio3/resources/straight_giano_2D_v1_1_old.f
gofio3/resources/*MASKC*.fits
gofio3/vradlib
gofio3/webuidatabases
No preview for this file type
GOFIO DRS
Language: Python 2.7, one subroutine in Fortran77
Language: Python 2.7 (gofio directory) or Python 3.x (gofio3 directory), one subroutine in Fortran77
If you use this software, please reference the following paper:
Rainer M., et al., 2018, Proc.SPIE 10702, 1070266
"Introducing GOFIO: a DRS for the GIANO-B near-infrared spectrograph",
https://doi.org/10.1117/12.2312130
Python packages:
Python packages with minimum version requirement:
- AstroPy v1.3
- ccdproc v1.2 (a sub-package of AstroPy)
- NumPy v1.12
......@@ -22,7 +22,7 @@ Other requirements:
Installation:
- preserve the directory tree:
gofio/
gofio/ OR gofio3/
__init__.py
__version__.py
gofioDRS.py
......
__version__ = '1.6.1'
__version__ = '1.6.2'
......@@ -183,8 +183,8 @@ CONFIG['BYPOS_UP'] = (' '.join((CONFIG['KEY_DRS'],'BSIGNAL_UP')),'Upper pixel po
# Wavelength calibration
CONFIG['CAL_FUNC'] = {'Oliva':True, 'Poly3':False} # function used for wavelength calibration (Tino Oliva Polynomial or 3-degree polynomial)
#CONFIG['CAL_FUNC'] = {'Oliva':False, 'Poly3':True}
CONFIG['CAL_FUNC'] = {'Oliva':True, 'Poly3':False, 'Poly4':False} # function used for wavelength calibration (Tino Oliva Polynomial or 3-degree polynomial)
#CONFIG['CAL_FUNC'] = {'Oliva':False, 'Poly3':False, 'Poly4':True}
CONFIG['CAL_FAILED'] = (' '.join((CONFIG['KEY_DRS'],'CAL ORDER')),'Calibration successful')
CONFIG['WLFIT'] = (' '.join((CONFIG['KEY_DRS'],'CAL WLFUNC')),'Function used for wavelength calibration')
......@@ -192,10 +192,13 @@ CONFIG['WLFIT'] = (' '.join((CONFIG['KEY_DRS'],'CAL WLFUNC')),'Function used for
if CONFIG['CAL_FUNC']['Oliva']:
CONFIG['WLFIT_FUNC'] = 'l0 + k1*(x-xc) + k2*(x-xc)**2 + k3*(x-xc)**3'
else:
if CONFIG['CAL_FUNC']['Poly3']:
CONFIG['WLFIT_FUNC'] = 'c0 + c1*x + c2*x**2 + c3*x**3'
CONFIG['WLCOEFFS'] = {'k1':(' '.join((CONFIG['KEY_DRS'],'CAL K1')),'k1 coefficient of the calibration function'),'k2':(' '.join((CONFIG['KEY_DRS'],'CAL K2')),'k2 coefficient of the calibration function'),'k3':(' '.join((CONFIG['KEY_DRS'],'CAL K3')),'k3 coefficient of the calibration function'),'l0':(' '.join((CONFIG['KEY_DRS'],'CAL L0')),'l0 coefficient of the calibration function'),'xc':(' '.join((CONFIG['KEY_DRS'],'CAL XC')),'xc coefficient of the calibration function'),'rms':(' '.join((CONFIG['KEY_DRS'],'CAL RMSE')),'[m/s] RMS error of the calibration'), 'c0':(' '.join((CONFIG['KEY_DRS'],'CAL C0')),'c0 coefficient of the calibration function'),'c1':(' '.join((CONFIG['KEY_DRS'],'CAL C1')),'c1 coefficient of the calibration function'),'c2':(' '.join((CONFIG['KEY_DRS'],'CAL C2')),'c2 coefficient of the calibration function'),'c3':(' '.join((CONFIG['KEY_DRS'],'CAL C3')),'c3 coefficient of the calibration function'),'rms_poly':(' '.join((CONFIG['KEY_DRS'],'CAL RMSE')),'[m/s] RMS error of the calibration')}
else:
CONFIG['WLFIT_FUNC'] = 'c0 + c1*x + c2*x**2 + c3*x**3 + c4*x**4'
CONFIG['WLCOEFFS'] = {'k1':(' '.join((CONFIG['KEY_DRS'],'CAL K1')),'k1 coefficient of the calibration function'),'k2':(' '.join((CONFIG['KEY_DRS'],'CAL K2')),'k2 coefficient of the calibration function'),'k3':(' '.join((CONFIG['KEY_DRS'],'CAL K3')),'k3 coefficient of the calibration function'),'l0':(' '.join((CONFIG['KEY_DRS'],'CAL L0')),'l0 coefficient of the calibration function'),'xc':(' '.join((CONFIG['KEY_DRS'],'CAL XC')),'xc coefficient of the calibration function'),'rms':(' '.join((CONFIG['KEY_DRS'],'CAL RMSE')),'[m/s] RMS error of the calibration'), 'c0':(' '.join((CONFIG['KEY_DRS'],'CAL C0')),'c0 coefficient of the calibration function'),'c1':(' '.join((CONFIG['KEY_DRS'],'CAL C1')),'c1 coefficient of the calibration function'),'c2':(' '.join((CONFIG['KEY_DRS'],'CAL C2')),'c2 coefficient of the calibration function'),'c3':(' '.join((CONFIG['KEY_DRS'],'CAL C3')),'c3 coefficient of the calibration function'),'c4':(' '.join((CONFIG['KEY_DRS'],'CAL C4')),'c4 coefficient of the calibration function'),'rms_poly':(' '.join((CONFIG['KEY_DRS'],'CAL RMSE')),'[m/s] RMS error of the calibration')}
#
# DB configuration
......@@ -304,6 +307,13 @@ 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
#
# Miscellaneous
#
CONFIG['LEAP_UPDATE'] = True # Used by baycorrpy to update the leapsecond. Set to False if the online table are not available
# radial velocity computation configuration
# TO DO
......
......@@ -19,11 +19,11 @@ The header options are:
Usage:
spa_gofio2ascii.py -h
spa_gofio2ascii.py
spa_gofio2ascii.py [--hea=<value> --split]
spa_gofio2ascii.py <list>
spa_gofio2ascii.py <list> [--hea=<value> --split]
gofio2ascii.py -h
gofio2ascii.py
gofio2ascii.py [--hea=<value> --split]
gofio2ascii.py <list>
gofio2ascii.py <list> [--hea=<value> --split]
Options:
-h,--help : show this screen
......@@ -89,6 +89,8 @@ with open(lista) as framelist:
hea = ''.join((hea1,heasel))
else:
hea = hea1
for o in xrange(50): #python2
#for o in range(50): #python3
......@@ -97,14 +99,18 @@ with open(lista) as framelist:
snr[o] = snr[o][::-1]
order[o] = o+32
if docopt_args['--split']:
#print(1)
txt = '_' + str(o+32) + '.txt'
order_ascii = frame.replace('.fits',txt)
order = np.vstack((wcalib[o],spec[o],snr[o],order[o]))
#print(txt)
order_data = np.vstack((wcalib[o],spec[o],snr[o],order[o]))
#print(2)
if docopt_args['--hea'] == 'none':
ascii.write(np.transpose(order),order_ascii, fmt=[wave_fmt, flux_fmt , snr_fmt , order_fmt])
np.savetxt(order_ascii,np.transpose(order_data), fmt=[wave_fmt, flux_fmt , snr_fmt , order_fmt])
else:
ascii.write(np.transpose(order),order_ascii, fmt=[wave_fmt, flux_fmt , snr_fmt , order_fmt], header=hea)
np.savetxt(order_ascii,np.transpose(order_data), fmt=[wave_fmt, flux_fmt , snr_fmt , order_fmt], header=hea)
print('Saved %s' % (order_ascii))
if not docopt_args['--split']:
......
......@@ -1039,7 +1039,7 @@ class GBNodding():
pass
try:
dbreduced = self.combine(acalib,bcalib,fsnr, asnrSpec, bsnrSpec)
dbreduced = self.combine(acalib, bcalib, fsnr, asnrSpec, bsnrSpec)
except:
pass
......
......@@ -53,6 +53,7 @@ def badpix(image,bad_mask,inverse_mask):
#t1 = time.time()
filtrarray = np.array([peso]*(half)+[0]+[peso]*(half))
print filtrarray
#t2 = time.time()
#print 'Creating the filter: %s ms' % str((t2-t1)*1000)
......@@ -509,7 +510,7 @@ def UNe_linelist():
#--------------------- UNe calibration -------------------
def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']['Oliva'],use_poly=CONFIG['CAL_FUNC']['Poly3']):
def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']['Oliva'],use_poly=CONFIG['CAL_FUNC']['Poly3'],use_poly4=CONFIG['CAL_FUNC']['Poly4']):
warnings.simplefilter('error',RuntimeWarning)
warnings.simplefilter("ignore", optimize.OptimizeWarning)
......@@ -773,7 +774,7 @@ def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']
#plt.show()
if use_poly:
#print 'Poly3'
fitpoly3 = poly.polyfit(all_pixels,all_waves,deg=3)
#fitpoly3 = np.polyfit(all_pixels,all_waves,deg=3)
#polycalib = np.polyval(fitpoly3,pixrange)
......@@ -808,6 +809,27 @@ def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']
#coeffs = OrderedDict({'c0':coeffc0,'c1':coeffc1,'c2':coeffc2,'c3':coeffc3,'rms':coeffrms})
coeffs.update({'c0':coeffc0,'c1':coeffc1,'c2':coeffc2,'c3':coeffc3,'rms_poly':coeffrms})
if use_poly4:
#print 'Poly4'
fitpoly4 = poly.polyfit(all_pixels,all_waves,deg=4)
chisq=((poly.polyval(all_pixels,fitpoly4)-all_waves)**2).sum()
rvchisq=(((poly.polyval(all_pixels,fitpoly4)-all_waves)/all_waves)**2).sum()
dof=max(len(all_pixels)-5,1)
rmse=np.sqrt(chisq/dof)
rvrmse=np.sqrt(rvchisq/dof)*const.c
coeffc0 = fitpoly4[0]
coeffc1 = fitpoly4[1]
coeffc2 = fitpoly4[2]
coeffc3 = fitpoly4[3]
coeffc4 = fitpoly4[4]
coeffrms = round(rvrmse.value,2)
coeffs.update({'c0':coeffc0, 'c1':coeffc1, 'c2':coeffc2, 'c3':coeffc3, 'c4':coeffc4, 'rms_poly':coeffrms})
else:
#print ' **** WARNING **** Order %s: not enough lines for the calibration!' % (str(order))
......@@ -819,6 +841,9 @@ def UNe_calibrate(lamp,order,select_lines,all_lines,use_oliva=CONFIG['CAL_FUNC']
if use_poly:
#coeffs = OrderedDict({'c0':None,'c1':None,'c2':None,'c3':None,'rms':None})
coeffs.update({'c0':None,'c1':None,'c2':None,'c3':None,'rms_poly':None})
if use_poly4:
#coeffs = OrderedDict({'c0':None,'c1':None,'c2':None,'c3':None,'rms':None})
coeffs.update({'c0':None,'c1':None,'c2':None,'c3':None,'c4':None,'rms_poly':None})
calib_failed = True
......@@ -869,7 +894,7 @@ def wcalib(heawave,o):
wave = lambdafit(pixrange,l0,xc)
else:
if CONFIG['CAL_FUNC']['Poly3']:
#def lambdafit(x):
# return c0 + c1*x + c2*(x**2) + c3*(x**3)
......@@ -889,6 +914,23 @@ def wcalib(heawave,o):
#wave = lambdafit(pixrange)
else:
keyc0 = ''.join((CONFIG['WLCOEFFS']['c0'][0],str(o+32)))
c0 = float(heawave[keyc0])
keyc1 = ''.join((CONFIG['WLCOEFFS']['c1'][0],str(o+32)))
c1 = float(heawave[keyc1])
keyc2 = ''.join((CONFIG['WLCOEFFS']['c2'][0],str(o+32)))
c2 = float(heawave[keyc2])
keyc3 = ''.join((CONFIG['WLCOEFFS']['c3'][0],str(o+32)))
c3 = float(heawave[keyc3])
keyc4 = ''.join((CONFIG['WLCOEFFS']['c4'][0],str(o+32)))
c4 = float(heawave[keyc4])
fitpoly4 = np.array([c0,c1,c2,c3,c4])
wave = poly.polyval(pixrange,fitpoly4)
return wave
......@@ -1226,10 +1268,10 @@ def berv_corr(hdr):
hjd = hjd.value - 2400000.5
#berv = bc.get_BC_vel(JDUTC=mjd, ra=ra, dec=dec, lat = latitude, longi = longitude, alt = elevation, pmra = pma, pmdec = pmd, epoch=epoch, ephemeris = 'de430', leap_update=True)
berv = bc.get_BC_vel(JDUTC=mjd, ra=ra, dec=dec, lat = latitude, longi = longitude, alt = elevation, pmra = pma, pmdec = pmd, epoch=epoch, leap_update=True)
berv = bc.get_BC_vel(JDUTC=mjd, ra=ra, dec=dec, lat = latitude, longi = longitude, alt = elevation, pmra = pma, pmdec = pmd, epoch=epoch, leap_update=CONFIG['LEAP_UPDATE'])
berv = berv[0][0]/1000.0
corr_time = bc.utc_tdb.JDUTC_to_BJDTDB(mjd, ra=ra, dec=dec, lat = latitude, longi = longitude, alt = elevation, pmra = pma, pmdec = pmd, epoch=epoch, leap_update=True)
corr_time = bc.utc_tdb.JDUTC_to_BJDTDB(mjd, ra=ra, dec=dec, lat = latitude, longi = longitude, alt = elevation, pmra = pma, pmdec = pmd, epoch=epoch, leap_update=CONFIG['LEAP_UPDATE'])
corr_time = corr_time[0][0] - 2400000.5
......
from __version__ import __version__
__version__ = '1.6.2'
"""
Remove files form calfiles that are not present in drs_calib.db
It must be run from the drslib directory with the command:
python clean_db.py
"""
import sqlite3, os, glob
from drslib.config import CONFIG
pathdb = CONFIG['DB_CALIB_PATH']
tablename = CONFIG['DB_CALIB_TBL']
pathcal = CONFIG['CALIB_DIR']
def connect_db_cal():
dbcal = sqlite3.connect(pathdb)
return dbcal
def column_names(dbcalib, tablename):
"""
Return the names of the columns in the database.
"""
dbcalib.row_factory = sqlite3.Row
cursor = dbcalib.execute("SELECT * FROM {table}"\
.format(table=tablename,))
row = cursor.fetchone()
names = row.keys()
return names
def check_db(dbcalib, tablename, columns, calname):
"""
Return True if the file does not exist in the database.
"""
cursor = dbcalib.cursor()
for col in columns:
#print(col)
try:
cursor.execute("SELECT * FROM {table} WHERE instr({fpath},?) > 0"\
.format(table=tablename,fpath=col),(calname,))
found = cursor.fetchone()[0]
if found:
return False
except:
pass
return True
if __name__ == "__main__":
# list the calibration files
names = os.path.join(pathcal,"*.fits")
cals = glob.glob(names)
cals.sort()
dbcal = connect_db_cal()
columns = column_names(dbcal, tablename)
while cals:
cal = os.path.basename(cals[0])
check = check_db(dbcal, tablename, columns, cal)
if check:
os.remove(cals[0])
cals.pop(0)
dbcal.close()
"""
Written by Avet Harutyunyan for the old GIANO pipeline
Implemented in the GIANOB DRS by Monica Rainer
"""
import os, tempfile, datetime
from collections import OrderedDict
from __version__ import __version__
def getdate(date_time=None):
tlimit = datetime.time(9, 0, 0)
oneday = datetime.timedelta(days=1)
if date_time:
if isinstance(date_time, datetime.datetime):
pass
elif isinstance(date_time, basestring):
date_time = datetime.datetime.strptime(date_time, '%Y-%m-%dT%H:%M:%S.%f')
else:
date_time = datetime.datetime.utcnow()
date_, time_ = date_time.date(), date_time.time()
if time_ < tlimit:
date_ = date_ - oneday
return date_.strftime('%Y-%m-%d')
def read_usr_config(path):
f = open(path, 'r')
cntnt = f.readlines()
f.close()
usrconfig = {}
for aline in cntnt:
aline = aline.strip()
#print(aline)
if aline:
if aline[0] != '#':
key, value = aline.split(':::')
#print(key)
#print(value)
usrconfig[key.strip()] = eval(value.strip())
return usrconfig
usr_cfg_path = os.path.join(os.getcwd(), 'gofio.cfg')
if os.path.isfile(usr_cfg_path):
#print('qui')
try:
USRCONFIG = read_usr_config(usr_cfg_path)
except:
USRCONFIG = {}
USRCONFIG['OFFLINE'] = False
#print(USRCONFIG)
else:
USRCONFIG ={}
USRCONFIG['OFFLINE'] = False
#print(USRCONFIG)
#
# pipeline configuration
#
CONFIG = {}
CONFIG['APPNAME'] = 'GOFIO'
#CONFIG['VERSION'] = 1.0
CONFIG['VERSION'] = __version__
CONFIG['DATE'] = getdate()
CONFIG['OFFLINE'] = False
#
# Directories
#
CONFIG['TMP_DIR'] = tempfile.gettempdir()
CONFIG['APP_DIR'] = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#CONFIG['BASE_RAW'] = '/mnt/nfs/RAW'
CONFIG['BASE_RAW'] = '/Users/monica/Documents/gofio/gofio3/raw'
CONFIG['BASE_RED_DIR'] = os.path.join(CONFIG['APP_DIR'],'reduced')
#CONFIG['BASE_RED_DIR'] = '/mnt/nfs/REDUCED'
CONFIG['BASE_RAMP'] = '/home/avet/gianorp/databases'
CONFIG['RAW_DIR'] = os.path.join(CONFIG['BASE_RAW'],CONFIG['DATE'])
CONFIG['RED_DIR'] = os.path.join(CONFIG['BASE_RED_DIR'],CONFIG['DATE'])
CONFIG['OFFLINE_DIR'] = False
CONFIG['RED_CALIB'] = os.path.join(CONFIG['RED_DIR'],'CALIB')
CONFIG['RED_STR'] = os.path.join(CONFIG['RED_DIR'],'STR')
# Resources
CONFIG['RES_DIR'] = os.path.join(CONFIG['APP_DIR'], 'resources')
CONFIG['BADPIX_MASK'] = os.path.join(CONFIG['RES_DIR'], 'badpix_mask.fits')
CONFIG['LOGGER'] = {'TERM':True,'FILE':True} # logger writes to terminal and/or to file
CONFIG['LOG_FILE'] = os.path.join(CONFIG['RED_DIR'], 'drs.log')
CONFIG['STRAIGHT'] = os.path.join(CONFIG['RES_DIR'],'straight_giano_2D')
CONFIG['STRAIGHT_OPT'] = ['I=1'] # the option DY is computed automatically
#CONFIG['STRAIGHT_OPT'] = ['I=1','DY=-5'] # define DY only if you want to override the automatic procedure
CONFIG['BASE_CALIB_DIR'] = os.path.join(CONFIG['APP_DIR'], 'calibrations')
CONFIG['CALIB_DIR'] = os.path.join(CONFIG['BASE_CALIB_DIR'], 'calfiles')
CONFIG['CALIB_DB_DIR'] = os.path.join(CONFIG['BASE_CALIB_DIR'], 'database')
CONFIG['WEBUI_DB_DIR'] = os.path.join(CONFIG['APP_DIR'], 'webuidatabases')
# Output name
CONFIG['MERGED'] = 's1d' # suffix for merged spectra
CONFIG['UNMERGED'] = 'ms1d' # suffix for unmerged spectra
#
# Header configuration
#
# Keywords used by the pipeline: change here if the keywords change
# If some keywords are added or removed, change varie/check_keywords accordingly.
CONFIG['KEYS'] = {'OBJECT' : 'OBJECT', 'OBSTYPE' : 'OBS-TYPE', 'OBSMODE' : 'OBSMODE' , 'IMANAME' : 'IMANAME', 'FILENAME' : 'FILENAME', 'NCOMBINE' : 'NCOMBINE', 'MJD' : 'MJD-OBS', 'EXPTIME' : 'EXPTIME', 'NODSTARE' : 'HIERARCH TNG TPL NAME' , 'GROUPN' : 'GROUP_N', 'GROUPI' : 'GROUP_I', 'SLIT' : 'SLIT_POS' , 'STARE' : 'HIERARCH TNG TPL STAREPOS' , 'GROUPID' : 'HIERARCH TNG TPL GROUPID' , 'ID' : 'HIERARCH TNG TPL OBSID' , 'PID' : 'HIERARCH TNG TPL PAIRID' , 'NPAIRS' : 'HIERARCH TNG TPL NPAIRS' , 'IPAIRS' : 'HIERARCH TNG TPL IPAIRS' ,'NREP' : 'HIERARCH TNG CAT EXP NREP' , 'EXTMODE' : 'HIERARCH TNG CAT DR SPEXTMODE' , 'RA' : 'HIERARCH TNG TEL TARG ALPHA' , 'DEC' : 'HIERARCH TNG TEL TARG DELTA' , 'PMA' : 'HIERARCH TNG TEL TARG PMA' , 'PMD' : 'HIERARCH TNG TEL TARG PMD' , 'EQUINOX' : 'HIERARCH TNG TEL TARG EQUINOX' , 'TARG_TYPE' : 'HIERARCH TNG CAT TARG TYPE' , 'AM' : 'AIRMASS' , 'RADVEL' : 'HIERARCH TNG TEL TARG RADVEL' }
# Values of the keyword:
# CONFIG['OBSTYPE'] keyword values to determine the nature of the files
CONFIG['DARK'] = 'DARK'
CONFIG['FLAT'] = 'FLAT'
CONFIG['WCAL_UNE'] = 'WCAL_UNE'
CONFIG['WCAL_FP'] = 'WCAL_FP'
#CONFIG['WCAL_FP'] = 'WCAL_LFC'
CONFIG['SCIENCE'] = 'SCIENCE'
# CONFIG['NODSTARE'] keyword values to determine if stare or nodding
#CONFIG['NODVALUE'] = 'GIANO_sci_nodding'
CONFIG['NODVALUE'] = 'GIANO_obs_nod' # keyword value contains this string
#CONFIG['STAREVALUE'] = 'GIANO_sci_stare'
CONFIG['STAREVALUE'] = 'GIANO_obs_stare' # keyword value contains this string
# CONFIG['SLIT'] keyword values to determine the slit position
CONFIG['A'] = 'A' # value of CONFIG['SLIT'] for A position
CONFIG['B'] = 'B' # value of CONFIG['SLIT'] for B position
CONFIG['C'] = 'C' # value of CONFIG['SLIT'] for C position
# CONFIG['STARE'] keyword values to determine the Obj-Sky position
CONFIG['OBJ'] = 'Obj'
CONFIG['SKY'] = 'Sky'
CONFIG['UNKNOWN'] = 'UNKNOWN'
# CONFIG['EXTMODE'] keyword values to determine to extraction mode
CONFIG['EXTPAIR'] = 'PAIR_EXT'
CONFIG['EXTAVG'] = 'GRPAVG_EXT'
CONFIG['EXTDEFAULT'] = CONFIG['EXTPAIR']
# CONFIG['TARG_TYPE'] keyword values to determine type of object (science, telluric, ...)
CONFIG['TELLURIC'] = 'TELLURIC'
CONFIG['FASTROT'] = 'FASTROT'
CONFIG['TYPE_SCIENCE'] = 'SCIENCE'
#
# Keywords added by the DRS, with relative comments
#
CONFIG['KEY_DRS'] = 'HIERARCH TNG DRS'
CONFIG['RON_EFF'] = (' '.join((CONFIG['KEY_DRS'],'RON')),'Effective RON after image reduction')
CONFIG['GAIN_EFF'] = (' '.join((CONFIG['KEY_DRS'],'GAIN')),'Effective gain after image reduction')
CONFIG['TEXP_EFF'] = (' '.join((CONFIG['KEY_DRS'],'EXPTIME')),'Effective exposure time after image reduction')
CONFIG['SPEC_USED'] = (' '.join((CONFIG['KEY_DRS'],'SPEC')),'Images combined')
CONFIG['SPEC_MJD'] = (' '.join((CONFIG['KEY_DRS'],'MJD')),'MJD of the relative image')
CONFIG['SNR'] = (' '.join((CONFIG['KEY_DRS'],'SNR')),'SNR in the middle of the order',)
CONFIG['STRAIGHT_PAR'] = OrderedDict([ ('P1',' '.join((CONFIG['KEY_DRS'],'STR2DP1'))), ('P2',' '.join((CONFIG['KEY_DRS'],'STR2DP2'))), ('P3',' '.join((CONFIG['KEY_DRS'],'STR2DP3'))), ('P4',' '.join((CONFIG['KEY_DRS'],'STR2DP4'))), ('P5',' '.join((CONFIG['KEY_DRS'],'STR2DP5'))), ('P6',' '.join((CONFIG['KEY_DRS'],'STR2DP6'))) ])
CONFIG['DRS_MJD'] = (' '.join((CONFIG['KEY_DRS'],'MJD')),'Mid-exposure MJD of the (combined) image')
CONFIG['BERV'] = (' '.join((CONFIG['KEY_DRS'],'BERV')),'Barycentric correction [km/s]')
CONFIG['HJD'] = (' '.join((CONFIG['KEY_DRS'],'HJD')),'Mid-exposure HJD (MJD, UTC) of the (combined) image')
CONFIG['BJD'] = (' '.join((CONFIG['KEY_DRS'],'BJD')),'Mid-exposure BJD (MJD, TDB) of the (combined) image')
CONFIG['AIRMASS'] = (' '.join((CONFIG['KEY_DRS'],'AIRMASS')),'Airmass of the combined image')
CONFIG['MASTERFLAT'] = (' '.join((CONFIG['KEY_DRS'],'FLAT')),'Flat-field used for the reduction')
CONFIG['MASTERLAMP'] = (' '.join((CONFIG['KEY_DRS'],'LAMP')),'Calibration lamp used for the reduction')
CONFIG['KEY_WEXT'] = (' '.join((CONFIG['KEY_DRS'],'WEXT')),'Standard extraction window [pixel]')
CONFIG['DRS_VERSION'] = (' '.join((CONFIG['KEY_DRS'],'VERSION')),'GOFIO version')
CONFIG['RED'] = (' '.join((CONFIG['KEY_DRS'],'RED')),'GOFIO reduced file')
CONFIG['RED_TYPE'] = (' '.join((CONFIG['KEY_DRS'],'RED TYPE')),'GOFIO reduced file type')
CONFIG['RED_SUBTYPE'] = (' '.join((CONFIG['KEY_DRS'],'RED SUBTYPE')),'GOFIO reduced file subtype')
CONFIG['RED_SLIT'] = (' '.join((CONFIG['KEY_DRS'],'RED SLIT')),'GOFIO reduced file slit')
CONFIG['YPOS'] = (' '.join((CONFIG['KEY_DRS'],'SIGNAL_POS')),'Pixel position of the signal maximum on the slit') # stare images
CONFIG['YPOS_LOW'] = (' '.join((CONFIG['KEY_DRS'],'SIGNAL_LOW')),'Lower pixel position of the signal on the slit') # stare images
CONFIG['YPOS_UP'] = (' '.join((CONFIG['KEY_DRS'],'SIGNAL_UP')),'Upper pixel position of the signal on the slit') # stare images
CONFIG['AYPOS'] = (' '.join((CONFIG['KEY_DRS'],'ASIGNAL_POS')),'Pixel position of the A signal maximum on the slit') # nodding images
CONFIG['AYPOS_LOW'] = (' '.join((CONFIG['KEY_DRS'],'ASIGNAL_LOW')),'Lower pixel position of the A signal on the slit') # nodding images
CONFIG['AYPOS_UP'] = (' '.join((CONFIG['KEY_DRS'],'ASIGNAL_UP')),'Upper pixel position of the A signal on the slit') # nodding images
CONFIG['BYPOS'] = (' '.join((CONFIG['KEY_DRS'],'BSIGNAL_POS')),'Pixel position of the B signal maximum on the slit') # nodding images
CONFIG['BYPOS_LOW'] = (' '.join((CONFIG['KEY_DRS'],'BSIGNAL_LOW')),'Lower pixel position of the B signal on the slit') # nodding images
CONFIG['BYPOS_UP'] = (' '.join((CONFIG['KEY_DRS'],'BSIGNAL_UP')),'Upper pixel position of the B signal on the slit') # nodding images
# Wavelength calibration
CONFIG['CAL_FUNC'] = {'Oliva':True, 'Poly3':False, 'Poly4':False} # function used for wavelength calibration (Tino Oliva Polynomial or 3-degree polynomial)
#CONFIG['CAL_FUNC'] = {'Oliva':False, 'Poly3':False, 'Poly4':True}
CONFIG['CAL_FAILED'] = (' '.join((CONFIG['KEY_DRS'],'CAL ORDER')),'Calibration successful')
CONFIG['WLFIT'] = (' '.join((CONFIG['KEY_DRS'],'CAL WLFUNC')),'Function used for wavelength calibration')
if CONFIG['CAL_FUNC']['Oliva']:
CONFIG['WLFIT_FUNC'] = 'l0 + k1*(x-xc) + k2*(x-xc)**2 + k3*(x-xc)**3'
if CONFIG['CAL_FUNC']['Poly3']:
CONFIG['WLFIT_FUNC'] = 'c0 + c1*x + c2*x**2 + c3*x**3'
else:
CONFIG['WLFIT_FUNC'] = 'c0 + c1*x + c2*x**2 + c3*x**3 + c4*x**4'
CONFIG['WLCOEFFS'] = {'k1':(' '.join((CONFIG['KEY_DRS'],'CAL K1')),'k1 coefficient of the calibration function'),'k2':(' '.join((CONFIG['KEY_DRS'],'CAL K2')),'k2 coefficient of the calibration function'),'k3':(' '.join((CONFIG['KEY_DRS'],'CAL K3')),'k3 coefficient of the calibration function'),'l0':(' '.join((CONFIG['KEY_DRS'],'CAL L0')),'l0 coefficient of the calibration function'),'xc':(' '.join((CONFIG['KEY_DRS'],'CAL XC')),'xc coefficient of the calibration function'),'rms':(' '.join((CONFIG['KEY_DRS'],'CAL RMSE')),'[m/s] RMS error of the calibration'), 'c0':(' '.join((CONFIG['KEY_DRS'],'CAL C0')),'c0 coefficient of the calibration function'),'c1':(' '.join((CONFIG['KEY_DRS'],'CAL C1')),'c1 coefficient of the calibration function'),'c2':(' '.join((CONFIG['KEY_DRS'],'CAL C2')),'c2 coefficient of the calibration function'),'c3':(' '.join((CONFIG['KEY_DRS'],'CAL C3')),'c3 coefficient of the calibration function'),'c4':(' '.join((CONFIG['KEY_DRS'],'CAL C4')),'c4 coefficient of the calibration function'),'rms_poly':(' '.join((CONFIG['KEY_DRS'],'CAL RMSE')),'[m/s] RMS error of the calibration')}
#
# DB configuration
#
# Ramp processor database
CONFIG['RAMP_NAME'] = 'ramps' + CONFIG['DATE'] + '.db'
CONFIG['DB_RAMP'] = os.path.join(CONFIG['BASE_RAMP'],CONFIG['RAMP_NAME'])
CONFIG['DB_RAMP_TBL'] = 'reducedramps'
CONFIG['DB_RAMP_COLS'] = {'fpath':'FPATH' , 'obstype':'OBSTYPE' , 'dateobs':'DATEOBS' , 'object' : 'OBJECT' , 'exptime':'EXPTIME' , 'nodstare':'NODSTARE' , 'slitpos':'SLITPOS' , 'groupi':'GROUPI' , 'groupn':'GROUPN'}
# Calibration database
CONFIG['DB_CALIB'] = 'drs_calib.db'
CONFIG['DB_CALIB_PATH'] = os.path.join(CONFIG['CALIB_DB_DIR'], CONFIG['DB_CALIB'])
CONFIG['DB_CALIB_TBL'] = 'calibrations'
CONFIG['DB_CALIB_COLS'] = OrderedDict([('01_data', 'date_calib'), ('dark10', 'masterdark10'), ('dark30', 'masterdark30'), ('dark60', 'masterdark60'), ('dark100', 'masterdark100'), ('dark200', 'masterdark200'), ('dark300', 'masterdark300'), ('dark600', 'masterdark600'),('flat', 'masterflat'), ('flatstr', 'masterflat_str'), ('flatnor', 'masterflat_nor'), ('shiftY', 'shift_Y') ,('une', 'wl_une'), ('une_str', 'wl_une_str'), ('une_calib', 'wl_une_calib'), ('fp', 'wl_fp'), ('fp_str', 'wl_fp_str'), ('fp_calib','wl_fp_calib')])
CONFIG['DB_CALIB_DATATYPE'] = OrderedDict()
for colname in CONFIG['DB_CALIB_COLS']:
CONFIG['DB_CALIB_DATATYPE'][colname] = 'TEXT'
CONFIG['DB_CALIB_DATATYPE']['01_data'] = 'TEXT unique'
CONFIG['DB_CALIB_DATATYPE']['shiftY'] = 'INTEGER'
# Night reduction database
CONFIG['DB_ONLINE'] = ''.join(('db_',CONFIG['DATE'],'_online.db'))
CONFIG['DB_OFFLINE'] = ''.join(('db_',CONFIG['DATE'],'_offline.db'))
CONFIG['DB_ONLINE_PATH'] = os.path.join(CONFIG['WEBUI_DB_DIR'], CONFIG['DB_ONLINE'])
CONFIG['DB_OFFLINE_PATH'] = os.path.join(CONFIG['WEBUI_DB_DIR'], CONFIG['DB_OFFLINE'])
CONFIG['DB_2D_TBL'] = 'spec2dfiles'
CONFIG['DB_1D_TBL'] = 'spec1dfiles'
CONFIG['DB_CAL_TBL'] = 'calib'
CONFIG['DB_2D_COLS'] = OrderedDict([('names', 'spec_2d_names'), ('stamp', 'process_timestamp')])
CONFIG['DB_1D_COLS'] = OrderedDict([('path', 'spec_1d_path'), ('stamp', 'process_timestamp'), ('id', 'spec_1d_id'), ('type', 'spec_1d_type'), ('stat', 'arch_stat'), ('name', 'objname'), ('slit', 'slitpos'), ('snry', 'snr1'), ('snrj', 'snr2'), ('snrh', 'snr3'), ('snrk', 'snr4')])
CONFIG['DB_CAL_COLS'] = OrderedDict([('type', 'calib_type'), ('names', 'calib_names'), ('status', 'calib_status'), ('stamp', 'process_timestamp')])
CONFIG['DB_2D_DATATYPE'] = {'names': 'TEXT unique', 'stamp': 'REAL'}
CONFIG['DB_1D_DATATYPE'] = {'path': 'TEXT unique', 'stamp': 'REAL', 'id': 'TEXT', 'type': 'TEXT', 'stat': 'INTEGER', 'name': 'TEXT', 'slit': 'TEXT', 'snry': 'REAL', 'snrj': 'REAL', 'snrh': 'REAL', 'snrk': 'REAL'}
CONFIG['DB_CAL_DATATYPE'] = {'type': 'TEXT', 'names': 'TEXT unique', 'status': 'TEXT', 'stamp': 'REAL'}
CONFIG['DB_NIGHT'] = CONFIG['DB_ONLINE']
CONFIG['DB_NIGHT_PATH'] = CONFIG['DB_ONLINE_PATH']
#
# Extraction info
#
CONFIG['MASK_C'] = os.path.join(CONFIG['RES_DIR'], 'GIANOB_MASKC.fits')
CONFIG['A_POS'] = 8. # guess pixel position for A
CONFIG['B_POS'] = 23. # guess pixel position for B
CONFIG['C_POS'] = 15. # guess pixel position for C
CONFIG['Y_POS'] = 7 # max. pixel difference between expected and real pixel position
CONFIG['HWTM'] = 6. # hwtm limit for contamination between A and B