def transform(images, out_images, coord_fits, data_path='.', params={}): """ Run iraf transform to rectify 2D spectrum. Parameters ---------- images : str Images to transform. out_images : str Output image file names. coord_fits: Name of coordinate fits in database. data_path : str Directory that contains the data. params : dict Iraf fitcoords parameters. """ _check_working_dir(data_path) logger.info('running iraf transform') iraf.transform.unlearn() iraf.transform.x1 = params.pop('x1', 'INDEF') iraf.transform.x2 = params.pop('x2', 'INDEF') iraf.transform.dx = params.pop('dx', 'INDEF') iraf.transform.nx = params.pop('nx', 'INDEF') iraf.transform.flux = params.pop('flux', 'yes') iraf.transform.interptype = params.pop('interptype', 'linear') iraf.transform(input=images, output=out_images, fitnames=coord_fits)
def transform(lst): f = open(lst) l = f.readlines() f.close() namelst = ['ftbo' + i for i in l] outputlst = ['wftbo' + i for i in l] # namelst = [i.split('.')[0] + 'otbf.fits' for i in l] # outputlst = [i.split('.')[0] + 'otbfw.fits' for i in l] f = open("temp1.txt", 'w') for i in namelst: f.write(i + '\n') f.close() f = open("temp2.txt", 'w') for i in outputlst: f.write(i + '\n') f.close() iraf.twodspec() iraf.longslit(dispaxis=2) # for i in namelst: # print '#' * 30, i, '===>', i.split('.')[0] + 'w.fits' # iraf.transform(input = i, output = i.split('.')[0] + 'w.fits', # minput = '', moutput = '', fitnames = 'LampLamp', # database = 'database', interptype = 'spline3', # flux = 'yes') iraf.transform(input='@temp1.txt', output='@temp2.txt', minput='', moutput='', fitnames='LampLamp', database='database', interptype='spline3', flux='yes')
def transform(lst): f = open(lst) l = f.readlines() f.close() namelst = ['ftb' + i for i in l] outputlst = ['wftb' + i for i in l] f = open("temp1.txt", 'w') for i in namelst: f.write(i + '\n') f.close() f = open("temp2.txt", 'w') for i in outputlst: f.write(i + '\n') f.close() iraf.twodspec() iraf.longslit(dispaxis=2) # iraf.transform(input='@temp1.txt', output='@temp2.txt', minput='', moutput='', fitnames='LampLamp', database='database', interptype='spline3', flux='yes')
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 transform(science_list,object_match,arc_fc_dict,arc_coords,fcstar='star'): '''Transforms filename to t+filename using noao>twodspec>longslit>transform''' irf_prm.set_transform(iraf.transform) for obj in science_list: fcarc = arc_fc_dict[object_match[obj]] dx_param = arc_coords[object_match[obj]] #These should be the same for each observing mode #Because then they're all mapped together for #Accurate flux calibration and imcombining iraf.transform.x1 = dx_param[0] iraf.transform.x2 = dx_param[1] iraf.transform.dx = dx_param[2] iraf.transform(input=obj,output='t'+obj,fitnames=fcstar+','+fcarc) return
def reduce2d(self, obj, arc, do_error=None): images = obj.name do_error = do_error if do_error is not None else self.do_error hduorig= fits.open(images) os.remove(images) hduimg = fits.PrimaryHDU(data=hduorig[0].data,header=hduorig[0].header) hduimg.writeto(images) hduvarimg = fits.PrimaryHDU(data=hduorig[1].data,header=hduorig[0].header) rt.rmexist([obj.var]) hduvarimg.writeto(obj.var) rt.prepare_image(images, do_error=do_error) self.rssidentify(arc) nxpix = obj.header['NAXIS1'] rt.loadparam(self.rssconfig, ['iraf.transform', 'iraf.fit1d']) config= self.rssconfig if self.do_error: iraf.errorpars.errtype='uniform' iraf.errorpars.resample='no' iraf.samplepars.axis=1 iraf.samplepars.setParam('naverage', config['iraf.fit1d']['naverage']) iraf.samplepars.setParam('low_reject', config['iraf.fit1d']['low_reject']) iraf.samplepars.setParam('high_reject', config['iraf.fit1d']['high_reject']) iraf.samplepars.setParam('niterate', config['iraf.fit1d']['niterate']) iraf.samplepars.setParam('grow', config['iraf.fit1d']['grow']) rt.rmexist([obj.wave, obj.bkg, obj.wave_var, obj.bkg_var]) # Wavelength calibration iraf.transform(obj.noext, obj.wave, fitnames = arc.noext, logfiles = self.logfile) iraf.fit1d(obj.wave, obj.sky, "fit", axis=2) iraf.imarith(obj.wave, "-", obj.sky, obj.bkg) # Calibrated error file if do_error: iraf.transform(obj.var, obj.wave_var, fitnames = arc.noext, logfiles = self.logfile) iraf.gfit1d(obj.wave, 'tmptab.tab', function=config['iraf.fit1d']['function'], order=config['iraf.fit1d']['order'], xmin=1, xmax=nxpix, interactive='no') iraf.tabpar('tmptab.tab',"rms", 1, Stdout=self.logfile) rmsval = float(iraf.tabpar.value) tmpval=rmsval*rmsval print('RMS of the fit (for VAR plane propagation) = %s ' %rmsval) iraf.imexpr("a+b",obj.bkg_var, a=obj.wave_var, b=tmpval) print("**** Done with image %s ****" % (images))
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)
def transform(basename, waveref, spatialref, overwrite=False): # input: input fits file basename to be corrected. # wavefef: wavelength reference basename. # spatialref referrence: spatial referrence basename. print('\n#############################') print('Transforming') hdl = fits.open(basename + '.ov.fits') if not fi.check_version(hdl): return False if not fi.check_version_f(waveref + '.ov.fits'): return False if not fi.check_version_f(spatialref + '.fcmb.fits'): return False hdr = hdl[0].header binfct1 = hdr['BIN-FCT1'] disperser = hdr['DISPERSR'] filter1 = hdr['FILTER01'] filter2 = hdr['FILTER02'] filter3 = hdr['FILTER03'] hdl.close() # entering the channel image directory. print('\t Entering the channel image directory, \"' + fi.chimagedir + '\".') os.chdir(fi.chimagedir) ny = 5500 # 300R + SO58 if disperser == 'SCFCGRMR01' and filter1 == 'NONE' and \ filter2 == 'SCFCFLSO58' and filter3 == 'NONE': y1 = 5600. dy = 1.34 ny = 3800 # 300R + L600 if disperser == 'SCFCGRMR01' and filter1 == 'SCFCFLL600' and \ filter2 == 'NONE' and filter3 == 'NONE': y1 = 2800. dy = 0.636 ny = 4000 # 300B+SY47 if disperser == 'SCFCGRMB01' and filter1 == 'NONE' and \ filter2 == 'SCFCFLSY47' and filter3 == 'NONE': y1 = 4500. dy = 1.34 ny = 4000 # 300B + NONE if disperser == 'SCFCGRMB01' and filter1 == 'NONE' and \ filter2 == 'NONE' and filter3 == 'NONE': y1 = 3500. dy = 1.34 ny = 3500 # VPH850 + SO58 if disperser == 'SCFCGRHD85' and filter1 == 'NONE' and \ filter2 == 'SCFCFLSO58' and filter3 == 'NONE': y1 = 5600. dy = 1.17 ny = 4600 # VPH520 if disperser == 'SCFCGRHD52' and filter1 == 'NONE' and \ filter2 == 'NONE' and filter3 == 'NONE': y1 = 4100.0 dy = 0.39 # VPH650+SY47 if disperser == 'SCFCGRHD65' and filter1 == 'NONE' and \ filter2 == 'SCFCFLSY47' and filter3 == 'NONE': y1 = 5200.0 dy = 0.60 # VPH900 + SO58 if disperser == 'SCFCGRHD90' and filter1 == 'NONE' and \ filter2 == 'SCFCFLSO58' and filter3 == 'NONE': y1 = 7400.0 dy = 0.74 # 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 for i in range(1, 25): checkfile = basename + '.ch%02d.wc.fits' % i if os.path.isfile(checkfile) and not overwrite: print('\t ' + checkfile + ' already exits. Skiped.') else: if overwrite: try: os.remove(basename + '.ch%02d.wc.fits' % i) except: pass iraf.transform(basename+'.ch%02d'%i, basename+'.ch%02d.wc'%i,\ waveref+'.ch%02d,'%i+spatialref+'.ch%02dedge'%i,\ interpt='linear', database='database',\ x1=1.0, x2='INDEF', dx=1.0, nx=int(200.0/binfct1), xlog='no',\ y1=y1, y2='INDEF', dy=dy, ny=ny,ylog='no',\ flux='no', blank=0, logfile='transform.log') hdl = fits.open(basename + '.ch%02d.wc.fits' % i, mode='update') #hdl.info() hdl[0].header['COMPBASE']=(waveref, \ 'Frame ID of the comparison frame.') hdl[0].header['DISTBASE']=(spatialref, \ 'Frame ID used for distortion correction.') hdl[0].header['CUNIT2'] = ('Angstrom') print('\t ' + basename + '.ch%02d.wc.fits was created.' % i) print('\t Going back to the original directory.') os.chdir('..') return True
print "transforming images " + image_to_reduce ### Add the parameter dispaxis to the image header ### else iraf.transform would query for it ### 1 indicates that the x axis is the dispersion axis iraf.hedit(images = image_to_reduce,fields="DISPAXIS",value="1",add=1,addonly=0,delete=0,verify=0,show=1,update=1) iraf.transform( input = image_to_reduce,\ output = output_images,\ minput = "",\ moutput = "",\ fitnames = im_slice + "_" + string.split(arc_name,".")[0],\ database = "database",\ interptype = "spline3",\ x1 = "INDEF",\ x2 = "INDEF",\ dx = "INDEF",\ nx = "INDEF",\ xlog = 0,\ y1 = "INDEF",\ y2 = "INDEF",\ dy = "INDEF",\ ny = "INDEF",\ ylog = 0,\ flux = 1,\ blank = "INDEF",\ logfile = "STDOUT,logfile",\ mode = "al")
file = item.split('\n')[0] shutil.copy(file, 'spec' + str(i) + '.fits') i += 1 #assign 2d dispersion solution - from now IRAF print('Applying wavelength solution...') print('.') print('.') iraf.noao.twodspec.longslit for file in os.listdir(os.getcwd()): if file.startswith('spec'): iraf.transform(file, output='w' + file, database="wavelength", fitnames="He_Ne_ThAr_bsHe_Ne_ThAr_bs", flux='yes') #minor tweak to wavelength solution iraf.hedit('wspec*.fits', fields='CRVAL2', value='2573.5979', verify='no', show='no') # #FROM NOW -> iraf print('.') print('.')