예제 #1
0
def calibrate(spec_in, spec_out, data_path='.', sens_prefix='sens', params={}):
    """
    Run iraf calibrate to flux calibrate input spectrum.

    Parameters
    ----------
    spec_in : str
        Input spectrum file name.
    spec_out : str
        Output spectrum file name.
    data_path : str
        Directory that contains the data.
    sens_prefix : str
        Sensitivity correction file name prefix.
    params : dict
        Iraf calibrate parameters.
    """

    _check_working_dir(data_path)

    logger.info('running iraf calibrate')

    iraf.calibrate.unlearn()
    iraf.calibrate.extinct = params.pop('extinct', 'no')
    iraf.calibrate.flux = params.pop('flux', 'yes')
    iraf.calibrate.extinction = params.pop('extinction', '')
    iraf.calibrate.ignoreaps = params.pop('ignoreaps', 'yes')
    iraf.calibrate.sensitivity = params.pop('sensitivity', sens_prefix)
    iraf.calibrate.fnu = params.pop('fnu', 'no')
    iraf.calibrate(input=spec_in, output=spec_out)
예제 #2
0
def calibrate(namelst):
    iraf.noao()
    iraf.twodspec()
    iraf.longslit(dispaxis=2,
                  nsum=1,
                  observatory='ca',
                  extinction=extpath,
                  caldir=stdpath)

    for fitname in namelst:
        outname = 'mark_' + fitname
        if os.path.isfile(outname):
            print('remove file ' + outname)
            os.remove(outname)

        iraf.calibrate(input=fitname,
                       output=outname,
                       extinct='yes',
                       flux='yes',
                       extinction=extpath,
                       ignoreaps='yes',
                       sensitivity='Sens',
                       fnu='no')
        iraf.splot(images=outname)
        iraf.flpr()
예제 #3
0
파일: kast_redux.py 프로젝트: cenko/python
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
예제 #4
0
파일: kast_redux.py 프로젝트: cenko/python
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
예제 #5
0
파일: agnspecred.py 프로젝트: jsamu/AGNKEY
def calibrate():
    scilist = glob.glob('AGN*LF.fits')
    for f in scilist:
        os.remove(f)
    scired = glob.glob('AGN*EL.fits')
    extinct = 'extinction_lasilla.dat'
    observ = 'paranal'
    for spec in scired:
        hdo = pyfits.getheader(spec)
        _airmass = np.average([hdo['HIERARCH ESO TEL AIRM START'],hdo['HIERARCH ESO TEL AIRM END']])
        _exptime = hdo['EXPTIME']
        name = spec.rsplit('_EL',1)[0]+'_LF'
        iraf.calibrate(spec,name,extinction=extinct,observatory=observ,airmass=_airmass,exptime=_exptime)
예제 #6
0
def calibrate_err(mefile):
    '''Apply a sensitivity function to a linearized multispectrum file.
    
    The error is propagated simply by dividing it by the sensitivity
    function. This makes the assumption that there is no error in the
    sensitivity function itself.
    '''
    outputname = mefile.replace('me_', 'me_rf_')
    iraf.calibrate(mefile,
                   outputname,
                   extinct=False,
                   flux=True,
                   ignoreap=True,
                   sensiti='sens',
                   fnu=False)

    return outputname
예제 #7
0
def calibrate_err(mefile):
    '''Apply a sensitivity function to a linearized multispectrum file.
    
    The error is propagated simply by dividing it by the sensitivity
    function. This makes the assumption that there is no error in the
    sensitivity function itself.
    '''
    outputname = mefile.replace('me_','me_rf_')
    iraf.calibrate(mefile,
                   outputname,
                   extinct=False,
                   flux=True,
                   ignoreap=True,
                   sensiti='sens',
                   fnu=False)

    return outputname
예제 #8
0
def calibrate():
    namelst = [i.split('\n')[0] for i in file(targetoutput)]
    for i in namelst:
        iraf.twodspec()
        iraf.longslit(dispaxis=2,
                      nsum=1,
                      observatory='Lijiang',
                      extinction='onedstds$LJextinct.dat',
                      caldir='onedstds$ctiocal/')
        iraf.calibrate(input=i,
                       output=i.split('.')[0] + 'f.fits',
                       extinct='yes',
                       flux='yes',
                       extinction='onedstds$LJextinct.dat',
                       ignoreaps='yes',
                       sensitivity='sens',
                       fnu='no')
예제 #9
0
def calibrate(lstfile):
    stdpath = os.path.split(os.path.realpath(__file__))[0] + os.sep + 'standarddir' + os.sep
    extpath = os.path.split(os.path.realpath(__file__))[0] + os.sep + 'LJextinct.dat'
    iraf.noao()
    iraf.twodspec()
    iraf.longslit(dispaxis = 2, nsum = 1, observatory = 'Lijiang', 
        extinction = extpath, caldir = stdpath)
    f = open(lstfile)
    l = f.readlines()
    f.close()
    l = [tmp.split('\n')[0] for tmp in l]
    for fitname in l:
        stdobjname = select_std(fitname)
        stdfitname = 'sensawftbo' + stdgroup[stdobjname][0]
        iraf.calibrate(input = 'awftbo'+ fitname, output = 'mark_awftbo' + fitname, 
            extinct = 'yes', flux = 'yes', extinction = extpath, 
            ignoreaps = 'yes', sensitivity = stdfitname, fnu = 'no')
        iraf.splot(images = 'mark_awftbo' + fitname)
예제 #10
0
def iraf_standard(directory, objecto, sensfile):
    '''
    Do the flux calibration on the targets in the directory using the
    sensfile

    Parameters
    -------------
    directory: Directory where all the science files are located.
               i.e. Objectname/Science
    objecto: Name of the object in the directory to flux calibrate
    sensfile: Full name of the sensfile to calibrate the data

    Output
    -------------
    Flux calibrated data
    '''

    # Check that the files don't exist
    if check_existence("%s/%s*OutWaveStd.fits" % (directory, objecto),
                       'iraf_standard'):
        return

    # Create file suffix
    suffix = sensfile[5:-5]

    # For each of the science targets, correct the flux
    list_of_objects = glob.glob('%s/%s*BiasFlatSkyOutWave.fits' %
                                (directory, objecto))
    for file_name in list_of_objects:
        calibrate(
            input=file_name,  # Input spectra to calibrate
            output=file_name[:-5] +
            "Std_%s.fits" % suffix,  # Output calibrated spectra
            extinct='no',  # Apply extinction correction
            flux='yes',  # Apply flux calibration
            extinction='',  # Extinction file
            observatory=')_.observatory',  # Observatory for data
            ignoreaps='yes',  # Ignore aperture numbers in flux calibration
            sensitivity=sensfile,  # Image root name for sensitivity spectra.
            fnu='no',  # Create spectra having units of FNU?
            airmass='',  #
            exptime='',  #
            mode='ql'  # IRAF mode
        )
예제 #11
0
def sens_corr_standard():

    """
    Check this has worked by correcting stanard for wavelength-dependent sensitivity
    """

    if os.path.exists('cdimcomb.ms.fits'):
        os.remove('cdimcomb.ms.fits')
        print 'Removing file cdimcomb.ms.fits'

    iraf.calibrate.unlearn()

    # Input spectra to calibrate. Output should have 'c' prefixed.
    iraf.calibrate.setParam('input','dimcomb.ms.fits[1]')

    iraf.calibrate.setParam('output','cdimcomb.ms.fits')

    # Should be found automatically from header - check this for target spectrum.
    iraf.calibrate.setParam('airmass','')
    iraf.calibrate.setParam('exptime','')

    # Apply extinction correction? Not sure what this does
    iraf.calibrate.setParam('extinct','no')

	# Apply flux calibration?
    iraf.calibrate.setParam('flux','yes')

	# Extinction file
    iraf.calibrate.setParam('extinction','')

	# Ignore aperture numbers in flux calibration? Maybe this should be yes
    iraf.calibrate.setParam('ignoreaps','yes')

	# Image root name for sensitivity spectra
    iraf.calibrate.setParam('sensitivity','sens.fits')

	# Create spectra having units of FNU?
    iraf.calibrate.setParam('fnu','no')

    iraf.calibrate()


    return None
예제 #12
0
def calibrate(imlist_name, obs):
    """
    calibrate -- Apply extinction corrections and flux calibrations
    calibrate input output [records]
    """
    import glob
    import os, sys
    from pyraf import iraf
    iraf.noao()
    iraf.onedspec()
    imlist = glob.glob(imlist_name)
    imlist.sort()
    for i in range(len(imlist)):
        inim = imlist[i]
        #iraf.calibrate(input=inim , output='s'+inim, extinct='/iraf/iraf/noao/lib/onedstds/ctioextinct.dat', flux='yes', observatory=obs)
        iraf.calibrate(input=inim,
                       output='s' + inim,
                       extinct='yes',
                       flux='yes',
                       observatory=obs)
예제 #13
0
def flux_cal_new(objname, stdobjnames):
    print 'run flux_cal...'
    iraf.imred()
    iraf.kpnoslit()
    stdname, stdmag, stdmagband = get_std_name(stdobjnames[0])
    print 'the standard star is ' + stdname
    stdmag = float(stdmag)
    stdairmass, stdexptime = get_fits_airmass_exptime(stdobjnames[0])
    scripath = sys.argv[0]
    tempindex = scripath.rfind(os.sep)
    scripath = scripath[:tempindex]
    extpath = scripath + os.sep + 'LJextinct.dat'
    calpath = scripath + os.sep + 'standarddir' + os.sep
    outname1 = 'std' + stdobjnames[0]
    stdobjname = ''
    for tempstdname in stdobjnames:
        stdobjname = stdobjname + tempstdname + ','
    stdobjname = stdobjname[:-1]
    if os.path.isfile(outname1):
        print 'file %s is already exist' % outname1
    else:
        print 'run standard...'
        print 'make file %s ...' % outname1
        iraf.standard(input = stdobjname
                , output = outname1, samestar = True, beam_switch = False
                , apertures = '', bandwidth = 30.0, bandsep = 20.0
                , fnuzero = 3.6800000000000E-20, extinction = extpath
                , caldir = calpath, observatory = ')_.observatory'
                , interact = True, graphics = 'stdgraph', cursor = ''
                , star_name = stdname, airmass = stdairmass, exptime = stdexptime
                , mag = stdmag, magband = stdmagband, teff = '', answer = 'yes')
    outname2 = 'sens' + stdobjname
    if os.path.isfile(outname2):
        print 'file %s is already exist' % outname2
    else:
        print 'run sensfunc...'
        print 'make file %s ...' % outname2
        iraf.sensfunc(standards = outname1
                , sensitivity = outname2, apertures = '', ignoreaps = True
                , logfile = 'logfile', extinction = ')_.extinction'
                , newextinction = extpath, observatory = 'bao', function = 'spline3'
                , order = 6, interactive = True, graphs = 'sr'
                , marks = 'plus cross box', colors = '2 1 3 4', cursor =''
                , device = 'stdgraph', answer = 'yes')
    outname3 = 'c' + objname
    if os.path.isfile(outname3):
        print 'file %s is already exist' % outname3
    else:
        print 'run calibrate...'
        print 'make file %s ...' % outname3
        iraf.calibrate(input = objname
                , output = outname3, extinct = True, flux = True
                , extinction = extpath, observatory = 'bao', ignoreaps = True
                , sensitivity = outname2, fnu = False)
    final_outname = 'mark_' + objname
    if os.path.isfile(final_outname):
        print 'file %s is already exist'
    else:
        print 'run scopy'
        print 'make file %s ...' % final_outname
        iraf.scopy(input = outname3
                , output = final_outname, w1 = 'INDEF', w2 = 'INDEF'
                , apertures = '', bands = 1, beams = '', apmodulus = 0
                , format = 'multispec', renumber = False, offset = 0
                , clobber = False, merge = False, rebin = True, verbose = False)
    print 'splot %s' % final_outname
    iraf.splot(images = final_outname)
    return final_outname
예제 #14
0
        mode = "al")

### Apply calibration to file_name
hdulist = pyfits.open("smoothdiv_" + file_name)
air_mass = hdulist[0].header['AIRMASS']
exposure_time = hdulist[0].header['EXPTIME']

os.system("rm fluxcal_" + file_name )

iraf.calibrate(
    input = "smoothdiv_" + file_name,\
    output = "fluxcal_" + file_name,\
    airmass = air_mass,\
    exptime = exposure_time,\
    extinct = 1,\
    flux = 1,\
    extinction = program_dir + "flux_data/extinsso.tab",\
    observatory = "SSO",\
    ignoreaps = 1,\
    sensitivity = "sens",\
    fnu = 0,\
    mode = "al")

### Apply high/low rejection again to remove cosmic rays
os.system("rm temp.fits")
iraf.continuum(
    input = "fluxcal_"+ file_name,\
    output = "temp.fits",\
    ask = "no",\
    lines = "*",\
    bands = "*",\
예제 #15
0
iraf.sensfunc(standard="std",
              sensitiv="sens",
              apertures="",
              ignoreaps="no",
              logfile="logfile",
              extinction="/home/aries/Music/Atsoa2018/iao_extinction.dat",
              newextinctio="extinct.dat",
              observatory=" ",
              function="spline3",
              order=6,
              interactive="yes",
              graphs="sr",
              marks="plus cross box",
              colors="2 1 3 4",
              cursor="",
              device="stdgraph",
              answer="yes")

iraf.calibrate(
    input="J105829_250_3500_4_Grism_7_2015_06_17_yf170018apbfcw.fits",
    output="J105829_250_3500_4_Grism_7_2015_06_17_yf170018apbfcwf.fits",
    extinct="yes",
    flux="yes",
    extinction="/home/aries/Music/Atsoa2018/iao_extinction.dat",
    observatory=" ",
    ignoreaps="yes",
    sensitivity="sens",
    fnu="no",
    airmass=2.3,
    exptime=2700)
예제 #16
0
파일: lris_carpy.py 프로젝트: cenko/python
def lris_extract(science, standards, dostandard=yes):

    '''Extract and flux calibrate LRIS spectra (assuming they have been
    processed into 2D images using LRIS_pipe above).'''

    if dostandard:
        lris_standard(standards)

    for src in science:

        bimages = iraffiles("%s_??_B.fits" % src)
        rimages = iraffiles("%s_??_R.fits" % src)
        joinstr = ""

        for bimage in bimages:

            bimage = bimage.split(".")[0]
            
            # Find appropriate standard for this image
            bstd = get_head("%s.fits" % bimage, "STDNAME")
            
            # Extract 1D spectra
            if get_head("%s.fits" % bimage, "SKYSUB"):
                iraf.apall(bimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="none",
                           reference=bstd)
            else:
                iraf.apall(bimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="fit",
                           reference=bstd)

            # Normalize by the standard continuua
            iraf.sarith("%s.ms" % bimage, "/", "../standards/s%s.ms.fits" % bstd,
                        "s%s.ms" % bimage, w1=INDEF, w2=INDEF)            
            
            # Telluric correct
            iraf.telluric("s%s.ms" % bimage, "ts%s.ms" % bimage,
                          "../standards/telluric.%s.fits" % bstd, tweakrms=yes,
                          interactive=yes, sample='6850:6950,7575:7700,8750:9925')
            
            # Flux calibration
            iraf.calibrate("ts%s.ms" % bimage, "fts%s.ms" % bimage, extinct=yes,
                           flux=yes, extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck", sens="../standards/%s.sens" % bstd,
                           airmass='', exptime='')

            joinstr += "fts%s.ms," % bimage

        for rimage in rimages:

            rimage = rimage.split(".")[0]
            
            # Find appropriate standard for this image
            rstd = get_head("%s.fits" % rimage, "STDNAME")
            
            # Extract 1D spectra
            if get_head("%s.fits" % rimage, "SKYSUB"):
                iraf.apall(rimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="none",
                           reference=rstd)
            else:
                iraf.apall(rimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="fit",
                           reference=rstd)

            # Normalize by the standard continuua
            iraf.sarith("%s.ms" % rimage, "/", "../standards/s%s.ms.fits" % rstd,
                        "s%s.ms" % rimage, w1=5500, w2=INDEF)
            
            # Telluric correct
            iraf.telluric("s%s.ms" % rimage, "ts%s.ms" % rimage,
                          "../standards/telluric.%s.fits" % rstd, tweakrms=yes,
                          interactive=yes, sample='6850:6950,7575:7700')
            
            # Flux calibration
            iraf.calibrate("ts%s.ms" % rimage, "fts%s.ms" % rimage, extinct=yes,
                           flux=yes, extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck", sens="../standards/%s.sens" % rstd,
                           airmass='', exptime='')

            joinstr += "fts%s.ms," % rimage
           
        # Combine
        iraf.scombine(joinstr[:-1], "%s.ms.fits" % src, combine="average",
                      reject="avsigclip", w1=INDEF, w2=INDEF, dw=INDEF, nw=INDEF,
                      scale="median", zero="none", weight="none", sample="5450:5600",
                      lsigma=3.0, hsigma=3.0, gain=RCCDGAIN, rdnoise=RCCDRNOISE)

        # Plot to enable final tweaks
        iraf.splot("%s.ms.fits" % src)

    return
예제 #17
0
파일: deimos_pipe.py 프로젝트: cenko/python
def deimos_extract(science, standard, dostandard=yes):

    '''Extract and flux calibrate DEIMOS spectra (assuming they have been
    processed into 2D images using deimos_pipe above).'''

    if dostandard:
        deimos_standard(standard)

    for source in science:

        images = iraffiles("%s_??_B.fits" % source)
        joinstr = ""

        for image in images:

            bimage = image.split(".")[0]; rimage = bimage[:-1] + "R"
            update_head(bimage, "FLUX_OBJ", standard)
            update_head(rimage, "FLUX_OBJ", standard)
            
            # Extract 1D spectra
            if get_head("%s.fits" % bimage, "SKYSUB"):
                iraf.apall(bimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="none",
                           reference="%s_01_B" % standard)
                iraf.apall(rimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="none",
                           reference="%s_01_R" % standard)
            else:
                iraf.apall(bimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="fit",
                           reference="%s_01_B" % standard)
                iraf.apall(rimage, output="", inter=yes, find=yes, recenter=yes,
                           resize=yes, edit=yes, trace=yes, fittrace=yes, extract=yes,
                           extras=yes, review=no, background="fit",
                           reference="%s_01_R" % standard)

            # Normalize by the standard continuua
            iraf.sarith("%s.ms" % bimage, "/", "s%s_01_B.ms.fits" % standard,
                        "s%s.ms" % bimage)
            iraf.sarith("%s.ms" % rimage, "/", "s%s_01_R.ms.fits" % standard,
                        "s%s.ms" % rimage)

            # Telluric correct
            bstd = "%s_01_B" % standard; rstd = "%s_01_R" % standard
            iraf.telluric("s%s.ms" % bimage, "ts%s.ms" % bimage,
                          "telluric.B.%s.fits" % bstd, tweakrms=yes,
                          interactive=yes, sample='6850:6950,7575:7700')
            iraf.telluric("s%s.ms" % rimage, "ts%s.ms" % rimage,
                          "telluric.R.%s.fits" % rstd, tweakrms=yes,
                          interactive=yes, sample='6850:6950,7575:7700')
            
            # Flux calibration
            iraf.calibrate("ts%s.ms" % bimage, "fts%s.ms" % bimage, extinct=yes,
                           flux=yes, extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck", sensitivity="%s.B.sens" % standard,
                           airmass='', exptime='')
            iraf.calibrate("ts%s.ms" % rimage, "fts%s.ms" % rimage, extinct=yes,
                           flux=yes, extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck", sensitivity="%s.R.sens" % standard,
                           airmass='', exptime='')

            joinstr += "fts%s.ms,fts%s.ms," % (bimage, rimage)
           
        # Combine
        iraf.scombine(joinstr[:-1], "%s.ms.fits" % source, combine="average",
                      reject="avsigclip", w1=INDEF, w2=INDEF, dw=INDEF, nw=INDEF,
                      scale="none", zero="none", weight="none", lsigma=3.0,
                      hsigma=3.0, gain=CCDGAIN, rdnoise=CCDRNOISE)

        # Plot to enable final tweaks
        iraf.splot("%s.ms.fits" % source)

    return
예제 #18
0
def lris_extract(science, standards, dostandard=yes):
    '''Extract and flux calibrate LRIS spectra (assuming they have been
    processed into 2D images using LRIS_pipe above).'''

    if dostandard:
        lris_standard(standards)

    for src in science:

        bimages = iraffiles("%s_??_B.fits" % src)
        rimages = iraffiles("%s_??_R.fits" % src)
        joinstr = ""

        for bimage in bimages:

            bimage = bimage.split(".")[0]

            # Find appropriate standard for this image
            bstd = get_head("%s.fits" % bimage, "STDNAME")

            # Extract 1D spectra
            if get_head("%s.fits" % bimage, "SKYSUB"):
                iraf.apall(bimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="none",
                           reference=bstd)
            else:
                iraf.apall(bimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="fit",
                           reference=bstd)

            # Normalize by the standard continuua
            iraf.sarith("%s.ms" % bimage,
                        "/",
                        "../standards/s%s.ms.fits" % bstd,
                        "s%s.ms" % bimage,
                        w1=INDEF,
                        w2=INDEF)

            # Telluric correct
            iraf.telluric("s%s.ms" % bimage,
                          "ts%s.ms" % bimage,
                          "../standards/telluric.%s.fits" % bstd,
                          tweakrms=yes,
                          interactive=yes,
                          sample='6850:6950,7575:7700,8750:9925')

            # Flux calibration
            iraf.calibrate("ts%s.ms" % bimage,
                           "fts%s.ms" % bimage,
                           extinct=yes,
                           flux=yes,
                           extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck",
                           sens="../standards/%s.sens" % bstd,
                           airmass='',
                           exptime='')

            joinstr += "fts%s.ms," % bimage

        for rimage in rimages:

            rimage = rimage.split(".")[0]

            # Find appropriate standard for this image
            rstd = get_head("%s.fits" % rimage, "STDNAME")

            # Extract 1D spectra
            if get_head("%s.fits" % rimage, "SKYSUB"):
                iraf.apall(rimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="none",
                           reference=rstd)
            else:
                iraf.apall(rimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="fit",
                           reference=rstd)

            # Normalize by the standard continuua
            iraf.sarith("%s.ms" % rimage,
                        "/",
                        "../standards/s%s.ms.fits" % rstd,
                        "s%s.ms" % rimage,
                        w1=5500,
                        w2=INDEF)

            # Telluric correct
            iraf.telluric("s%s.ms" % rimage,
                          "ts%s.ms" % rimage,
                          "../standards/telluric.%s.fits" % rstd,
                          tweakrms=yes,
                          interactive=yes,
                          sample='6850:6950,7575:7700')

            # Flux calibration
            iraf.calibrate("ts%s.ms" % rimage,
                           "fts%s.ms" % rimage,
                           extinct=yes,
                           flux=yes,
                           extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck",
                           sens="../standards/%s.sens" % rstd,
                           airmass='',
                           exptime='')

            joinstr += "fts%s.ms," % rimage

        # Combine
        iraf.scombine(joinstr[:-1],
                      "%s.ms.fits" % src,
                      combine="average",
                      reject="avsigclip",
                      w1=INDEF,
                      w2=INDEF,
                      dw=INDEF,
                      nw=INDEF,
                      scale="median",
                      zero="none",
                      weight="none",
                      sample="5450:5600",
                      lsigma=3.0,
                      hsigma=3.0,
                      gain=RCCDGAIN,
                      rdnoise=RCCDRNOISE)

        # Plot to enable final tweaks
        iraf.splot("%s.ms.fits" % src)

    return
예제 #19
0
def sens_corr_target():

    """
    Take out wavelength-dependent sensitivity
    """

    if not os.path.exists('sens.fits'):
    	print 'need file sens.fits'

    if not os.path.exists('model_tell_spec.fits'):
    	print 'need file model_tell_spec.fits'

    if os.path.exists('cdimcomb.ms.fits'):
        os.remove('cdimcomb.ms.fits')
        print 'Removing file cdimcomb.ms.fits'

    """
    for some reason dimcomb+bkgd doesn't have much in its fits header,
    so we need to add these keys words
    """

    # hdulist = fits.open('dimcomb.ms.fits')
    # airmass = hdulist[0].header['airmass']
    # exptime = float(hdulist[0].header['ncombine']) * 60.0

    # hdulist = fits.open('dimcomb.ms.fits', mode='update')
    # hdulist[0].header['airmass'] = airmass
    # hdulist[0].header['exptime'] = exptime
    # hdulist.flush()

    iraf.calibrate.unlearn()

    # Input spectra to calibrate. Output should have 'c' prefixed.
    iraf.calibrate.setParam('input','dimcomb.ms.fits')  # might need to specify extension.

    iraf.calibrate.setParam('output','cdimcomb.ms.fits')

    # Should be found automatically from header - check this for target spectrum.
    iraf.calibrate.setParam('airmass','')
    iraf.calibrate.setParam('exptime','')

    # Apply extinction correction? Not sure what this does
    iraf.calibrate.setParam('extinct','no')

	# Apply flux calibration?
    iraf.calibrate.setParam('flux','yes')

	# Extinction file
    iraf.calibrate.setParam('extinction','')

	# Ignore aperture numbers in flux calibration? Maybe this should be yes
    iraf.calibrate.setParam('ignoreaps','yes')

	# Image root name for sensitivity spectra
    iraf.calibrate.setParam('sensitivity','sens.fits')

	# Create spectra having units of FNU?
    iraf.calibrate.setParam('fnu','no')

    iraf.calibrate()

    return None
예제 #20
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
    print('\n' + 'Combining spectra...')
    iraf.scombine(input='@speclist',
                  output='allspec',
                  group='all',
                  combine='median',
                  gain=2.45,
                  reject='crreject',
                  lthresh=1e-30,
                  hthresh=hthresh2)

    print('\n' + 'Applying flux calibration to sensitivity function...')
    iraf.calibrate(
        '@speclist',
        'allspeccal',
        obs='lapalma',
        sens=sensfile,
        extinct='no',
        ignoreaps='yes'
    )  ## If extinct='yes', try extinction ='onedstds$ctioextinct.dat'

    print('\n' +
          'Extracting the 1D spectra from the calibrated multispec file...')
    iraf.scopy('allspeccal[0]',
               'allspeccal2',
               format='onedspec',
               w1=4000,
               w2=8000,
               rebin='no')

    print('\n' + '1D spectrum output...')
    iraf.wspectext('allspeccal2.0001', obj + '_' + date + '.txt', header='no')
예제 #22
0
def deimos_extract(science, standard, dostandard=yes):
    '''Extract and flux calibrate DEIMOS spectra (assuming they have been
    processed into 2D images using deimos_pipe above).'''

    if dostandard:
        deimos_standard(standard)

    for source in science:

        images = iraffiles("%s_??_B.fits" % source)
        joinstr = ""

        for image in images:

            bimage = image.split(".")[0]
            rimage = bimage[:-1] + "R"
            update_head(bimage, "FLUX_OBJ", standard)
            update_head(rimage, "FLUX_OBJ", standard)

            # Extract 1D spectra
            if get_head("%s.fits" % bimage, "SKYSUB"):
                iraf.apall(bimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="none",
                           reference="%s_01_B" % standard)
                iraf.apall(rimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="none",
                           reference="%s_01_R" % standard)
            else:
                iraf.apall(bimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="fit",
                           reference="%s_01_B" % standard)
                iraf.apall(rimage,
                           output="",
                           inter=yes,
                           find=yes,
                           recenter=yes,
                           resize=yes,
                           edit=yes,
                           trace=yes,
                           fittrace=yes,
                           extract=yes,
                           extras=yes,
                           review=no,
                           background="fit",
                           reference="%s_01_R" % standard)

            # Normalize by the standard continuua
            iraf.sarith("%s.ms" % bimage, "/", "s%s_01_B.ms.fits" % standard,
                        "s%s.ms" % bimage)
            iraf.sarith("%s.ms" % rimage, "/", "s%s_01_R.ms.fits" % standard,
                        "s%s.ms" % rimage)

            # Telluric correct
            bstd = "%s_01_B" % standard
            rstd = "%s_01_R" % standard
            iraf.telluric("s%s.ms" % bimage,
                          "ts%s.ms" % bimage,
                          "telluric.B.%s.fits" % bstd,
                          tweakrms=yes,
                          interactive=yes,
                          sample='6850:6950,7575:7700')
            iraf.telluric("s%s.ms" % rimage,
                          "ts%s.ms" % rimage,
                          "telluric.R.%s.fits" % rstd,
                          tweakrms=yes,
                          interactive=yes,
                          sample='6850:6950,7575:7700')

            # Flux calibration
            iraf.calibrate("ts%s.ms" % bimage,
                           "fts%s.ms" % bimage,
                           extinct=yes,
                           flux=yes,
                           extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck",
                           sensitivity="%s.B.sens" % standard,
                           airmass='',
                           exptime='')
            iraf.calibrate("ts%s.ms" % rimage,
                           "fts%s.ms" % rimage,
                           extinct=yes,
                           flux=yes,
                           extinction="home$extinct/maunakeaextinct.dat",
                           observatory="Keck",
                           sensitivity="%s.R.sens" % standard,
                           airmass='',
                           exptime='')

            joinstr += "fts%s.ms,fts%s.ms," % (bimage, rimage)

        # Combine
        iraf.scombine(joinstr[:-1],
                      "%s.ms.fits" % source,
                      combine="average",
                      reject="avsigclip",
                      w1=INDEF,
                      w2=INDEF,
                      dw=INDEF,
                      nw=INDEF,
                      scale="none",
                      zero="none",
                      weight="none",
                      lsigma=3.0,
                      hsigma=3.0,
                      gain=CCDGAIN,
                      rdnoise=CCDRNOISE)

        # Plot to enable final tweaks
        iraf.splot("%s.ms.fits" % source)

    return
예제 #23
0
        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'):
        finalcomb.append(file)


file1 = open('listascombine', 'w')
file1.writelines(["%s\n" % item  for item in finalcomb])
file1.close()

iraf.scombine('@listascombine', 'temp_quick.fits')

iraf.scopy('temp_quick.fits',target+'_quick.fits',w1='4000',w2='9000')
예제 #24
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