def identify(arc_fn, arc_lamp, mods_channel, data_path='.', params={}): """ Run iraf identify to find and label lines in arc lamp for wavelength solution. This one needs to be done by hand :( Parameters ---------- arc_fn : str The arc lamp fits file name 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 identify parameters """ _check_working_dir(data_path) line_list = os.path.join( calipath, 'line_lists/{}_{}.wav'.format(arc_lamp, mods_channel)) logger.info('running iraf identify') iraf.identify.unlearn() iraf.identify.units = 'angstrom' iraf.identify.nsum = params.pop('nsum', 30) iraf.identify.function = params.pop('function', 'chebyshev') iraf.identify.order = params.pop('order', 4) iraf.identify.cradius = params.pop('cradius', 5) iraf.identify.database = params.pop('database', 'database') iraf.identify(images=arc_fn, coordlist=line_list)
def identify(): iraf.twodspec() iraf.longslit() iraf.identify(images='Lamp.fits', section='middle column', database='database', coordlist=cdherb_file, 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.flpr()
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')
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)
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
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
def reference_arc(image, output, reference, coordlist='home$linelists/licklinelist.dat'): '''Construct reference wavelength solution from arc lamps''' iraf.apall(image, output=output, references=reference, interactive=no, find=no, recenter=no, resize=no, edit=no, trace=no, fittrace=no, extract=yes, extras=yes, review=no, background='none') iraf.identify(output, coordlist=coordlist) return
def wavelength_calibration(targetdir): """ Does wavelength calibration. Writes every fit to database so make sure it's using the correct one. This needs to be run in object directory for database """ print 'Target directory is ' + targetdir print 'Doing wavelength calibration...' if os.getcwd() != targetdir: print 'Warning: current working directory must be target directory!' return None iraf.noao(_doprint=0) iraf.onedspec(_doprint=0) iraf.unlearn('identify') iraf.identify.setParam('images','aimcomb.fits') iraf.identify.setParam('coordli','/home/lc585/Dropbox/IoA/WHT_Proposal_2015a/argon+xenon.dat') iraf.identify.setParam('niterat',1) iraf.identify.setParam('function','spline3') iraf.identify.setParam('order',3) iraf.identify.setParam('zwidth',200.0) # Zoom graph width in user units iraf.identify.setParam('database','database') iraf.identify() # Update fits header print '\n' '\n' '\n' print 'Updating fits header...' iraf.hedit.setParam('images','imcomb.ms.fits') iraf.hedit.setParam('fields','REFSPEC1') iraf.hedit.setParam('value','aimcomb.fits') # should be wavelength calibrated? iraf.hedit.setParam('add','yes') iraf.hedit.setParam('verify','yes') iraf.hedit.setParam('show','yes') iraf.hedit() return None
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
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
def get_wl_identy(filename, coordlistname): iraf.onedspec() print 'run get_wl_identy identify...' print 'the input file is ' + filename print 'implot %s' % filename iraf.implot(image = filename) print 'run identify...' iraf.identify(images = filename , section = 'middle line', database = 'database' , coordlist = coordlistname, units = '', nsum = 10 , match = -3.0, maxfeatures = 50, zwidth = 100.0 , ftype = 'emission', fwidth = 18.0, cradius = 5.0 , threshold = 0.0, minsep = 2.0, function = 'spline3' , order = 1, sample = '*', niterate = 0 , low_reject = 3.0, high_reject = 3.0, grow = 0.0 , autowrite = False, graphics = 'stdgraph', cursor = '' , crval = '', cdelt = '')
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
def identify(imlist_name): """ identify arc image for wavelength calibration. image section "column" is good. fitting function : "chebyshev", "legendre", "spline1", or "spline3" """ import glob import os, sys from pyraf import iraf iraf.noao() iraf.imred() iraf.kpnoslit() imlist = glob.glob(imlist_name) imlist.sort() for i in range(len(imlist)): inim = imlist[i] print('Identification ongoing...') iraf.identify(images=inim, section='middle column', function='chebyshev', order=15, niterate=20, low_reject=3, high_reject=3)
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
print("Starting the identify task") iraf.identify(images="FeAr_250_3500_4_Grism_7_2015_06_17_yf170019bap.fits", section="middle line", database="database", coordlist="/home/aries/Music/Atsoa2018/fear_new.dat", units="", nsum="10", match=10., maxfeatures=50, zwidth=100., ftype="emission", fwidth=4., cradius=5., threshold=0., minsep=2., function="spline3", order=1, sample="*", niterate=0, low_reject=3., high_reject=3., grow=0., autowrite="no", graphics="stdgraph", cursor="", crval="", cdelt="", aidpars="") print('header editing')
# Run the spectral extraction program. iraf.apextract.setParam("dispaxis", "1") iraf.apall(input=filename, find="No", recenter="No", resize="No", interactive="Yes") # Make sure that the dispersion axis is in the header. iraf.hedit(images=[filename], fields=["DISPAXIS"], value=["1"], add="Yes") iraf.identify(filename[:-5], coordli=home + "/Downloads/HgNe(1).dat", section="line 105 125", crval=crval, cdelt=dispersion, fwidth=5) # Tell the extracted spectrum what the wavelength solutions are. iraf.hedit(images=[extracted_filename], fields=["REFSPEC1"], \ value=[filename], add="Yes") iraf.refspec(input=extracted_filename, referen=filename[:-5], sort='', group='', confirm='no') iraf.dispcor(input=extracted_filename, output=calibrated_filename) # Plot the extracted spectrum?
print('\n' + 'Extracting arc file') iraf.apall(input=arcfile, output='arc.ms', apertur=1, interac='yes', find='yes', nfind=1, recente='yes', resize='yes', background='none') ## identify lines print('\n' + 'Identify arc lines') iraf.identify(images='arc.ms', coordlist='Xe.txt', function='spline3', order=3, maxfeatures=10) if extract_spectra != 'n': ### apall on spectrum for n in final: ### Remove previous extractions if os.path.exists(n + '.ms.fits') == True: print('Removing', n + '.ms.fits') os.remove(n + '.ms.fits') if os.path.exists(n + '.w.fits') == True: print('Removing', n + '.w.fits') os.remove(n + '.w.fits')
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)
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
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")
overscan=False, darkcor=False, trim=True, zerocor=True, flatcor=True, trimsec='[*,20:4600]', zero='Zero', flat='niFlat') iraf.ccdlist('Zero, nFlat, niFlat, {0}, {1}'.format(science, cal)) iraf.imstat('Zero') iraf.imstat('nFlat') iraf.imstat(science) iraf.imstat(cal) ref = str(raw_input('Imagen de referencia (eg. hd161103_0001.fits):')) iraf.imexamine(ref) iraf.apall.unlearn() iraf.apall(input=science, format='onedspec', readnoise='rdnoise', gain='gain') iraf.apall(input=cal, format='onedspec', reference=ref, readnoise='rdnoise', gain='gain') iraf.identify(images=cal[:-5] + '*.0001.fits', coordlist=linelist)
os.system("rm "+extracted_filename+" "+calibrated_filename) # Run the spectral extraction program. iraf.apextract.setParam("dispaxis", "1") iraf.apall(input=filename, find="No", recenter="No", resize="No",interactive="Yes") # Make sure that the dispersion axis is in the header. iraf.hedit(images=[filename], fields=["DISPAXIS"], value=["1"], add="Yes") iraf.identify(filename[:-5], coordli=home+"/Downloads/HgNe(1).dat", section="line 105 125", crval=crval, cdelt=dispersion, fwidth=5) # Tell the extracted spectrum what the wavelength solutions are. iraf.hedit(images=[extracted_filename], fields=["REFSPEC1"], \ value=[filename], add="Yes") iraf.refspec(input = extracted_filename,referen=filename[:-5],sort='',group='',confirm='no') iraf.dispcor(input=extracted_filename, output=calibrated_filename) # Plot the extracted spectrum? iraf.splot(calibrated_filename)
arcspec = np.median(np.array(arcspecs), 0) archeader = thesearcheaders[jj] keys = 'BANDID1', 'BANDID2', 'BANDID3', 'BANDID4', 'APNUM1', 'WCSDIM' , 'CTYPE3' , 'CD3_3' , 'LTM1_1' , 'LTM2_2' , 'LTM3_3' , 'WAT0_001', 'WAT1_001', 'WAT2_001', 'WAT3_001', 3 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)
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
# Delete previous results. os.system("rm "+extracted_filename+" "+calibrated_filename) # Make sure that the dispersion axis is in the header. iraf.hedit(images=[filename], fields=["DISPAXIS"], value=["1"], add="Yes") # Run the spectral extraction program. iraf.apextract.setParam("dispaxis", "1") iraf.apall(input=filename, find="No", recenter="No", resize="No") # Now identify the spectral lines in the arc lamps. Need to replace l1 l2 # with the range of rows that have the spectral lines. iraf.identify(filename, section="line 265 285") # Tell the extracted spectrum what the wavelength solutions are. iraf.hedit(images=[extracted_filename], fields=["REFSPEC1"], \ value=[filename], add="Yes") iraf.dispcor(input=extracted_filename, output=calibrated_filename) # Plot the extracted spectrum? iraf.splot(calibrated_filename)
# Delete previous results. os.system("rm " + extracted_filename + " " + calibrated_filename) # Make sure that the dispersion axis is in the header. iraf.hedit(images=[filename], fields=["DISPAXIS"], value=["1"], add="Yes") # Run the spectral extraction program. iraf.apextract.setParam("dispaxis", "1") iraf.apall(input=filename, find="No", recenter="No", resize="No") # Now identify the spectral lines in the arc lamps. Need to replace l1 l2 # with the range of rows that have the spectral lines. iraf.identify(filename, section="line 265 285") # Tell the extracted spectrum what the wavelength solutions are. iraf.hedit(images=[extracted_filename], fields=["REFSPEC1"], \ value=[filename], add="Yes") iraf.dispcor(input=extracted_filename, output=calibrated_filename) # Plot the extracted spectrum? iraf.splot(calibrated_filename)