def apall_config( config_file, config_default='/Users/ando/andry/research/Make_software/saltrss/apall_conf.yml' ): config = yaml.safe_load(open(config_default)) custom_config = {} if os.path.exists(config_file): custom_config = yaml.safe_load(open(config_file)) config = config_merge(custom_config, config) sections = [ 'iraf.apall', ] iraf.noao(_doprint=0) iraf.twodspec(_doprint=0) iraf.onedspec(_doprint=0) iraf.apextract(_doprint=0) iraf.apextract.unlearn() iraf.apall.unlearn() iraf.apsum.unlearn() iraf.apextract.setParam('dispaxis', 1) for section_name in sections: params = config[section_name].items() for param_id in params: eval(section_name).setParam(param_id[0], param_id[1]) return config
def apall(lstfile): iraf.noao() iraf.twodspec() iraf.apextract(dispaxis = 2, database = 'database') f = open(lstfile) l = f.readlines() f.close() l = [tmp.split('\n')[0] for tmp in l] path = os.getcwd() for i in l: infile = 'wftbo' + i outfile = 'awftbo' + i while True: if os.path.isfile(outfile): print('remove ' + outfile) os.remove(outfile) delfile = path + os.sep + 'database/ap' + infile[0:-5] if os.path.isfile(delfile): print('remove ' + delfile) os.remove(delfile) iraf.apall(input = infile , output = outfile, apertures = 2, format = 'multispec' , references = '', profiles = '', interactive = True , find = True, recenter = True, resize = False , edit = True, trace = True, fittrace = True , extract = True, extras = True, review = True , line = 'INDEF', nsum = 10, lower = -15.0 , upper = 15.0, apidtable = '', b_function = 'chebyshev' , b_order = 2, b_sample = '-50:-26,26:50', b_naverage = -25 , b_niterate = 1, b_low_reject = 3.0, b_high_reject = 3.0 , b_grow = 0.0, width = 5.0, radius = 10.0 , threshold = 0.0, nfind = 2, minsep = 5.0 , maxsep = 100000.0, order = 'increasing', aprecenter = '' , npeaks = 'INDEF', shift = True, llimit ='INDEF' , ulimit = 'INDEF', ylevel = 0.1, peak = True , bkg = True, r_grow = 0.0, avglimits = False , t_nsum = 20, t_step = 10, t_nlost = 3, t_function = 'legendre' , t_order = 7, t_sample = '*', t_naverage = 1 , t_niterate = 1, t_low_reject = 3.0, t_high_reject = 3.0 , t_grow = 0.0, background = 'fit', skybox = 1 , weights = 'variance', pfit = 'fit1d', clean = True , saturation = 'INDEF', readnoise = 9.4, gain = 0.35 , lsigma = 4.0, usigma = 4.0, nsubaps = 1) iraf.flpr() sspecplot.sspecplot(outfile) getval = raw_input('Are you need repeat apall,may be clean should be close(r/n)') if getval != 'r': break
def apall(ilst, olst): iraf.noao() iraf.twodspec() iraf.apextract(dispaxis=1, database='database') for i, infile in enumerate(ilst): outfile = olst[i] laper, raper, back_samp = -7, 7, '-30:-15,15:30' while True: if os.path.isfile(outfile): print('remove ' + outfile) os.remove(outfile) delfile = os.getcwd()+os.sep+'database/ap'+infile[0:-5] if os.path.isfile(delfile): print('remove ' + delfile) os.remove(delfile) iraf.apall(input=infile, output=outfile, apertures=2, format='multispec', references='', profiles='', interactive=True, find=True, recenter=True, resize=False, edit=True, trace=True, fittrace=True, extract=True, extras=True, review=True, line='INDEF', nsum=10, lower=laper, upper=raper, apidtable='', b_function='chebyshev', b_order=2, b_sample=back_samp, b_naverage=-25, b_niterate=1, b_low_reject=3.0, b_high_reject=3.0, b_grow=0.0, width=5.0, radius=10.0, threshold=0.0, nfind=2, minsep=5.0, maxsep=100000.0, order='increasing', aprecenter='', npeaks='INDEF', shift=True, llimit='INDEF', ulimit='INDEF', ylevel=0.1, peak=True, bkg=True, r_grow=0.0, avglimits=False, t_nsum=20, t_step=10, t_nlost=3, t_function='legendre', t_order=12, t_sample='*', t_naverage=1, t_niterate=1, t_low_reject=3.0, t_high_reject=3.0, t_grow=0.0, background='median', skybox=1, weights='none', pfit='fit1d', clean=True, saturation='INDEF', readnoise='CCDRON', gain='CCDGAIN', lsigma=4.0, usigma=4.0, nsubaps=1) iraf.flpr() getval = raw_input(('Are you need repeat apall,' 'may be clean should be close(r/n)')) if getval != 'r': break
def ApallTask(self, InputFile, OutputFile, Fits_Folder, line, nsum = None, lower_lim = None, upper_lim = None, extras = 'yes', Suffix = 'bg'): iraf.noao(_doprint=0) iraf.twodspec(_doprint=0) iraf.apextract(_doprint=0) #Incase no output name is given, we generate one with the provided "preffix" (The defaul format is a_std_wolf.dat) if OutputFile == None: OutputFile = self.outputNameGenerator(InputFile + '[1]', Suffix) ApallConf = self.ApallAttributes(InputFile, OutputFile, Fits_Folder, line, nsum, lower_lim, upper_lim, extras) #Display the equivalent command in IRAF Command = self.printIrafCommand('apall', ApallConf) print '--- Using the command' print Command # p = Popen(iraf.twodspec.apextract.apall(**ApallConf), shell=True, stdout=PIPE, stderr=STDOUT) #Run the task iraf.twodspec.apextract.apall(**ApallConf) return OutputFile
import operator import time import traceback from lmfit import minimize, Parameters, report_fit #import cosmics iraf.noao(_doprint=0,Stdout="/dev/null") iraf.rv(_doprint=0,Stdout="/dev/null") iraf.imred(_doprint=0,Stdout="/dev/null") iraf.ccdred(_doprint=0,Stdout="/dev/null") iraf.images(_doprint=0,Stdout="/dev/null") iraf.immatch(_doprint=0,Stdout="/dev/null") iraf.onedspec(_doprint=0,Stdout="/dev/null") iraf.twodspec(_doprint=0,Stdout="/dev/null") iraf.apextract(_doprint=0,Stdout="/dev/null") iraf.imutil(_doprint=0,Stdout="/dev/null") iraf.echelle(_doprint=0,Stdout="/dev/null") iraf.astutil(_doprint=0,Stdout="/dev/null") iraf.apextract.dispaxi=1 iraf.echelle.dispaxi=1 #fixes a bug with latest versions of iraf iraf.ccdred.instrum='blank.txt' os.environ['PYRAF_BETA_STATUS'] = '1' # REFS NEW: ecEC59550 ecEC59758 ecEC59795 ecEC59842 ecEC59844 ecEC59864 ecEC59866 ecEC59881 ecEC59883 ecEC59885 observations = { 'cemp_cand': {'ORIG_DIR':'/home/nandir/IRAF_Echelle_Asiago/CEMP_obs/201712/',
def load_modules(): # Define a function to load all of the modules so that they don't' import # unless we need them global iraf from pyraf import iraf iraf.pysalt() iraf.saltspec() iraf.saltred() iraf.set(clobber='YES') global sys import sys global os import os global shutil import shutil global glob from glob import glob global pyfits import pyfits global np import numpy as np global lacosmicx import lacosmicx global interp from scipy import interp global signal from scipy import signal global ndimage from scipy import ndimage global interpolate from scipy import interpolate global WCS from astropy.wcs import WCS global optimize from scipy import optimize global ds9 import pyds9 as ds9 global GaussianProcess from sklearn.gaussian_process import GaussianProcess global pandas import pandas iraf.onedspec() iraf.twodspec() iraf.longslit() iraf.apextract() iraf.imutil() iraf.rvsao(motd='no')
''' from glob import glob from pyraf import iraf iraf.stsdas() iraf.hst_calib() iraf.stis() import pyfits from numpy import isnan, min, logical_and, bitwise_and, linspace, median, arange, correlate, exp, average from scipy.interpolate import interp1d from scipy.integrate import trapz import os from scipy.optimize import curve_fit import stistools iraf.twodspec() iraf.apextract() iraf.set(clobber='yes') def gauss(x, a, x0, sigma, sky): return a * exp(-(x - x0)**2 / (2 * sigma**2) + sky) def tofits(filename, data, hdr=None, clobber=False): """simple pyfits wrapper to make saving fits files easier.""" from pyfits import PrimaryHDU, HDUList hdu = PrimaryHDU(data) if hdr is not None: hdu.header = hdr hdulist = HDUList([hdu]) hdulist.writeto(filename, clobber=clobber, output_verify='ignore')
# SALT/RSS longslit reduction # # # ######################################################################################### ''' import os from pyraf import iraf from astropy.io import fits from shutil import copy2 import rsstools as rt import numpy as np iraf.noao(_doprint=0) iraf.twodspec(_doprint=0) iraf.longslit(_doprint=0) iraf.apextract(dispaxis='1') iraf.stsdas(_doprint=0) iraf.analysis(_doprint=0) iraf.fitting(_doprint=0) class arc(object): def __init__(self, name): self.name = name self.noext = os.path.splitext(self.name)[0] self.idname = rt.makesetups(self.name,"arc") self.idfits = self.idname+'.fits' self.linelist = self.idname.split('_')[0].lower()+'.dat' self.header = self.read_header() def read_header(self): return fits.getheader(self.name)
def extract_spectrum(targetdir, trace, arcspec, refspec, t_nsum, t_step, line, ylevel, interactive): """ Extract spectrum Must be in target directory. """ iraf.noao(_doprint=0) iraf.onedspec(_doprint=0) iraf.twodspec(_doprint=0) iraf.apextract(_doprint=0) basedir = '/data/lc585/WHT_20150331/OBS/' targetdir = os.path.join(basedir,targetdir,'Reduced') print 'Target directory is ' + targetdir print 'Extracting spectrum...' if os.path.exists( os.path.join(targetdir, 'imcomb.ms.fits') ): os.remove( os.path.join( targetdir, 'imcomb.ms.fits') ) print 'Removing file ' + os.path.join( targetdir, 'imcomb.ms.fits') # If can't fit trace use trace from nearby object if trace == 'no': dest = os.path.join(targetdir,'database') if not os.path.exists(dest): os.makedirs(dest) db = os.path.join(basedir,refspec,'Reduced','database','ap_data_lc585_WHT_20150331_OBS_'+refspec+'_Reduced_imcomb') shutil.copy(db,dest) iraf.apall.setParam('references',os.path.join(basedir,refspec,'Reduced','imcomb.fit')) # List of aperture reference images print 'Using trace from reference spectra ' + refspec # Since frame is averaged I think we need to scale down read nosie but gain will stay the same. names = [] for n in os.listdir(targetdir): if (n.endswith('.fit')) & (n.startswith('r')): names.append(n) nframes = float(len(names)) # Doesn't seem to work if I give it absolute path to input! iraf.apall.setParam('input','imcomb.fit') # List of input images iraf.apall.setParam('output','') # List of output spectra iraf.apall.setParam('apertur','') # Apertures iraf.apall.setParam('format','multispec') # Extracted spectra format iraf.apall.setParam('referen','') # List of aperture reference images iraf.apall.setParam('profile','') # List of aperture profile images iraf.apall.setParam('interac',interactive) # Run task interactively? iraf.apall.setParam('find','no') # Find apertures? iraf.apall.setParam('recente','no') # Recenter apertures? iraf.apall.setParam('resize','no') # Resize apertures? iraf.apall.setParam('edit','yes') # Edit apertures? iraf.apall.setParam('trace',trace) # Trace apertures? iraf.apall.setParam('fittrac',interactive) # Fit the traced points interactively? iraf.apall.setParam('extract','yes') # Extract spectra? iraf.apall.setParam('extras','yes') # Extract sky, sigma, etc.? iraf.apall.setParam('review',interactive) # Review extractions? iraf.apall.setParam('line',line) # Dispersion line iraf.apall.setParam('nsum',20) # Number of dispersion lines to sum or median # DEFAULT APERTURE PARAMETERS iraf.apall.setParam('lower',-5.) # Lower aperture limit relative to center iraf.apall.setParam('upper',5.) # Upper aperture limit relative to center iraf.apall.setParam('apidtab','') # Aperture ID table (optional) # DEFAULT BACKGROUND PARAMETERS # Background is now a constant at each wavelength iraf.apall.setParam('b_funct','chebyshev') # Background function iraf.apall.setParam('b_order',1) # Background function order iraf.apall.setParam('b_sampl','-10:-6,6:10') # Background sample regions iraf.apall.setParam('b_naver',-3) # Background average or median iraf.apall.setParam('b_niter',2) # Background rejection iterations iraf.apall.setParam('b_low_r',3.) # Background lower rejection sigma iraf.apall.setParam('b_high_',3.) # Background upper rejection sigma iraf.apall.setParam('b_grow',0.) # Background rejection growing radius # APERTURE CENTERING PARAMETERS iraf.apall.setParam('width',5.) # Profile centering width iraf.apall.setParam('radius',10.) # Profile centering radius iraf.apall.setParam('thresho',0.) # Detection threshold for profile centering # AUTOMATIC FINDING AND ORDERING PARAMETERS iraf.apall.setParam('nfind','') # Number of apertures to be found automatically iraf.apall.setParam('minsep',5.) # Minimum separation between spectra iraf.apall.setParam('maxsep',100000.) # Maximum separation between spectra iraf.apall.setParam('order','increasing') # Order of apertures # RECENTERING PARAMETERS iraf.apall.setParam('aprecen','') # Apertures for recentering calculation iraf.apall.setParam('npeaks','INDEF') # Select brightest peaks iraf.apall.setParam('shift','yes') # Use average shift instead of recentering? # RESIZING PARAMETERS iraf.apall.setParam('llimit','INDEF') # Lower aperture limit relative to center iraf.apall.setParam('ulimit','INDEF') # Upper aperture limit relative to center iraf.apall.setParam('ylevel',0.2) # Fraction of peak or intensity for automatic widt iraf.apall.setParam('peak','yes') # Is ylevel a fraction of the peak? iraf.apall.setParam('bkg','yes') # Subtract background in automatic width? iraf.apall.setParam('r_grow',0.) # Grow limits by this factor iraf.apall.setParam('avglimi','no') # Average limits over all apertures? # TRACING PARAMETERS iraf.apall.setParam('t_nsum',20) # Number of dispersion lines to sum iraf.apall.setParam('t_step', 20) # Tracing step iraf.apall.setParam('t_nlost',3) # Number of consecutive times profile is lost befo iraf.apall.setParam('t_funct','spline3') # Trace fitting function iraf.apall.setParam('t_order',2) # Trace fitting function order iraf.apall.setParam('t_sampl','*') # Trace sample regions iraf.apall.setParam('t_naver',1) # Trace average or median iraf.apall.setParam('t_niter',2) # Trace rejection iterations iraf.apall.setParam('t_low_r',3.) # Trace lower rejection sigma iraf.apall.setParam('t_high_',3.) # Trace upper rejection sigma iraf.apall.setParam('t_grow',0.) # Trace rejection growing radius # EXTRACTION PARAMETERS iraf.apall.setParam('backgro','none') # Background to subtract iraf.apall.setParam('skybox',1) # Box car smoothing length for sky iraf.apall.setParam('weights','variance') # Extraction weights (none|variance) iraf.apall.setParam('pfit','fit1d') # Profile fitting type (fit1d|fit2d) iraf.apall.setParam('clean','yes') # Detect and replace bad pixels? iraf.apall.setParam('saturat',300000.) # Saturation level # iraf.apall.setParam('readnoi',17.0) iraf.apall.setParam('readnoi',17./np.sqrt(nframes)) # Read out noise sigma (photons) iraf.apall.setParam('gain',4.) # Photon gain (photons/data number) iraf.apall.setParam('lsigma',4.) # Lower rejection threshold iraf.apall.setParam('usigma',4.) # Upper rejection threshold iraf.apall.setParam('nsubaps',1) # Number of subapertures per aperture iraf.apall.setParam('mode','q') # h = hidden, q = query, l = learn iraf.apall() # Now extract arc through same aperture for wavelength calibration print '\n' '\n' '\n' print 'Extracting Arc through same aperture...' if os.path.exists( os.path.join(targetdir,'aimcomb.fits')): os.remove( os.path.join(targetdir, 'aimcomb.fits') ) print 'Removing file ' + os.path.join(targetdir, 'aimcomb.fits') arcspec = os.path.join(basedir,arcspec) iraf.apall.setParam('input', arcspec) iraf.apall.setParam('output', 'aimcomb') iraf.apall.setParam('references', 'imcomb.fit' ) iraf.apall.setParam('recenter','no') iraf.apall.setParam('trace','no') iraf.apall.setParam('background','no') iraf.apall.setParam('interactive','no') iraf.apall() if os.path.exists( os.path.join(targetdir, 'imcomb+bkgd.ms.fits') ): os.remove( os.path.join( targetdir, 'imcomb+bkgd.ms.fits') ) print 'Removing file ' + os.path.join( targetdir, 'imcomb+bkgd.ms.fits') iraf.apall.setParam('input','imcomb+bkgd.fit') # List of input images iraf.apall.setParam('output','') # List of output spectra iraf.apall.setParam('referen','imcomb.fit') # List of aperture reference images iraf.apall.setParam('interac','yes') # Run task interactively? iraf.apall.setParam('find','yes') # Find apertures? iraf.apall.setParam('recenter','no') # Recenter apertures? iraf.apall.setParam('resize','no') # Resize apertures? iraf.apall.setParam('edit','yes') # Edit apertures? iraf.apall.setParam('trace','no') # Trace apertures? iraf.apall.setParam('fittrac',interactive) # Fit the traced points interactively? iraf.apall.setParam('extract','yes') # Extract spectra? iraf.apall.setParam('extras','yes') # Extract sky, sigma, etc.? iraf.apall.setParam('review','yes') # Review extractions? # DEFAULT BACKGROUND PARAMETERS # Background is now a constant at each wavelength iraf.apall.setParam('b_funct','chebyshev') # Background function iraf.apall.setParam('b_order',1) # Background function order iraf.apall.setParam('b_sampl','-10:-6,6:10') # Background sample regions iraf.apall.setParam('b_naver',-3) # Background average or median iraf.apall.setParam('b_niter',2) # Background rejection iterations iraf.apall.setParam('b_low_r',3.) # Background lower rejection sigma iraf.apall.setParam('b_high_',3.) # Background upper rejection sigma iraf.apall.setParam('b_grow',0.) # Background rejection growing radius # EXTRACTION PARAMETERS # before i wasn't dividing by the square root of the frames, but surely this must be true if I'm taking the average iraf.apall.setParam('backgro','median') # Background to subtract iraf.apall.setParam('skybox',1) # Box car smoothing length for sky iraf.apall.setParam('weights','variance') # Extraction weights (none|variance) iraf.apall.setParam('pfit','fit1d') # Profile fitting type (fit1d|fit2d) iraf.apall.setParam('clean','yes') # Detect and replace bad pixels? iraf.apall.setParam('saturat',300000.) # Saturation level # iraf.apall.setParam('readnoi',17.0) iraf.apall.setParam('readnoi',17.0/np.sqrt(nframes)) # Read out noise sigma (photons) iraf.apall.setParam('gain',4.) # Photon gain (photons/data number) iraf.apall.setParam('lsigma',4.) # Lower rejection threshold iraf.apall.setParam('usigma',4.) # Upper rejection threshold iraf.apall.setParam('nsubaps',1) # Number of subapertures per aperture iraf.apall() hdulist = fits.open(os.path.join(targetdir, 'imcomb+bkgd.ms.fits')) sigma = hdulist[0].data[3,0,:] hdulist.close() hdulist = fits.open(os.path.join(targetdir, 'imcomb.ms.fits'), mode='update') hdulist[0].data[2,0,:] = sigma hdulist.flush() hdulist.close() return None
from numpy import * from scipy.optimize import leastsq,fsolve#,fmin_slsqp from scipy.integrate import quad from scipy.stats import * from datetime import datetime, date, time import matplotlib.pyplot as plt from datetime import timedelta from numpy.random import randint import pyfits iraf.tables() iraf.noao() iraf.imred() iraf.twodspec() iraf.onedspec() iraf.ccdred() iraf.apextract() iraf.longslit() iraf.plot() iraf.stsdas() iraf.nebular() from time import strftime ############################################################# ########Setup a list of lines and fitting regions ############################################################# #the list of lines linenames=[3727,4102,4340,4363,4686,4861,4959,5007,5755,5876,6548,6562,6584,6717,6731] elines=array([.5*(3727.092+3729.875),4102.89,4341.68,4364.436,4686,4862.68,4960.295,5008.240,5754.59,5876,6549.86,6564.61,6585.27,6718.29,6732.67]) #define a preferred background region width
def load_modules(): # Define a function to load all of the modules so that they don't' import # unless we need them global iraf from pyraf import iraf iraf.pysalt() iraf.saltspec() iraf.saltred() iraf.set(clobber='YES') global sys import sys global os import os global shutil import shutil global glob from glob import glob global pyfits import pyfits global np import numpy as np global lacosmicx import lacosmicx global interp from scipy import interp global signal from scipy import signal global ndimage from scipy import ndimage global interpolate from scipy import interpolate global WCS from astropy.wcs import WCS global optimize from scipy import optimize global ds9 import ds9 global GaussianProcess from sklearn.gaussian_process import GaussianProcess global pandas import pandas iraf.onedspec() iraf.twodspec() iraf.longslit() iraf.apextract() iraf.imutil()
def main(): iraf.noao() iraf.imred() iraf.ccdred() iraf.crutil() iraf.twodspec() iraf.apextract() name = os.popen('ls object*.lst').readlines() name = [i.split('\n')[0] for i in name] if len(name) == 0: print 'no object, the script end' for i in name: print 'open file ' + i + '...' f = open(i) l = f.readlines() f.close() l = [i2.split('\n')[0] for i2 in l] for i2 in l: print i2 objs = [] calibs = [] standards = [] fno = l.index('object') + 1 while fno < len(l): if '.fits' not in l[fno]: break objs.append('ftbo' + l[fno]) fno += 1 fno = l.index('calibration') + 1 while fno < len(l): if '.fits' not in l[fno]: break calibs.append('ftbo' + l[fno]) fno += 1 fno = l.index('standard') + 1 while fno < len(l): if '.fits' not in l[fno]: break standards.append('ftbo' + l[fno]) fno += 1 print '=' * 20, 'reject cosmic ray', '=' * 20 #cobj = shift_align(objs) #cstandard = shift_align(standards) cobjs = [] cstandards = [] for eobj in objs: cobjs.append(cos_clear([eobj])) for eobj in standards: cstandards.append(cos_clear([eobj])) print 'The fits having rejected cosmic ray is: ' print cobjs print cstandards print '=' * 20, 'get spectrum line', '=' * 20 acobjs = [] acstandards = [] for cobj in cobjs: acobjs.append(get_spec_line(cobj)) for cobj in cstandards: acstandards.append(get_spec_line(cobj)) acalibs = [] for i3 in calibs: acalibs.append(get_cal_spec_line(i3, cobj)) print '=' * 20, 'wavelength identify', '=' * 20 iacalibs = wl_identy(acalibs) print '=' * 20, 'wavelength calibrate', '=' * 20 inamepart = i.replace('.','_').split('_') objnames = [] stdobjnames = [] for numb in xrange(len(acobjs)): objnames.append( 'iac' + inamepart[1] + '_' + inamepart[2] + '_' + inamepart[3] + '_' + str(numb) + '.fits') for numb in xrange(len(acstandards)): stdobjnames.append('iacstd' + inamepart[1] + '_' + inamepart[2] + '_' + inamepart[3] + '_' + str(numb) + '.fits') for numb in xrange(len(objnames)): wl_cal(acobjs[numb], objnames[numb], iacalibs) for numb in xrange(len(stdobjnames)): wl_cal(acstandards[numb], stdobjnames[numb], iacalibs) print '=' * 20, 'flux calibrate', '=' * 20 for objname in objnames: final_objname = flux_cal_new(objname, stdobjnames) print 'the final object name is', final_objname
for j in range(len(file_list)): if sensfile not in file_list[j]: if arcfile not in file_list[j]: if '.ms.fits' not in file_list[j]: if '.w.fits' not in file_list[j]: final.append(file_list[j]) ### Define the object name obj = name(final[0]) ### Save the list of spectra np.savetxt('./speclist', final, fmt="%s") ### apall on arc iraf.twodspec() iraf.apextract(dispaxis=1) if extract_arc != 'n': 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.noao(_doprint=0,Stdout="/dev/null") iraf.imred(_doprint=0,Stdout="/dev/null") iraf.ccdred(_doprint=0,Stdout="/dev/null") # <codecell> #bias subtract iraf.ccdproc(images=flat, ccdtype='', fixpix='no', oversca='no', trim='no', zerocor='yes', darkcor='no', flatcor='no', zero='masterbias',Stdout="/dev/null") # <codecell> #apall on a flat field print " + Extract masterflat" iraf.noao(_doprint=0,Stdout="/dev/null") iraf.twodspec(_doprint=0,Stdout="/dev/null") iraf.apextract(_doprint=0,Stdout="/dev/null") # <codecell> #adds DISPAXIS=1 to the header iraf.hedit(images=flat, fields='DISPAXIS', value=1, add='yes', verify='no', update='yes',Stdout="/dev/null") # <codecell> iraf.unlearn('apall') #restores initial paramenters to apall # <codecell> shift_master(ap_ref[ccd], "database/ap%s" % ap_ref[ccd][:-5]) # <codecell>
def oned_extract(object_b_fn, object_b_fn_ec, order_def, colour): # Import IRAF modules: iraf.noao(_doprint=0) iraf.twodspec(_doprint=0) iraf.apextract(_doprint=0) # Check input file and reference extraction exist before proceeding: if os.path.isfile(object_b_fn) == True: if os.path.isfile(order_def) == True: # Extract one dimensional spectrum from bias- and background scatter-subtracted # normalized flat-fielded red object frame using IRAF task apall: if colour == 'red': parList = "r_oned_extraction_apall.par" if os.path.isfile(parList) == True: iraf.apall.setParList(ParList = "r_oned_extraction_apall.par") iraf.apall(input=object_b_fn, output=object_b_fn_ec, references=order_def) print ' ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'One dimensional spectral extraction of bias- and ' print 'background-subtracted, normalized flat-fielded ' print 'red object ' + object_b_fn print 'to create ' + object_b_fn_ec + '.' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print ' ' else: print ' ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'One dimensional extraction IRAF .par file ' print str(parList) print 'does not exist. Exiting script. ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print ' ' print ' ' sys.exit() # Extract one dimensional spectrum from bias- and background scatter-subtracted # normalized flat-fielded blue object frame using IRAF task apall: if colour == 'blue': parList = "b_oned_extraction_apall.par" if os.path.isfile(parList) == True: iraf.apall.setParList(ParList = "b_oned_extraction_apall.par") iraf.apall(input=object_b_fn, output=object_b_fn_ec, references=order_def) print ' ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'One dimensional spectral extraction of bias- and ' print 'background-subtracted, normalized flat-fielded ' print 'blue object ' + object_b_fn print 'to create ' + object_b_fn_s + '.' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print ' ' else: print ' ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'One dimensional extraction IRAF .par file ' print str(parList) print 'does not exist. Exiting script. ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print ' ' print ' ' sys.exit() else: print ' ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'Order definition frame ' print str(order_def) print 'does not exist. Exiting script. ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print ' ' print ' ' sys.exit() else: print ' ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print 'Input frame ' print str(object_b_fn) print 'does not exist. Exiting script. ' print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' print ' ' print ' ' sys.exit()
lowerclip_gr7 = 3500 upperclip_gr7 = 7720 lowerclip_gr8 = 5900 upperclip_gr8 = 9150 combclip_gr7 = 7065 combclip_gr8 = 6965 # ------------------------------------------------------------------------------------------------------------------- # # ------------------------------------------------------------------------------------------------------------------- # # Load IRAF Packages # ------------------------------------------------------------------------------------------------------------------- # iraf.noao(_doprint=0) iraf.images(_doprint=0) iraf.twodspec(_doprint=0) iraf.apextract(_doprint=0) iraf.onedspec(_doprint=0) # ------------------------------------------------------------------------------------------------------------------- # # ------------------------------------------------------------------------------------------------------------------- # # Functions For File Handling # ------------------------------------------------------------------------------------------------------------------- # def remove_file(file_name): """ Removes the file "file_name" in the constituent directory. Args: file_name : Name of the file to be removed from the current directory Returns: None
# Delete some directories/files from previous runs. os.system("rm -rf login.cl pyraf database uparm") os.system("mkiraf") # Now load IRAF import pyraf.iraf as iraf # Load the packages we might need. iraf.noao(_doprint=0) iraf.onedspec(_doprint=0) iraf.twodspec(_doprint=0) iraf.apextract(_doprint=0) iraf.unlearn(iraf.apall) # The name of the science file. filename = 'vega_9.3narrow.fit' extracted_filename = 'vega_9.3narrow.ms.fits' calibrated_filename = 'vega_9.3narrow.calib.fits' # 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")
def apall(imlist_name, reference=''): """ Extract 1d spectrum by tracing column of 2d data. Interactive mode is turned on by default. On the interactive mode; (1) Aperture selection :w -> e1, e2 : Zoom in :w -> a : Zoom out :m : Select aperture :l -> Click left of the aper. : Set lower limit of the aperture. :u -> Click right of the aper. : Set upper limit of the aperture. (2) Background selection :z : Delete previously-selected background region. :b : Enter the background mode :s1, s2 (on the left part of bkg) : Set the region of left bkg. :s3, s4 (on the right part of bkg) : Set the region of right bkg. And then enter q --> Yes, Yes (3) Fitting mode :d : Exclude a point :function : Change the fitting function. ("legendre" by default) :order=15 : Change the function order into 15. :niterate : Cliping iteration (3 times by default) :f : Go fitting :q : Confirm And the enter q --> Yes, Yes Output image will be saved as "XXX.ms.fits" reference='' : Not using specified aperture used. reference='??.ms' : Use the same aperture of ??.ms. Do copy of database of the reference into the same location of input image*** """ import glob import os, sys from pyraf import iraf iraf.noao() iraf.twodspec() iraf.apextract() imlist = glob.glob(imlist_name) imlist.sort() for i in range(len(imlist)): inim = imlist[i] print('1d extraction for ' + inim + '...') if reference == '': iraf.apall(input=inim, apertures='', interactive='yes', find='no', t_function="legendre", t_order=15, t_niterate=3, t_low_reject=3, t_high_reject=3.) elif reference != '': iraf.apall(input=inim, apertures='', reference=reference, interactive='no', find='no', recenter='no', trace='no', t_function="legendre", t_order=15, t_niterate=3, t_low_reject=3, t_high_reject=3.) print('Done.')