def ImportPackages(): iraf.noao(_doprint=0) iraf.rv(_doprint=0) iraf.imred(_doprint=0) iraf.kpnoslit(_doprint=0) iraf.ccdred(_doprint=0) iraf.astutil(_doprint=0) iraf.keywpars.setParam('ra','CAT-RA') iraf.keywpars.setParam('dec','CAT-DEC') iraf.keywpars.setParam('ut','UT') iraf.keywpars.setParam('utmiddl','UT-M_E') iraf.keywpars.setParam('exptime','EXPTIME') iraf.keywpars.setParam('epoch','CAT-EPOC') iraf.keywpars.setParam('date_ob','DATE-OBS') iraf.keywpars.setParam('hjd','HJD') iraf.keywpars.setParam('mjd_obs','MJD-OBS') iraf.keywpars.setParam('vobs','VOBS') iraf.keywpars.setParam('vrel','VREL') iraf.keywpars.setParam('vhelio','VHELIO') iraf.keywpars.setParam('vlsr','VLSR') iraf.keywpars.setParam('vsun','VSUN') iraf.keywpars.setParam('mode','ql') iraf.fxcor.setParam('continu','both') iraf.fxcor.setParam('filter','none') iraf.fxcor.setParam('rebin','smallest') iraf.fxcor.setParam('pixcorr','no') iraf.fxcor.setParam('apodize','0.2') iraf.fxcor.setParam('function','gaussian') iraf.fxcor.setParam('width','INDEF') iraf.fxcor.setParam('height','0.') iraf.fxcor.setParam('peak','no') iraf.fxcor.setParam('minwidt','3.') iraf.fxcor.setParam('maxwidt','21.') iraf.fxcor.setParam('weights','1.') iraf.fxcor.setParam('backgro','0.') iraf.fxcor.setParam('window','INDEF') iraf.fxcor.setParam('wincent','INDEF') iraf.fxcor.setParam('verbose','long') iraf.fxcor.setParam('imupdat','no') iraf.fxcor.setParam('graphic','stdgraph') iraf.fxcor.setParam('interac','yes') iraf.fxcor.setParam('autowri','yes') iraf.fxcor.setParam('autodra','yes') iraf.fxcor.setParam('ccftype','image') iraf.fxcor.setParam('observa','lapalma') iraf.fxcor.setParam('mode','ql') return 0
def dispcor(imlist_name, database='database'): """ dispcor -- Dispersion correct and resample spectra dispcor input output [records] database -- path in which idXXX file. ex) /data1/SN2019ein/work/SAO_Spectrum/red/20190509/arc/database/ dispcor fcdbstd.ms.fits wfcdbstd.ms.fits """ 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] iraf.dispcor(input=inim, output='w' + inim, database='database', linearize='no') iraf.splot(images='w' + inim)
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)
import os folderroot = '/Users/lucaizzo/Documents/NOT/test/' os.chdir(folderroot) import numpy as np from astropy.io import fits from matplotlib import pyplot as plt import shutil import sys from pyraf import iraf iraf.noao(_doprint=0) iraf.imred(_doprint=0) iraf.ccdred(_doprint=0) iraf.twodspec(_doprint=0) iraf.longslit(_doprint=0) iraf.kpnoslit(_doprint=0) iraf.astutil(_doprint=0) iraf.onedspec(_doprint=0) iraf.twodspec.longslit.dispaxis = 2 #read object keywords for file in os.listdir(os.getcwd()): if file.endswith('.fits'): testfile = file hduo = fits.open(testfile) #name targets (science & standard) target = hduo[0].header['OBJECT'] #target2 = 'SP0644p375'
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")
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
import sys import os import string from numpy import * import functions import spectype_functions import spectype_numerical_functions import matplotlib import matplotlib.pyplot as plt import pyfits from pyraf import iraf from scipy import interpolate iraf.kpnoslit() iraf.noao() iraf.rv() ################### ### Description ### ################### ### Take input spectrum ### Find chisq in logg - teff space for every reddenining ### Add over reddening ### Find min chisq ### usage: python spectype_main.py file_path file_name ### Takes input params from config_file #################
############################## ### Apply flux calibration ### ############################## ### Check new_data_test to see if we need to create new sensfunc new_data_test = open("new_data_test").read() new_data_test = string.split(new_data_test,"\n")[0] if new_data_test == "True": ### Setup kpnoslit iraf.kpnoslit( extinction = program_dir + "flux_data/extinsso.tab",\ caldir = program_dir + "flux_data/",\ observatory = "SSO",\ interp = "poly5",\ dispaxis = 2,\ nsum = "1",\ database = "database",\ verbose = 1,\ logfile = "logfile") ### Run iraf.standard os.system("rm std") for i in range(len(SpecPhot_list)): flux_name = "smoothdiv_"+SpecPhot_list[i] + ".fits" hdulist = pyfits.open(flux_name) name = hdulist[0].header['OBJECT'] air_mass = hdulist[0].header['AIRMASS'] exposure_time = hdulist[0].header['EXPTIME'] iraf.standard(