Esempio n. 1
0
def RA(img, _header, _telescope):
    import string, re
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    _RA = ''
    try:
        _RA = float(geth[_header['hed_RA']])
        if _RA:
            if _telescope=='NOT' or _telescope=='NTT' or _telescope=='FORS1' or _telescope=='FORS2' \
                    or _telescope=='ca' or _telescope=='rem' or _telescope=='swift' or _telescope=='dutch' \
                    or _telescope=='TNG' or _telescope=='SOFI':
                print 'change RA(degree) in RA(h)'
                _RA = _RA / 15.
    except:
        try:
            _RA = geth[_header['hed_RA']]
            if string.count(_RA, '"'): _RA = eval(_RA)
            if _telescope == 'trp': _RA = string.join(string.split(_RA), ':')
            if string.count(_RA, ':') == 2:
                if _telescope == 'PS1':
                    _RA = ((float(string.split(_RA, ':')[2]) / 60 +
                            float(string.split(_RA, ':')[1])) /
                           60) + (float(string.split(_RA, ':')[0]) / 15.)
                else:
                    _RA = ((float(string.split(_RA, ':')[2]) / 60 +
                            float(string.split(_RA, ':')[1])) / 60) + float(
                                string.split(_RA, ':')[0])

        except:
            print "WARNING: RA keyword has not been found in " + str(
                img) + " !!!!"
        #sys.exit()
    return _RA
Esempio n. 2
0
def DEC(img, _header, _telescope):
    import string
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    _DEC = ''
    try:
        _DEC = float(geth[_header['hed_DEC']])
    except:
        try:
            _DEC = geth[_header['hed_DEC']]
            if string.count(_DEC, '"'): _DEC = eval(_DEC)
            if _telescope == 'trp': _DEC = string.join(string.split(_DEC), ':')
            if string.count(_DEC, ':') == 2:
                if string.count(str(string.split(_DEC, ':')[0]), '-') == 0:
                    _DEC = ((float(string.split(_DEC, ':')[2]) / 60 +
                             float(string.split(_DEC, ':')[1])) / 60) + float(
                                 string.split(_DEC, ':')[0])
                else:
                    _DEC = (-1) * ((
                        (abs(float(string.split(_DEC, ':')[2]) / 60) +
                         float(string.split(_DEC, ':')[1])) / 60) +
                                   abs(float(string.split(_DEC, ':')[0])))
        except:
            print "WARNING: DEC keyword has not been found in " + str(
                img) + " !!!!"
            #sys.exit()
    return _DEC
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
def dichroic(img, _header, _telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    try:
        _dichroic = geth[_header['hed_dichroic']]
    except:
        print "WARNING: Dichroic keyword has not been found !!!!"
    return _dichroic
Esempio n. 6
0
def biassec(img, header, telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    try:
        _biassec = geth[_header['hed_biassec']]
    except:
        print "WARNING: biassec keyword has not been found in " + str(
            img) + " !!!!"
        #sys.exit()
    return _biassec
Esempio n. 7
0
def catlog(img, _header, _telescope):
    from snoopy2 import src
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    img = src.replace_directory(img)
    try:
        _catlog = geth[_header['hed_catlog']]
    except:
        print "WARNING: catalogue keyword has not been found in " + str(
            img) + " !!!!"
        #sys.exit()
    return _catlog
Esempio n. 8
0
def obsmode(img, _header, _telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    _obsmode = ''
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    try:
        _obsmode = geth[_header['hed_OBSMODE']]
    except:
        print "WARNING: obsmode keyword has not been found in " + str(
            img) + " !!!!"
        #sys.exit()
    return _obsmode
Esempio n. 9
0
def exptime(img, _header, _telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)

    try:
        _exptime = float(geth[_header['hed_exptime']])
    except:
        _exptime = ''
        print "WARNING: exposure time keyword has not been found in " + str(
            img) + " !!!!"
    return _exptime
Esempio n. 10
0
def instrument(img, _header, _telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    import string, re
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    try:
        _instrum = geth[_header['hed_instrume']]
        _instrum = re.sub("'", "", _instrum)
    except:
        _instrum = ''
        print "WARNING: INSTRUMENT keyword has not been found in " + str(
            img) + " !!!!"
    return _instrum
Esempio n. 11
0
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
Esempio n. 12
0
def ccdmax(img, _header, _telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    try:
        _ccdmax = float(_header['datamax_value'])
    except:
        try:
            _ccdmax = float(geth[_header['datamax_value']])
        except:
            _ccdmax = []
            print "WARNING: datamin keyword has not been found in " + str(
                img) + " !!!!"
    return _ccdmax
Esempio n. 13
0
def cenwav(img, _header, telescope):
    from snoopy2 import src
    img = src.replace_directory(img)

    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)

    _cenwav = ''
    try:
        _cenwav = float(geth[_header['hed_cenwav']])
    except:
        print "WARNING: central wavlength keyword has not been found in " + str(
            img) + " !!!!"
        #sys.exit()
    return _cenwav
Esempio n. 14
0
def gain(img, _header, _telescope):
    print '#######', img
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    try:
        _gain = float(_header['GAIN_value'])
    except:
        try:
            _gain = float(geth[_header['GAIN_value']])
        except:
            _gain = []
            print "WARNING: GAIN keyword has not been found in " + str(
                img) + " !!!!"
    return _gain
Esempio n. 15
0
def ron(img, _header, _telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)

    try:
        _ron = float(_header['RON_value'])
    except:
        try:
            _ron = float(geth[_header['RON_value']])
        except:
            _ron = 0
            print "WARNING: RON keyword has not been found in " + str(
                img) + " !!!!"
    return _ron
Esempio n. 16
0
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
Esempio n. 17
0
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
Esempio n. 18
0
def date(img, _header, _telescope):
    import re, string
    from snoopy2 import src
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    img = src.replace_directory(img)
    _date = ''
    try:
        _date = geth[_header['hed_date']]
        _date = re.sub('-', '', _date)
        _date = re.sub('/', '', _date)
        if not string.find(_date, 'T') == -1:
            _date = _date[0:string.find(_date, 'T')]
        if _telescope == 'kait':
            print '###telescope= ' + _telescope
            _date = _date[4:8] + _date[2:4] + _date[0:2]
        if len(_date) == 6:
            if int(_date[4:6]) > 50:
                y = str('19' + str(_date[4:6]))
            else:
                y = str('20' + str(_date[4:6]))
            m = str(_date[2:4])
            g = str(_date[0:2])
            _date = str(y) + str(m) + str(g)
    except:
        try:
            JD = src.JD(img, _header, _telescope)
            month, day, year, hour, _min = jd2ut(JD + 2400000)
            if len(str(month)) == 1: month = '0' + str(month)
            if len(str(day)) == 1: day = '0' + str(day)

            _date = str(year) + str(month) + str(day)
            print month, day, year, hour, _min
            src.updateheader(img, 0, _header['hed_date'], _date)
        except:
            print "WARNING: DATE keyword has not been found in " + str(
                img) + " !!!!"


#           sys.exit()
    return _date
Esempio n. 19
0
def trimsec(img, _header, _telescope):
    from snoopy2 import src
    img = src.replace_directory(img)
    from astropy.io import fits as pyfits
    geth = pyfits.getheader(img)
    if _telescope == 'NOT':
        try:
            _trimsec = _header['hed_trimsec']
        except:
            print "WARNING: trimsec keyword has not been found in " + str(
                img) + " !!!!"
            _trimsec = []
        #sys.exit()
    else:
        try:
            _trimsec = geth[_header['hed_trimsec']]
        except:
            print "WARNING: trimsec keyword has not been found in " + str(
                img) + " !!!!"
            _trimsec = []
            #sys.exit()
    return _trimsec
Esempio n. 20
0
def sn_coordinate(imgl, _interactive):
    from math import sqrt
    from snoopy2 import src
    import snoopy2
    from pyraf import iraf
    import string
    import os
    imgl = src.replace_directory(imgl)
    if imgl[-5:] != '.fits':
        imgllong = imgl + '.fits'
    else:
        imgllong = imgl
    listastandard = snoopy2.__path__[
        0] + '/standard/fluxstandard/supernovaelist.txt'
    f = open(listastandard, 'r')
    liststd = f.readlines()
    f.close()
    star, ra, dec = [], [], []
    for i in liststd:
        vector = string.split(i)
        star.append(vector[0])
        #print vector
        ra.append(
            float(vector[1]) + ((float(vector[2]) +
                                 (float(vector[3]) / 60.)) / 60.))
        if float(vector[4]) > 0:
            dec.append(
                float(vector[4]) + ((float(vector[5]) +
                                     (float(vector[6]) / 60.)) / 60.))
        else:
            aa = -1 * ((abs(float(vector[4]))) +
                       ((float(vector[5]) + (float(vector[6]) / 60.)) / 60.))
            dec.append(aa)
        print ra[-1], dec[-1], star[-1]
    _telescope = src.telescope(imgllong)
    _system = src.check_system(_telescope, imgllong, Stdout=True)
    _header = src.read_parameter(_telescope, _system)
    if _telescope == 'other':
        print 'other'
        _xdimen = src.xdimen(imgllong, _telescope)
        _ydimen = src.ydimen(imgllong, _telescope)
        xcenter = int(float(_xdimen) / 2)
        ycenter = int(float(_ydimen) / 2)
        f = open('_tmp.tv', 'w')
        f.write(str(xcenter) + '  ' + str(ycenter) + '\n')
        f.close()
        iraf.delete('tmp.coo')
        iraf.wcsctran('_tmp.tv',
                      'tmp.coo',
                      imgl,
                      inwcs='logical',
                      units='degrees degrees',
                      outwcs='world',
                      columns='1 2',
                      formats='%10.8f %10.8f')
        sss = iraf.fields('tmp.coo', '1,2', Stdout=1)
        _RA, _DEC = string.split(sss[2])
        _RA = float(_RA) / 15.
        _DEC = float(_DEC)
    else:
        _RA = src.RA(imgllong, _header, _telescope)
        _DEC = src.DEC(imgllong, _header, _telescope)
    print _RA, _DEC
    ra0 = ''
    if _RA and _DEC:
        for st in range(len(star)):
            distance = sqrt((float(_RA) - float(ra[st]))**2 +
                            (float(_DEC) - float(dec[st]))**2)
            print st, distance
            if distance <= 0.5:
                print str(star[st]), str(_RA), str(_DEC), str(distance)
                refstar = string.split(star[st])[0]
                ra0, dec0 = ra[st], dec[st]
                if _interactive:
                    print ''
                    print '############################################'
                    question = raw_input(
                        'Is this the right object ? [y/n] [y]')
                    print '############################################'
                    print ''
                    if not question: question = 'y'
                    if question in ['Yes', 'Y', 'y', 'YES', 'yes']:
                        break
                    else:
                        ra0, dec0 = '', ''
                else:
                    print '############################################'
                    print ' object found ' + str(refstar)
                    print '############################################'
                    break
    if ra0:
        os.system('rm -rf tmp.*')
        ff = open('tmp.tv', 'w')
        ff.write(str(ra0 * 15.) + ' ' + str(dec0))
        ff.close()
        iraf.wcsctran('tmp.tv',
                      'tmp.pix',
                      imgl,
                      inwcs='world',
                      units='degrees degrees',
                      outwcs='logical',
                      columns='1 2',
                      formats='%10.1f %10.1f')
        iraf.tvmark(1,
                    'tmp.pix',
                    mark="circle",
                    number='yes',
                    radii=10,
                    nxoffse=5,
                    nyoffse=5,
                    color=214,
                    txsize=2)
        xx, yy = string.split(iraf.fields('tmp.pix', '1,2', Stdout=1)[2])
        print xx, yy
        os.system('rm -rf tmp.*')
    else:
        xx, yy = '', ''
        print '### WARNING: no object in the list'
    return xx, yy
Esempio n. 21
0
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