def thar_cal(object_b_fn_ec, object_b_fn_ec_w, colour):
# Import IRAF modules:
  iraf.noao(_doprint=0)
  iraf.onedspec(_doprint=0)
# Check input file and reference extraction exist before proceeding:
  if os.path.isfile(object_b_fn_ec) == True:
# Perform dispersion correction:
    iraf.dispcor(input=object_b_fn_ec, output=object_b_fn_ec_w)
    print ' '
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    print colour.capitalize() + ' object spectrum             '
    print '(' + str(object_b_fn_ec) + ')'
    print 'successfully wavelength calibrated in file         '
    print str(object_b_fn_ec_w) + '.'
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    print ' '
  else:
    print ' '
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    print 'Input frame                                        ' 
    print str(object_b_fn_ec)
    print 'does not exist. Exiting script.                    '
    print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
    print ' '
    print ' '
    sys.exit()
示例#2
0
def dispcor_err(msfile):
    '''Propagate error through wavelength rectification.

    Read wavelength solution information from the FITS header and resample an
    image to a linear wavelength scale.

    The error is propagated by simply passing a squared .ms.fits file to
    **dispcor** and taking the square root of the result. This method makes the
    following assumptions:

     1. The wavelength solution in the header is close enough to linear that
        spline3 interpolation used by DISPCOR essentially becomes a linear
        interpolation. This means the error on each output pixel is just the
        quadrature sum of the errors of the input pixels that went into that
        output pixel (divided by the number of pixels).

     2. Any effects of fractional pixels is minimal.
    '''
    tmpname = 'tmp_sq{}'.format(msfile)
    outputname = msfile.replace('me.fits', 'me_lin.fits')
    tmpoutput = 'tmp_sq{}'.format(outputname)
    pow_image(msfile, tmpname, 2.)

    iraf.dispcor(tmpname, tmpoutput, linearize=True, samedisp=True)

    pow_image(tmpoutput, outputname, 0.5)

    return outputname
示例#3
0
def wl_cal(filename, outname, cals):
    print 'run wavelength calibration...'
    if os.path.isfile(outname):
        print 'file %s is already exist' % outname
    else:
        iraf.imred()
        iraf.specred()
        print 'The calibration file is listed below:'
        for i in xrange(len(cals)):
            print i, cals[i], get_fits_objname(cals[i])
        valget = 0
        if len(cals) > 1:
            valget = raw_input('Which one are you want to use?:')
            while type(eval(valget)) != int:
                valget = raw_input('input is not a int type, please reinput:')
            valget = int(valget)
        iraf.refspectra(input = filename
                , references = cals[valget], apertures = '', refaps = ''
                , ignoreaps = True, select = 'interp', sort = ''
                , group = '', time = False, timewrap = 17.0
                , override = False, confirm = True, assign = True
                , logfiles = 'STDOUT,logfile', verbose = False, answer = 'yes')
        print 'make file ' + outname + '...'
        iraf.dispcor(input = filename
                , output = outname, linearize = True, database = 'database'
                , table = '', w1 = 'INDEF', w2 = 'INDEF', dw = 'INDEF'
                , nw = 'INDEF', log = False, flux = True, blank = 0.0
                , samedisp = False, ignoreaps = True
                , confirm = False, listonly = False, verbose = True
                , logfile = '')
    print 'splot %s' % outname
    iraf.splot(images = outname)
示例#4
0
def correlate():
    scilist = glob.glob('AGN*EX.fits')
    stdlist = glob.glob('STD*EX.fits')
    lamps = glob.glob('LAMP*EX.fits')

    for img in lamps:
        hdu = pyfits.getheader(img)
        if hdu['HIERARCH ESO DPR TECH'] == 'SPECTRUM':
            specref = img.rsplit('.fits',1)[0]
        elif hdu['HIERARCH ESO DPR TECH'] == 'MOS':
            mosref = img.rsplit('.fits',1)[0]



    for spec in scilist:
        spec = spec.rsplit('.fits',1)[0]
        iraf.refspectra(spec,references=specref,sort='',group='',confirm='no',assign='yes')
        name = spec.rsplit('_EX',1)[0]+'_EL'
        iraf.dispcor(spec,output=name)

    for spec in stdlist:
        spec = spec.rsplit('.fits',1)[0]
        iraf.refspectra(spec,references=mosref,sort='',group='',confirm='no',assign='yes')
        name = spec.rsplit('_EX',1)[0]+'_EL'
        iraf.dispcor(spec,output=name)
示例#5
0
def dispcor_err(msfile):
    '''Propagate error through wavelength rectification.

    Read wavelength solution information from the FITS header and resample an
    image to a linear wavelength scale.

    The error is propagated by simply passing a squared .ms.fits file to
    **dispcor** and taking the square root of the result. This method makes the
    following assumptions:

     1. The wavelength solution in the header is close enough to linear that
        spline3 interpolation used by DISPCOR essentially becomes a linear
        interpolation. This means the error on each output pixel is just the
        quadrature sum of the errors of the input pixels that went into that
        output pixel (divided by the number of pixels).

     2. Any effects of fractional pixels is minimal.
    '''
    tmpname = 'tmp_sq{}'.format(msfile)
    outputname =  msfile.replace('me.fits','me_lin.fits')
    tmpoutput = 'tmp_sq{}'.format(outputname)
    pow_image(msfile,tmpname,2.)

    iraf.dispcor(tmpname,
                 tmpoutput,
                 linearize=True,
                 samedisp=True)

    pow_image(tmpoutput,outputname,0.5)

    return outputname
示例#6
0
文件: SCRIPT.py 项目: dafh/stuff
def wave_cal (images):
    iraf.dispcor.glo = 'no'
    iraf.dispcor.flux = 'yes'
    iraf.dispcor.input = '@'+ images
    iraf.dispcor.output = 'd//@' + images
    iraf.lpar(iraf.dispcor)
    iraf.dispcor(mode = 'h')
示例#7
0
def red_science(image, flats, spath, object=None, arc='Arc-Red.fits', 
                smooth='BD284211.smooth.fits', telluric='telluric.fits',
                sens='BD284211.sens', biassec=REDBIAS, trimsec=REDTRIM, 
                outflat='Flat-Red.fits', gain=REDGAIN, rdnoise=REDRDNOISE):

    '''Full reduction of KAST science spectra on red CCD'''

    # Bias subtract everything first
    redbias(image, biassec=biassec, trimsec=trimsec)
    redbias(flats, biassec=biassec, trimsec=trimsec)

    # Create and apply flat-field
    make_flat(flats, outflat, gain=gain, rdnoise=rdnoise)
    iraf.ccdproc(image[0], ccdtype='', noproc=no, fixpix=no, overscan=no, 
                 trim=no, zerocor=no, darkcor=no, flatcor=yes, illumcor=no,
                 fringecor=no, readcor=no, scancor=no, flat=outflat)

    # Cosmic ray rejection
    #iraf.lacos_spec(image[0], 'c%s' % image[0], 'cm%s' % image[0],
    #                gain=gain, readn=rdnoise, xorder=9, yorder=3,
    #                sigclip=4.5, sigfrac=0.5, objlim=1.0, niter=3)

    # Extract spectrum
    if object==None:
        object=get_head(image, 'OBJECT')
    iraf.apall('%s' % image[0], output=object, references='', interactive=yes, 
               find=yes, recenter=yes, resize=yes, edit=yes, trace=yes, 
               fittrace=yes, extract=yes, extras=yes, review=no, 
               background='fit', weights='variance', pfit='fit1d', 
               readnoise=rdnoise, gain=gain)

    # Apply wavelength solution to standard
    shutil.copy('%s/%s' % (spath, arc), '.')
    shutil.copy('%s/database/id%s' % (spath, arc.rstrip('.fits')), 'database')
    iraf.refspec(object, references=arc, sort="", group="", override=yes,
                 confirm=no, assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Smooth
    shutil.copy('%s/%s' % (spath, smooth), '.')
    iraf.sarith('%s.w' % object, '/', smooth, '%s.s' % object)

    # Create and apply telluric correction
    shutil.copy('%s/%s' % (spath, telluric), '.')
    iraf.telluric('%s.s' % object, '%s.t' % object, telluric, xcorr=yes,
                  tweakrms=yes, interactive=yes, sample='6850:6950,7575:7700')

    # Flux calibration
    shutil.copy('%s/%s.0001.fits' % (spath, sens), '.')
    iraf.calibrate('%s.t' % object, '%s.f' % object, extinct=yes, flux=yes,
                   extinction='onedstds$kpnoextinct.dat', 
                   observatory='Lick', sensitivity=sens, airmass='',
                   exptime='')

    return
示例#8
0
def blue_science(image, spath, object=None, flat='Flat-Blue.fits', 
                 arc='Arc-Blue.fits', smooth='BD284211.smooth.fits',
                 sens='BD284211.sens', biassec1=BLUEBIAS1, trimsec1=BLUETRIM1,
                 biassec2=BLUEBIAS2, trimsec2=BLUETRIM2, gain=BLUEGAIN, 
                 rdnoise=BLUERDNOISE):

    '''Full reduction of KAST science spectra on blue CCD'''

    # Bias subtract everything first
    bluebias(image, biassec1=biassec1, trimsec1=trimsec1, biassec2=biassec2,
             trimsec2=trimsec2)

    # Apply flat-field
    shutil.copy('%s/%s' % (spath, flat), '.')
    iraf.ccdproc('j%s' % image[0], ccdtype='', noproc=no, fixpix=no, 
                 overscan=no, trim=no, zerocor=no, darkcor=no, flatcor=yes, 
                 illumcor=no, fringecor=no, readcor=no, scancor=no, 
                 flat=flat)

    # Cosmic ray rejection
   #iraf.lacos_spec('j%s' % image[0], 'cj%s' % image[0], 'cmj%s' % image[0],
   #                gain=gain, readn=rdnoise, xorder=9, yorder=3,
   #                sigclip=4.5, sigfrac=0.5, objlim=1.0, niter=3)

    # Extract spectrum
    if object==None:
        object=get_head(image, 'OBJECT')
    iraf.apall('j%s' % image[0], output=object, references='', 
               interactive=yes, find=yes, recenter=yes, resize=yes, edit=yes, 
               trace=yes, fittrace=yes, extract=yes, extras=yes, review=no, 
               background='fit', weights='variance', pfit='fit1d', 
               readnoise=rdnoise, gain=gain)

    # Apply wavelength solution to standard
    shutil.copy('%s/%s' % (spath, arc), '.')
    shutil.copy('%s/database/id%s' % (spath, arc.rstrip('.fits')), 'database')
    iraf.refspec(object, references=arc, sort="", group="", override=yes,
                 confirm=no, assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Smooth
    shutil.copy('%s/%s' % (spath, smooth), '.')
    iraf.sarith('%s.w' % object, '/', smooth, '%s.s' % object)

    # Flux calibration
    shutil.copy('%s/%s.0001.fits' % (spath, sens), '.')
    iraf.calibrate('%s.s' % object, '%s.f' % object, extinct=yes, flux=yes,
                   extinction='onedstds$kpnoextinct.dat', 
                   observatory='Lick', sensitivity=sens, airmass='',
                   exptime='')

    return
示例#9
0
def applywavesolution(inputre, calspec):
    ''' apply calibration solution to science spectra '''

    inputlist = glob.glob(inputre)
    inputstring = ', '.join(inputlist)
    outputstring = ', '.join([inp[:-5] + '_spec.fits' for inp in inputlist])

    iraf.hedit.unlearn()
    iraf.dispcor.unlearn()

    iraf.hedit.fields = 'REFSPEC1'
    iraf.hedit.value = calspec
    iraf.hedit.add = True
    iraf.hedit(images=inputstring)

    iraf.dispcor(input=inputstring, output=outputstring)
示例#10
0
def applywavesolution(inputre, calspec):
    ''' apply calibration solution to science spectra '''

    inputlist = glob.glob(inputre)
    inputstring = ', '.join(inputlist)
    outputstring = ', '.join([inp[:-5]+'_spec.fits' for inp in inputlist])

    iraf.hedit.unlearn()
    iraf.dispcor.unlearn()

    iraf.hedit.fields = 'REFSPEC1'
    iraf.hedit.value = calspec
    iraf.hedit.add = True
    iraf.hedit(images=inputstring)

    iraf.dispcor(input=inputstring, output=outputstring)
def apply_wav_solution(WORK_DIR, include_cal=False):
  print '\n + Applying the wavelength solution\n'
  
  iraf.unlearn('dispcor')

  for i, obj in enumerate(observations[WORK_DIR]['objects']):
    cal = observations[WORK_DIR]['calibs'][i]+'.ec'
    # export wav calibrated spectra
    print 'Using cal:', cal
    for j in ['.ec', '.ec.nosky']:
      #iraf.hedit(images=obj, fields='refspec1', value=observations[WORK_DIR]['calibs'][0]+'.ec', add='yes', verify='no')
      iraf.refspectra(input=obj+j, referen=cal, sort='', group='', confirm='no', Stdout="/dev/null")
      iraf.dispcor(input=obj+j, output=obj+j, lineari='no', verbose='yes')
    if include_cal:
      os.remove(cal+'_wvl.fits')
      # export wav calibrated cal image
      iraf.refspectra(input=cal, referen=cal, sort='', group='', confirm='no', Stdout="/dev/null")
      iraf.dispcor(input=cal, output=cal+'_wvl', lineari='no', verbose='yes')
示例#12
0
def dispcor(imlist_name, database='database'):
    """
    dispcor -- Dispersion correct and resample spectra
    dispcor input output [records]
    database -- path in which idXXX file. ex) /data1/SN2019ein/work/SAO_Spectrum/red/20190509/arc/database/
     dispcor fcdbstd.ms.fits wfcdbstd.ms.fits
    """
    import glob
    import os, sys
    from pyraf import iraf
    iraf.noao()
    iraf.imred()
    iraf.kpnoslit()
    imlist = glob.glob(imlist_name)
    imlist.sort()
    for i in range(len(imlist)):
        inim = imlist[i]
        iraf.dispcor(input=inim,
                     output='w' + inim,
                     database='database',
                     linearize='no')
        iraf.splot(images='w' + inim)
示例#13
0
def blue_standard(image,
                  arcs,
                  flats,
                  object=None,
                  biassec1=BLUEBIAS1,
                  trimsec1=BLUETRIM1,
                  biassec2=BLUEBIAS2,
                  trimsec2=BLUETRIM2,
                  outflat='Flat-Blue.fits',
                  gain=BLUEGAIN,
                  rdnoise=BLUERDNOISE,
                  arc='Arc-Blue.fits',
                  caldir='home$standards/'):
    '''Reduce and calibrate standard star observation with blue CCD'''

    # Bias subtract everything first
    bluebias(image,
             biassec1=biassec1,
             trimsec1=trimsec1,
             biassec2=biassec2,
             trimsec2=trimsec2)
    bluebias(arcs,
             biassec1=biassec1,
             trimsec1=trimsec1,
             biassec2=biassec2,
             trimsec2=trimsec2)
    bluebias(flats,
             biassec1=biassec1,
             trimsec1=trimsec1,
             biassec2=biassec2,
             trimsec2=trimsec2)

    # Create and apply flat-field
    for i in range(len(flats)):
        flats[i] = 'j%s' % flats[i]
    make_flat(flats, outflat, gain=gain, rdnoise=rdnoise)
    iraf.ccdproc('j%s' % image[0],
                 ccdtype='',
                 noproc=no,
                 fixpix=no,
                 overscan=no,
                 trim=no,
                 zerocor=no,
                 darkcor=no,
                 flatcor=yes,
                 illumcor=no,
                 fringecor=no,
                 readcor=no,
                 scancor=no,
                 flat=outflat)
    iraf.ccdproc('j%s' % arcs[0],
                 ccdtype='',
                 noproc=no,
                 fixpix=no,
                 overscan=no,
                 trim=no,
                 zerocor=no,
                 darkcor=no,
                 flatcor=yes,
                 illumcor=no,
                 fringecor=no,
                 readcor=no,
                 scancor=no,
                 flat=outflat)

    # Extract spectrum of standard
    if object == None:
        object = get_head(image, 'OBJECT')
    iraf.apall('j%s' % image[0],
               output=object,
               references='',
               interactive=yes,
               find=yes,
               recenter=yes,
               resize=yes,
               edit=yes,
               trace=yes,
               fittrace=yes,
               extract=yes,
               extras=yes,
               review=no,
               background='fit',
               weights='variance',
               pfit='fit1d',
               readnoise=rdnoise,
               gain=gain)

    # Extract arc and fit wavelength solution
    reference_arc('j%s' % arcs[0], arc, 'j%s' % image[0])

    # Apply wavelength solution to standard
    iraf.refspec(object,
                 references=arc,
                 sort="",
                 group="",
                 override=yes,
                 confirm=no,
                 assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Remove absorption features and smooth
    iraf.splot('%s.w' % object, 1, 1)
    iraf.gauss('temp1[*,1,1]', '%s.smooth' % object, 3.0)
    iraf.sarith('%s.w' % object, '/', '%s.smooth' % object, '%s.s' % object)

    # Define bandpasses for standard star calculation
    iraf.standard('%s.s' % object,
                  '%s.std' % object,
                  extinction='onedstds$kpnoextinct.dat',
                  caldir=caldir,
                  observatory='Lick',
                  interact=yes,
                  star_name=object,
                  airmass='',
                  exptime='')

    # Determine sensitivity function
    iraf.sensfunc('%s.std' % object,
                  '%s.sens' % object,
                  extinction='onedstds$kpnoextinct.dat',
                  newextinction='extinct.dat',
                  observatory='Lick',
                  function='legendre',
                  order=3,
                  interactive=yes)

    return
示例#14
0
def salt_scombine(objlist):

    obj = np.loadtxt(objlist, dtype="str", unpack=True, ndmin=1)
    objlist1d = objlist + '1d'
    objj = os.path.splitext(obj[0])[0]
    if os.path.isfile(objj + 'wsf.fits'):
        os.system('sed s/.fits/wsf1d.fits/ ' + objlist + ' > ' + objlist1d)
        objnofits = string.split(obj[0], sep='.')[0] + 'wsf'
        os.system('sed s/.fits/wsf1d_var.fits/ ' + objlist + ' > templist')
    else:
        os.system('sed s/.fits/ws1d.fits/ ' + objlist + ' > ' + objlist1d)
        objnofits = string.split(obj[0], sep='.')[0] + 'ws'
        os.system('sed s/.fits/ws1d_var.fits/ ' + objlist + ' > templist')

    low_ap = float(
        rt.getsh("grep -i 'low\t' database/ap" + objnofits +
                 " |  awk '{print $3}'"))
    high_ap = float(
        rt.getsh("grep -i 'high\t' database/ap" + objnofits +
                 " |  awk '{print $3}'"))

    apradius = abs(low_ap) + abs(high_ap)
    readnoise = 2.45 * np.sqrt(apradius)
    print "ggg = %s" % readnoise

    iraf.scombine.combine = 'average'
    iraf.scombine.rdnoise = readnoise
    iraf.scombine.reject = 'ccdclip'
    iraf.scombine.scale = 'median'

    outnam = ''.join(rt.header(obj[0], 'OBJECT').split()).lower()
    outname = outnam + '_' + objlist
    if os.path.isfile(outname + '.fits'):
        os.system('rm ' + outname + '.fits')

    inname = str('@' + objlist1d)

    iraf.scombine(input=inname, output=outname, first='yes')

    tempfile = 'temp.fits'
    if os.path.isfile(tempfile):
        os.system('rm ' + tempfile)

    iraf.imsum('@templist', tempfile)
    nspec = len(obj)
    outname_var = outname + '_var'
    if os.path.isfile(outname_var + '.fits'):
        os.system('rm ' + outname_var + '.fits')

    nspec = nspec * nspec

    iraf.imarith(tempfile, '/', nspec, outname_var)

    os.system('rm *temp.fits')
    os.system('rm templist')
    iraf.dispcor(outname_var, output='', table=outname)
    outnametxt = outname + '.txt'
    outname_vartxt = outname_var + '.txt'
    iraf.wspectext(outname, outnametxt, header='no')
    iraf.wspectext(outname_var, outname_vartxt, header='no')

    rssdate = rt.header(obj[0], 'DATE-OBS')
    rssdate = string.replace(rssdate, '-', '')
    pastefinal = outname + '_final_' + rssdate + '.txt'
    os.system('paste ' + outnametxt + ' ' + outname_vartxt + '  > ' +
              pastefinal)
示例#15
0
def wavelength_solution(targetdir,
                        islog,
                        w1,
                        w2,
                        npix,
                        dw,
                        dv):

    """
    Applies wavelength solution using dispcor. Must be run in target directory.
    """

    print 'Target directory is ' + targetdir
    print 'Applying wavelength solution...'

    if os.getcwd() != targetdir:

        raise ValueError('Current working directory must be target directory!')

    if os.path.exists('dimcomb.ms.fits'):
        os.remove('dimcomb.ms.fits')

    iraf.unlearn('dispcor')

    iraf.dispcor.setParam('input','imcomb.ms.fits')
    iraf.dispcor.setParam('output','dimcomb.ms.fits')
    iraf.dispcor.setParam('confirm','yes')

    if len(w1) == 0:
        w1 = None
    if len(w2) == 0:
        w2 = None
    if len(npix) == 0:
        npix = None
    if len(dw) == 0:
        dw = None
    if len(dv) == 0:
        dv = None

    if islog == 'no':

        iraf.dispcor.setParam('log','no')

        if None not in (w1,w2,npix,dw):
            w1 = float(w1)
            w2 = float(w2)
            npix = float(npix)
            dw = float(dw)

        elif None not in (w1, w2, npix):
            w1 = float(w1)
            w2 = float(w2)
            npix = float(npix)
            dw = 'INDEF'

        elif None not in (w1, w2, dw):
            w1 = float(w1)
            w2 = float(w2)
            dw = float(dw)
            npix = 'INDEF'

        elif None not in (w1, dw, npix):
            w1 = float(w1)
            npix = float(npix)
            dw = float(dw)
            w2 = 'INDEF'

        elif None not in (w2, dw, npix):
            w2 = float(w1)
            npix = float(npix)
            dw = float(dw)
            w1 = 'INDEF'

        else:
            raise ValueError('Not enough info to make a wavelength scale!')


        print 'User input w1 = {}, w2 = {}, dw = {}, nw = {}'.format(w1,w2,dw,npix)

        iraf.dispcor.setParam('w1',w1) # Starting wavelength
        iraf.dispcor.setParam('w2',w2) # Ending wavelength
        iraf.dispcor.setParam('nw',npix) # Number of output pixels
        iraf.dispcor.setParam('dw',dw) # Wavelength interval per pixel

    elif islog == 'yes':

        iraf.dispcor.setParam('log','yes')

        # Leave everything black ecept dv

        if None not in (w1,w2,dv):

            w1 = float(w1)
            w2 = float(w2)
            dv = float(dv)
            print 'Constant dv = %.3f km/s' % dv

            from scipy.constants import c
            c = c / 1e3
            dwlog = -np.log10(1 - dv / c)
            dw = dwlog * (w2 - w1) / (np.log10(w2) - np.log10(w1))

        else:
            raise ValueError('Need w1, w2 and dv!')

        print 'User input w1 = {}, w2 = {}, dv = {}, nw = INDEF'.format(w1,w2,dv)

        iraf.dispcor.setParam('w1',w1) # Starting wavelength
        iraf.dispcor.setParam('w2',w2) # Ending wavelength
        iraf.dispcor.setParam('nw','INDEF') # Number of output pixels
        iraf.dispcor.setParam('dw',dw) # Wavelength interval per pixel

    iraf.dispcor()

    return None
示例#16
0
           verify="no",
           show="yes",
           update="yes")

print('Starting dispersion correction')

iraf.dispcor(
    input="J105829_250_3500_4_Grism_7_2015_06_17_yf170018bfcap.fits",
    output="J105829_250_3500_4_Grism_7_2015_06_17_yf170018bfcapw.fits",
    linearize="yes",
    database="database",
    table="",
    w1="3000",
    w2="8000",
    dw="INDEF",
    nw="INDEF",
    log="no",
    flux="yes",
    blank=0.,
    samedisp="no",
    ignoreaps="no",
    confirm="yes",
    listonly="no",
    verbose="no",
    logfile="yes")

#os.system("ls *apbfcw.fits> air.in")
#iraf.asthedit(' @air.in /home/aries/Music/Atsoa2018/airmass.dat')

iraf.standard(
    input="J105829_250_3500_4_Grism_7_2015_06_17_yf170018bfcapw.fits",
示例#17
0
#!/usr/bin/env python
#
# Associate wavelenght solution to science spectra
#
import glob
from pyraf import iraf

calspec = str(raw_input("Enter calibrated spectra: "))

inputre = str(raw_input("Enter regular expression for science spectra: "))
inputlist = glob.glob(inputre)

iraf.hedit.unlearn()
iraf.dispcor.unlearn()
iraf.hedit.fields = 'REFSPEC1'
iraf.hedit.value = calspec
iraf.hedit.add = True
for img in inputlist:
    iraf.hedit(images=img)
    iraf.dispcor(input=img, output=img[:-5] + '_spec')

print '--- DONE ---'
示例#18
0
def reduce_data(filelist_new, filelist_masterflats, filelist_masterthars):
    if len(filelist_new) == 0:
        print("Please, choose science files to reduce first!")
    elif len(filelist_masterflats) == 0:
        print("Please, choose masterflat files first!")
    elif len(filelist_masterthars) == 0:
        print("Please, choose Thorium-Argon reference files first!")
    else:
        print("Starting reduction process...")
        extracted_science_files = []
        current_directory = os.getcwd()

        years = [
            '{:04d}'.format(year) for year in range(2005,
                                                    date.today().year + 1)
        ]
        month = ['{:02d}'.format(mon) for mon in range(1, 13)]

        for i in range(len(filelist_new)):
            trim = trim_remove_bias(filelist_new[i])
            chosen_masterflat = None

            dummyI = trim.replace(".trim_will_be_removed.fits", ".dummyI.fits")
            dummyII = trim.replace(".trim_will_be_removed.fits",
                                   ".dummyII.fits")

            if os.path.exists(dummyI):
                os.remove(dummyI)
            if os.path.exists(dummyII):
                os.remove(dummyII)

            for y in years:
                for mon in month:
                    date_check_1 = y + "_" + mon
                    date_check_2 = y + "-" + mon
                    if ((date_check_1 in trim)
                            or (date_check_2 in trim)) == True:
                        for masterflat in filelist_masterflats:
                            if ((date_check_1 in masterflat)
                                    or (date_check_2 in masterflat)) == True:
                                chosen_masterflat = masterflat

            if chosen_masterflat is None:
                print("Masterflat File not found!!")
                continue

            iraf.imarith(trim, "/", chosen_masterflat, dummyI)

            iraf.apscatter(dummyI,
                           output=dummyII,
                           interactive="No",
                           apertures="1-51",
                           references="find_orders.fits")

            clean = trim.replace(".trim_will_be_removed.fits", ".clean.fits")
            mask = trim.replace(".trim_will_be_removed.fits", ".mask.fits")

            mean_image = iraf.imstat(dummyII,
                                     Stdout=1,
                                     fields="mean",
                                     format="no")
            print(mean_image)

            if float(mean_image[0]) > 5000:
                array, header = cosmics.fromfits(dummyII)

                sigclip = 50.0
                objlim = 50.0

                c = cosmics.cosmicsimage(array,
                                         gain=0.368,
                                         readnoise=3.7,
                                         sigclip=sigclip,
                                         sigfrac=10.0,
                                         objlim=objlim)

                c.run(maxiter=0)
                cosmics.tofits(clean, c.cleanarray, header)
                cosmics.tofits(mask, c.mask, header)

            elif 5000 > float(mean_image[0]) > 1000:
                array, header = cosmics.fromfits(dummyII)
                sigclip = 20.0
                objlim = 20.0
                c = cosmics.cosmicsimage(array,
                                         gain=0.368,
                                         readnoise=3.7,
                                         sigclip=sigclip,
                                         sigfrac=4.0,
                                         objlim=objlim)

                c.run(maxiter=2)
                cosmics.tofits(clean, c.cleanarray, header)
                cosmics.tofits(mask, c.mask, header)
            else:
                array, header = cosmics.fromfits(dummyII)

                sigclip = 5.0
                objlim = 5.0

                c = cosmics.cosmicsimage(array,
                                         gain=0.368,
                                         readnoise=3.7,
                                         sigclip=sigclip,
                                         sigfrac=1.8,
                                         objlim=objlim)

                c.run(maxiter=2)
                cosmics.tofits(clean, c.cleanarray, header)
                cosmics.tofits(mask, c.mask, header)

            extract = trim.replace(".trim_will_be_removed.fits",
                                   ".extracted.fits")
            extracted_science_files.append(extract)

            iraf.apall(clean,
                       output=extract,
                       references="find_orders",
                       profiles="find_orders",
                       apertures="1-51")
            #    iraf.apall(clean, output=extract, references= "find_orders", profiles= "find_orders", apertures = "3-50" )
            #    iraf.apall(clean, output=extract, references= "find_orders", profiles= "find_orders", apertures = "3-50" )
            os.remove(dummyI)
            os.remove(dummyII)
            os.remove(trim)

        write_reftable(filelist_new, filelist_masterthars)

        thar_directory = os.path.dirname(filelist_masterthars[0])

        if thar_directory == os.path.dirname(filelist_new[0]):
            pass
        else:
            remove_file(thar_directory, "science.lis")
            remove_file(thar_directory, "reftable.dat")

            shutil.move("science.lis", thar_directory)
            shutil.move("reftable.dat", thar_directory)
        os.chdir(thar_directory)

        iraf.refspectra("@science.lis",
                        references="reftable.dat",
                        ignoreaps="Yes",
                        sort="",
                        group="",
                        override="yes",
                        confirm="no",
                        assign="yes")
        iraf.dispcor("@science.lis", output="@science.lis")

        if thar_directory == os.path.dirname(filelist_new[0]):
            pass
        else:
            remove_file(current_directory, "science.lis")
            remove_file(current_directory, "reftable.dat")

            shutil.move("science.lis", current_directory)
            shutil.move("reftable.dat", current_directory)
        os.chdir(current_directory)

        normalize_and_merge(extracted_science_files)

        print("Success! Reduction process complete.")
示例#19
0
def red_standard(image, arcs, flats, object=None, biassec=REDBIAS, 
                 trimsec=REDTRIM, outflat='Flat-Red.fits', gain=REDGAIN,
                 rdnoise=REDRDNOISE, arc='Arc-Red.fits', 
                 caldir='home$standards/'):

    '''Reduce and calibrate standard star observation with red CCD'''

    
    # Bias subtract everything first
    redbias(image, biassec=biassec, trimsec=trimsec)
    redbias(arcs, biassec=biassec, trimsec=trimsec)
    redbias(flats, biassec=biassec, trimsec=trimsec)

    # Create and apply flat-field
    make_flat(flats, outflat, gain=gain, rdnoise=rdnoise)
    iraf.ccdproc(image[0], ccdtype='', noproc=no, fixpix=no, overscan=no, 
                 trim=no, zerocor=no, darkcor=no, flatcor=yes, illumcor=no,
                 fringecor=no, readcor=no, scancor=no, flat=outflat)
    arcimages=','.join(arcs)
    iraf.ccdproc(arcs, ccdtype='', noproc=no, fixpix=no, overscan=no, 
                 trim=no, zerocor=no, darkcor=no, flatcor=yes, illumcor=no,
                 fringecor=no, readcor=no, scancor=no, flat=outflat)

    # Extract spectrum of standard
    if object==None:
        object=get_head(image, 'OBJECT')
    iraf.apall(image[0], output=object, references='', interactive=yes, 
               find=yes, recenter=yes, resize=yes, edit=yes, trace=yes, 
               fittrace=yes, extract=yes, extras=yes, review=no, 
               background='fit', weights='variance', pfit='fit1d', 
               readnoise=rdnoise, gain=gain)

    # Extract arc and fit wavelength solution
    iraf.imarith(arcs[0], '+', arcs[1], 'Arc-Sum.fits')
    reference_arc('Arc-Sum.fits', arc, image[0])

    # Apply wavelength solution to standard
    iraf.refspec(object, references=arc, sort="", group="", override=yes,
                 confirm=no, assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Remove absorption features and smooth
    iraf.splot('%s.w' % object, 1, 1)
    iraf.gauss('temp1[*,1,1]', '%s.smooth' % object, 3.0)
    iraf.sarith('%s.w' % object, '/', '%s.smooth' % object, '%s.s' % object)

    # Create and apply telluric correction
    iraf.sarith('%s.w' % object, '/', 'temp1', 'telluric')
    iraf.splot('telluric', 1, 1)
    iraf.telluric('%s.s' % object, '%s.t' % object, 'telluric', xcorr=no,
                  tweakrms=no, interactive=no, sample='6850:6950,7575:7700')

    # Define bandpasses for standard star calculation
    iraf.standard('%s.t' % object, '%s.std' % object, 
                  extinction='onedstds$kpnoextinct.dat', caldir=caldir,
                  observatory='Lick', interact=yes, star_name=object, 
                  airmass='', exptime='')

    # Determine sensitivity function
    iraf.sensfunc('%s.std' % object, '%s.sens' % object, 
                  extinction='onedstds$kpnoextinct.dat', 
                  newextinction='extinct.dat', observatory='Lick',
                  function='legendre', order=3, interactive=yes)

    return
示例#20
0
#!/usr/bin/env python
#
# Associate wavelenght solution to science spectra
#
import glob
from pyraf import iraf

calspec = str(raw_input("Enter calibrated spectra: "))

inputre = str(raw_input("Enter regular expression for science spectra: "))
inputlist = glob.glob(inputre)

iraf.hedit.unlearn()
iraf.dispcor.unlearn()
iraf.hedit.fields = 'REFSPEC1'
iraf.hedit.value = calspec
iraf.hedit.add = True
for img in inputlist:
    iraf.hedit(images=img)
    iraf.dispcor(input=img, output=img[:-5]+'_spec')

print '--- DONE ---'
示例#21
0
def red_science(image,
                flats,
                spath,
                object=None,
                arc='Arc-Red.fits',
                smooth='BD284211.smooth.fits',
                telluric='telluric.fits',
                sens='BD284211.sens',
                biassec=REDBIAS,
                trimsec=REDTRIM,
                outflat='Flat-Red.fits',
                gain=REDGAIN,
                rdnoise=REDRDNOISE):
    '''Full reduction of KAST science spectra on red CCD'''

    # Bias subtract everything first
    redbias(image, biassec=biassec, trimsec=trimsec)
    redbias(flats, biassec=biassec, trimsec=trimsec)

    # Create and apply flat-field
    make_flat(flats, outflat, gain=gain, rdnoise=rdnoise)
    iraf.ccdproc(image[0],
                 ccdtype='',
                 noproc=no,
                 fixpix=no,
                 overscan=no,
                 trim=no,
                 zerocor=no,
                 darkcor=no,
                 flatcor=yes,
                 illumcor=no,
                 fringecor=no,
                 readcor=no,
                 scancor=no,
                 flat=outflat)

    # Cosmic ray rejection
    #iraf.lacos_spec(image[0], 'c%s' % image[0], 'cm%s' % image[0],
    #                gain=gain, readn=rdnoise, xorder=9, yorder=3,
    #                sigclip=4.5, sigfrac=0.5, objlim=1.0, niter=3)

    # Extract spectrum
    if object == None:
        object = get_head(image, 'OBJECT')
    iraf.apall('%s' % image[0],
               output=object,
               references='',
               interactive=yes,
               find=yes,
               recenter=yes,
               resize=yes,
               edit=yes,
               trace=yes,
               fittrace=yes,
               extract=yes,
               extras=yes,
               review=no,
               background='fit',
               weights='variance',
               pfit='fit1d',
               readnoise=rdnoise,
               gain=gain)

    # Apply wavelength solution to standard
    shutil.copy('%s/%s' % (spath, arc), '.')
    shutil.copy('%s/database/id%s' % (spath, arc.rstrip('.fits')), 'database')
    iraf.refspec(object,
                 references=arc,
                 sort="",
                 group="",
                 override=yes,
                 confirm=no,
                 assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Smooth
    shutil.copy('%s/%s' % (spath, smooth), '.')
    iraf.sarith('%s.w' % object, '/', smooth, '%s.s' % object)

    # Create and apply telluric correction
    shutil.copy('%s/%s' % (spath, telluric), '.')
    iraf.telluric('%s.s' % object,
                  '%s.t' % object,
                  telluric,
                  xcorr=yes,
                  tweakrms=yes,
                  interactive=yes,
                  sample='6850:6950,7575:7700')

    # Flux calibration
    shutil.copy('%s/%s.0001.fits' % (spath, sens), '.')
    iraf.calibrate('%s.t' % object,
                   '%s.f' % object,
                   extinct=yes,
                   flux=yes,
                   extinction='onedstds$kpnoextinct.dat',
                   observatory='Lick',
                   sensitivity=sens,
                   airmass='',
                   exptime='')

    return
示例#22
0
def extractSpectra():
    """
    Extract 1D spectra using IRAF interactively

    Interpolate across the two arcs either side to
    get the most accurate wavelength solution

    TODO: Finish docstring
          Add method of using super arc for inital
          identify
    """
    # load IRAF from the location of the login.cl file
    here = os.getcwd()
    os.chdir(loginCl_location)
    from pyraf import iraf
    os.chdir(here)
    time.sleep(2)

    # make a list of the science images to be analysed
    templist = g.glob('i_s*')
    # import IRAF packages for spectroscopy
    iraf.imred(_doprint=0)
    iraf.kpnoslit(_doprint=0)
    # apall parameters
    iraf.apall.setParam('format', 'multispec')
    iraf.apall.setParam('interac', 'yes')
    iraf.apall.setParam('find', 'yes')
    iraf.apall.setParam('recen', 'yes')
    iraf.apall.setParam('resize', 'yes')
    iraf.apall.setParam('trace', 'yes')
    iraf.apall.setParam('fittrac', 'yes')
    iraf.apall.setParam('extract', 'yes')
    iraf.apall.setParam('extras', 'yes')
    iraf.apall.setParam('review', 'yes')
    iraf.apall.setParam('line', 'INDEF')
    iraf.apall.setParam('nsum', '12')
    iraf.apall.setParam('lower', '-6')
    iraf.apall.setParam('upper', '6')
    iraf.apall.setParam('b_funct', 'chebyshev')
    iraf.apall.setParam('b_order', '1')
    iraf.apall.setParam('b_sampl', '-25:-15,15:25')
    iraf.apall.setParam('b_naver', '-100')
    iraf.apall.setParam('b_niter', '0')
    iraf.apall.setParam('b_low_r', '3')
    iraf.apall.setParam('b_high', '3')
    iraf.apall.setParam('b_grow', '0')
    iraf.apall.setParam('width', '10')
    iraf.apall.setParam('radius', '10')
    iraf.apall.setParam('threshold', '0')
    iraf.apall.setParam('nfind', '1')
    iraf.apall.setParam('t_nsum', '10')
    iraf.apall.setParam('t_step', '10')
    iraf.apall.setParam('t_nlost', '3')
    iraf.apall.setParam('t_niter', '7')
    iraf.apall.setParam('t_funct', 'spline3')
    iraf.apall.setParam('t_order', '3')
    iraf.apall.setParam('backgro', 'fit')
    iraf.apall.setParam('skybox', '1')
    iraf.apall.setParam('weights', 'variance')
    iraf.apall.setParam('pfit', 'fit1d')
    iraf.apall.setParam('clean', 'yes')
    iraf.apall.setParam('saturat', SATURATION)
    iraf.apall.setParam('readnoi', RDNOISE)
    iraf.apall.setParam('gain', GAIN)
    iraf.apall.setParam('lsigma', '4.0')
    iraf.apall.setParam('usigma', '4.0')
    iraf.apall.setParam('nsubaps', '1')
    iraf.apall.saveParList(filename="apall.pars")

    # make reference arc for reidentify
    if '.' in args.refarc:
        args.refarc = args.refarc.split('.')[0]
    refarc = "a_s_{}_t.fits".format(args.refarc)
    refarc_out = "a_s_{}_t.ms.fits".format(args.refarc)

    # loop over all the the spectra
    for i in range(0, len(templist)):
        hdulist = fits.open(templist[i])
        prihdr = hdulist[0].header
        target_id = prihdr['CAT-NAME']
        spectrum_id = int(templist[i].split('_')[2].split('r')[1])
        if args.ds9:
            os.system('xpaset fuckingds9 fits < {}'.format(templist[i]))
        # extract the object spectrum
        print("[{}/{}] Extracting spectrum of {} from image {}".format(i+1, len(templist), target_id, templist[i]))
        print("[{}/{}] Check aperture and background. Change if required".format(i+1, len(templist)))
        print("[{}/{}] AP: m = mark aperture, d = delete aperture".format(i+1, len(templist)))
        print("[{}/{}] SKY: s = mark sky, t = delete sky, f = refit".format(i+1, len(templist)))
        print("[{}/{}] q = continue".format(i+1, len(templist)))
        iraf.apall(input=templist[i])
        print("Spectrum extracted!")
        # find the arcs either side of the object
        arclist = []
        arc1 = "a_s_r{0:d}_t.fits".format(spectrum_id-1)
        arc2 = "a_s_r{0:d}_t.fits".format(spectrum_id+1)
        arc1_out = "a_s_r{0:d}_t.ms.fits".format(spectrum_id-1)
        arc2_out = "a_s_r{0:d}_t.ms.fits".format(spectrum_id+1)
        # predict the arc names
        print("\nPredicting arcs names...")
        print("Arc1: {}".format(arc1))
        print("Arc2: {}".format(arc2))
        # setup a reference filename for the arc conditions in database
        reffile = templist[i].split('.fits')[0]
        # extract the arcs
        print("\nExtracting arcs under the same conditions...")
        if os.path.exists(arc1):
            iraf.apall(input=arc1,
                       reference=reffile,
                       recente="no",
                       trace="no",
                       backgro="no",
                       interac="no")
            print("Arc1 {} extracted".format(arc1))
            arclist.append(arc1_out)
        else:
            print("\n\nArc1 {} FILE NOT FOUND\n\n".format(arc1))
        if os.path.exists(arc2):
            iraf.apall(input=arc2,
                       reference=reffile,
                       recente="no",
                       trace="no",
                       backgro="no",
                       interac="no")
            print("Arc2 {} extracted".format(arc2))
            arclist.append(arc2_out)
        else:
            print("\n\nArc2 {} FILE NOT FOUND\n\n".format(arc2))
        # get a list of the extracted arcs and objects
        spectrum_out = "i_s_r{0:d}_t.ms.fits".format(spectrum_id)
        if i == 0:
            # extract the master reference arc
            print("\nExtracting master arc {} under the same conditions...".format(refarc))
            iraf.apall(input=refarc,
                       reference=reffile,
                       recente="no",
                       trace="no",
                       backgro="no",
                       interac="no")
            print("Reference arc {} extracted".format(refarc))
            # identify the lines in it
            print("\nIdentify arc lines:")
            print("Enter the following in the splot window")
            print("\t:thres 500")
            print("\t:order 1, max = 3")
            print("\tfwidth 2")
            print("Select 3-5 arc lines from line atlas")
            print("Press 'm' to mark, then enter wavelength")
            print("Then press 'l' to automatically ID the other lines")
            print("Press 'f' to fit the dispersion correction")
            print("Use 'd' to remove bad points, 'f' to refit")
            print("'q' from fit, then 'q' from identify to continue\n")
            iraf.identify(images=refarc_out, coordlist=lineList_location)
        # use the refarc to ID all the subsequent arcs
        for arc in arclist:
            print("\nReidentifying arclines from {}".format(arc))
            iraf.reidentify(reference=refarc_out, images=arc)
        # add the refspec keywords to the image header for dispcor
        # refspec_factor tells IRAF how to interpolate the arcs
        refspec_factor = round((1./len(arclist)), 1)
        for i in range(0, len(arclist)):
            refspec = "{} {}".format(arclist[i].split(".fits")[0], refspec_factor)
            print("REFSPEC{}: {}".format(i+1, refspec))
            iraf.hedit(images=spectrum_out,
                       fields="REFSPEC{}".format(i+1),
                       value=refspec,
                       add="yes",
                       verify="no",
                       show="yes")
        print("Headers updated!\n")
        # apply the dispersion correction
        print("Applying the dispersion correction")
        iraf.dispcor(input=spectrum_out,
                     output=spectrum_out,
                     lineari="yes",
                     databas="database",
                     table="")
        print("Correction applied!")
        # normalize the spectrum using continuum
        normspec_out = "{}n.ms.fits".format(spectrum_out.split('.ms')[0])
        iraf.continuum(input=spectrum_out,
                       output=normspec_out,
                       logfile="logfile",
                       interac="yes",
                       functio="spline3",
                       order="5",
                       niterat="10",
                       markrej="yes")
        print("\n\n")
示例#23
0
def blue_science(image,
                 spath,
                 object=None,
                 flat='Flat-Blue.fits',
                 arc='Arc-Blue.fits',
                 smooth='BD284211.smooth.fits',
                 sens='BD284211.sens',
                 biassec1=BLUEBIAS1,
                 trimsec1=BLUETRIM1,
                 biassec2=BLUEBIAS2,
                 trimsec2=BLUETRIM2,
                 gain=BLUEGAIN,
                 rdnoise=BLUERDNOISE):
    '''Full reduction of KAST science spectra on blue CCD'''

    # Bias subtract everything first
    bluebias(image,
             biassec1=biassec1,
             trimsec1=trimsec1,
             biassec2=biassec2,
             trimsec2=trimsec2)

    # Apply flat-field
    shutil.copy('%s/%s' % (spath, flat), '.')
    iraf.ccdproc('j%s' % image[0],
                 ccdtype='',
                 noproc=no,
                 fixpix=no,
                 overscan=no,
                 trim=no,
                 zerocor=no,
                 darkcor=no,
                 flatcor=yes,
                 illumcor=no,
                 fringecor=no,
                 readcor=no,
                 scancor=no,
                 flat=flat)

    # Cosmic ray rejection
    #iraf.lacos_spec('j%s' % image[0], 'cj%s' % image[0], 'cmj%s' % image[0],
    #                gain=gain, readn=rdnoise, xorder=9, yorder=3,
    #                sigclip=4.5, sigfrac=0.5, objlim=1.0, niter=3)

    # Extract spectrum
    if object == None:
        object = get_head(image, 'OBJECT')
    iraf.apall('j%s' % image[0],
               output=object,
               references='',
               interactive=yes,
               find=yes,
               recenter=yes,
               resize=yes,
               edit=yes,
               trace=yes,
               fittrace=yes,
               extract=yes,
               extras=yes,
               review=no,
               background='fit',
               weights='variance',
               pfit='fit1d',
               readnoise=rdnoise,
               gain=gain)

    # Apply wavelength solution to standard
    shutil.copy('%s/%s' % (spath, arc), '.')
    shutil.copy('%s/database/id%s' % (spath, arc.rstrip('.fits')), 'database')
    iraf.refspec(object,
                 references=arc,
                 sort="",
                 group="",
                 override=yes,
                 confirm=no,
                 assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Smooth
    shutil.copy('%s/%s' % (spath, smooth), '.')
    iraf.sarith('%s.w' % object, '/', smooth, '%s.s' % object)

    # Flux calibration
    shutil.copy('%s/%s.0001.fits' % (spath, sens), '.')
    iraf.calibrate('%s.s' % object,
                   '%s.f' % object,
                   extinct=yes,
                   flux=yes,
                   extinction='onedstds$kpnoextinct.dat',
                   observatory='Lick',
                   sensitivity=sens,
                   airmass='',
                   exptime='')

    return
示例#24
0
def red_standard(image,
                 arcs,
                 flats,
                 object=None,
                 biassec=REDBIAS,
                 trimsec=REDTRIM,
                 outflat='Flat-Red.fits',
                 gain=REDGAIN,
                 rdnoise=REDRDNOISE,
                 arc='Arc-Red.fits',
                 caldir='home$standards/'):
    '''Reduce and calibrate standard star observation with red CCD'''

    # Bias subtract everything first
    redbias(image, biassec=biassec, trimsec=trimsec)
    redbias(arcs, biassec=biassec, trimsec=trimsec)
    redbias(flats, biassec=biassec, trimsec=trimsec)

    # Create and apply flat-field
    make_flat(flats, outflat, gain=gain, rdnoise=rdnoise)
    iraf.ccdproc(image[0],
                 ccdtype='',
                 noproc=no,
                 fixpix=no,
                 overscan=no,
                 trim=no,
                 zerocor=no,
                 darkcor=no,
                 flatcor=yes,
                 illumcor=no,
                 fringecor=no,
                 readcor=no,
                 scancor=no,
                 flat=outflat)
    arcimages = ','.join(arcs)
    iraf.ccdproc(arcs,
                 ccdtype='',
                 noproc=no,
                 fixpix=no,
                 overscan=no,
                 trim=no,
                 zerocor=no,
                 darkcor=no,
                 flatcor=yes,
                 illumcor=no,
                 fringecor=no,
                 readcor=no,
                 scancor=no,
                 flat=outflat)

    # Extract spectrum of standard
    if object == None:
        object = get_head(image, 'OBJECT')
    iraf.apall(image[0],
               output=object,
               references='',
               interactive=yes,
               find=yes,
               recenter=yes,
               resize=yes,
               edit=yes,
               trace=yes,
               fittrace=yes,
               extract=yes,
               extras=yes,
               review=no,
               background='fit',
               weights='variance',
               pfit='fit1d',
               readnoise=rdnoise,
               gain=gain)

    # Extract arc and fit wavelength solution
    iraf.imarith(arcs[0], '+', arcs[1], 'Arc-Sum.fits')
    reference_arc('Arc-Sum.fits', arc, image[0])

    # Apply wavelength solution to standard
    iraf.refspec(object,
                 references=arc,
                 sort="",
                 group="",
                 override=yes,
                 confirm=no,
                 assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Remove absorption features and smooth
    iraf.splot('%s.w' % object, 1, 1)
    iraf.gauss('temp1[*,1,1]', '%s.smooth' % object, 3.0)
    iraf.sarith('%s.w' % object, '/', '%s.smooth' % object, '%s.s' % object)

    # Create and apply telluric correction
    iraf.sarith('%s.w' % object, '/', 'temp1', 'telluric')
    iraf.splot('telluric', 1, 1)
    iraf.telluric('%s.s' % object,
                  '%s.t' % object,
                  'telluric',
                  xcorr=no,
                  tweakrms=no,
                  interactive=no,
                  sample='6850:6950,7575:7700')

    # Define bandpasses for standard star calculation
    iraf.standard('%s.t' % object,
                  '%s.std' % object,
                  extinction='onedstds$kpnoextinct.dat',
                  caldir=caldir,
                  observatory='Lick',
                  interact=yes,
                  star_name=object,
                  airmass='',
                  exptime='')

    # Determine sensitivity function
    iraf.sensfunc('%s.std' % object,
                  '%s.sens' % object,
                  extinction='onedstds$kpnoextinct.dat',
                  newextinction='extinct.dat',
                  observatory='Lick',
                  function='legendre',
                  order=3,
                  interactive=yes)

    return
示例#25
0
#FROM NOW -> iraf
iraf.noao.twodspec.apextract
iraf.apall('spec*.fits')

#assign dispersion solution - from now IRAF

shutil.copy('./arc/database/idarc1.ms','./database/.')
for file in os.listdir(os.getcwd()):
    if file.endswith('ms.fits'):
        iraf.hedit(file,fields="REFSPEC1",value="arc1.ms",add='yes',ver='no',show='yes')

#wavelength calinration
for file in os.listdir(os.getcwd()):
    if file.endswith('ms.fits'):
        iraf.dispcor(file, 'd'+file)


#flux calibration
shutil.copy('./stds/sens.0001.fits','.')
shutil.copy('./stds/lapalmaextinct.dat','.')


for file in os.listdir(os.getcwd()):
    if file.startswith('dspec'):
        iraf.calibrate(file, 'f'+file)

#combine spectra
finalcomb = []
for file in os.listdir(os.getcwd()):
    if file.startswith('fds'):
示例#26
0
iraf.apall(input=filename,
           find="No",
           recenter="No",
           resize="No",
           interactive="Yes")

# Make sure that the dispersion axis is in the header.

iraf.hedit(images=[filename], fields=["DISPAXIS"], value=["1"], add="Yes")
iraf.identify(filename[:-5],
              coordli=home + "/Downloads/HgNe(1).dat",
              section="line 105 125",
              crval=crval,
              cdelt=dispersion,
              fwidth=5)

# Tell the extracted spectrum what the wavelength solutions are.
iraf.hedit(images=[extracted_filename],
           fields=["REFSPEC1"], \
        value=[filename], add="Yes")
iraf.refspec(input=extracted_filename,
             referen=filename[:-5],
             sort='',
             group='',
             confirm='no')
iraf.dispcor(input=extracted_filename, output=calibrated_filename)

# Plot the extracted spectrum?
iraf.splot(calibrated_filename)
示例#27
0
def blue_standard(image, arcs, flats, object=None, biassec1=BLUEBIAS1,
                  trimsec1=BLUETRIM1, biassec2=BLUEBIAS2, 
                  trimsec2=BLUETRIM2, outflat='Flat-Blue.fits', gain=BLUEGAIN,
                  rdnoise=BLUERDNOISE, arc='Arc-Blue.fits', 
                  caldir='home$standards/'):

    '''Reduce and calibrate standard star observation with blue CCD'''
  
    # Bias subtract everything first
    bluebias(image, biassec1=biassec1, trimsec1=trimsec1, biassec2=biassec2,
             trimsec2=trimsec2)
    bluebias(arcs, biassec1=biassec1, trimsec1=trimsec1, biassec2=biassec2,
             trimsec2=trimsec2)
    bluebias(flats, biassec1=biassec1, trimsec1=trimsec1, biassec2=biassec2,
             trimsec2=trimsec2)

    # Create and apply flat-field
    for i in range(len(flats)):
        flats[i]='j%s' % flats[i]
    make_flat(flats, outflat, gain=gain, rdnoise=rdnoise)
    iraf.ccdproc('j%s' % image[0], ccdtype='', noproc=no, fixpix=no, 
                 overscan=no, trim=no, zerocor=no, darkcor=no, flatcor=yes, 
                 illumcor=no, fringecor=no, readcor=no, scancor=no, 
                 flat=outflat)
    iraf.ccdproc('j%s' % arcs[0], ccdtype='', noproc=no, fixpix=no, 
                 overscan=no, trim=no, zerocor=no, darkcor=no, flatcor=yes, 
                 illumcor=no, fringecor=no, readcor=no, scancor=no, 
                 flat=outflat)

    # Extract spectrum of standard
    if object==None:
        object=get_head(image, 'OBJECT')
    iraf.apall('j%s' % image[0], output=object, references='', interactive=yes, 
               find=yes, recenter=yes, resize=yes, edit=yes, trace=yes, 
               fittrace=yes, extract=yes, extras=yes, review=no, 
               background='fit', weights='variance', pfit='fit1d', 
               readnoise=rdnoise, gain=gain)

    # Extract arc and fit wavelength solution
    reference_arc('j%s' % arcs[0], arc, 'j%s' % image[0])

    # Apply wavelength solution to standard
    iraf.refspec(object, references=arc, sort="", group="", override=yes,
                 confirm=no, assign=yes)
    iraf.dispcor(object, '%s.w' % object, confirm=no, listonly=no)

    # Remove absorption features and smooth
    iraf.splot('%s.w' % object, 1, 1)
    iraf.gauss('temp1[*,1,1]', '%s.smooth' % object, 3.0)
    iraf.sarith('%s.w' % object, '/', '%s.smooth' % object, '%s.s' % object)

    # Define bandpasses for standard star calculation
    iraf.standard('%s.s' % object, '%s.std' % object, 
                  extinction='onedstds$kpnoextinct.dat', caldir=caldir,
                  observatory='Lick', interact=yes, star_name=object, 
                  airmass='', exptime='')

    # Determine sensitivity function
    iraf.sensfunc('%s.std' % object, '%s.sens' % object, 
                  extinction='onedstds$kpnoextinct.dat', 
                  newextinction='extinct.dat', observatory='Lick',
                  function='legendre', order=3, interactive=yes)

    return
示例#28
0
                assign=yes)

iraf.refspectra('@arcs_extracted',
                references='@arcs_extracted',
                select='match',
                confirm=no,
                override=yes,
                assign=yes)

# APPLY DISPERSION SOLUTION TO OBJECT SPECTRA
# Apply the dispersion solution to object spectra based on the previously-
# assigned comparison spectra
iraf.dispcor(input='@targets_extracted',
             output='@targets_extracted',
             flux=no,
             linearize=no,
             log=no,
             verbose=yes,
             samedisp=no)

iraf.dispcor(input='sig_//@targets_extracted',
             output='sig_//@targets_extracted',
             flux=no,
             linearize=no,
             log=no,
             verbose=yes,
             samedisp=no)

# Just as a check to the dispersion solution.
iraf.dispcor(input='@arcs_extracted',
             output='z//@arcs_extracted',
                   interac='yes',
                   find='yes',
                   nfind=1,
                   recente='yes',
                   resize='yes',
                   background='fit')

        print('\n' +
              'Editing the header to point to the wavelength calibration...')
        iraf.hedit(images=n + '.ms',
                   addonly='yes',
                   fields='REFSPEC1',
                   value='arc.ms')

        print('\n' + 'Applying the dispersion correction...')
        iraf.dispcor(input=n + '.ms', output=n + '.w')

        print('\n' + 'Wavelength calibrated spectrum output as ' + n +
              '.w.fits')

print('\nBeginning flux calibration...')

## create the speclist but importing all fits files in folder but rejecting the sensfunc file
file_list = glob.glob('./*.fits')
file_list.sort()
final = []
for j in range(len(file_list)):
    if 'fits.w.fits' in file_list[j]:
        final.append(file_list[j])

np.savetxt('./speclist', final, fmt="%s")
# Delete previous results.

os.system("rm "+extracted_filename+" "+calibrated_filename)

# Make sure that the dispersion axis is in the header.

iraf.hedit(images=[filename], fields=["DISPAXIS"], value=["1"], add="Yes")

# Run the spectral extraction program.

iraf.apextract.setParam("dispaxis", "1")

iraf.apall(input=filename, find="No", recenter="No", resize="No")

# Now identify the spectral lines in the arc lamps. Need to replace l1 l2 
# with the range of rows that have the spectral lines.

iraf.identify(filename, section="line 265 285")

# Tell the extracted spectrum what the wavelength solutions are.

iraf.hedit(images=[extracted_filename], fields=["REFSPEC1"], \
        value=[filename], add="Yes")

iraf.dispcor(input=extracted_filename, output=calibrated_filename)

# Plot the extracted spectrum?

iraf.splot(calibrated_filename)

                update = 1)

            count = count + 1

        ### Run dispcor to calibrate the object spectrum according to the dispersion
        ### solution
        print "Using dispcor to apply the dispersion solution to the object image"

        os.system("rm dispcorr_" + im_slice + "_" + file_name)

        iraf.dispcor(
            input = "t" + im_slice + "_" + string.split(file_name,".")[0] + ".ms.fits",\
            output = "dispcorr_" + im_slice + "_" + file_name,\
            linearize = "no",\
            database = "database",\
            log = 0,\
            flux = 1,\
            samedisp = 0,\
            ignoreaps = 0,\
            confirm = 0,\
            listonly = 0,\
            verbose = 1)

        iraf.hedit(images="dispcorr_" + im_slice + "_" + file_name,fields="SFIT",value="1",add=0,delete=1,verify=0,show=1,update=1)
        iraf.hedit(images="dispcorr_" + im_slice + "_" + file_name,fields="SFITB",value="1",add=0,delete=1,verify=0,show=1,update=1)

        ### Apply high rejection to remove cosmic rays, dead pixels, etc.
        print "Applying high rejection"

        ### Be more lenient if apertures will be combined
        if combine_aps == "true":
            lowrej = 50.0