Beispiel #1
0
def reidentify():
    iraf.twodspec()
    iraf.longslit()
    iraf.reidentify(reference='Lamp',
                    images='Lamp',
                    interactive='no',
                    section='column',
                    newaps='yes',
                    override='yes',
                    refit='yes',
                    trace='no',
                    step=10,
                    nsum=10,
                    shift=0.0,
                    search=0.0,
                    nlost=5,
                    cradius=7.0,
                    threshold=0.0,
                    addfeatures='no',
                    coordlist=cdherb_file,
                    match=-3.0,
                    maxfeatures=50,
                    minsep=2.0,
                    database='database')
    iraf.flpr()
Beispiel #2
0
def wal(lstfile):
    iraf.noao()
    iraf.twodspec()
    iraf.longslit()
    iraf.identify(images = 'Lamp'
        , section = 'middle column', database = 'database'
        , coordlist = 'linelists$idhenear.dat', units = '', nsum = 10
        , match = -3.0, maxfeatures = 50, zwidth = 100.0
        , ftype = 'emission', fwidth = 20.0, cradius = 5.0
        , threshold = 0.0, minsep = 2.0, function = 'chebyshev'
        , order = 6, sample = '*', niterate = 0
        , low_reject = 3.0, high_reject = 3.0, grow = 0.0
        , autowrite = False, graphics = 'stdgraph', cursor = ''
        , crval = '', cdelt = '')
    iraf.reidentify(reference = 'Lamp'
        , images = 'Lamp', interactive = 'no', section = 'column'
        , newaps = True, override = True, refit = True, trace = False
        , step = 10, nsum = 10, shift = 0.0, search = 0.0, nlost = 5
        , cradius = 7.0, threshold = 0.0, addfeatures = False
        , coordlist = 'linelists$idhenear.dat', match = -3.0, maxfeatures = 50
        , minsep = 2.0, database = 'database', logfiles = 'logfile'
        , plotfile = '', verbose = False, graphics = 'stdgraph', cursor = ''
        , answer = 'yes', crval = '', cdelt = '', mode = 'al')
    iraf.fitcoords(images = 'Lamp'
        , fitname = 'Lamp', interactive = True, combine = False, database = 'database'
        , deletions = 'deletions.db', function = 'chebyshev', xorder = 6
        , yorder = 6, logfiles = 'STDOUT,logfile', plotfile = 'plotfile'
        , graphics = 'stdgraph', cursor = '', mode = 'al')
    iraf.longslit(dispaxis = 2)
    iraf.transform(input = '%ftbo%ftbo%@' + lstfile
        , output = '%wftbo%wftbo%@' + lstfile, minput = '', moutput = ''
        , fitnames = 'LampLamp', database = 'database', interptype = 'spline3'
        , flux = True)
Beispiel #3
0
def make_lambda_solution(arc_list,fcnamedict):
    irf_prm.set_identify_calibration(iraf.identify)
    irf_prm.set_reidentify_calibration(iraf.reidentify)
    irf_prm.set_fitcoords_calibration(iraf.fitcoords)
    for arc in arc_list:
        iraf.identify(images=arc)
        iraf.reidentify(reference=arc,images=arc)
        iraf.fitcoords(images=arc[:-5],fitname=fcnamedict[arc])
    return
Beispiel #4
0
def reid(refpath,idref):
    if not os.path.isdir('database'):
        os.mkdir('database')
    os.system('cp '+refpath+' ./database')
    lexlist = glob.glob('LAMP*EX.fits')
    linelist = 'Lines_HgCdHeNeAr600.dat'
    width = 10.0
    radius = 15.0
    for img in lexlist:
        iraf.reidentify(idref,img,cradius=radius)
Beispiel #5
0
def ident():
    lexlist = glob.glob('LAMP*EX.fits')
    linelist = 'Lines_HgCdHeNeAr600.dat'
    width = 10.0
    radius = 15.0
    idref = lexlist[0].rsplit('.fits',1)[0]
    iraf.identify(idref,coordlist=linelist,fwidth=width,cradius=radius)
    lexlist = lexlist[1:]
    for img in lexlist:
        iraf.reidentify(idref,img,cradius=radius)
    return idref
Beispiel #6
0
def standard_trace(standard_list,supplement_list,outname='star'):
    irf_prm.set_identify_standard(iraf.identify)
    irf_prm.set_reidentify_standard(iraf.reidentify)
    irf_prm.set_fitcoords_standard(iraf.fitcoords)
    all_standards = ''
    for standrd in standard_list:
        iraf.identify(images=standrd)
        iraf.reidentify(reference=standrd,images=standrd)
        all_standards += standrd[:-5]+','
    for supplement in supplement_list:
        iraf.identify(images=supplement)
        iraf.reidentify(reference=supplement,images=supplement)
        all_standards += supplement[:-5]+','
    iraf.fitcoords(images=all_standards,fitname=outname)
    return
Beispiel #7
0
def identify_gap(infile, overwrite=False):
    print('\n#############################')
    print('Identifying the spectrum gaps.')

    database = 'database'
    
    idfile = database + '/id' + os.path.splitext(infile)[0]
    if os.path.exists(idfile):
        if overwrite:
            try:
                os.remove(idfile)
            except:
                pass
        else:
            print('\t ID file already exists: '+idfile)
            print('\t This precedure is skipped.')
            return

    # Checking version consistency
    if not fi.check_version_f(infile):
        return
    
    # Not to display items in IRAF packages
    sys.stdout = open('/dev/null', 'w')
    iraf.noao()
    iraf.twodspec()
    iraf.longslit()
    sys.stdout = sys.__stdout__ # Back to the stadard output

    binfct1 = fits.getval(infile, 'BIN-FCT1')
    coordlist = fi.filibdir+'pseudoslitgap_binx'+str(binfct1)+'.dat'

    iraf.identify(infile, section='middle line', database=database, \
                  coordlist=coordlist, units='', nsum=20,\
                  match=-15., ftype='absorption', fwidth=16./binfct1, \
                  cradius=5.,\
                  threshold=0., function='chebyshev', order=2, sample='*', \
                  niter=0, autowrite='no')

    iraf.reidentify(infile, infile, interac='no', nsum=50, \
                    section='middle line', newaps='no', override='no',\
                    refit='yes', trace='yes', step=100, shift=0,\
                    nlost=20, cradius=5., threshold=0., addfeatures='no',\
                    coordlist=coordlist, match=-3., \
                    database=database, logfile='identify_gap.log', plotfile='', \
                    verbose='yes', cursor='')
    return
Beispiel #8
0
def identify_each(inname, database='database', \
                    coordlist=fi.filibdir+'thar.300.dat', \
                    section_x=50, \
                    overwrite=False):

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

    idfile = database + '/id' + inname
    if os.path.isfile(idfile) and overwrite == False:
        print('ID file already exists. '+idfile)
    else:
        if os.path.isfile(idfile) and overwrite == True:
            print('Removing ' + idfile)
            try:
                os.remove(idfile)
            except:
                pass

        # Creating the "section" parameter
        section = 'y '+str(section_x)
    
        iraf.identify(inname, section=section,
                  database=database, coordlist=coordlist, units='',
                  nsum=nsum, match=match, ftype='emission', fwidth=fwidth,
                  cradius=cradius, threshold=threshold,
                  function='chebyshev', order=order, sample='*',
                  niter=niter, autowrite=autowrite, cursor='')

        iraf.reidentify(inname, inname,
                    interac='no', section=section, newaps=newaps,
                    override=override, refit=refit, trace=trace,
                    step=step, shift=0, nlost=nlost, cradius=cradius,
                    threshold=threshold, addfeatures=addfeatures,
                    coordlist=coordlist, match=match, database=database,
                    logfile=logfile, plotfile='', verbose=verbose,
                    cursor='')
    return
Beispiel #9
0
 def rssidentify(self, arc):
     if not os.path.exists('database'): os.system('mkdir database')
     rt.loadparam(self.rssconfig, ['iraf.identify', 'iraf.reidentify', 'iraf.fitcoords'])
     coordfile = self.linelist_dir+arc.linelist
     while not os.path.exists(coordfile):
         print("***** rssidentify error *** The coordinate "+str(coordfile)+" IS NOT in our directory *****")
         coordfile = raw_input('Enter a correct path for coordinate files:  ')
     arc.coordfile = coordfile
     copy2(coordfile, './')
     # check if the setup has been already identified before
     if os.path.isfile(self.rssdatadir+"/database/id"+arc.idname) and \
                     os.path.isfile(self.rssdatadir+"/"+arc.idfits):
         copy2(self.rssdatadir+"/database/id"+arc.idname, 'database/')
         copy2(self.rssdatadir+"/"+arc.idfits,'./')
     else:
         copy2(arc.name, arc.idfits)
         rt.rsswave(arc.idfits)
         iraf.identify(arc.idname, coordlist=coordfile, mode='h')
         iraf.reidentify(arc.idname, arc.idname, coordlist=coordfile, mode='h')  
         iraf.fitcoord(arc.idname, mode='h')
         copy2(arc.idfits, self.rssdatadir+'/'+arc.idfits)
         copy2('database/id'+arc.idname, self.rssdatadir+'/database/id'+arc.idname)
         copy2('database/fc'+arc.idname, self.rssdatadir+'/database/fc'+arc.idname)
     print("***** Reducing of ARCs *****")
     if not os.path.isfile("database/id"+arc.noext) or not os.path.isfile("database/fc"+arc.noext):
         iraf.reidentify(arc.idname, arc.noext, coordlist=coordfile, mode='h')
         iraf.reidentify(arc.noext, arc.noext, coordlist=coordfile, mode='h')        
         iraf.fitcoord(arc.noext, mode='h')
Beispiel #10
0
def reidentify(ref_fn, images, arc_lamp, mods_channel, data_path='.', 
               params={}):
    """
    Run iraf reidentify to trace identified lines along the spatial axis. 

    Parameters
    ----------
    ref_fn : str
        Reference image file name.
    images : str
        Image(s) to be reidentified.
    arc_lamp : str
        The arc lamp
    mods_channel : str
        MODS red or blue channel
    data_path : str
        Directory that contains the data.
    params : dict
        Iraf redidentify parameters.
    """

    _check_working_dir(data_path)

    line_list = os.path.join(
        calipath, 'line_lists/{}_{}.wav'.format(arc_lamp, mods_channel))

    logger.info('running iraf reidentify')

    iraf.reidentify.unlearn()
    iraf.reidentify.interactive = params.pop('interactive', 'no')
    iraf.reidentify.newaps = params.pop('newaps', 'yes')
    iraf.reidentify.refit = params.pop('refit', 'yes')
    iraf.reidentify.override = params.pop('override', 'no')
    iraf.reidentify.nlost = params.pop('nlost', 5)
    iraf.reidentify.verbose = params.pop('verbose', 'yes')
    iraf.reidentify.coordlist = line_list
    iraf.reidentify(reference=ref_fn, images=images)
Beispiel #11
0
def identify_edge(infile, overwrite=False):
    print('\n#############################')
    print('Identifying the edges.')

    binfct1 = fits.getval(infile, 'BIN-FCT1')
    coordlist = fi.filibdir + 'edge' + str(binfct1) + '.dat'

    section = 'middle line'
    verbose = 'yes'
    nsum = 50
    match = -10.
    fwidth = 6. / binfct1
    cradius = 20. / binfct1
    threshold = 0.
    function = 'chebyshev'
    order = 2
    niter = 0
    autowrite = 'yes'

    newaps = 'yes'
    override = 'yes'
    refit = 'no'
    trace = 'yes'
    step = 50
    shift = 0
    nlost = 0
    minsep = 60. / binfct1
    addfeatures = 'no'
    database = 'database'
    logfile = 'identify_edge.log'

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

    # entering the channel image directory.
    # os.chdir() does not change the directory for pyraf only in this function.
    print('\t Entering the channel image directory, \"' + fi.chimagedir +
          '\".')
    iraf.cd(fi.chimagedir)

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

    idfile = database + '/id' + basename + '.ch01edge'
    if os.path.isfile(idfile) and not overwrite:
        print('\t Edge identification files already exist, ' + idfile \
              + '. Skipping.')
    else:
        if os.path.isfile(idfile) and overwrite:
            print('\t Removing ' + idfile)
            try:
                os.remove(idfile)
            except:
                pass

        print('\t Identifying: ' + basename + '.ch01edge.fits')
        iraf.identify(basename + '.ch01edge',
                      section=section,
                      database=database,
                      coordlist=coordlist,
                      units='',
                      nsum=nsum,
                      match=match,
                      maxfeat=2,
                      ftype='emission',
                      fwidth=fwidth,
                      cradius=cradius,
                      threshold=threshold,
                      function=function,
                      order=order,
                      sample='*',
                      niter=niter,
                      autowrite=autowrite)

        print('\t Reidentifying: ' + basename + '.ch01edge.fits')
        iraf.reidentify(basename + '.ch01edge',
                        basename + '.ch01edge',
                        interac='no',
                        section=section,
                        newaps=newaps,
                        override=override,
                        refit=refit,
                        trace=trace,
                        step=step,
                        nsum=nsum,
                        shift=shift,
                        nlost=nlost,
                        cradius=cradius,
                        threshold=threshold,
                        addfeatures=addfeatures,
                        coordlist=coordlist,
                        match=match,
                        maxfeat=2,
                        minsep=minsep,
                        database=database,
                        logfile=logfile,
                        plotfile='',
                        verbose=verbose,
                        cursor='')

    for i in range(2, 25):
        print('\t Reidentifying: ' + basename + '.ch%02dedge.fits' % i)
        idfile = database + '/id' + basename + '.ch%02dedge' % i
        if os.path.isfile(idfile) and not overwrite:
            print('\t Edge identification files already exist, ' + idfile +
                  '. Skipping.')
        else:
            if os.path.isfile(idfile) and overwrite:
                print('\t Removing ' + idfile)
                try:
                    os.remove(idfile)
                except:
                    pass
            # treatment for VPH650
            if i == 12:
                disperser = fits.getval(basename + '.ch12edge.fits',
                                        'DISPERSR')
                if disperser == 'SCFCGRHD65':
                    nlost = 1
            if i == 13:
                disperser = fits.getval(basename + '.ch12edge.fits',
                                        'DISPERSR')
                if disperser == 'SCFCGRHD65':
                    nlost = 0

            iraf.reidentify(basename+'.ch%02dedge'%(i-1), \
                            basename+'.ch%02dedge'%i, \
                            interac='no', section=section, newaps=newaps, \
                            override=override, refit=refit, trace=trace, \
                            step=0.0, nsum=nsum, shift=shift, nlost=nlost, \
                            cradius=cradius, threshold=threshold, \
                            addfeatures=addfeatures, coordlist=coordlist, \
                            match=match, maxfeat=2, minsep=minsep, \
                            database=database, logfile=logfile, \
                            plotfile='', verbose=verbose, cursor='')
            #Check the result
            iraf.identify(basename+'.ch%02dedge'%i, section=section, \
                          database=database, coordlist=coordlist, units='', \
                          nsum=nsum, match=match, maxfeat=2,ftype='emission', \
                          fwidth=fwidth, cradius=cradius, threshold=threshold, \
                          function=function, order=order, sample='*', \
                          niter=niter, autowrite=autowrite)

            iraf.reidentify(basename+'.ch%02dedge'%i, \
                            basename+'.ch%02dedge'%i, \
                            interac='no', section=section, newaps=newaps, \
                            override=override, refit=refit, trace=trace, \
                            step=step, nsum=nsum, shift=shift, nlost=nlost, \
                            cradius=cradius, threshold=threshold, \
                            addfeatures=addfeatures, coordlist=coordlist, \
                            match=match, maxfeat=2, minsep=minsep, \
                            database=database, logfile=logfile, \
                            plotfile='', verbose=verbose, cursor='')

    print('\t Go back to the original directory.')
    iraf.cd('..')

    disperser = fits.getval(fi.chimagedir + basename + '.ch12edge.fits',
                            'DISPERSR')
    if disperser == 'SCFCGRHD65':
        correct_ch12_edge(basename, overwrite=overwrite)

    return
Beispiel #12
0
def wal(lstfile, lampname):
    iraf.noao()
    iraf.twodspec()
    iraf.longslit()
    # iraf.identify(images = 'Lamp.fits', section = 'middle column',
    #     database = 'database', coordlist = 'linelists$idhenear.dat',
    #     nsum = 10, match = -3.0, maxfeatures = 50, zwidth = 100.0,
    #     ftype = 'emission', fwidth = 20.0, cradius = 7.0, threshold = 0.0,
    #     minsep = 2.0, function = 'chebyshev', order = 6, sample = '*',
    #     niterate = 0, low_reject = 3.0, high_reject = 3.0, grow = 0.0,
    #     autowrite = 'no')

    #    iraf.reidentify(reference = 'Lamp', images = 'Lamp', interactive = 'no',
    #            section = 'column', newaps = 'yes', override = 'yes', refit = 'yes',
    #            trace = 'no', step = 10, nsum = 10, shift = 0.0, search = 0.0,
    #            nlost = 5, cradius = 7.0, threshold = 0.0, addfeatures = 'no',
    #            coordlist = 'linelists$idhenear.dat', match = -3.0,
    #            maxfeatures = 50, minsep = 2.0, database = 'database')

    iraf.identify(images=lampname,
                  section='middle column',
                  database='database',
                  coordlist='linelists$idhenear.dat',
                  units='',
                  nsum=10,
                  match=-3.0,
                  maxfeatures=50,
                  zwidth=100.0,
                  ftype='emission',
                  fwidth=20.0,
                  cradius=7.0,
                  threshold=0.0,
                  minsep=2.0,
                  function='chebyshev',
                  order=6,
                  sample='*',
                  niterate=0,
                  low_reject=3.0,
                  high_reject=3.0,
                  grow=0.0,
                  autowrite=False,
                  graphics='stdgraph',
                  cursor='',
                  crval='',
                  cdelt='')
    iraf.reidentify(reference=lampname,
                    images=lampname,
                    interactive='no',
                    section='column',
                    newaps=True,
                    override=True,
                    refit=True,
                    trace=False,
                    step=10,
                    nsum=10,
                    shift=0.0,
                    search=0.0,
                    nlost=5,
                    cradius=7.0,
                    threshold=0.0,
                    addfeatures=False,
                    coordlist='linelists$idhenear.dat',
                    match=-3.0,
                    maxfeatures=50,
                    minsep=2.0,
                    database='database',
                    logfiles='logfile',
                    plotfile='',
                    verbose=False,
                    graphics='stdgraph',
                    cursor='',
                    answer='yes',
                    crval='',
                    cdelt='',
                    mode='al')
    iraf.fitcoords(images=lampname,
                   fitname=lampname,
                   interactive=True,
                   combine=False,
                   database='database',
                   deletions='deletions.db',
                   function='chebyshev',
                   xorder=6,
                   yorder=6,
                   logfiles='STDOUT,logfile',
                   plotfile='plotfile',
                   graphics='stdgraph',
                   cursor='',
                   mode='al')
    iraf.longslit(dispaxis=2)
    iraf.transform(input='%ftbo%ftbo%@' + lstfile,
                   output='%wftbo%wftbo%@' + lstfile,
                   minput='',
                   moutput='',
                   fitnames=lampname + lampname,
                   database='database',
                   interptype='spline3',
                   flux=True)
Beispiel #13
0
                iraf.identify(loc_redfn,
                              database=_wldat,
                              ftype='emission',
                              fwidth=3,
                              order=2,
                              niterate=3,
                              cradius=3,
                              coordlist=lamp_list,
                              function='spline3')
                waveCalRef = '' + loc_redfn
            else:
                iraf.reidentify(waveCalRef,
                                loc_redfn,
                                interactive='no',
                                override='yes',
                                refit='yes',
                                nlost=1,
                                cradius=10,
                                addfeatures='no',
                                coordlist=lamp_list
                                )  #, function='spline3', order=2, niterate=3)
            disp_soln = ns.getdisp(
                _wldat + os.sep + 'id' + loc_redfn.replace('.fits', ''),
                'spline3')
            if writefiles:
                ns.wspectext(loc_redfn)
        datasets.append([redfns[-nthissci:], redfn])

        os.chdir(dir0)
        iraf.chdir(dir0)

ns.strl2f('tempjunkcal', calfns)
 iraf.reidentify(
     reference = template, \
     images = "nearraw_"+im_slice + "_" + arc_name,\
     answer = "no",\
     crval = "",\
     cdelt = "",\
     interactive = "no",\
     section = "first line",\
     newaps = 0,\
     override = 1,\
     refit = 1,\
     trace = 0,\
     step = "10",\
     nsum = "10",\
     shift = "INDEF",\
     search = "INDEF",\
     nlost = 2,\
     cradius = 5.0,\
     threshold = 5.0,\
     addfeatures = 0,\
     coordlist = program_dir + "cal_linelists/" + linelist,\
     match = -2.0,\
     maxfeatures = 60,\
     minsep = 2.0,\
     database = "database",\
     plotfile = "",\
     verbose = 1,\
     graphics = "stdgraph",\
     cursor = "",\
     aidpars = "",\
     mode = "ql")
Beispiel #15
0
def extractSpectra():
    """
    Extract 1D spectra using IRAF interactively

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

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

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

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

    # loop over all the the spectra
    for i in range(0, len(templist)):
        hdulist = fits.open(templist[i])
        prihdr = hdulist[0].header
        target_id = prihdr['CAT-NAME']
        spectrum_id = int(templist[i].split('_')[2].split('r')[1])
        if args.ds9:
            os.system('xpaset fuckingds9 fits < {}'.format(templist[i]))
        # extract the object spectrum
        print("[{}/{}] Extracting spectrum of {} from image {}".format(i+1, len(templist), target_id, templist[i]))
        print("[{}/{}] Check aperture and background. Change if required".format(i+1, len(templist)))
        print("[{}/{}] AP: m = mark aperture, d = delete aperture".format(i+1, len(templist)))
        print("[{}/{}] SKY: s = mark sky, t = delete sky, f = refit".format(i+1, len(templist)))
        print("[{}/{}] q = continue".format(i+1, len(templist)))
        iraf.apall(input=templist[i])
        print("Spectrum extracted!")
        # find the arcs either side of the object
        arclist = []
        arc1 = "a_s_r{0:d}_t.fits".format(spectrum_id-1)
        arc2 = "a_s_r{0:d}_t.fits".format(spectrum_id+1)
        arc1_out = "a_s_r{0:d}_t.ms.fits".format(spectrum_id-1)
        arc2_out = "a_s_r{0:d}_t.ms.fits".format(spectrum_id+1)
        # predict the arc names
        print("\nPredicting arcs names...")
        print("Arc1: {}".format(arc1))
        print("Arc2: {}".format(arc2))
        # setup a reference filename for the arc conditions in database
        reffile = templist[i].split('.fits')[0]
        # extract the arcs
        print("\nExtracting arcs under the same conditions...")
        if os.path.exists(arc1):
            iraf.apall(input=arc1,
                       reference=reffile,
                       recente="no",
                       trace="no",
                       backgro="no",
                       interac="no")
            print("Arc1 {} extracted".format(arc1))
            arclist.append(arc1_out)
        else:
            print("\n\nArc1 {} FILE NOT FOUND\n\n".format(arc1))
        if os.path.exists(arc2):
            iraf.apall(input=arc2,
                       reference=reffile,
                       recente="no",
                       trace="no",
                       backgro="no",
                       interac="no")
            print("Arc2 {} extracted".format(arc2))
            arclist.append(arc2_out)
        else:
            print("\n\nArc2 {} FILE NOT FOUND\n\n".format(arc2))
        # get a list of the extracted arcs and objects
        spectrum_out = "i_s_r{0:d}_t.ms.fits".format(spectrum_id)
        if i == 0:
            # extract the master reference arc
            print("\nExtracting master arc {} under the same conditions...".format(refarc))
            iraf.apall(input=refarc,
                       reference=reffile,
                       recente="no",
                       trace="no",
                       backgro="no",
                       interac="no")
            print("Reference arc {} extracted".format(refarc))
            # identify the lines in it
            print("\nIdentify arc lines:")
            print("Enter the following in the splot window")
            print("\t:thres 500")
            print("\t:order 1, max = 3")
            print("\tfwidth 2")
            print("Select 3-5 arc lines from line atlas")
            print("Press 'm' to mark, then enter wavelength")
            print("Then press 'l' to automatically ID the other lines")
            print("Press 'f' to fit the dispersion correction")
            print("Use 'd' to remove bad points, 'f' to refit")
            print("'q' from fit, then 'q' from identify to continue\n")
            iraf.identify(images=refarc_out, coordlist=lineList_location)
        # use the refarc to ID all the subsequent arcs
        for arc in arclist:
            print("\nReidentifying arclines from {}".format(arc))
            iraf.reidentify(reference=refarc_out, images=arc)
        # add the refspec keywords to the image header for dispcor
        # refspec_factor tells IRAF how to interpolate the arcs
        refspec_factor = round((1./len(arclist)), 1)
        for i in range(0, len(arclist)):
            refspec = "{} {}".format(arclist[i].split(".fits")[0], refspec_factor)
            print("REFSPEC{}: {}".format(i+1, refspec))
            iraf.hedit(images=spectrum_out,
                       fields="REFSPEC{}".format(i+1),
                       value=refspec,
                       add="yes",
                       verify="no",
                       show="yes")
        print("Headers updated!\n")
        # apply the dispersion correction
        print("Applying the dispersion correction")
        iraf.dispcor(input=spectrum_out,
                     output=spectrum_out,
                     lineari="yes",
                     databas="database",
                     table="")
        print("Correction applied!")
        # normalize the spectrum using continuum
        normspec_out = "{}n.ms.fits".format(spectrum_out.split('.ms')[0])
        iraf.continuum(input=spectrum_out,
                       output=normspec_out,
                       logfile="logfile",
                       interac="yes",
                       functio="spline3",
                       order="5",
                       niterat="10",
                       markrej="yes")
        print("\n\n")
Beispiel #16
0
        keyvals = 'spectrum: background fit, weights variance, clean yes' , 'background: background fit'  ,'sigma - background fit, weights variance, clean yes', 'wavelength', '1 1 540.99 550.99','1 1 538.02 548.02' ,'LINEAR  ',    1.,    1.,    1.,    1., 'system=equispec'   , 'wtype=linear label=Pixel'    , 'wtype=linear' , 'wtype=linear' 
        for kk, kv in zip(keys, keyvals):
            archeader[kk] = kv

        if writefiles:
            pyfits.writeto(redfn, np.tile(arcspec, (4,1,1)).astype(np.float32), archeader, clobber=clobber)

        if wavecal:
            os.chdir(_proc)
            iraf.chdir(_proc)
            loc_redfn =os.path.split(redfn)[1]
            if waveCalRef is None:
                iraf.identify(loc_redfn, database=_wldat, ftype='emission', fwidth=3, order=2, niterate=3, cradius=3, coordlist=lamp_list, function='spline3')
                waveCalRef = '' + loc_redfn
            else:
                iraf.reidentify(waveCalRef, loc_redfn, interactive='no', override='yes', refit='yes', nlost=1, cradius=10, addfeatures='no', coordlist=lamp_list) #, function='spline3', order=2, niterate=3)
            disp_soln = ns.getdisp(_wldat + os.sep + 'id' + loc_redfn.replace('.fits',''), 'spline3')
            if writefiles:
                ns.wspectext(loc_redfn)
        datasets.append([redfns[-nthissci:], redfn])
    
        os.chdir(dir0)
        iraf.chdir(dir0)





ns.strl2f('tempjunkcal', calfns)
ns.strl2f('tempjunkred', redfns)
Beispiel #17
0
def reidentify_each(refname, inname, database='database', \
                    coordlist=fi.filibdir+'thar.300.dat', \
                    section_x=50, \
                    overwrite=False):

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

    idfile = database + '/id' + inname
    if os.path.isfile(idfile) and overwrite == False:
        print('ID file already exists. '+idfile)
    else:
        if os.path.isfile(idfile) and overwrite == True:
            print('Removing ' + idfile)
            try:
                os.remove(idfile)
            except:
                pass

        cdelt = fits.getval(inname+'.fits', 'CDELT2')
        # Derivering shift with respect to the reference.
        refdata = fits.getdata(refname+'.fits')
        y_ref = np.mean(refdata[:,section_x-5:section_x+5], axis=1)
        indata = fits.getdata(inname+'.fits')
        y_in = np.mean(indata[:,section_x-5:section_x+5], axis=1)
        shift = fi.cross_correlate(y_in, y_ref, sep=0.1, fit=False) 
        print('%s - %s; %.2f pix'%(refname, inname, shift))

        # Creating the "section" parameter
        section = 'y '+str(section_x)
    
        print('\t reidentify '+inname)
        iraf.reidentify(refname, inname, interac='no',
                section=section, newaps=newaps, override=override,
                refit=refit, trace=trace, step=0, shift=shift*cdelt,
                nlost=nlost, cradius=cradius, threshold=threshold,
                addfeatures=addfeatures, coordlist=coordlist, match=match,
                database=database, logfile=logfile, plotfile='',
                        verbose=verbose, cursor='')

        #Check the result
        iraf.identify(inname, section=section,
                database=database, coordlist=coordlist, units='',
                nsum=nsum, match=match, ftype='emission', fwidth=fwidth,
                cradius=cradius, threshold=threshold,
                function='chebyshev', order=order, sample='*',
                      niter=niter, autowrite=autowrite, cursor='')

        iraf.reidentify(inname, inname,
                interac='no', section=section, newaps=newaps,
                override=override, refit=refit, trace=trace,
                step=step, shift=0, nlost=nlost, cradius=cradius,
                threshold=threshold, addfeatures=addfeatures,
                coordlist=coordlist, match=match, database=database,
                logfile=logfile, plotfile='', verbose=verbose,
                cursor='')

    return