示例#1
0
def airmass(img, overwrite=True, _observatory='lasilla'):
    import lsc
    from lsc.util import readhdr, readkey3, delete, updateheader
    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.:
            updateheader(
                img, 0,
                {'AIRMASS': (_air, 'mean airmass computed with astcalc')})
    else:
        _air = ''
    return _air
示例#2
0
def airmass(img,overwrite=True,_observatory='lasilla'):
   import lsc
   from lsc.util import readhdr,readkey3, delete, updateheader
   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.:
         updateheader(img,0,{'AIRMASS':(_air,'mean airmass computed with astcalc')})
   else:   _air=''
   return _air
示例#3
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