def loadfpring(self): date = os.getcwd().split('/')[-1] self.getFitsHeader() fits = "mbxpP%s%04d.fits" % (date, self.filenumber) if self.flatnumber != 0: flat = "mbxpP%s%04d.fits" % (date, self.flatnumber) else: flat="/home/ccd/erc/FP_utils/DefaultNeFlat.fits" ffits='f'+fits fpfile='p'+ffits maskedfile='m'+fpfile if (not os.path.isfile(maskedfile)): saltflat(fits,ffits,'',flat, clobber='yes',verbose='no') saltfpprep(ffits,fpfile,'',clobber='yes',verbose='no') saltfpmask(fpfile,maskedfile,'',axc=798*4/self.xbin,ayc=503*4/self.ybin,arad=450*4/self.xbin,clobber='yes', verbose='no') self.good, self.rsq, self.prof, self.fit, self.pars = fit_rings(maskedfile) self.resid = self.prof - self.fit self.rms = self.resid.std() self.saveFitToFile() return
def fpcal(profile, flatimage=None, minflat=15000, bthresh=5, niter=5, displayimage=False, clobber=False, logfile='saltclean.log', verbose=True): """Flatfield and determine the ring center for SALT FP calibration data""" #run saltflat if flatimage: saltflat(profile, outimages='', outpref='p', flatimage=flatimage,minflat=minflat, clobber=clobber, logfile=logfile, verbose=verbose) #run saltfpprep saltfpprep('p'+profile, outimages='', outpref='f', clobber=clobber, logfile=logfile, verbose=verbose) #run saltfpringfit section='[600:800,300:500]' #*TODO* Update so it automatically determines this outfile='fpout.txt' saltfpringfit('fp'+profile, outfile, section=section, bthresh=bthresh, niter=niter, displayimage=displayimage, clobber=clobber,logfile=logfile, verbose=verbose)
def fpcal(profile, flatimage=None, minflat=15000, bthresh=5, niter=5, displayimage=False, clobber=False, logfile='saltclean.log', verbose=True): """Flatfield and determine the ring center for SALT FP calibration data""" #run saltflat if flatimage: saltflat(profile, outimages='', outpref='p', flatimage=flatimage, minflat=minflat, clobber=clobber, logfile=logfile, verbose=verbose) #run saltfpprep saltfpprep('p' + profile, outimages='', outpref='f', clobber=clobber, logfile=logfile, verbose=verbose) #run saltfpringfit section = '[600:800,300:500]' #*TODO* Update so it automatically determines this outfile = 'fpout.txt' saltfpringfit('fp' + profile, outfile, section=section, bthresh=bthresh, niter=niter, displayimage=displayimage, clobber=clobber, logfile=logfile, verbose=verbose)
def loadfpring(self): date = os.getcwd().split('/')[-1] self.getFitsHeader() fits = "mbxpP%s%04d.fits" % (date, self.filenumber) if self.flatnumber != 0: flat = "mbxpP%s%04d.fits" % (date, self.flatnumber) else: flat = "/home/ccd/erc/FP_utils/DefaultNeFlat.fits" ffits = 'f' + fits fpfile = 'p' + ffits maskedfile = 'm' + fpfile if (not os.path.isfile(maskedfile)): saltflat(fits, ffits, '', flat, clobber='yes', verbose='no') saltfpprep(ffits, fpfile, '', clobber='yes', verbose='no') saltfpmask(fpfile, maskedfile, '', axc=798 * 4 / self.xbin, ayc=503 * 4 / self.ybin, arad=450 * 4 / self.xbin, clobber='yes', verbose='no') self.good, self.rsq, self.prof, self.fit, self.pars = fit_rings( maskedfile) self.resid = self.prof - self.fit self.rms = self.resid.std() self.saveFitToFile() return
def imred(rawdir, prodir, cleanup=True): print rawdir print prodir #get the name of the files infile_list=glob.glob(rawdir+'*.fits') infiles=','.join(['%s' % x for x in infile_list]) #get the current date for the files obsdate=os.path.basename(infile_list[0])[1:9] print obsdate #set up some files that will be needed logfile='imred'+obsdate+'.log' flatimage='FLAT%s.fits' % (obsdate) dbfile='spec%s.db' % obsdate #create the observation log obs_dict=obslog(infile_list) #prepare the data saltprepare(infiles, '', 'p', createvar=False, badpixelimage='', clobber=True, logfile=logfile, verbose=True) #bias subtract the data saltbias('pP*fits', '', 'b', subover=True, trim=True, subbias=False, masterbias='', median=False, function='polynomial', order=5, rej_lo=3.0, rej_hi=5.0, niter=10, plotover=False, turbo=False, clobber=True, logfile=logfile, verbose=True) #gain correct the data saltgain('bpP*fits', '', 'g', usedb=False, mult=True, clobber=True, logfile=logfile, verbose=True) #cross talk correct the data saltxtalk('gbpP*fits', '', 'x', xtalkfile = "", usedb=False, clobber=True, logfile=logfile, verbose=True) #cosmic ray clean the data #only clean the object data for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS'): img='xgbp'+os.path.basename(infile_list[i]) saltcrclean(img, img, '', crtype='edge', thresh=5, mbox=11, bthresh=5.0, flux_ratio=0.2, bbox=25, gain=1.0, rdnoise=5.0, fthresh=5.0, bfactor=2, gbox=3, maxiter=5, multithread=True, clobber=True, logfile=logfile, verbose=True) #flat field correct the data flat_imgs='' for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('FLAT'): if flat_imgs: flat_imgs += ',' flat_imgs += 'xgbp'+os.path.basename(infile_list[i]) if len(flat_imgs)!=0: saltcombine(flat_imgs,flatimage, method='median', reject=None, mask=False, \ weight=True, blank=0, scale='average', statsec='[200:300, 600:800]', lthresh=3, \ hthresh=3, clobber=True, logfile=logfile, verbose=True) #saltillum(flatimage, flatimage, '', mbox=11, clobber=True, logfile=logfile, verbose=True) saltflat('xgbpP*fits', '', 'f', flatimage, minflat=500, clobber=True, logfile=logfile, verbose=True) else: flats=None imfiles=glob.glob('xgbpP*fits') for f in imfiles: shutil.copy(f, 'f'+f) #mosaic the data geomfile=iraf.osfn("pysalt$data/rss/RSSgeom.dat") saltmosaic('fxgbpP*fits', '', 'm', geomfile, interp='linear', cleanup=True, geotran=True, clobber=True, logfile=logfile, verbose=True) #clean up the images if cleanup: for f in glob.glob('p*fits'): os.remove(f) for f in glob.glob('bp*fits'): os.remove(f) for f in glob.glob('gbp*fits'): os.remove(f) for f in glob.glob('xgbp*fits'): os.remove(f) for f in glob.glob('fxgbp*fits'): os.remove(f)
for filenum in range(startnum, lastnum+1): # glitch - this expects the working directory name to be the date! date = os.getcwd().split('/')[-1] fits = "mbxgpP%s%04d.fits" % (date, filenum) flat = "mbxgpP%s%04d.fits" % (date, flatnum) ffits='f'+fits fpfile='p'+ffits maskedfile='m'+fpfile if (not os.path.isfile(maskedfile)): saltflat(fits,ffits,'',flat, clobber='yes',verbose='no') saltfpprep(ffits,fpfile,'',clobber='yes',verbose='no') saltfpmask(fpfile,maskedfile,'',axc=798,ayc=503,arad=450,clobber='yes', verbose='no') good, rsq, prof, fit, pars = fit_rings(maskedfile) resid = prof - fit rms = resid.std() hdu = pyfits.open(fits) (data, header) = (hdu[0].data, hdu[0].header) etalon = int(header['ET-STATE'].split()[3])
def imred(rawdir, prodir, cleanup=True): print rawdir print prodir #get the name of the files infile_list = glob.glob(rawdir + '*.fits') infiles = ','.join(['%s' % x for x in infile_list]) #get the current date for the files obsdate = os.path.basename(infile_list[0])[1:9] print obsdate #set up some files that will be needed logfile = 'imred' + obsdate + '.log' flatimage = 'FLAT%s.fits' % (obsdate) dbfile = 'spec%s.db' % obsdate #create the observation log obs_dict = obslog(infile_list) #prepare the data saltprepare(infiles, '', 'p', createvar=False, badpixelimage='', clobber=True, logfile=logfile, verbose=True) #bias subtract the data saltbias('pP*fits', '', 'b', subover=True, trim=True, subbias=False, masterbias='', median=False, function='polynomial', order=5, rej_lo=3.0, rej_hi=5.0, niter=10, plotover=False, turbo=False, clobber=True, logfile=logfile, verbose=True) #gain correct the data saltgain('bpP*fits', '', 'g', usedb=False, mult=True, clobber=True, logfile=logfile, verbose=True) #cross talk correct the data saltxtalk('gbpP*fits', '', 'x', xtalkfile="", usedb=False, clobber=True, logfile=logfile, verbose=True) #cosmic ray clean the data #only clean the object data for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count( 'OBJECT') and obs_dict['INSTRUME'][i].count('RSS'): img = 'xgbp' + os.path.basename(infile_list[i]) saltcrclean(img, img, '', crtype='edge', thresh=5, mbox=11, bthresh=5.0, flux_ratio=0.2, bbox=25, gain=1.0, rdnoise=5.0, fthresh=5.0, bfactor=2, gbox=3, maxiter=5, multithread=True, clobber=True, logfile=logfile, verbose=True) #flat field correct the data flat_imgs = '' for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('FLAT'): if flat_imgs: flat_imgs += ',' flat_imgs += 'xgbp' + os.path.basename(infile_list[i]) if len(flat_imgs) != 0: saltcombine(flat_imgs,flatimage, method='median', reject=None, mask=False, \ weight=True, blank=0, scale='average', statsec='[200:300, 600:800]', lthresh=3, \ hthresh=3, clobber=True, logfile=logfile, verbose=True) #saltillum(flatimage, flatimage, '', mbox=11, clobber=True, logfile=logfile, verbose=True) saltflat('xgbpP*fits', '', 'f', flatimage, minflat=500, clobber=True, logfile=logfile, verbose=True) else: flats = None imfiles = glob.glob('xgbpP*fits') for f in imfiles: shutil.copy(f, 'f' + f) #mosaic the data geomfile = iraf.osfn("pysalt$data/rss/RSSgeom.dat") saltmosaic('fxgbpP*fits', '', 'm', geomfile, interp='linear', cleanup=True, geotran=True, clobber=True, logfile=logfile, verbose=True) #clean up the images if cleanup: for f in glob.glob('p*fits'): os.remove(f) for f in glob.glob('bp*fits'): os.remove(f) for f in glob.glob('gbp*fits'): os.remove(f) for f in glob.glob('xgbp*fits'): os.remove(f) for f in glob.glob('fxgbp*fits'): os.remove(f)
filenum = sys.argv[1] try: filenum = int(filenum) except: print "Specify file as a number, e.g. 25" exit() date = os.getcwd().split('/')[-1] fits = "mbxgpP%s%04d.fits" % (date, filenum) flat = "mbxgpP%s%04d.fits" % (date, 22) ffits='f'+fits print flat saltflat(fits,ffits,'',flat, clobber='yes',verbose='no') fpfile='p'+ffits saltfpprep(ffits,fpfile,'',clobber='yes',verbose='no') maskedfile='m'+fpfile saltfpmask(fpfile,maskedfile,'',axc=798,ayc=503,arad=450,clobber='yes', verbose='no') good, rsq, prof, fit, pars = fit_rings(maskedfile) resid = prof - fit rms = resid.std() print "\tR = %.3f, Amp = %.3f, RMS = %.3f, Gamma = %.3f, FWHM = %.3f" % \ (pars['R'][0], pars['Amplitude'][0], rms, pars['Gamma'][0],
def science_red(rawdir, prodir, imreduce=True, specreduce=True, bpmfile=None, calfile=None, lampfile='Ar', automethod='Matchlines', skysection=[800,1000], cleanup=True): print rawdir print prodir #get the name of the files infile_list=glob.glob(rawdir+'P*.fits') infiles=','.join(['%s' % x for x in infile_list]) #get the current date for the files obsdate=os.path.basename(infile_list[0])[1:9] print obsdate #set up some files that will be needed logfile='spec'+obsdate+'.log' flatimage='FLAT%s.fits' % (obsdate) dbfile='spec%s.db' % obsdate #create the observation log obs_dict=obslog(infile_list) if imreduce: #prepare the data saltprepare(infiles, '', 'p', createvar=False, badpixelimage='', clobber=True, logfile=logfile, verbose=True) #bias subtract the data saltbias('pP*fits', '', 'b', subover=True, trim=True, subbias=False, masterbias='', median=False, function='polynomial', order=5, rej_lo=3.0, rej_hi=5.0, niter=10, plotover=False, turbo=False, clobber=True, logfile=logfile, verbose=True) add_variance('bpP*fits', bpmfile) #gain correct the data saltgain('bpP*fits', '', 'g', usedb=False, mult=True, clobber=True, logfile=logfile, verbose=True) #cross talk correct the data saltxtalk('gbpP*fits', '', 'x', xtalkfile = "", usedb=False, clobber=True, logfile=logfile, verbose=True) #flat field correct the data flat_imgs='' for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('FLAT'): if flat_imgs: flat_imgs += ',' flat_imgs += 'xgbp'+os.path.basename(infile_list[i]) if 0: #len(flat_imgs)!=0: saltcombine(flat_imgs,flatimage, method='median', reject=None, mask=False, \ weight=False, blank=0, scale=None, statsec='[200:300, 600:800]', lthresh=3, \ hthresh=3, clobber=True, logfile=logfile, verbose=True) saltillum(flatimage, flatimage, '', mbox=11, clobber=True, logfile=logfile, verbose=True) saltflat('xgbpP*fits', '', 'f', flatimage, minflat=0.8, allext=False, clobber=True, logfile=logfile, verbose=True) else: flats=None imfiles=glob.glob('xgbpP*fits') for f in imfiles: shutil.copy(f, 'f'+f) #cosmic ray clean the data #only clean the object data for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS'): img='fxgbp'+os.path.basename(infile_list[i]) saltcrclean(img, img, '', crtype='edge', thresh=5, mbox=11, bthresh=5.0, flux_ratio=0.2, bbox=25, gain=1.0, rdnoise=5.0, fthresh=5.0, bfactor=2, gbox=3, maxiter=5, multithread=True, clobber=True, logfile=logfile, verbose=True) #mosaic the data geomfile=iraf.osfn("pysalt$data/rss/RSSgeom.dat") saltmosaic('fxgbpP*fits', '', 'm', geomfile, interp='linear', cleanup=True, geotran=True, clobber=True, logfile=logfile, verbose=True) #clean up the images if cleanup: for f in glob.glob('p*fits'): os.remove(f) for f in glob.glob('bp*fits'): os.remove(f) for f in glob.glob('gbp*fits'): os.remove(f) for f in glob.glob('xgbp*fits'): os.remove(f) for f in glob.glob('fxgbp*fits'): os.remove(f) #set up the name of the images if specreduce: for i in range(len(infile_list)): if obs_dict['OBJECT'][i].upper().strip()=='ARC': lamp=obs_dict['LAMPID'][i].strip().replace(' ', '') arcimage='mfxgbp'+os.path.basename(infile_list[i]) #lampfile=iraf.osfn("pysalt$data/linelists/%s.salt" % lamp) specidentify(arcimage, lampfile, dbfile, guesstype='rss', guessfile='', automethod=automethod, function='legendre', order=3, rstep=100, rstart='middlerow', mdiff=50, thresh=2, niter=5, smooth=3, inter=True, clobber=True, logfile=logfile, verbose=True) specrectify(arcimage, outimages='', outpref='x', solfile=dbfile, caltype='line', function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None, blank=0.0, clobber=True, logfile=logfile, verbose=True) objimages='' for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS'): if objimages: objimages += ',' objimages+='mfxgbp'+os.path.basename(infile_list[i]) if specreduce: #run specidentify on the arc files specrectify(objimages, outimages='', outpref='x', solfile=dbfile, caltype='line', function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None, blank=0.0, clobber=True, logfile=logfile, verbose=True) return
def specred(rawdir, prodir, imreduce=True, specreduce=True, calfile=None, lamp='Ar', automethod='Matchlines', skysection=[800,1000], cleanup=True): print rawdir print prodir #get the name of the files infile_list=glob.glob(rawdir+'*.fits') infiles=','.join(['%s' % x for x in infile_list]) #get the current date for the files obsdate=os.path.basename(infile_list[0])[1:9] print obsdate #set up some files that will be needed logfile='spec'+obsdate+'.log' flatimage='FLAT%s.fits' % (obsdate) dbfile='spec%s.db' % obsdate #create the observation log obs_dict=obslog(infile_list) if imreduce: #prepare the data saltprepare(infiles, '', 'p', createvar=False, badpixelimage='', clobber=True, logfile=logfile, verbose=True) #bias subtract the data saltbias('pP*fits', '', 'b', subover=True, trim=True, subbias=False, masterbias='', median=False, function='polynomial', order=5, rej_lo=3.0, rej_hi=5.0, niter=10, plotover=False, turbo=False, clobber=True, logfile=logfile, verbose=True) #gain correct the data saltgain('bpP*fits', '', 'g', usedb=False, mult=True, clobber=True, logfile=logfile, verbose=True) #cross talk correct the data saltxtalk('gbpP*fits', '', 'x', xtalkfile = "", usedb=False, clobber=True, logfile=logfile, verbose=True) #cosmic ray clean the data #only clean the object data for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS'): img='xgbp'+os.path.basename(infile_list[i]) saltcrclean(img, img, '', crtype='edge', thresh=5, mbox=11, bthresh=5.0, flux_ratio=0.2, bbox=25, gain=1.0, rdnoise=5.0, fthresh=5.0, bfactor=2, gbox=3, maxiter=5, multithread=True, clobber=True, logfile=logfile, verbose=True) #flat field correct the data flat_imgs='' for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('FLAT'): if flat_imgs: flat_imgs += ',' flat_imgs += 'xgbp'+os.path.basename(infile_list[i]) if len(flat_imgs)!=0: saltcombine(flat_imgs,flatimage, method='median', reject=None, mask=False, \ weight=True, blank=0, scale='average', statsec='[200:300, 600:800]', lthresh=3, \ hthresh=3, clobber=True, logfile=logfile, verbose=True) saltillum(flatimage, flatimage, '', mbox=11, clobber=True, logfile=logfile, verbose=True) saltflat('xgbpP*fits', '', 'f', flatimage, minflat=500, clobber=True, logfile=logfile, verbose=True) else: flats=None imfiles=glob.glob('cxgbpP*fits') for f in imfiles: shutil.copy(f, 'f'+f) #mosaic the data geomfile=iraf.osfn("pysalt$data/rss/RSSgeom.dat") saltmosaic('fxgbpP*fits', '', 'm', geomfile, interp='linear', cleanup=True, geotran=True, clobber=True, logfile=logfile, verbose=True) #clean up the images if cleanup: for f in glob.glob('p*fits'): os.remove(f) for f in glob.glob('bp*fits'): os.remove(f) for f in glob.glob('gbp*fits'): os.remove(f) for f in glob.glob('xgbp*fits'): os.remove(f) for f in glob.glob('fxgbp*fits'): os.remove(f) #set up the name of the images if specreduce: for i in range(len(infile_list)): if obs_dict['OBJECT'][i].upper().strip()=='ARC': lamp=obs_dict['LAMPID'][i].strip().replace(' ', '') arcimage='mfxgbp'+os.path.basename(infile_list[i]) lampfile=iraf.osfn("pysalt$data/linelists/%s.txt" % lamp) specidentify(arcimage, lampfile, dbfile, guesstype='rss', guessfile='', automethod=automethod, function='legendre', order=5, rstep=100, rstart='middlerow', mdiff=10, thresh=3, niter=5, inter=True, clobber=True, logfile=logfile, verbose=True) specrectify(arcimage, outimages='', outpref='x', solfile=dbfile, caltype='line', function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None, blank=0.0, clobber=True, logfile=logfile, verbose=True) objimages='' for i in range(len(infile_list)): if obs_dict['CCDTYPE'][i].count('OBJECT') and obs_dict['INSTRUME'][i].count('RSS'): if objimages: objimages += ',' objimages+='mfxgbp'+os.path.basename(infile_list[i]) if specreduce: #run specidentify on the arc files specrectify(objimages, outimages='', outpref='x', solfile=dbfile, caltype='line', function='legendre', order=3, inttype='interp', w1=None, w2=None, dw=None, nw=None, blank=0.0, clobber=True, logfile=logfile, verbose=True) #create the spectra text files for all of our objects spec_list=[] for img in objimages.split(','): spec_list.extend(createspectra('x'+img, obsdate, smooth=False, skysection=skysection, clobber=True)) print spec_list #determine the spectrophotometric standard extfile=iraf.osfn('pysalt$data/site/suth_extinct.dat') for spec, am, et, pc in spec_list: if pc=='CAL_SPST': stdstar=spec.split('.')[0] print stdstar, am, et stdfile=iraf.osfn('pysalt$data/standards/spectroscopic/m%s.dat' % stdstar.lower().replace('-', '_')) print stdfile ofile=spec.replace('txt', 'sens') calfile=ofile #assumes only one observations of a SP standard specsens(spec, ofile, stdfile, extfile, airmass=am, exptime=et, stdzp=3.68e-20, function='polynomial', order=3, thresh=3, niter=5, clobber=True, logfile='salt.log',verbose=True) for spec, am, et, pc in spec_list: if pc!='CAL_SPST': ofile=spec.replace('txt', 'spec') speccal(spec, ofile, calfile, extfile, airmass=am, exptime=et, clobber=True, logfile='salt.log',verbose=True) #clean up the spectra for bad pixels cleanspectra(ofile)