示例#1
0
def check_system(_telescope, img, Stdout=True):
    from snoopy2 import src
    try:
        import pyfits
    except:
        from astropy.io import fits as pyfits

    import re
    if pyfits.getheader(img).get('INSTRUME') == 'SOFI' or pyfits.getheader(
            img).get('INSTRUME') == 'NICS':
        _system = 1
    else:
        aa = 'unknown'
        _header = src.read_parameter(_telescope, 0)
        if _header:
            _filter = src.filter(img, _header, _telescope)
            aa = src.filtername(_telescope, _filter, 0)
        if aa != 'unknown':
            if Stdout:
                print '##################################'
                print 'System optical: UBVRI'
                print '##################################'
            _system = 0
        if aa == 'unknown':
            _header = src.read_parameter(_telescope, 1)
            if _header:
                _filter = src.filter(img, _header, _telescope)
                aa = src.filtername(_telescope, _filter, 1)
            if aa != 'unknown':
                if Stdout:
                    print '##################################'
                    print 'System infrared: JHK'
                    print '##################################'
                _system = 1
        if aa == 'unknown':
            _header = src.read_parameter(_telescope, 2)
            if _header:
                _filter = src.filter(img, _header, _telescope)
                aa = src.filtername(_telescope, _filter, 2)
            if aa != 'unknown':
                if Stdout:
                    print '##################################'
                    print 'System sloan: ugriz'
                    print '##################################'
                _system = 2
        if aa == 'unknown':
            if Stdout:
                print '##################################'
                print 'WARNING: FILTER not recognised in ' + str(
                    img) + ' !!!  '
                print '##################################'
            _system = 99
        #      sys.exit()
    return _system
示例#2
0
def check_tel(img, _aa, _system):
    from snoopy2 import src
    try:
        _header = src.read_parameter(_aa, _system)
        filter = src.filter(img, _header, _aa)
        instrument = src.instrument(img, _header, _aa)
        _airmass = src.airmass(img, _header, _aa)
        _exptime = src.exptime(img, _header, _aa)
        _date = src.date(img, _header, _aa)
        xdim = src.xdimen(img, _aa)
        ydim = src.ydimen(img, _aa)
        _object = src.objects(img, _header, _aa)
        _julday = src.JD(img, _header, _aa)
        _UT = src.UT(img, _header, _aa)
        print '#### Header check ......ok '
        check = 1
    except Exception as e:
        print e
        check = 0
    return check
示例#3
0
def enlargeimage(img, outputimage, _system, factor):
    import snoopy2
    from snoopy2 import src
    _telescope = src.telescope(img)
    _header = src.read_parameter(_telescope, _system)
    _xdimen = src.xdimen(img, _telescope)
    _ydimen = src.ydimen(img, _telescope)
    S = int(_xdimen / factor)
    xtot = S + int(_xdimen) + S
    ytot = S + int(_ydimen) + S
    xstart = S
    xstop = S + int(_xdimen)
    ystart = S
    ystop = S + int(_ydimen)
    from iraf import ctio
    src.delete('testim.fits')
    iraf.imcreate('testim.fits',
                  naxis=2,
                  naxis1=xtot,
                  naxis2=ytot,
                  header='copy',
                  referen=img)
    mm = iraf.imstat(img, fields='mean', nclip=3, lsigma=5, usigma=2,
                     Stdout=1)[1]
    src.delete('testim2.fits')
    iraf.imarith(operand1='testim.fits',
                 op='+',
                 operand2=mm,
                 result='testim2.fits')
    src.delete(outputimage)
    print 'testim2.fits[' + str(xstart) + ':' + str(xstop) + ',' + str(
        ystart) + ':' + str(ystop) + ']'
    iraf.imcopy(input=img,
                output='testim2.fits[' + str(xstart) + ':' + str(xstop) + ',' +
                str(ystart) + ':' + str(ystop) + ']')
    iraf.imrename('testim2.fits', outputimage)
    return outputimage
示例#4
0
        print img
    img = raw_input('Which image do you want to test [' + str(listfits[0]) +
                    '] ? ')
    if not img: img = listfits[0]
else:
    img = sys.argv[1]

_telescope = src.telescope(img)
print '## '
print _telescope
print '## '

_system = src.check_system(_telescope, img, Stdout=True)

if _system not in [0, 1, 2]:
    _header = src.read_parameter(_telescope, 0)
else:
    _header = src.read_parameter(_telescope, _system)

_imagetype = src.imagetype(img, _header, _telescope)
_object = src.objects(img, _header, _telescope)
_JD = src.JD(img, _header, _telescope)
_airmass = src.airmass(img, _header, _telescope)
_filter = src.filter(img, _header, _telescope)
_grism = src.grism(img, _header, _telescope)
_exptime = src.exptime(img, _header, _telescope)
_date = src.date(img, _header, _telescope)
_gain = src.gain(img, _header, _telescope)
_ron = src.ron(img, _header, _telescope)
_lampid = src.lampid(img, _header, _telescope)
_RA = src.RA(img, _header, _telescope)
示例#5
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
示例#6
0
def fwhm_computation(img, tmpfiltercoo, stars, system, interactive):
    from snoopy2 import src
    import snoopy2
    import string, os
    from numpy import compress
    from numpy import array
    from numpy import average
    from numpy import mean
    from numpy import median
    from numpy import std
    from pyraf import iraf
    from numpy import log10
    _telescope = src.telescope(img)
    _header = src.read_parameter(_telescope, system)
    _xdimen = src.xdimen(img, _telescope)
    _ydimen = src.ydimen(img, _telescope)
    _filter = src.filter(img, _header, _telescope)
    try:
        filter = src.filtername(_telescope, _filter, system)
    except:
        filter = _filter
    _exptime = src.exptime(img, _header, _telescope)

    iraf.delete("tmp.imex_output", verify='no')
    stars_pos = []
    alllines = []

    ff = open(tmpfiltercoo, 'r')
    for j in range(0, 3):
        exl = ff.readline()
    for j in range(len(stars)):
        alllines.append(ff.readline())
        xx = string.split(alllines[-1])[0:2]
        os.system('echo ' + xx[0] + ' ' + xx[1] + '> tmp.two')
        pp = iraf.imexam(input=img,
                         frame=1,
                         logfile='',
                         keeplog='no',
                         imagecur='tmp.two',
                         defkey='m',
                         wcs='logical',
                         use_disp='no',
                         Stdout=1)
        if not 1. <= float(xx[0]) <= float(_xdimen) or not 1. <= float(
                xx[1]) <= float(_ydimen):
            stars_pos.append(0)
        elif string.split(pp[1])[-1] == string.split(pp[1])[-2]:
            stars_pos.append(0)
        else:
            stars_pos.append(1)
    ff.close()
    ff = open('tmp.' + img + 'good.coo', 'w')
    for i in range(len(stars_pos)):
        if stars_pos[i]:
            ff.write(alllines[i])
    ff.close()
    for i in range(len(alllines)):
        if stars_pos[i]:
            ff = open('tmp.one', 'w')
            xx = string.split(alllines[i])[0:2]
            ff.write(xx[0] + ' ' + xx[1] + '  a')
            ff.close()
            try:
                iraf.imexam(input=img,
                            frame=1,
                            logfile='tmp.imex_output',
                            keeplog='yes',
                            imagecur='tmp.one',
                            wcs='logical',
                            use_disp='no')
            except:
                if not os.path.isfile('tmp.imex_output'):
                    os.system("echo '# [1] " + str(img) + " - " +
                              str(coordinatelist) + "' > tmp.imex_output")
                    os.system(
                        "echo '#   COL    LINE   COORDINATES      R    MAG    FLUX     SKY    PEAK    E   PA BETA ENCLOSED   MOFFAT DIRECT' >> tmp.imex_output"
                    )
                    os.system(
                        "echo '999.  999. 999. 999.  INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF' >> tmp.imex_output"
                    )
                else:
                    os.system(
                        "echo '999.  999. 999. 999.  INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF INDEF' >> tmp.imex_output"
                    )

    _fwhm0 = iraf.fields('tmp.imex_output', '15', Stdout=1)
    _mag = iraf.fields('tmp.imex_output', '6', Stdout=1)
    _fwhm, _magime = [], []
    j = 0
    for i in range(len(stars)):
        if stars_pos[i]:
            try:
                _magime.append(float(_mag[j]) + 2.5 * log10(_exptime))
            except:
                _magime.append(float(9999))
            try:
                _fwhm.append(float(_fwhm0[j]))
            except:
                _fwhm.append(float(9999))
            j = j + 1
        else:
            _magime.append(float(9999))
            _fwhm.append(float(9999))

    fwhm_ave = compress((array(_fwhm) < 999), _fwhm)

    fwhm_ave1 = compress(
        (average(fwhm_ave) - 2 * std(fwhm_ave) < array(fwhm_ave)) &
        (array(fwhm_ave) < average(fwhm_ave) + std(fwhm_ave) * 2),
        array(fwhm_ave))
    _fwhm_ave = mean(
        compress((average(fwhm_ave1) - 2 * std(fwhm_ave1) < array(fwhm_ave1)) &
                 (array(fwhm_ave1) < average(fwhm_ave1) + std(fwhm_ave1) * 2),
                 array(fwhm_ave1)))

    fwhm_ave22 = compress(
        (average(fwhm_ave) - 2 * std(fwhm_ave) < array(fwhm_ave)) &
        (array(fwhm_ave) < average(fwhm_ave) + std(fwhm_ave) * 2),
        array(fwhm_ave))
    _fwhm_ave2 = median(
        compress(
            (average(fwhm_ave22) - 2 * std(fwhm_ave22) < array(fwhm_ave22)) &
            (array(fwhm_ave22) < average(fwhm_ave22) + std(fwhm_ave22) * 2),
            array(fwhm_ave22)))

    checkfwhm = 'yes'
    while checkfwhm == 'yes':
        print '################ FWHM(median) = ' + str(_fwhm_ave2) + '  '
        print '################ FWHM(mean) = ' + str(_fwhm_ave) + '  '
        if interactive:
            fwhm_ave = raw_input('################ FWHM = [' +
                                 str(_fwhm_ave2) + '] ? ')
        else:
            fwhm_ave = str(_fwhm_ave2)
        try:
            if not fwhm_ave: fwhm_ave = _fwhm_ave2
            else: fwhm_ave = float(fwhm_ave)
            checkfwhm = 'no'
        except:
            print 'WARNING: FWHM not good !!!!'
            checkfwhm = 'yes'

    #fwhm[filter]=fwhm_ave
    iraf.hedit(img, 'qubafwhm', fwhm_ave, add='yes', update='yes', verify='no')
    return fwhm_ave, _magime, stars_pos, _fwhm