Example #1
0
def lris_standard(standards, xcorr=yes):

    '''Extract standard stars and calculate sensitivity functions.'''

    for ofile, nstd in standards:

        shutil.copy(ofile, "%s.fits" % nstd)
        
        # Extract standard
        if get_head("%s.fits" % nstd, "SKYSUB"):
            iraf.apall(nstd, output="", inter=yes, find=yes, recenter=yes, resize=yes,
                       edit=yes, trace=yes, fittrace=yes, extract=yes, extras=yes,
                       review=no, background="none")
        else:
            iraf.apall(nstd, output="", inter=yes, find=yes, recenter=yes, resize=yes,
                       edit=yes, trace=yes, fittrace=yes, extract=yes, extras=yes,
                       review=no, background="fit")

        if xcorr:
            # Cross correlate to tweak wavelength
            iraf.xcsao("%s.ms" % nstd, templates=XCTEMPLATE,
                       correlate="wavelength", logfiles="%s.xcsao" % ofile)

            # If a solution was found, apply shift
            try:
                xcsaof = open("%s.xcsao" % ofile)
                shift = float(xcsaof.readlines()[6].split()[14])
            except:
                shift = 0.0
                iraf.specshift("%s.ms" % nstd, -shift)
        
        # Create telluric
        iraf.splot("%s.ms" % nstd) # Remove telluric and absorption, save as a%s.ms
        iraf.sarith("%s.ms" % nstd, "/", "a%s.ms" % nstd, "telluric.%s.fits" % nstd)
        iraf.imreplace("telluric.%s.fits" % nstd, 1.0, lower=0.0, upper=0.0)
        iraf.splot("telluric.%s.fits" % nstd) # Remove stellar features and resave
        
        # Create smoothed standard
        iraf.gauss("a%s.ms[*,1,1]" % nstd, "s%s.ms" % nstd, 5.0)
        iraf.sarith("%s.ms" % nstd, "/", "s%s.ms" % nstd, "ds%s.ms" % nstd)

        # Apply telluric correction
        iraf.telluric("ds%s.ms" % nstd, "tds%s.ms" % nstd, "telluric.%s.fits" % nstd,
                      xcorr=no, tweakrms=no, interactive=no,
                      sample='4000:4010,6850:6975,7150:7350,7575:7725,8050:8400,8900:9725')

        # Define bandpasses for standard star calculation
        obj=get_head("%s.fits" % nstd, "OBJECT")
        iraf.standard("tds%s.ms" % nstd, "%s.std" % nstd,
                  extinction='home$extinct/maunakeaextinct.dat',
                  caldir='home$standards/', observatory='Keck', interac=yes,
                  star_name=obj, airmass='', exptime='')
    
        # Determine sensitivity function
        iraf.sensfunc('%s.std' % nstd, '%s.sens' % nstd,
                      extinction='home$extinct/maunakeaextinct.dat',
                      newextinction='extinct.dat', observatory='Keck',
                      function='legendre', order=4, interactive=yes)

    return
Example #2
0
def standard():
    extinct = 'extinction_lasilla.dat'
    observ = 'paranal'

    if os.path.isfile('std'):
        os.remove('std')
    senslist = glob.glob('sens*.fits')
    for f in senslist:
        os.remove(f)

#    os.system('cp /dark/jsamuel/VLTdata/sens.0001.fits ./')



    stars = {'specphot-LTT7379':'l7379','specphot-LDS749B':'lds749b','specphot-EG274':'eg274','specphot-G138-31':'g13831','specphot-C-32d9927':'cd32','specphot-LTT9491':'l9491','specphot-LTT7987':'l7987'}

    stdlist = glob.glob('STD*EL.fits')

    for spec in stdlist:
        _std = 'std'
        hds = pyfits.getheader(spec)
        _starname = stars[hds['HIERARCH ESO OBS NAME']]
        if _starname in ['l7379','eg274','cd32','l7987','l9491']:
            _caldir = '/dark/jsamuel/agn/standards/stds/'
        else:
            print '%s not found in caldir list' % (_starname)
        _airmass = np.average([hds['HIERARCH ESO TEL AIRM START'],hds['HIERARCH ESO TEL AIRM END']])
        iraf.standard(input=spec,output=_std,extinction=extinct,caldir=_caldir,observatory=observ,star_name=_starname,airmass=_airmass,interact='no')


    iraf.sensfunc(standards='std',sensitivity='sens',extinction=extinct,observatory=observ,interactive='no')
Example #3
0
def standard():
    stdpath = os.path.split(os.path.realpath(__file__))[0] + os.sep + 'standarddir' + os.sep
    print('standard dir is ' + stdpath)
    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)
    for objname in stdgroup:
        stdname, stdmag, stdmagband = get_std_name(objname)
        print('the standard star is ' + stdname)
        stdmag = float(stdmag)
        outname1 = 'stdawftbo' + stdgroup[objname][0]
        inname   = ''
        for tmpname in stdgroup[objname]:
            inname = inname + 'awftbo' + tmpname + ','
        inname = inname[0:-1]
        iraf.standard(input = inname
                , output = outname1, samestar = True, beam_switch = False
                , apertures = '', bandwidth = 30.0, bandsep = 20.0
                , fnuzero = 3.6800000000000E-20, extinction = extpath
                , caldir = stdpath, observatory = ')_.observatory'
                , interact = True, graphics = 'stdgraph', cursor = ''
                , star_name = stdname, airmass = '', exptime = ''
                , mag = stdmag, magband = stdmagband, teff = '', answer = 'yes')
    for name in stdgroup:
        inpar = 'stdawftbo' + stdgroup[name][0]
        iraf.sensfunc(standards = inpar, sensitivity = 'sensawftbo' + stdgroup[name][0], 
            extinction = extpath, function = 'spline3', order = 9)
Example #4
0
def standard(namelst):
    iraf.noao()
    iraf.twodspec()
    iraf.longslit(dispaxis=2, nsum=1, observatory=func.obs.name,
                  extinction=extpath, caldir=stdpath)
    if os.path.isfile('Std'):
        print('remove file Std')
        os.remove('Std')
    for std_fitsname in namelst:
        stdname, stdmag, stdmagband = func.standard_star_info(std_fitsname)
        print(colored('the standard star is ' + stdname, 'green'))
        wid, sep = get_band_width_sep(std_fitsname)
        airmas = pyfits.getval(std_fitsname, 'airmass')
        exposure = pyfits.getval(std_fitsname, 'exptime')
        iraf.standard(input=std_fitsname, output='Std', samestar=True,
                    beam_switch=False, apertures='', bandwidth=wid,
                    bandsep=sep,  # 30.0  20.0
                    fnuzero=3.6800000000000E-20, extinction=extpath,
                    caldir=stdpath, observatory=func.obs.name, interact=True,
                    graphics='stdgraph', cursor='', star_name=stdname,
                    airmass=airmas, exptime=exposure, mag=stdmag,
                    magband=stdmagband, teff='', answer='yes')
    if os.path.isfile('Sens.fits'):
        print('remove file Sens.fits')
        os.remove('Sens.fits')
    iraf.sensfunc(standards='Std', sensitivity='Sens',
                  extinction=extpath, function='spline3', order=9)
    iraf.splot('Sens')
Example #5
0
File: SCRIPT.py Project: dafh/stuff
def sens(std):
    iraf.sensfunc.standard = std
    iraf.sensfunc.sensitiv = 'sens'
    iraf.sensfunc.interac= 'yes'
    iraf.sensfunc.ignorea= 'no'
    iraf.sensfunc.funct = 'spline3'
    iraf.sensfunc.order = 6
    iraf.sensfunc.observatory = 'observatory'
    iraf.sensfunc.extinc = 'onedstds$lasilla.dat'
    #iraf.lpar(iraf.sensfunc)
    iraf.sensfunc(mode='h')
Example #6
0
def sensfunc():
    iraf.twodspec()
    iraf.longslit(dispaxis=2,
                  nsum=1,
                  observatory='Lijiang',
                  extinction='onedstds$LJextinct.dat',
                  caldir='onedstds$ctiocal/')
    iraf.sensfunc(standards='std',
                  sensitivity='sens',
                  extinction='onedstds$LJextinct.dat',
                  function='spline3',
                  order=9)
Example #7
0
def standard_sens(infile, caldir=')_.caldir', noext=False, overwrite=False):
    print('\n#############################')
    print('Deriving sensitivity funciton')

    # Not to display items in IRAF packages
    sys.stdout = open('/dev/null', 'w')
    iraf.noao()
    iraf.onedspec()
    sys.stdout = sys.__stdout__  # Back to the stadard output

    basename = fits.getval(infile, 'FRAMEID')
    std = basename + '.std'

    if noext:
        extinction = ''
    else:
        extinction = fi.filibdir + 'mkoextinct.dat'

    if os.path.isfile(std) and not overwrite:
        print('\t The output file of IRAF STANDARD '+\
              'task already exits. '+std)
        print('\t STANDARD is skipped.')
    else:
        if overwrite:
            print('Removing ' + std)
            try:
                os.remove(std)
            except:
                pass

        iraf.standard(infile, std, extinction=extinction,\
                      caldir=caldir, beam_sw='no', aperture='')
        print('Output file of IRAF STANDARD task: ' + std)

    sens = basename + '.sens.fits'
    if os.path.isfile(sens) and not overwrite:
        print('\t The output file of IRAF SENSFUNC task already exits. ' +
              sens)
        print('\t SENSFUNC is skipped.')
    else:
        if overwrite:
            print('Removing ' + sens)
            try:
                os.remove(sens)
            except:
                pass

        iraf.sensfunc(std, sens, aperture='', ignoreaps='yes',\
                      extinction=extinction,\
                      logfile='sensfunc.log')
        print('Output file of IRAF SENSFUNC task: ' + sens)

    return sens, True
Example #8
0
def standard(namelst):
    iraf.noao()
    iraf.twodspec()
    iraf.longslit(dispaxis=2,
                  nsum=1,
                  observatory='ca',
                  extinction=extpath,
                  caldir=stdpath)
    std_fitsname = namelst[0]
    stdname, stdmag, stdmagband = standard_star_info(std_fitsname)
    wid, sep = get_band_width_sep(stdname)
    print('<<<<<the standard star is ', stdname, '>>>>>')
    print std_fitsname
    if os.path.isfile('Std'):
        print('remove file Std')
        os.remove('Std')

    iraf.standard(
        input=std_fitsname,
        output='Std',
        samestar=True,
        beam_switch=False,
        apertures='',
        bandwidth=wid,
        bandsep=sep,  # 30.0  20.0
        fnuzero=3.6800000000000E-20,
        extinction=extpath,
        caldir=stdpath,
        observatory='ca',
        interact=True,
        graphics='stdgraph',
        cursor='',
        star_name=stdname,
        airmass='',
        exptime='',
        mag=stdmag,
        magband=stdmagband,
        teff='',
        answer='yes')

    if os.path.isfile('Sens.fits'):
        print('remove file Sens.fits')
        os.remove('Sens.fits')

    iraf.sensfunc(standards='Std',
                  sensitivity='Sens',
                  extinction=extpath,
                  function='spline3',
                  order=15)

    iraf.splot('Sens')
    iraf.flpr()
Example #9
0
def sensfunc(standards, obs):
    """
    sensfunc -- Determine sensitivity and extinction functions
    sensfunc standards sensitivity
    """
    import glob
    import os, sys
    from pyraf import iraf
    iraf.noao()
    iraf.onedspec()
    output_sens = "sens"
    iraf.sensfunc(standards=standards,
                  sensitivity=output_sens,
                  extinct='/iraf/iraf/noao/lib/onedstds/ctioextinct.dat',
                  observatory=obs)
    iraf.splot(output_sens)
Example #10
0
def standard_star(std_in, std_out, star_name, sampling=10, data_path='.',  
                  sens_prefix='sens', params={}):
    """
    Run iraf transform to rectify 2D spectrum.

    Parameters
    ----------
    std_in : str
        Input standard star extracted spectrum file name prefix.
    std_out : str
        Output file name prefix.
    star_name : str
        Standard star name.
    sampling : str
        Delta wavelength in angstrom (10 or 50 angstrom)
    data_path : str
        Directory that contains the data.
    sens_prefix : str
        Sensitivity correction file name prefix.
    params : dict
        Iraf standard and senfunc parameters.
    """

    _check_working_dir(data_path)

    logger.info('running iraf standard')


    iraf.standard.unlearn()
    interactive = params.pop('interactive', 'yes')
    iraf.standard.extinct = os.path.join(calipath, 'lbtextinct.dat')
    iraf.standard.caldir = os.path.join(calipath, 'modsSpecPhot/Tables') + '/'
    iraf.standard.star_name = '{}_{}a'.format(star_name.lower(), sampling)
    iraf.standard.interact = interactive
    iraf.standard.answer = params.pop('answer', 'yes')
    iraf.standard(input=std_in, output=std_out)

    logger.info('running iraf sensfunc')

    iraf.sensfunc.unlearn()
    iraf.sensfunc.interactive = interactive
    iraf.sensfunc.extinction = os.path.join(calipath, 'lbtextinct.dat')
    iraf.sensfunc.newextinction = params.pop('newextinction', 'newext.dat')
    iraf.sensfunc.sensitivity = params.pop('sensitivity', sens_prefix)
    iraf.sensfunc.answer = params.pop('answer', 'yes')
    iraf.sensfunc(standards=std_out)
Example #11
0
 def rssstdred(self, obj, arc):
     rt.rmexist([obj[0].sensout,obj[0].sensout+'.fits'])
     for std in obj:
         self.reduce2d(std, arc, do_error=False)
         rt.loadparam(self.rssconfig, ['iraf.apall'])
         std_data = self.caldir+'/'+std.object+".dat"
         rt.rmexist([std.oned,std.oned0])
         while not os.path.isfile(std_data):
             print("Cannot find file ", std_data)
             std_data = raw_input('Enter a star database:  ')
         iraf.apall(std.bkg, b_niterate=5, b_sample='-100:-40,40:100', b_high_reject=1.5, b_low_reject=2)
         os.system('mv %s %s' %  (std.oned0,std.oned))
         if not rt.header(std.oned,'AIRMASS'): rt.rssairmass(std.oned)
         iraf.standard(input=std.oned, output=std.sensout, caldir=self.caldir, interact='yes',
                   star_name=std.object, extinct=self.extinction)
     # Sensitivity files    
     iraf.sensfunc(std.sensout, std.sensout+'.fits', interactive= 'yes', extinct=self.extinction,
                   newextinction='extinct.dat')
     rt.getsh('cp %s %s' %  (std.sensout+'.fits',self.rssdatadir)) 
     return std.sensout+'.fits'
Example #12
0
def telluric_sensfunc():

    """
    sensfunc: determine sensitivity

    """
    iraf.sensfunc.unlearn()

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

    # Input standard star data file (from STANDARD)
    iraf.sensfunc.setParam('standards','std')

    iraf.sensfunc.setParam('ignoreaps','yes')

    # Output root sensitivity function imagename
    iraf.sensfunc.setParam('sensitivity','sens')

    #(no|yes|NO|YES)
    iraf.sensfunc.setParam('answer','yes')

    # Fitting function
    iraf.sensfunc.setParam('function','spline3')

    # Order of fit
    iraf.sensfunc.setParam('order','9')

    # Determine sensitivity function interactively?
    iraf.sensfunc.setParam('interactive','yes')

    # Graphs to be displayed
    # s = sensitivity vs wavelength
    # r = residual sensitivty vs wavelength
    # i = flux calibrated spectrum vs wavelength
    iraf.sensfunc.setParam('graphs','si')

    iraf.sensfunc()

    return None
Example #13
0
    interac="yes",
    graphic="stdgraph",
    star_name="g191b2b",
    airmass=1.99,
    exptime=900,
    answer="yes")

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",
Example #14
0
def create_standard_sens(directory,
                         objecto,
                         iraf_name,
                         iraf_directory='iidscal',
                         suffix=''):
    '''
    Calculate the flux calibration for the standard star and save. The list of standards
    can be found in: http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?onedstds

    Parameters
    -------------
    directory: Directory where all the reduced standard files are located.
               i.e. Objectname/Science
    iraf_name: Name of the standard in the IRAF tables
    object_name: The object you intend to correct
    iraf_directory: Directory where the extinction file is. Options:
        blackbody
        bstdscal
        ctiocal
        ctionewcal
        iidscal
        irscal
        oke1990
        redcal
        spec16cal
        spec50cal
        spechayescal
    suffix: Optional suffix to be appended at the end of the file name

    Output
    -------------
    A file that will be used by SENSFUNC.
    The calibratied sens file
    The flux corrected images of the target.
    '''

    # Use the first image of the standard to calculate the calibration
    standard_file = glob.glob("%s/%s*BiasFlatSkyOutWave.fits" %
                              (directory, objecto))[0]

    # Check that the files don't exist
    if check_existence(iraf_name + '_flux' + suffix + '.fits',
                       'create_standard_sens'):
        return

    # Run the standard
    standard(
        input=standard_file,  # Input name of the image
        output=iraf_name + '_flux' +
        suffix,  # Output flux file used by Sensfunc
        samestar='yes',  # Same star in all apertures?
        beam_switch='no',  # Beam switch spectra?
        apertures='',  # Aperture selection list
        bandwidth=
        'INDEF',  # Bandpass widths, if INDEF use the default values in the standard calibration file
        bandsep=
        'INDEF',  # Bandpass separation, if INDEF use the default values in the standard calibration file
        fnuzero='3.68E-20',  # Absolute flux zero point
        extinction='/iraf/iraf/noao/lib/onedstds/%s/%s.dat' %
        (iraf_directory, iraf_name),  # Extinction file
        caldir='/iraf/iraf/noao/lib/onedstds/%s/' %
        iraf_directory,  # Directory containing calibration data
        observatory=')_.observatory',  # Observatory for data
        interact='yes',  # Graphic interaction to define new bandpasses
        graphics='stdgraph',  # Graphics output device
        cursor='',  # Graphics cursor input
        star_name=iraf_name,  # Star name in calibration list
        airmass='',  # Airmass
        exptime='',  # Exposure time (seconds)
        mag='',  # Magnitude of Star
        magband='U',  # Magnitude type
        teff='',  # Effective temperature or spectral type
        answer='y',  # no, yes, NO, YES, NO!, YES!
        mode='ql',  # IRAF mode
    )

    # Create the sensitivity file
    sensfunc(
        standards=iraf_name + '_flux' +
        suffix,  # Input standard star data file
        sensitivity='sens_' + iraf_name +
        suffix,  # Output root sensitivty function imagename
        apertures='',  # Aperture selection list
        ignoreaps='yes',  # Ignore apertures and make one sensitivity function?
        logfile='logfile',  # Output log for statistics information
        extinction='',  # Extinction file
        newextinction='',  # Output revised extinction file
        observatory=')_.observatory',  # Observatory for data
        function='legendre',  # Fitting function
        order='6',  # Order to fit
        interactive='yes',  # Determine sensitivity function interactively?
        graphs='sr',  # Graphs per frame
        marks='plus cross box',  # Data mark types
        colors='2 1 3 4',  # Colors
        cursor='',  # Graphics cursor input
        device='stdgraph',  # Graphics output device
        answer='yes',  # no, yes, NO, YES
        mode='ql',  # IRAF mode
    )
Example #15
0
def deimos_standard(standard):

    '''Extract standard star and calculate sensitivit function.'''
    
    bstd = "%s_01_B" % standard; rstd = "%s_01_R" % standard

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

    # Fit the continuum
    #iraf.continuum("%s.ms" % bstd, output="s%s.ms" % bstd, lines=1, bands=1,
    #               type="fit", sample="*", naverage=1, function="chebyshev",
    #               order=15, low_reject=3.0, high_reject=5.0, niterate=10, grow=1.0,
    #               interac=yes)
    #iraf.continuum("%s.ms" % rstd, output="s%s.ms" % rstd, lines=1, bands=1,
    #               type="fit", sample="*", naverage=1, function="chebyshev",
    #               order=15, low_reject=3.0, high_reject=5.0, niterate=10, grow=1.0,
    #               interac=yes)

    # Create telluric
    iraf.splot("%s.ms" % bstd) # Remove telluric and absorption, save as a%s.ms
    iraf.sarith("%s.ms" % bstd, "/", "a%s.ms" % bstd, "telluric.B.%s.fits" % bstd)
    iraf.imreplace("telluric.B.%s.fits" % bstd, 1.0, lower=0.0, upper=0.0)
    iraf.splot("telluric.B.%s.fits" % bstd) # Remove stellar features and resave

    iraf.splot("%s.ms" % rstd) # Remove telluric and absorption, save as a%s.ms
    iraf.sarith("%s.ms" % rstd, "/", "a%s.ms" % rstd, "telluric.R.%s.fits" % rstd)
    iraf.imreplace("telluric.R.%s.fits" % rstd, 1.0, lower=0.0, upper=0.0)
    iraf.splot("telluric.R.%s.fits" % rstd) # Remove stellar features and resave
    
    # Create smoothed standard
    iraf.gauss("a%s.ms[*,1,1]" % bstd, "s%s.ms" % bstd, 5.0)
    iraf.sarith("%s.ms" % bstd, "/", "s%s.ms" % bstd, "ds%s.ms" % bstd)
    iraf.gauss("a%s.ms[*,1,1]" % rstd, "s%s.ms" % rstd, 5.0)
    iraf.sarith("%s.ms" % rstd, "/", "s%s.ms" % rstd, "ds%s.ms" % rstd)

    # Divide through by smoothed standard
    #iraf.sarith("%s.ms" % bstd, "/", "s%s.ms" % bstd, "ds%s.ms" % bstd)
    #iraf.sarith("%s.ms" % rstd, "/", "s%s.ms" % rstd, "ds%s.ms" % rstd)

    # Create and apply telluric correction
    #iraf.splot("%s.ms" % bstd) # Remove telluric, save as a%s.ms
    #iraf.splot("%s.ms" % rstd) # Remove telluric, save as a%s.ms
    #iraf.sarith("%s.ms" % bstd, "/", "a%s.ms" % bstd, "telluric.B.fits")
    #iraf.sarith("%s.ms" % rstd, "/", "a%s.ms" % rstd, "telluric.R.fits")
    #iraf.imreplace("telluric.B.fits", 1.0, lower=0.0, upper=0.0)
    #iraf.imreplace("telluric.R.fits", 1.0, lower=0.0, upper=0.0)
    iraf.telluric("ds%s.ms" % bstd, "tds%s.ms" % bstd, "telluric.B.%s.fits" % bstd,
                  xcorr=no, tweakrms=no, interactive=no, sample='6850:6950,7575:7700')
    iraf.telluric("ds%s.ms" % rstd, "tds%s.ms" % rstd, "telluric.R.%s.fits" % rstd,
                  xcorr=no, tweakrms=no, interactive=no, sample='6850:6950,7575:7700')

    # Define bandpasses for standard star calculation
    iraf.standard("tds%s.ms" % bstd, "%s.B.std" % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  caldir='home$standards/', observatory='Keck', interac=yes,
                  star_name=standard, airmass='', exptime='')
    iraf.standard("tds%s.ms" % rstd, "%s.R.std" % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  caldir='home$standards/', observatory='Keck', interac=yes,
                  star_name=standard, airmass='', exptime='')

    # Determine sensitivity function
    iraf.sensfunc('%s.B.std' % standard, '%s.B.sens' % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  newextinction='extinct.dat', observatory='Keck',
                  function='legendre', order=4, interactive=yes)
    iraf.sensfunc('%s.R.std' % standard, '%s.R.sens' % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  newextinction='extinct.dat', observatory='Keck',
                  function='legendre', order=4, interactive=yes)

    return
Example #16
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
Example #17
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
Example #18
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
Example #19
0
iraf.standard(input=ptfstar2ms,
              output=stdstar2,
              star_name=ptfstar2_name,
              airmass=ptfstar2_air,
              exptime=ptfstar2_exp,
              answer=yes,
              caldir=default_caldir,
              extinction='mk_extinct.txt',
              observatory='Keck')

sensstar1 = 'sensstar1'
sensstar2 = 'sensstar2'

#Fit Sensitivity Function
iraf.sensfunc(standards=stdstar1,
              sensitivity=sensstar1,
              observatory='Keck',
              order=4)
iraf.sensfunc(standards=stdstar2,
              sensitivity=sensstar2,
              observatory='Keck',
              order=4)

ptfsn1f = 'ptfsn1.f'
ptfsn2f = 'ptfsn2.f'
sensstar1 = 'sensstar1.fits'
sensstar2 = 'sensstar2.fits'

#Calibrate Spectra
print '\n provide the following manually: \n'
print ptfsn1_name, ptfsn1_air, ptfsn1_exp
print '\n'
Example #20
0
def deimos_standard(standard):
    '''Extract standard star and calculate sensitivit function.'''

    bstd = "%s_01_B" % standard
    rstd = "%s_01_R" % standard

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

    # Fit the continuum
    #iraf.continuum("%s.ms" % bstd, output="s%s.ms" % bstd, lines=1, bands=1,
    #               type="fit", sample="*", naverage=1, function="chebyshev",
    #               order=15, low_reject=3.0, high_reject=5.0, niterate=10, grow=1.0,
    #               interac=yes)
    #iraf.continuum("%s.ms" % rstd, output="s%s.ms" % rstd, lines=1, bands=1,
    #               type="fit", sample="*", naverage=1, function="chebyshev",
    #               order=15, low_reject=3.0, high_reject=5.0, niterate=10, grow=1.0,
    #               interac=yes)

    # Create telluric
    iraf.splot("%s.ms" %
               bstd)  # Remove telluric and absorption, save as a%s.ms
    iraf.sarith("%s.ms" % bstd, "/", "a%s.ms" % bstd,
                "telluric.B.%s.fits" % bstd)
    iraf.imreplace("telluric.B.%s.fits" % bstd, 1.0, lower=0.0, upper=0.0)
    iraf.splot("telluric.B.%s.fits" %
               bstd)  # Remove stellar features and resave

    iraf.splot("%s.ms" %
               rstd)  # Remove telluric and absorption, save as a%s.ms
    iraf.sarith("%s.ms" % rstd, "/", "a%s.ms" % rstd,
                "telluric.R.%s.fits" % rstd)
    iraf.imreplace("telluric.R.%s.fits" % rstd, 1.0, lower=0.0, upper=0.0)
    iraf.splot("telluric.R.%s.fits" %
               rstd)  # Remove stellar features and resave

    # Create smoothed standard
    iraf.gauss("a%s.ms[*,1,1]" % bstd, "s%s.ms" % bstd, 5.0)
    iraf.sarith("%s.ms" % bstd, "/", "s%s.ms" % bstd, "ds%s.ms" % bstd)
    iraf.gauss("a%s.ms[*,1,1]" % rstd, "s%s.ms" % rstd, 5.0)
    iraf.sarith("%s.ms" % rstd, "/", "s%s.ms" % rstd, "ds%s.ms" % rstd)

    # Divide through by smoothed standard
    #iraf.sarith("%s.ms" % bstd, "/", "s%s.ms" % bstd, "ds%s.ms" % bstd)
    #iraf.sarith("%s.ms" % rstd, "/", "s%s.ms" % rstd, "ds%s.ms" % rstd)

    # Create and apply telluric correction
    #iraf.splot("%s.ms" % bstd) # Remove telluric, save as a%s.ms
    #iraf.splot("%s.ms" % rstd) # Remove telluric, save as a%s.ms
    #iraf.sarith("%s.ms" % bstd, "/", "a%s.ms" % bstd, "telluric.B.fits")
    #iraf.sarith("%s.ms" % rstd, "/", "a%s.ms" % rstd, "telluric.R.fits")
    #iraf.imreplace("telluric.B.fits", 1.0, lower=0.0, upper=0.0)
    #iraf.imreplace("telluric.R.fits", 1.0, lower=0.0, upper=0.0)
    iraf.telluric("ds%s.ms" % bstd,
                  "tds%s.ms" % bstd,
                  "telluric.B.%s.fits" % bstd,
                  xcorr=no,
                  tweakrms=no,
                  interactive=no,
                  sample='6850:6950,7575:7700')
    iraf.telluric("ds%s.ms" % rstd,
                  "tds%s.ms" % rstd,
                  "telluric.R.%s.fits" % rstd,
                  xcorr=no,
                  tweakrms=no,
                  interactive=no,
                  sample='6850:6950,7575:7700')

    # Define bandpasses for standard star calculation
    iraf.standard("tds%s.ms" % bstd,
                  "%s.B.std" % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  caldir='home$standards/',
                  observatory='Keck',
                  interac=yes,
                  star_name=standard,
                  airmass='',
                  exptime='')
    iraf.standard("tds%s.ms" % rstd,
                  "%s.R.std" % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  caldir='home$standards/',
                  observatory='Keck',
                  interac=yes,
                  star_name=standard,
                  airmass='',
                  exptime='')

    # Determine sensitivity function
    iraf.sensfunc('%s.B.std' % standard,
                  '%s.B.sens' % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  newextinction='extinct.dat',
                  observatory='Keck',
                  function='legendre',
                  order=4,
                  interactive=yes)
    iraf.sensfunc('%s.R.std' % standard,
                  '%s.R.sens' % standard,
                  extinction='home$extinct/maunakeaextinct.dat',
                  newextinction='extinct.dat',
                  observatory='Keck',
                  function='legendre',
                  order=4,
                  interactive=yes)

    return
Example #21
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
Example #22
0
            graphics = "stdgraph",\
            cursor = "",\
            mode = "al")

    ### Apply sensfunc
    os.system("rm sens*.fits")
    iraf.sensfunc(
        standards = "std",\
        sensitivity = "sens",\
        answer = "yes",\
        apertures = "",\
        ignoreaps = 1,\
        logfile = "logfile",\
        extinction = program_dir + "flux_data/extinsso.tab",\
        newextinctio = "extinct.dat",\
        observatory = "SSO",\
        function = "spline3",\
        order = 15,\
        interactive = 1,\
        graphs = "sr",\
        marks = "plus cross box",\
        colors = "2 1 3 4",\
        cursor = "",\
        device = "stdgraph",\
        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']
Example #23
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
Example #24
0
def lris_standard(standards, xcorr=yes):
    '''Extract standard stars and calculate sensitivity functions.'''

    for ofile, nstd in standards:

        shutil.copy(ofile, "%s.fits" % nstd)

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

        if xcorr:
            # Cross correlate to tweak wavelength
            iraf.xcsao("%s.ms" % nstd,
                       templates=XCTEMPLATE,
                       correlate="wavelength",
                       logfiles="%s.xcsao" % ofile)

            # If a solution was found, apply shift
            try:
                xcsaof = open("%s.xcsao" % ofile)
                shift = float(xcsaof.readlines()[6].split()[14])
            except:
                shift = 0.0
                iraf.specshift("%s.ms" % nstd, -shift)

        # Create telluric
        iraf.splot("%s.ms" %
                   nstd)  # Remove telluric and absorption, save as a%s.ms
        iraf.sarith("%s.ms" % nstd, "/", "a%s.ms" % nstd,
                    "telluric.%s.fits" % nstd)
        iraf.imreplace("telluric.%s.fits" % nstd, 1.0, lower=0.0, upper=0.0)
        iraf.splot("telluric.%s.fits" %
                   nstd)  # Remove stellar features and resave

        # Create smoothed standard
        iraf.gauss("a%s.ms[*,1,1]" % nstd, "s%s.ms" % nstd, 5.0)
        iraf.sarith("%s.ms" % nstd, "/", "s%s.ms" % nstd, "ds%s.ms" % nstd)

        # Apply telluric correction
        iraf.telluric(
            "ds%s.ms" % nstd,
            "tds%s.ms" % nstd,
            "telluric.%s.fits" % nstd,
            xcorr=no,
            tweakrms=no,
            interactive=no,
            sample='4000:4010,6850:6975,7150:7350,7575:7725,8050:8400,8900:9725'
        )

        # Define bandpasses for standard star calculation
        obj = get_head("%s.fits" % nstd, "OBJECT")
        iraf.standard("tds%s.ms" % nstd,
                      "%s.std" % nstd,
                      extinction='home$extinct/maunakeaextinct.dat',
                      caldir='home$standards/',
                      observatory='Keck',
                      interac=yes,
                      star_name=obj,
                      airmass='',
                      exptime='')

        # Determine sensitivity function
        iraf.sensfunc('%s.std' % nstd,
                      '%s.sens' % nstd,
                      extinction='home$extinct/maunakeaextinct.dat',
                      newextinction='extinct.dat',
                      observatory='Keck',
                      function='legendre',
                      order=4,
                      interactive=yes)

    return
Example #25
0
for imname in objects_pars.keys():
    if 'ztfstar' in imname:
        print(objects_pars[imname][4])
        iraf.standard(input=objects_pars[imname][4],
                      output='std_' + imname,
                      star_name=objects_pars[imname][0],
                      airmass=objects_pars[imname][1],
                      exptime=objects_pars[imname][2],
                      answer=yes,
                      caldir=default_caldir,
                      observatory='Keck')

for imname in objects_pars.keys():
    if 'ztfstar' in imname:
        iraf.sensfunc(standards='std_' + imname,
                      sensitivity='sens_' + imname,
                      observatory='Keck',
                      order=4)
        if '520' in imname:
            sensstar520 = 'sens_' + imname
        elif '525' in imname:
            sensstar525 = 'sens_' + imname

combname = []
for imname in objects_pars:
    if 'sn' in objects_pars[imname][3]:
        print('name,airmass,exptime,obstype')
        print(objects_pars[imname])
        if '520' in imname:
            sensstar520 = 'sens_ztfstar_520_3.fits'
            usesens = sensstar520
        elif '525' in imname:
Example #26
0
def sensfunc(stdidx):
    iraf.sensfunc(standards='std'+str(stdidx),sensitivity='sens'+str(stdidx))
    return