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
def rvsao(bin_sci, task, template_spectra, rvsao_file, rvsao_bin_list, interactive="no", linesig=1.5, czguess=0., st_lambda="INDEF", end_lambda="INDEF", badlines=None): """ Use the rvsao task emsao or xcsao to measure relative velocity from emission or absoption spectra Note: make sure you select the parameters for your desired use. Refer to the IRAF rvsao package help for description of what each parameter is/does """ assert task == 'xcsao' or task == 'emsao', "task is not either 'xcsao' or 'emsao'" if os.path.exists(rvsao_file): print('File {} already exists'.format(rvsao_file)) return fixbad = "no" if badlines: fixbad = "yes" bin_list = [] for i in range(len(glob.glob(bin_sci.format('*')))): # to ensure order is 0-61 (not 0, 1, 10, 11, etc) bin_list.append(bin_sci.format(i)) assert len(bin_list) > 0, 'Absorption/emission(?) bin spectra do not exist: {}'.format(em_bin_sci.format('*')) np.array(bin_list).tofile(rvsao_bin_list, sep='\n') from pyraf import iraf iraf.images() iraf.rvsao() if task == 'xcsao': iraf.xcsao('@{}'.format(rvsao_bin_list), templates=bin_sci.format(template_spectra), report_mode=2, logfiles=rvsao_file, displot=interactive, low_bin=10, top_low=20, top_nrun=80, nrun=211, zeropad="yes", nzpass=1, curmode="no", pkmode=2, s_emchop="no", vel_init="guess", czguess=czguess, st_lambda=st_lambda, end_lambda=end_lambda, fixbad=fixbad, badlines=badlines) elif task == 'emsao': # Run this interactively as the fit can fail often. Depending on S/N you may have to decrease the linesig # to detect the lines, or if lines are matched inconsistently play with the st_lambda, end_lambda parameters iraf.emsao('@{}'.format(rvsao_bin_list), logfiles=rvsao_file, displot=interactive, report_mode=2, contsub_plot="no", st_lambda=st_lambda, end_lambda=end_lambda, # vel_init="guess", czguess=czguess, linesig=linesig, fixbad=fixbad, badlines=badlines)
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