def imagetype(img, _header, _telescope): from snoopy2 import src img = src.replace_directory(img) import re from astropy.io import fits as pyfits geth = pyfits.getheader(img) try: _imagetype = geth[_header['hed_imagetyp']] except: _imagetype = '' if not _imagetype: if _telescope == 'FORS1' or _telescope == 'FORS2' or _telescope == 'NTT': try: _imagetype = src.esosecondheader(img, _telescope, 'hed_imagetyp', _header['hed_imagetyp']) except: _imagetype = '' if _imagetype: _imagetype = re.sub("'", "", _imagetype) _imagetype = re.sub('"', '', _imagetype) else: print "WARNING: imagetype keyword has not been found in " + str( img) + " !!!!" #sys.exit() return _imagetype
def objects(img, _header, _telescope): _object = '' import re from snoopy2 import src from astropy.io import fits as pyfits img = src.replace_directory(img) geth = pyfits.getheader(img) try: _object = geth[_header['hed_object']] if not _object: if _telescope == 'FORS1' or _telescope == 'FORS2' or _telescope == 'NTT': _object = src.esosecondheader(img, _telescope, 'hed_object', _header['hed_object']) _object = re.sub("'", "", _object) _object = re.sub(" ", "", _object) _object = re.sub('"', '', _object) _object = re.sub('/', '_', _object) _object = re.sub("\+", "_", _object) _object = re.sub("\.", "_", _object) _object = re.sub("\,", "_", _object) _object = re.sub("\#", "", _object) except: print "WARNING: object keyword has not been found in " + str( img) + " !!!!" #sys.exit() return _object
def slitw(img, _header, _telescope): import snoopy2 from snoopy2 import src img = src.replace_directory(img) import string, re from astropy.io import fits as pyfits geth = pyfits.getheader(img) _slitw = '' if _telescope == 'ca': _slitw = 'slit' else: try: _slitw = float(geth[_header['hed_slitw']]) if _telescope == 'WHT': _slitw = '%.1f' % (_slitw ) #_slitw=((round_(float(_slitw)*2,0))/2) if _telescope == 'ekar': _slitw = '%.2f' % (_slitw) except: try: _slitw = geth[_header['hed_slitw']] except: _slitw = '' if not _slitw: if _telescope == 'NTT' or _telescope == 'FORS1' or _telescope == 'FORS2': try: _slitw = src.esosecondheader(img, _telescope, 'hed_slitw', _header['hed_slitw']) except: _slitw = '' if _slitw: if _telescope == 'TNG': try: for i in string.split(_slitw, '_'): try: tmpslit = float(i) except: pass _slitw = str(tmpslit) + '_arcsec' except: pass _slitw = re.sub('"', '', _slitw) _slitw = re.sub('#', '', _slitw) else: print "WARNING: slit width keyword has not been found in " + str( img) + " !!!!" #sys.exit() return _slitw
def grism(img, _header, _telescope): from snoopy2 import src img = src.replace_directory(img) import string, re from snoopy2 import src import snoopy2 from astropy.io import fits as pyfits geth = pyfits.getheader(img) from time import sleep rec_grism2 = [ 'R158R', 'R300B', 'R316R', 'R1200R', 'R600B', 'LR-B', 'LR-R', 'VHR-R', 'VHR-V', 'Grism_4', 'Grism_8', 'Grism_7', 'Grism_5', 'GR02', 'GR04', 'gr02', 'gr04', 'VPH4', 'gr08', 'GR08', 'Gr_4Hori', 'green-200', 'red-200', 'blue-200', 'blue-100', 'red-100' ] _grism = '' try: _grism = geth[_header['hed_grism']] except: _grism = '' if not _grism: if _telescope == 'FORS1' or _telescope == 'FORS2' or _telescope == 'NTT': try: _grism = src.esosecondheader(img, _telescope, 'hed_grism', _header['hed_grism']) except: _grism = '' if _grism: if _telescope == 'ekar': _filter = filter(img, _header, _telescope) if string.count(rec_grism2, _filter): _grism = _filter if _grism[0] == '"' and _grism[-1] == '"': _grism = eval(_grism) _grism = re.sub('"', '', _grism) _grism = re.sub("'", "", _grism) _grism = re.sub("#", "", _grism) _grism = re.sub(" ", "", _grism) else: print "WARNING: GRISM keyword has not been found in " + str( img) + " !!!!" #sys.exit() return _grism
def UT(img, _header, _telescope): from snoopy2 import src from astropy.io import fits as pyfits import string, re img = src.replace_directory(img) geth = pyfits.getheader(img) try: _UT = str(geth[_header['hed_UT']]) _UT = re.sub(' ', '', _UT) _UT = re.sub('"', '', _UT) _UT = re.sub("'", "", _UT) if not _UT: if _telescope == 'FORS1' or _telescope == 'FORS2' or _telescope == 'NTT': _UT = src.esosecondheader(img, _telescope, 'hed_UT', _header['hed_UT']) if _telescope == 'prompt': _UT = string.split(_UT, 'T')[1] if _telescope == 'Meckering': _UT = string.split(_UT, 'T')[1] if _telescope == 'PS1': _UT = string.split(_UT, 'T')[1] if _telescope == 'wise': _UT = string.split(_UT, 'T')[1] if _telescope == 'trp': _UT = string.split(_UT, 'T')[1] if _telescope == 'swift': _UT = string.split(_UT, 'T')[1] if _telescope == 'sch': _UT = string.split(_UT, 'T')[1] if string.count(_UT, ':') == 1: uh = int(string.split(_UT, ':')[0]) um = (float(string.split(_UT, ':')[1])) elif string.count(_UT, ':') == 2: uh = int(string.split(_UT, ':')[0]) um = (float(string.split(_UT, ':')[1]) + (float(string.split(_UT, ':')[2]) / 60.)) _UT = str(uh) + ':' + str(um) elif string.count(_UT, ':') == 0: if int(float(_UT)) >= 24: _UT = float(_UT) / 3600. uh = int(float(_UT)) um = (float(_UT) - int(float(_UT))) * 60. _UT = str(uh) + ':' + str(um) except: _UT = '' print "WARNING: UT keyword has not been found in " + str(img) + " !!!!" #sys.exit() return _UT
def filter(img, _header, _telescope): import os, re, string import snoopy2 from snoopy2 import src from astropy.io import fits as pyfits #img=src.replace_directory(img) ############################## filter with pyfits geth = pyfits.getheader(img) try: _filter = geth[_header['hed_filter1']] except: _filter = '' ############################### if not _filter: if _telescope == 'FORS1' or _telescope == 'FORS2' or _telescope == 'NTT': try: _filter = src.esosecondheader(img, _telescope, 'hed_filter1', _header['hed_filter1']) except: _filter = '' elif _telescope == 'WHT': _filter = pyfits.open(img)[0].header.get(_header['hed_filter2']) elif _telescope == 'ACAM': _filter = pyfits.open(img)[0].header.get(_header['hed_filter1']) if _filter == 'CLEAR': _filter = pyfits.open(img)[0].header.get( _header['hed_filter2']) if _telescope == 'lp' and _filter == 'clear': _filter = pyfits.open(img)[0].header.get(_header['hed_filter2']) if _telescope == 'FTN' and _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter2']) if _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter3']) if _telescope == 'mer' and _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter2']) if _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter3']) if _telescope == 'FTS' and _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter2']) if _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter3']) if _telescope == 'lsc' and _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter2']) if _filter == 'air': _filter = pyfits.open(img)[0].header.get(_header['hed_filter3']) if _telescope == 'lco0m4' and _filter == 'NOTPRESENT': _filter = pyfits.open(img)[0].header.get(_header['hed_filter2']) if _filter == 'NOTPRESENT': _filter = pyfits.open(img)[0].header.get(_header['hed_filter3']) if _telescope == 'PS1': _filter = re.sub('.00000', '', _filter) if _filter: _filter = re.sub('-', '', _filter) _filter = re.sub('"', '', _filter) _filter = re.sub('_', '', _filter) _filter = re.sub(' ', '', _filter) _filter = re.sub('\#', '', _filter) _filter = re.sub('\*', '', _filter) _filter = re.sub('\t', '', _filter) return _filter
def airmass(img, _header, _telescope): import string, os, sys import snoopy2 from snoopy2 import src img = src.replace_directory(img) from astropy.io import fits as pyfits geth = pyfits.getheader(img) _checkairmass = 1 _airmass = '' try: _airmass = float(geth[_header['hed_airmass']]) except: pass if not _airmass: if _telescope == 'FORS1' or _telescope == 'FORS2' or _telescope == 'NTT': try: _airmass = src.esosecondheader(img, _telescope, 'hed_airmass', _header['hed_airmass']) except: _airmass = '' if not _airmass: #or _airmass>=99: print 'WARNING: Airmass header keyword not found !!' _airmass = 0.00001 _RA = src.RA(img, _header, _telescope) _DEC = src.DEC(img, _header, _telescope) _UT = src.UT(img, _header, _telescope) _date = src.date(img, _header, _telescope) if not _RA or not _DEC: _checkairmass = 0 try: _UT2 = string.split(_UT, ':')[0] + ':' + string.split( string.split(_UT, ':')[1], '.')[0] + ':' + str( int((float(string.split(_UT, ':')[1]) - float( string.split(string.split(_UT, ':')[1], '.')[0])) * 60)) _date2 = _date[0:4] + '-' + _date[4:6] + '-' + _date[6:8] except: print 'WARNING: UT or DATE keywords not found in header, airmmass check not possible.' _checkairmass = 0 if _telescope == 'WHT' or _telescope == 'TNG' or _telescope == 'NOT' or _telescope == 'lp': _observatory = 'lapalma' elif _telescope == 'ekar': _observatory = 'ekar' elif _telescope == 'NTT' or _telescope == 'dutch' or _telescope == 'danish': _observatory = 'lasilla' elif _telescope == 'FORS1' or _telescope == 'FORS2': _observatory = 'paranal' elif _telescope == 'montsec': _observatory = 'montsec' else: print 'WARNING: observatory not found, airmass check not possible.' _observatory = '' _checkairmass = 0 if _observatory and _checkairmass: import pyraf from pyraf import iraf from iraf import astutil f = file('airmass.txt', 'w') f.write('mst = mst ("' + str(_date2) + '",' + str(_UT2) + ', 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] if ((float(_air) - float(_airmass))**2) > 0.01: if _telescope == 'ekar' or _telescope == 'dutch' or _telescope == 'danish' or _telescope == 'montsec': src.updateheader(img, 0, _header['hed_airmass'], _air) #iraf.hedit(img,_header['hed_airmass'],_air,add='yes',update='yes',verify='no') else: print 'Airmass value: ok ' _airmass = float(geth[_header['hed_airmass']]) else: print 'WARNING: airmass check not done ' output = _airmass return output