Exemplo n.º 1
0
            file_list = f.read().split()
            for element in file_list:
                list_name.append(element)
    python_list_to_text_list(list_name, text_list)

    return list_name

# ------------------------------------------------------------------------------------------------------------------- #


# ------------------------------------------------------------------------------------------------------------------- #
# Load IRAF Packages
# ------------------------------------------------------------------------------------------------------------------- #
iraf.noao(_doprint=0)
iraf.imred(_doprint=0)
iraf.crutil(_doprint=0)
iraf.images(_doprint=0)
iraf.ccdred.instrument = "ccddb$kpno/camera.dat"
# ------------------------------------------------------------------------------------------------------------------- #


# ------------------------------------------------------------------------------------------------------------------- #
# Functions For Tasks In IRAF
# ------------------------------------------------------------------------------------------------------------------- #

def hedit(textlist_files, field_name, value, add_keyword='no'):
    """
    Edits the header key specified by the 'field_name' of all the FITS files in the file 'text_list_files'
    and substitutes it with 'value'.
    Args:
        textlist_files  : Text list containing the names of files whose header is to be edited
Exemplo n.º 2
0
def main():
    iraf.noao()
    iraf.imred()
    iraf.ccdred()
    iraf.crutil()
    iraf.twodspec()
    iraf.apextract()
    name = os.popen('ls object*.lst').readlines()
    name = [i.split('\n')[0] for i in name]
    if len(name) == 0:
        print 'no object, the script end'
    for i in name:
        print 'open file ' + i + '...'
        f = open(i)
        l = f.readlines()
        f.close()
        l = [i2.split('\n')[0] for i2 in l]
        for i2 in l:
            print i2
        objs = []
        calibs = []
        standards = []
        fno = l.index('object') + 1
        while fno < len(l):
            if '.fits' not in l[fno]:
                break
            objs.append('ftbo' + l[fno])
            fno += 1
        fno = l.index('calibration') + 1
        while fno < len(l):
            if '.fits' not in l[fno]:
                break
            calibs.append('ftbo' + l[fno])
            fno += 1
        fno = l.index('standard') + 1
        while fno < len(l):
            if '.fits' not in l[fno]:
                break
            standards.append('ftbo' + l[fno])
            fno += 1
        print '=' * 20, 'reject cosmic ray', '=' * 20
        #cobj = shift_align(objs)
        #cstandard = shift_align(standards)
        cobjs = []
        cstandards = []
        for eobj in objs:
            cobjs.append(cos_clear([eobj]))
        for eobj in standards:
            cstandards.append(cos_clear([eobj]))
        print 'The fits having rejected cosmic ray is: '
        print cobjs
        print cstandards
        print '=' * 20, 'get spectrum line', '=' * 20
        acobjs = []
        acstandards = []
        for cobj in cobjs:
            acobjs.append(get_spec_line(cobj))
        for cobj in cstandards:
            acstandards.append(get_spec_line(cobj))
        acalibs = []
        for i3 in calibs:
            acalibs.append(get_cal_spec_line(i3, cobj))
        print '=' * 20, 'wavelength identify', '=' * 20
        iacalibs = wl_identy(acalibs)
        print '=' * 20, 'wavelength calibrate', '=' * 20
        inamepart = i.replace('.','_').split('_')
        objnames = []
        stdobjnames = []
        for numb in xrange(len(acobjs)):
            objnames.append( 'iac' + inamepart[1] + '_' + inamepart[2] + '_' + inamepart[3] +
                    '_' + str(numb) + '.fits')
        for numb in xrange(len(acstandards)):
            stdobjnames.append('iacstd' + inamepart[1] + '_' + inamepart[2] + '_' + inamepart[3] +
                    '_' + str(numb) + '.fits')
        for numb in xrange(len(objnames)):
            wl_cal(acobjs[numb], objnames[numb], iacalibs)
        for numb in xrange(len(stdobjnames)):
            wl_cal(acstandards[numb], stdobjnames[numb], iacalibs)
        print '=' * 20, 'flux calibrate', '=' * 20
        for objname in objnames:
            final_objname = flux_cal_new(objname, stdobjnames)
        print 'the final object name is', final_objname
Exemplo n.º 3
0
#!/usr/bin/env python
# -*- coding=utf-8 -*-

import os
from pyraf import iraf

iraf.imred()
iraf.crutil()


def crmedian(fn, oname):
    """
    Reject cosmic ray with iraf command crmedian
    fn : fits name or fits name list, like abc.fits or abc.fits,abd.fits or
        @name.lst, should required with iraf syntax.
    type : string
    oname : out put file name or file name list, like cabc.fits or
        cabc.fits,cabd.fits or @cname.lst, should required with iraf syntax.
    """
    if os.path.isfile(oname):
        print 'remove file ' + oname
        os.remove(oname)
    iraf.crmedian(input=fn, output=oname, crmask='', median='', sigma='',
                  residual='', var0=0.0, var1=0.0, var2=0.0, lsigma=10.0,
                  hsigma=3.0, ncmed=5, nlmed=5, ncsig=25, nlsig=25)


def main():
    """
    reject cosmic ray, after wavelength calibration here.
    out file name add a char 'c', like cwftbo*.fits.
Exemplo n.º 4
0
rotoff['F9'] = -225.0
rotoff['MMIRS'] = 180

fitsfiles = sys.argv[1]
mode = sys.argv[2]
spottol = int(sys.argv[3])

fitsfile = average(fitsfiles)
if fitsfile.find('/') is -1:
    fitsfile = "%s/%s" % (os.getcwd(), fitsfile)

os.system("rm -f back.fits")
iraf.images()
iraf.images.imfit()
iraf.images.imutil()
iraf.crutil()
iraf.set(uparm="./uparm")
if mode == 'MMIRS':
    iraf.imsurfit(fitsfile, 'back.fits', xorder=3, yorder=3, upper=2, lower=2, ngrow=35, rows='[20:510]', columns='[20:510]')
    iraf.imarith(fitsfile, '-', 'back.fits', fitsfile)
    iraf.cosmicrays(fitsfile,fitsfile,interactive='no',threshold=20,fluxratio=3,window=7)
else:
    iraf.imsurfit(fitsfile, 'back.fits', xorder=2, yorder=2, upper=2, lower=2, ngrow=15)
    iraf.imarith(fitsfile, '-', 'back.fits', fitsfile)

hdu = rfits(fitsfile)
hdu.verify('fix')
image = hdu.data
hdr = hdu.header
try:
    rot = hdr['ROT']