def searchflat(img, listflat): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = readhdr(img) JD = readkey3(hdr, 'JD') _instrume = readkey3(hdr, 'TELID') grism0 = readkey3(hdr, 'grism') if not listflat: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/flat/' + grism0 listflat = glob.glob(directory + '/*fits') else: directory = '' if listflat: faltfile = '' distance = [] goodlist = [] for flat in listflat: hdrf = readhdr(flat) JDflat = readkey3(hdrf, 'JD') filter1 = readkey3(hdrf, 'filter') if filter0 == filter1: goodlist.append(flat) distance.append(abs(JD - JDflat)) if len(distance) >= 1: flatfile = goodlist[argmin(distance)] else: flatfile = '' else: flatfile = '' return flatfile, directory
def clean_image(img, cleanimg): import floyds from floyds.util import readkey3, readhdr, delete array, header = floyds.cosmics.fromfits(img, verbose=False) import warnings def fxn(): warnings.warn(" ", DeprecationWarning) original_filters = warnings.filters[:] # Ignore warnings. warnings.simplefilter("ignore") try: c = floyds.cosmics.cosmicsimage(array, gain=readkey3(header, 'gain'), readnoise=readkey3(header, 'ron'), sigclip=5.0, sigfrac=0.3, objlim=5.0, verbose=False) c.run(maxiter=4, verbose=False) fxn() finally: warnings.filters = original_filters if not cleanimg: delete(img) cleanimg = img floyds.cosmics.tofits(cleanimg, c.cleanarray, header, verbose=False) return cleanimg
def phase3header(img): import floyds import string from floyds.util import readhdr, readkey3 from numpy import max, min, isfinite from astropy.io import fits img_data = fits.open(img)[0].data hdr = readhdr(img) hedvec0 = { 'DATAMIN': [float(min(img_data[isfinite(img_data)])), ''], 'DATAMAX': [float(max(img_data[isfinite(img_data)])), ''], 'ORIGIN': ['ESO', 'European Southern Observatory'], 'PROCSOFT': ['floyds_' + str(floyds.__version__), 'pipeline version'] } if readkey3(hdr, 'filter'): hedvec0['FILTER'] = [readkey3(hdr, 'filter'), 'Filter name'] if readkey3(hdr, 'gain'): hedvec0['GAIN'] = [ readkey3(hdr, 'gain'), 'Conversion from electrons to ADU' ] if readkey3(hdr, 'esoid'): hedvec0['OBID'] = [readkey3(hdr, 'esoid'), 'Observation block ID'] if readkey3(hdr, 'esoprog'): hedvec0['PROG_ID'] = [ readkey3(hdr, 'esoprog'), 'ESO program identification' ] if readkey3(hdr, 'tech'): hedvec0['OBSTECH'] = [readkey3(hdr, 'tech'), 'Observation technique'] floyds.util.updateheader(img, 0, hedvec0)
def searchatmo(img, listatmo): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = floyds.util.readhdr(img) JD = readkey3(hdr, 'JD') _instrume = readkey3(hdr, 'TELID') grism0 = readkey3(hdr, 'grism') if not listatmo: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/atmo/' + grism0 listatmo = glob.glob(directory + '/*fits') else: directory = '' if listatmo: atmofile = '' distance = [] goodlist = [] for atmo in listatmo: print atmo hdra = readhdr(atmo) JDarc = readkey3(hdra, 'JD') grism1 = readkey3(hdra, 'grism') # slit1=readkey3(hdra,'slit') if grism0 == grism1: goodlist.append(atmo) distance.append(abs(JD - JDarc)) if len(distance) >= 1: atmofile = goodlist[argmin(distance)] else: atmofile = '' else: atmofile = '' return atmofile, directory
def searchatmo(img, listatmo): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = floyds.util.readhdr(img) JD = readkey3(hdr, 'JD') _instrume = readkey3(hdr, 'TELID') grism0 = readkey3(hdr, 'grism') if not listatmo: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/atmo/' + grism0 listatmo = glob.glob(directory + '/*fits') else: directory = '' if listatmo: atmofile = '' distance = [] goodlist = [] for atmo in listatmo: print atmo hdra = readhdr(atmo) JDarc = readkey3(hdra, 'JD') grism1 = readkey3(hdra, 'grism') # slit1=readkey3(hdra,'slit') if grism0 == grism1: goodlist.append(atmo) distance.append(abs(JD - JDarc)) if len(distance) >= 1: atmofile = goodlist[argmin(distance)] else: atmofile = '' else: atmofile = '' return atmofile, directory
def searchflat(img, listflat): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = readhdr(img) JD = readkey3(hdr, 'JD') _instrume = readkey3(hdr, 'TELID') grism0 = readkey3(hdr, 'grism') if not listflat: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/flat/' + grism0 listflat = glob.glob(directory + '/*fits') else: directory = '' if listflat: faltfile = '' distance = [] goodlist = [] for flat in listflat: hdrf = readhdr(flat) JDflat = readkey3(hdrf, 'JD') filter1 = readkey3(hdrf, 'filter') if filter0 == filter1: goodlist.append(flat) distance.append(abs(JD - JDflat)) if len(distance) >= 1: flatfile = goodlist[argmin(distance)] else: flatfile = '' else: flatfile = '' return flatfile, directory
def fluxcalib2d(img2d, sensfun): # flux calibrate 2d images import pyfits import re, string from pyfits import open as popen from numpy import arange, array, float32 from numpy import interp as ninterp import floyds from floyds.util import readhdr, readkey3, delete _tel = floyds.util.readkey3(floyds.util.readhdr(re.sub('\n', '', img2d)), 'TELID') if _tel == 'fts': _extinction = 'ssoextinct.dat' _observatory = 'sso' elif _tel == 'ftn': _extinction = 'maua.dat' _observatory = 'cfht' else: sys.exit('ERROR: observatory not recognised') data2d, hdr2d = pyfits.getdata(img2d, 0, header=True) if 'GRISM' in hdr2d: _arm = hdr2d['GRISM'] else: _arm = '' xxd = arange(len(data2d[0, :])) crvald = popen(img2d)[0].header.get('CRVAL1') cdd = popen(img2d)[0].header.get('CD1_1') _exptime, _airmass = readkey3(readhdr(img2d), 'exptime'), readkey3(readhdr(img2d), 'airmass') # read sensfunction and interpole pixel of 2D image yys = popen(sensfun)[0].data crvals = popen(sensfun)[0].header.get('CRVAL1') cds = popen(sensfun)[0].header.get('CD1_1') yys = (10**(yys / 2.5)) * cds # from sens iraf in sens flux xxs = arange(len(yys)) aasens = crvals + (xxs) * cds xxs2 = (aasens - crvald) / cdd aasens2 = ninterp(xxd, xxs2, yys) # read atmosferic function and interpole pixel of 2D image aae, yye = floyds.util.ReadAscii2(floyds.__path__[0] + '/standard/extinction/' + _extinction) aae, yye = array(aae, float), array(yye, float) xxe = (aae - crvald) / cdd atm_xx = ninterp(xxd, xxe, yye) aircorr = 10**(0.4 * array(atm_xx) * _airmass) img2df = re.sub('.fits', '_2df.fits', img2d) for i in range(len(data2d[:, 0])): data2d[i, :] = ( (array(data2d[i, :] / _exptime) * array(aircorr)) / aasens2) * 1e20 floyds.util.delete(img2df) pyfits.writeto(img2df, float32(data2d), hdr2d) floyds.util.updateheader( img2df, 0, {'SENSFUN' + _arm[0]: [string.split(sensfun, '/')[-1], '']}) floyds.util.updateheader( img2df, 0, {'BUNIT': ['erg/cm2/s/A 10^20', 'Physical unit of array values']}) return img2df
def clean_image(img, cleanimg): import floyds from floyds.util import readkey3, readhdr, delete array, header = floyds.cosmics.fromfits(img, verbose=False) import warnings def fxn(): warnings.warn(" ", DeprecationWarning) original_filters = warnings.filters[:] # Ignore warnings. warnings.simplefilter("ignore") try: c = floyds.cosmics.cosmicsimage(array, gain=readkey3(header, 'gain'), readnoise=readkey3(header, 'ron'), sigclip=5.0, sigfrac=0.3, objlim=5.0, verbose=False) c.run(maxiter=4, verbose=False) fxn() finally: warnings.filters = original_filters if not cleanimg: delete(img) cleanimg = img floyds.cosmics.tofits(cleanimg, c.cleanarray, header, verbose=False) return cleanimg
def fluxcalib2d(img2d,sensfun): # flux calibrate 2d images import pyfits import re,string from pyfits import open as popen from numpy import arange, array, float32 from numpy import interp as ninterp import floyds from floyds.util import readhdr,readkey3,delete _tel=floyds.util.readkey3(floyds.util.readhdr(re.sub('\n','',img2d)),'TELID') if _tel=='fts': _extinction='ssoextinct.dat' _observatory='sso' elif _tel=='ftn': _extinction='maua.dat' _observatory='cfht' else: sys.exit('ERROR: observatory not recognised') data2d, hdr2d = pyfits.getdata(img2d, 0, header=True) if 'GRISM' in hdr2d: _arm=hdr2d['GRISM'] else: _arm='' xxd=arange(len(data2d[0,:])) crvald=popen(img2d)[0].header.get('CRVAL1') cdd=popen(img2d)[0].header.get('CD1_1') _exptime,_airmass=readkey3(readhdr(img2d),'exptime'),readkey3(readhdr(img2d),'airmass') # read sensfunction and interpole pixel of 2D image yys=popen(sensfun)[0].data crvals=popen(sensfun)[0].header.get('CRVAL1') cds=popen(sensfun)[0].header.get('CD1_1') yys=(10**(yys/2.5))*cds # from sens iraf in sens flux xxs=arange(len(yys)) aasens=crvals+(xxs)*cds xxs2=(aasens-crvald)/cdd aasens2=ninterp(xxd,xxs2,yys) # read atmosferic function and interpole pixel of 2D image aae,yye=floyds.util.ReadAscii2(floyds.__path__[0]+'/standard/extinction/'+_extinction) aae,yye=array(aae,float),array(yye,float) xxe=(aae-crvald)/cdd atm_xx=ninterp(xxd,xxe,yye) aircorr=10**(0.4*array(atm_xx)*_airmass) img2df=re.sub('.fits','_2df.fits',img2d) for i in range(len(data2d[:,0])): data2d[i,:]=((array(data2d[i,:]/_exptime)*array(aircorr))/aasens2)*1e20 floyds.util.delete(img2df) pyfits.writeto(img2df, float32(data2d), hdr2d) floyds.util.updateheader(img2df,0,{'SENSFUN'+_arm[0]:[string.split(sensfun,'/')[-1],'']}) floyds.util.updateheader(img2df,0,{'BUNIT':['erg/cm2/s/A 10^20','Physical unit of array values']}) return img2df
def searchsens(img, listsens): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = readhdr(img) if 'MJD' in hdr: JD = readkey3(hdr, 'MJD') elif 'MJD-OBS' in hdr: JD = readkey3(hdr, 'MJD-OBS') _instrume = readkey3(hdr, 'TELID') camera = readkey3(hdr, 'INSTRUME') grism0 = readkey3(hdr, 'grism') if not listsens: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/' + camera + '/sens/' + grism0 listsens = glob.glob(directory + '/*fits') else: directory = '' if listsens: sensfile = '' distance = [] goodlist = [] for sens in listsens: hdrs = readhdr(sens) if 'MJD' in hdrs: JDsens = readkey3(hdrs, 'MJD') elif 'MJD-OBS' in hdrs: JDsens = readkey3(hdrs, 'MJD-OBS') grism1 = readkey3(hdrs, 'grism') if readkey3(hdrs, 'grism') else readkey3(hdrs, 'GRISM') if grism0 == grism1: goodlist.append(sens) distance.append(abs(JD - JDsens)) if len(distance) >= 1: sensfile = goodlist[argmin(distance)] else: sensfile = '' else: sensfile = '' return sensfile, directory
def name_duplicate(img, nome, ext): ########################### import re, string, os, glob import floyds from floyds.util import readhdr, readkey3, delete dimg = readkey3(readhdr(img), 'DATE-OBS') listafile = glob.glob(nome + '_?' + ext + '.fits') + glob.glob(nome + '_??' + ext + '.fits') if len(listafile) == 0: nome = nome + "_1" + ext + '.fits' else: date = [] for l in listafile: date.append(readkey3(readhdr(l), 'DATE-OBS')) if dimg in date: nome = listafile[date.index(dimg)] else: n = 1 while nome + '_' + str(n) + str(ext) + '.fits' in listafile: n = n + 1 nome = nome + '_' + str(n) + str(ext) + '.fits' return nome
def name_duplicate(img, nome, ext): ########################### import re, string, os, glob import floyds from floyds.util import readhdr, readkey3, delete dimg = readkey3(readhdr(img), 'DATE-OBS') listafile = glob.glob(nome + '_?' + ext + '.fits') + glob.glob(nome + '_??' + ext + '.fits') if len(listafile) == 0: nome = nome + "_1" + ext + '.fits' else: date = [] for l in listafile: date.append(readkey3(readhdr(l), 'DATE-OBS')) if dimg in date: nome = listafile[date.index(dimg)] else: n = 1 while nome + '_' + str(n) + str(ext) + '.fits' in listafile: n = n + 1 nome = nome + '_' + str(n) + str(ext) + '.fits' return nome
def airmass(img, overwrite=True, _observatory='lasilla'): import floyds from floyds.util import readhdr, readkey3, delete from pyraf import iraf iraf.astutil(_doprint=0) hdr = readhdr(img) if readkey3(hdr, 'UTC'): _UT = (readkey3(hdr, 'UTC') + (readkey3(hdr, 'exptime') / 2)) / 3600 _date = readkey3(hdr, 'date-obs') _date = _date[0:4] + '-' + _date[4:6] + '-' + _date[6:8] _RA = readkey3(hdr, 'RA') / 15 _DEC = readkey3(hdr, 'DEC') f = file('airmass.txt', 'w') f.write('mst = mst ("' + str(_date) + '",' + str(_UT) + ', obsdb ("' + str(_observatory) + '", "longitude"))\n') f.write( 'air = airmass (' + str(_RA) + ',' + str(_DEC) + ',mst, obsdb ("' + str(_observatory) + '", "latitude"))\n') f.write('print(air)\n') f.close() _air = iraf.astcalc(image=img, command="airmass.txt", Stdout=1)[0] try: _air = float(_air) except: _air = 999 delete('airmass.txt') if overwrite and _air < 99.: floyds.util.updateheader(img, 0, {'AIRMASS': [_air, 'mean airmass computed with astcalc']}) else: _air = '' return _air
def airmass(img, overwrite=True, _observatory='lasilla'): import floyds from floyds.util import readhdr, readkey3, delete from pyraf import iraf iraf.astutil(_doprint=0) hdr = readhdr(img) if readkey3(hdr, 'UTC'): _UT = (readkey3(hdr, 'UTC') + (readkey3(hdr, 'exptime') / 2)) / 3600 _date = readkey3(hdr, 'date-obs') _date = _date[0:4] + '-' + _date[4:6] + '-' + _date[6:8] _RA = readkey3(hdr, 'RA') / 15 _DEC = readkey3(hdr, 'DEC') f = file('airmass.txt', 'w') f.write('mst = mst ("' + str(_date) + '",' + str(_UT) + ', obsdb ("' + str(_observatory) + '", "longitude"))\n') f.write( 'air = airmass (' + str(_RA) + ',' + str(_DEC) + ',mst, obsdb ("' + str(_observatory) + '", "latitude"))\n') f.write('print(air)\n') f.close() _air = iraf.astcalc(image=img, command="airmass.txt", Stdout=1)[0] try: _air = float(_air) except: _air = 999 delete('airmass.txt') if overwrite and _air < 99.: floyds.util.updateheader(img, 0, {'AIRMASS': [_air, 'mean airmass computed with astcalc']}) else: _air = '' return _air
def correctobject(img, coordinatefile): import os, re, sys, string from numpy import arccos, sin, cos, pi, argmin import floyds from floyds.util import readstandard, readhdr, readkey3 scal = pi / 180. std, rastd, decstd, magstd = readstandard(coordinatefile) img = re.sub('\n', '', img) correctcard(img) hdr = readhdr(img) _ra = readkey3(hdr, 'RA') _dec = readkey3(hdr, 'DEC') dd = arccos( sin(_dec * scal) * sin(decstd * scal) + cos(_dec * scal) * cos(decstd * scal) * cos((_ra - rastd) * scal)) * ( (180 / pi) * 3600) if min(dd) < 5200: floyds.util.updateheader(img, 0, {'OBJECT': [std[argmin(dd)], 'Original target.']}) aa, bb, cc = rastd[argmin(dd)], decstd[argmin(dd)], std[argmin(dd)] else: aa, bb, cc = '', '', '' return aa, bb, cc
def spectraresolution(img): from floyds import readkey3, readhdr hdr = readhdr(img) _instrume = readkey3(hdr, 'instrume') _slit = readkey3(hdr, 'slit') _grism = readkey3(hdr, 'grism') risoluzioni = {} risoluzioni['floyds'] = {} risoluzioni['floyds']['blu', '6.0'] = 99 risoluzioni['floyds']['blu', '2.0'] = 99 risoluzioni['floyds']['blu', '1.6'] = 99 risoluzioni['floyds']['red', '6.0'] = 99 risoluzioni['floyds']['red', '2.0'] = 99 risoluzioni['floyds']['red', '1.6'] = 99 if _instrume in risoluzioni.keys(): if (_grism, _slit) in risoluzioni[_instrume].keys(): return risoluzioni[_instrume][_grism, _slit] else: return '' else: return ''
def correctobject(img, coordinatefile): import os, re, sys, string from numpy import arccos, sin, cos, pi, argmin import floyds from floyds.util import readstandard, readhdr, readkey3 scal = pi / 180. std, rastd, decstd, magstd = readstandard(coordinatefile) img = re.sub('\n', '', img) # correctcard(img) hdr = readhdr(img) _ra = readkey3(hdr, 'RA') _dec = readkey3(hdr, 'DEC') dd = arccos( sin(_dec * scal) * sin(decstd * scal) + cos(_dec * scal) * cos(decstd * scal) * cos((_ra - rastd) * scal)) * ( (180 / pi) * 3600) if min(dd) < 5200: floyds.util.updateheader(img, 0, {'OBJECT': [std[argmin(dd)], 'Original target.']}) aa, bb, cc = rastd[argmin(dd)], decstd[argmin(dd)], std[argmin(dd)] else: aa, bb, cc = '', '', '' return aa, bb, cc
def spectraresolution(img): from floyds import readkey3, readhdr hdr = readhdr(img) _instrume = readkey3(hdr, 'instrume') _slit = readkey3(hdr, 'slit') _grism = readkey3(hdr, 'grism') risoluzioni = {} risoluzioni['floyds'] = {} risoluzioni['floyds']['blu', '6.0'] = 99 risoluzioni['floyds']['blu', '2.0'] = 99 risoluzioni['floyds']['blu', '1.6'] = 99 risoluzioni['floyds']['red', '6.0'] = 99 risoluzioni['floyds']['red', '2.0'] = 99 risoluzioni['floyds']['red', '1.6'] = 99 if _instrume in risoluzioni.keys(): if (_grism, _slit) in risoluzioni[_instrume].keys(): return risoluzioni[_instrume][_grism, _slit] else: return '' else: return ''
def searchsens(img, listsens): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = readhdr(img) if 'MJD' in hdr: JD = readkey3(hdr, 'MJD') elif 'MJD-OBS' in hdr: JD = readkey3(hdr, 'MJD-OBS') _instrume = readkey3(hdr, 'TELID') grism0 = readkey3(hdr, 'grism') if not listsens: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/sens/' + grism0 listsens = glob.glob(directory + '/*fits') else: directory = '' if listsens: sensfile = '' distance = [] goodlist = [] for sens in listsens: hdrs = readhdr(sens) if 'MJD' in hdrs: JDsens = readkey3(hdrs, 'MJD') elif 'MJD-OBS' in hdrs: JDsens = readkey3(hdrs, 'MJD-OBS') grism1 = readkey3(hdrs, 'grism') if readkey3(hdrs, 'grism') else readkey3(hdrs, 'GRISM') if grism0 == grism1: goodlist.append(sens) distance.append(abs(JD - JDsens)) if len(distance) >= 1: sensfile = goodlist[argmin(distance)] else: sensfile = '' else: sensfile = '' return sensfile, directory
def phase3header(img): import floyds import string from floyds.util import readhdr, readkey3 from numpy import max, min, isfinite from pyfits import open as popen img_data = popen(img)[0].data hdr = readhdr(img) hedvec0 = {'DATAMIN': [float(min(img_data[isfinite(img_data)])), ''], 'DATAMAX': [float(max(img_data[isfinite(img_data)])), ''], 'ORIGIN': ['ESO', 'European Southern Observatory'], 'PROCSOFT': ['floyds_' + str(floyds.__version__), 'pipeline version']} if readkey3(hdr, 'filter'): hedvec0['FILTER'] = [readkey3(hdr, 'filter'), 'Filter name'] if readkey3(hdr, 'gain'): hedvec0['GAIN'] = [readkey3(hdr, 'gain'), 'Conversion from electrons to ADU'] if readkey3(hdr, 'esoid'): hedvec0['OBID'] = [readkey3(hdr, 'esoid'), 'Observation block ID'] if readkey3(hdr, 'esoprog'): hedvec0['PROG_ID'] = [readkey3(hdr, 'esoprog'), 'ESO program identification'] if readkey3(hdr, 'tech'): hedvec0['OBSTECH'] = [readkey3(hdr, 'tech'), 'Observation technique'] floyds.util.updateheader(img, 0, hedvec0)
def searcharc(img, listarc): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = floyds.util.readhdr(img) JD = readkey3(hdr, 'JD') _instrume = readkey3(hdr, 'TELID') camera = readkey3(hdr, 'INSTRUME') grism0 = readkey3(hdr, 'grism') slit0 = readkey3(hdr, 'slit') #if slit0=='6.0' and _instrume in ['fts','2m0b']: slit0='2.0' #if slit0=='6.0' and _instrume in ['ftn','2m0a']: slit0='1.6' if not listarc: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/' + camera + '/arc/' + grism0 + '/' + slit0 listarc = glob.glob(directory + '/*fits') else: directory = '' if listarc: arcfile = '' distance = [] goodlist = [] for arc in listarc: print arc hdra = readhdr(arc) JDarc = readkey3(hdra, 'JD') grism1 = readkey3(hdra, 'grism') slit1 = readkey3(hdra, 'slit') if slit0 == slit1 and grism0 == grism1: goodlist.append(arc) distance.append(abs(JD - JDarc)) if len(distance) >= 1: arcfile = goodlist[argmin(distance)] else: arcfile = '' else: arcfile = '' return arcfile, directory
def searcharc(img, listarc): from floyds.util import readhdr, readkey3 import floyds import glob, re from numpy import argmin, abs hdr = floyds.util.readhdr(img) JD = readkey3(hdr, 'JD') _instrume = readkey3(hdr, 'TELID') grism0 = readkey3(hdr, 'grism') slit0 = readkey3(hdr, 'slit') #if slit0=='6.0' and _instrume in ['fts','2m0b']: slit0='2.0' #if slit0=='6.0' and _instrume in ['ftn','2m0a']: slit0='1.6' if not listarc: directory = floyds.__path__[0] + '/archive/' + str(_instrume) + '/arc/' + grism0 + '/' + slit0 listarc = glob.glob(directory + '/*fits') else: directory = '' if listarc: arcfile = '' distance = [] goodlist = [] for arc in listarc: print arc hdra = readhdr(arc) JDarc = readkey3(hdra, 'JD') grism1 = readkey3(hdra, 'grism') slit1 = readkey3(hdra, 'slit') if slit0 == slit1 and grism0 == grism1: goodlist.append(arc) distance.append(abs(JD - JDarc)) if len(distance) >= 1: arcfile = goodlist[argmin(distance)] else: arcfile = '' else: arcfile = '' return arcfile, directory
def readkey3(hdr, keyword): import re, string, sys import pyfits if pyfits.__version__: if int(re.sub('\.', '', str(pyfits.__version__))[:2]) <= 30: aa = 'HIERARCH ' else: aa = '' else: aa = '' try: _instrume = hdr.get('INSTRUME').lower() except: _instrume = 'none' if _instrume in ['en05', 'en06']: if not hdr.get('HDRVER'): useful_keys = {'object': 'OBJECT', 'date-obs': 'DATE-OBS', 'ut': 'UTSTART', 'obstype': 'OBSTYPE', 'RA': 'RA', 'DEC': 'DEC', 'datamin': -100, 'datamax': 60000, 'grpid': 'BLKUID', 'exptime': 'EXPTIME', 'JD': 'MJD', 'MJD': 'MJD', 'lamp': 'LMP_ID', 'gain': 'GAIN', 'instrume': 'INSTRUME', 'grism': 'GRISM', 'ron': 'READNOIS', 'airmass': 'AIRMASS', 'slit': 'APERWID', 'telescop': 'TELESCOP'} else: useful_keys = {'object': 'OBJECT', 'date-obs': 'DATE-OBS', 'ut': 'UTSTART', 'obstype': 'OBSTYPE', 'RA': 'RA', 'DEC': 'DEC', 'datamin': -100, 'datamax': 60000, 'grpid': 'BLKUID', 'exptime': 'EXPTIME', 'JD': 'MJD-OBS', 'MJD': 'MJD-OBS', 'lamp': 'LMP1ID', 'gain': 'GAIN', 'instrume': 'INSTRUME', 'grism': 'GRISM', 'ron': 'RDNOISE', 'airmass': 'AIRMASS', 'slit': 'APERWID', 'telescop': 'TELESCOP'} else: useful_keys = {'object': 'OBJECT', 'date-obs': 'DATE-OBS'} if keyword in useful_keys: if type(useful_keys[keyword]) == float: value = useful_keys[keyword] else: value = hdr.get(useful_keys[keyword]) if keyword == 'date-obs': import string, re try: value = re.sub('-', '', string.split(value, 'T')[0]) except: pass elif keyword == 'ut': import string, re try: value = string.split(value, 'T')[1] except: pass elif keyword == 'JD': value = float(value) + 0.5 elif keyword == 'instrume': value = value.lower() elif keyword == 'grism': if not value: value = 'full' elif keyword == 'RA': import string, re value0 = string.split(value, ':') try: value = ((float(value0[0]) + ((float(value0[1]) + (float(value0[2]) / 60.)) / 60.)) * 15) except: value = 0 elif keyword == 'DEC': import string, re value0 = string.split(value, ':') try: if '-' in str(value0[0]): value = ((-1) * (abs(float(value0[0])) + ((float(value0[1]) + (float(value0[2]) / 60.)) / 60.))) else: value = (float(value0[0]) + ((float(value0[1]) + (float(value0[2]) / 60.)) / 60.)) except: value = 0 elif keyword == 'slit': value = re.sub('\"', '', re.sub('slit', '', str(value).lower())) value = re.sub('as', '', re.sub('_', '', str(value.lower()))) if value == 'UNKNOWN': value = '1.6' elif keyword == 'object': value = re.sub('\}', '', value) value = re.sub('\+', '', value) value = re.sub('\{', '', value) value = re.sub('\[', '', value) value = re.sub('\]', '', value) value = re.sub('\(', '', value) value = re.sub('\)', '', value) value = re.sub('\,', '', value) value = re.sub(' ', '', value) else: if keyword == 'date-night': import datetime _date = readkey3(hdr, 'DATE-OBS') a = (datetime.datetime.strptime(string.split(_date, '.')[0], "20%y-%m-%dT%H:%M:%S") - datetime.timedelta( .0)).isoformat() value = re.sub('-', '', string.split(a, 'T')[0]) elif keyword == 'TELID': value = hdr.get(keyword) value = re.sub('-', '', value) if value not in ['fts', 'ftn']: value = hdr.get('SITEID') if value in ['ogg']: value = 'ftn' if value in ['coj']: value = 'fts' else: try: value = hdr.get(keyword) except: sys.exit('Warning: keyword not valid') if type(value) == str: value = re.sub('\#', '', value) return value
def readkey3(hdr, keyword): import re, string, sys try: _instrume = hdr.get('INSTRUME').lower() except: _instrume = 'none' if _instrume in ['en05', 'en06', 'en12']: if not hdr.get('HDRVER'): useful_keys = {'object': 'OBJECT', 'date-obs': 'DATE-OBS', 'ut': 'UTSTART', 'obstype': 'OBSTYPE', 'RA': 'RA', 'DEC': 'DEC', 'CAT-RA': 'CAT-RA', 'CAT-DEC': 'CAT-DEC', 'datamin': -100, 'datamax': 60000, 'grpid': 'BLKUID', 'exptime': 'EXPTIME', 'JD': 'MJD', 'MJD': 'MJD', 'lamp': 'LMP_ID', 'gain': 'GAIN', 'instrume': 'INSTRUME', 'grism': 'GRISM', 'ron': 'READNOIS', 'airmass': 'AIRMASS', 'slit': 'APERWID', 'telescop': 'TELESCOP'} else: useful_keys = {'object': 'OBJECT', 'date-obs': 'DATE-OBS', 'ut': 'UTSTART', 'obstype': 'OBSTYPE', 'RA': 'RA', 'DEC': 'DEC', 'CAT-RA': 'CAT-RA', 'CAT-DEC': 'CAT-DEC', 'datamin': -100, 'datamax': 60000, 'grpid': 'BLKUID', 'exptime': 'EXPTIME', 'JD': 'MJD-OBS', 'MJD': 'MJD-OBS', 'lamp': 'LMP1ID', 'gain': 'GAIN', 'instrume': 'INSTRUME', 'grism': 'GRISM', 'ron': 'RDNOISE', 'airmass': 'AIRMASS', 'slit': 'APERWID', 'telescop': 'TELESCOP'} else: useful_keys = {'object': 'OBJECT', 'date-obs': 'DATE-OBS'} if keyword in useful_keys: if type(useful_keys[keyword]) == float: value = useful_keys[keyword] else: value = hdr.get(useful_keys[keyword]) if keyword == 'date-obs': import string, re try: value = re.sub('-', '', string.split(value, 'T')[0]) except: pass elif keyword == 'ut': import string, re try: value = string.split(value, 'T')[1] except: pass elif keyword == 'JD': value = float(value) + 0.5 elif keyword == 'instrume': value = value.lower() elif keyword == 'grism': if not value: value = 'full' elif keyword == 'grpid': value = '_'.join([hdr.get('BLKUID'), hdr.get('OBJECT')]) elif keyword == 'RA' or keyword == 'CAT-RA': import string, re value0 = string.split(value, ':') try: value = ((float(value0[0]) + ((float(value0[1]) + (float(value0[2]) / 60.)) / 60.)) * 15) except: value = 0 elif keyword == 'DEC' or keyword == 'CAT-DEC': import string, re value0 = string.split(value, ':') try: if '-' in str(value0[0]): value = ((-1) * (abs(float(value0[0])) + ((float(value0[1]) + (float(value0[2]) / 60.)) / 60.))) else: value = (float(value0[0]) + ((float(value0[1]) + (float(value0[2]) / 60.)) / 60.)) except: value = 0 elif keyword == 'slit': value = re.sub('\"', '', re.sub('slit', '', str(value).lower())) value = re.sub('as', '', re.sub('_', '', str(value.lower()))) if value == 'UNKNOWN': value = '1.6' elif keyword == 'object': value = re.sub('\}', '', value) #value = re.sub('\+', '', value) value = re.sub('\{', '', value) value = re.sub('\[', '', value) value = re.sub('\]', '', value) value = re.sub('\(', '', value) value = re.sub('\)', '', value) value = re.sub('\,', '', value) value = re.sub(' ', '', value) else: if keyword == 'date-night': import datetime _date = readkey3(hdr, 'DATE-OBS') a = (datetime.datetime.strptime(string.split(_date, '.')[0], "20%y-%m-%dT%H:%M:%S") - datetime.timedelta( .0)).isoformat() value = re.sub('-', '', string.split(a, 'T')[0]) elif keyword == 'TELID': value = hdr.get(keyword) value = re.sub('-', '', value) if value not in ['fts', 'ftn']: value = hdr.get('SITEID') if value in ['ogg']: value = 'ftn' if value in ['coj']: value = 'fts' else: try: value = hdr.get(keyword) except: sys.exit('Warning: keyword not valid') if type(value) == str: value = re.sub('\#', '', value) return value