def clean(struct, createvar=False, badpixelstruct=None, mult=True, dblist=None, ampccd=2, xdict=[], subover=True,trim=True, subbias=False, bstruct=None, median=False, function='polynomial',order=3,rej_lo=3,rej_hi=3,niter=10, plotover=False, log=None, verbose=True): infile=struct #prepare the files struct=prepare(struct, createvar=createvar, badpixelstruct=badpixelstruct) #reset the names in the structures for i in range(1,len(struct)): struct[i].name=struct[i].header['EXTNAME'] #gain correct the files usedb=False if dblist: usedb=True struct=gain(struct, mult=mult,usedb=usedb, dblist=dblist, ampccd=ampccd, log=log, verbose=verbose) #xtalk correct the files usedb=False if xdict: obsdate=saltkey.get('DATE-OBS', struct[0]) try: obsdate=int('%s%s%s' % (obsdate[0:4],obsdate[5:7], obsdate[8:])) xkey=np.array(xdict.keys()) date=xkey[abs(xkey-obsdate).argmin()] xcoeff=xdict[date] except Exception,e : msg='WARNING--Can not find xtalk coefficient for %s because %s' % (e, infile) if log: log.warning(msg) xcoeff=xdict[xdict.keys()[-1]]
def clean(struct, createvar=False, badpixelstruct=None, mult=True, \ subover=True, trim=True, subbias=False, bstruct=None, imstack=False, median=False, \ function='polynomial', order=5, rej_lo=3, rej_hi=3, niter=5, \ log=None, verbose=True): """Clean HRS data and files. This includes the following steps currently: * overscan correction * bias subtraction * gain correction * mosaic correction """ infile = struct tfile = struct[0]._file #prepare the HRS files struct = hrsprepare(struct) struct[0]._file = tfile ampccd = len(struct) - 1 #prepare the files struct = prepare(struct, createvar=createvar, badpixelstruct=badpixelstruct, namps=ampccd) #gain correct the files usedb = False struct = gain(struct, mult=mult, usedb=usedb, dblist=None, ampccd=ampccd, log=log, verbose=verbose) #overscan and bias correction struct = bias(struct, subover=subover, trim=trim, subbias=subbias, bstruct=bstruct, median=median, function=function, order=order, rej_lo=rej_lo, rej_hi=rej_hi, niter=niter, plotover=False, log=log, verbose=verbose) #stack the data if requested if imstack and ampccd > 1: struct = stack(struct) #struct=salt2iraf(struct) return struct
def clean(struct, createvar=False, badpixelstruct=None, mult=True, dblist=None, ampccd=2, xdict=[], subover=True, trim=True, subbias=False, bstruct=None, median=False, function='polynomial', order=3, rej_lo=3, rej_hi=3, niter=10, plotover=False, log=None, verbose=True): infile = struct #prepare the files struct = prepare(struct, createvar=createvar, badpixelstruct=badpixelstruct) #reset the names in the structures for i in range(1, len(struct)): struct[i].name = struct[i].header['EXTNAME'] #gain correct the files usedb = False if dblist: usedb = True struct = gain(struct, mult=mult, usedb=usedb, dblist=dblist, ampccd=ampccd, log=log, verbose=verbose) #xtalk correct the files usedb = False if xdict: obsdate = saltkey.get('DATE-OBS', struct[0]) try: obsdate = int('%s%s%s' % (obsdate[0:4], obsdate[5:7], obsdate[8:])) xkey = np.array(xdict.keys()) date = xkey[abs(xkey - obsdate).argmin()] xcoeff = xdict[date] except Exception, e: msg = 'WARNING--Can not find xtalk coefficient for %s because %s' % ( e, infile) if log: log.warning(msg) xcoeff = xdict[xdict.keys()[-1]]
def clean(struct, createvar=False, badpixelstruct=None, mult=True, dblist=None, ampccd=2, xdict=[], subover=True,trim=True, subbias=False, bstruct=None, median=False, function='polynomial',order=3,rej_lo=3,rej_hi=3,niter=10, crtype=None,thresh=5,mbox=3, bbox=11, \ bthresh=3, flux_ratio=0.2, gain=1, rdnoise=5, bfactor=2, fthresh=5,\ gbox=3, maxiter=5, \ plotover=False, log=None, verbose=True): infile=struct #prepare the files struct=prepare(struct, createvar=False, badpixelstruct=None) #bias correct the file struct=bias(struct,subover=subover, trim=trim, subbias=subbias, bstruct=bstruct, median=median, function=function, order=order, rej_lo=rej_lo, rej_hi=rej_hi, niter=niter, plotover=plotover, log=log, verbose=verbose) #reset the names in the structures for i in range(1,len(struct)): struct[i].name=struct[i].header['EXTNAME'] #add the variance and bad pixel frame nextend=len(struct)-1 nsciext=nextend if createvar: #create the inv. variance frames for i in range(1, nsciext+1): hdu=CreateVariance(struct[i], i, nextend+i) try: pass except Exception, e: msg='Cannot create variance frame in extension %i of %s because %s' % (nextend+i, infile, e) raise SaltError(msg) struct[i].header['VAREXT'] = (nextend+i, 'Extension for Variance Frame') struct.append(hdu) nextend+=nsciext #create the badpixelframes for i in range(1, nsciext+1): try: hdu=createbadpixel(struct, badpixelstruct, i, nextend+i) except Exception, e: msg='Could not create bad pixel extension in ext %i of %s because %s' % (nextend+i, infile, e) raise SaltError(msg) struct[i].header['BPMEXT'] = (nextend+i, 'Extension for Bad Pixel Mask') struct.append(hdu)
def clean(struct, createvar=False, badpixelstruct=None, mult=True, \ subover=True, trim=True, subbias=False, bstruct=None, imstack=False, median=False, \ function='polynomial', order=5, rej_lo=3, rej_hi=3, niter=5, \ log=None, verbose=True): """Clean HRS data and files. This includes the following steps currently: * overscan correction * bias subtraction * gain correction * mosaic correction """ infile=struct tfile=struct[0]._file #prepare the HRS files struct=hrsprepare(struct) struct[0]._file=tfile ampccd=len(struct)-1 #prepare the files struct=prepare(struct, createvar=createvar, badpixelstruct=badpixelstruct, namps=ampccd) #gain correct the files usedb=False struct=gain(struct, mult=mult,usedb=usedb, dblist=None, ampccd=ampccd, log=log, verbose=verbose) #overscan and bias correction struct=bias(struct,subover=subover, trim=trim, subbias=subbias, bstruct=bstruct, median=median, function=function, order=order, rej_lo=rej_lo, rej_hi=rej_hi, niter=niter, plotover=False, log=log, verbose=verbose) #stack the data if requested if imstack and ampccd>1: struct=stack(struct) #struct=salt2iraf(struct) return struct
def quickclean(filename, interp='linear', cleanup=True, clobber=False, logfile='saltclean.log', verbose=True): """Start the process to reduce the data and produce a single mosaicked image""" print filename #create the input file name status=0 infile=os.path.basename(filename) rawpath=os.path.dirname(filename) outpath='./' outfile=outpath+'mbxp'+infile print infile, rawpath, outpath #check to see if it exists and return if clobber is no if os.path.isfile(outfile) and not clobber: return #set up the files needed if infile[0]=='P': gaindb = iraf.osfn('pysalt$data/rss/RSSamps.dat') xtalkfile = iraf.osfn('pysalt$data/rss/RSSxtalk.dat') geomfile = iraf.osfn('pysalt$data/rss/RSSgeom.dat') elif infile[0]=='S': gaindb = iraf.osfn('pysalt$data/scam/SALTICAMamps.dat') xtalkfile = iraf.osfn('pysalt$data/scam/SALTICAMxtalk.dat') geomfile = iraf.osfn('pysalt$data/scam/SALTICAMgeom.dat') #verify the file struct=saltio.openfits(rawpath+'/'+infile) struct.verify('exception') #check to see if detmode is there if not saltkey.found('DETMODE', struct[0]): return #reduce the file struct=prepare(struct, createvar=False, badpixelstruct=None) #reset the names in the structures for i in range(1,len(struct)): struct[i].name=struct[i].header['EXTNAME'] #gain correct the files usedb=True dblist= saltio.readgaindb(gaindb) log=open(logfile, 'a') ampccd = struct[0].header['NAMPS'] / struct[0].header['NCCDS'] struct=gain(struct, mult=True,usedb=usedb, dblist=dblist, ampccd=ampccd, log=None, verbose=verbose) struct=bias(struct, subover=True,trim=True,subbias=False, median=False,function='polynomial',order=5,rej_lo=3,rej_hi=3,niter=10, plotover=False,log=None, verbose=verbose) if struct[0].header['CCDTYPE']=='OBJECT' and struct[0].header['EXPTIME']>90: struct = multicrclean(struct, crtype='median', thresh=5, mbox=5, bbox=25, bthresh=5, flux_ratio=0.2, \ gain=1, rdnoise=5, bfactor=2, fthresh=5, gbox=0, maxiter=5, log=None, verbose=verbose) pinfile=outpath+'bxp'+infile saltio.writefits(struct, pinfile, clobber) saltred.saltmosaic(images=pinfile, outimages='',outpref=outpath+'m',geomfile=geomfile, fill=True, interp=interp,cleanup=cleanup,clobber=clobber,logfile=logfile, verbose=verbose) profile=outpath+'mbxp'+infile #remove intermediate steps if cleanup: if os.path.isfile(pinfile): os.remove(pinfile) return
def quickclean(filename, interp='linear', cleanup=True, clobber=False, logfile='saltclean.log', verbose=True): """Start the process to reduce the data and produce a single mosaicked image""" print filename #create the input file name status = 0 infile = os.path.basename(filename) rawpath = os.path.dirname(filename) outpath = './' outfile = outpath + 'mbxp' + infile print infile, rawpath, outpath #check to see if it exists and return if clobber is no if os.path.isfile(outfile) and not clobber: return #set up the files needed if infile[0] == 'P': gaindb = iraf.osfn('pysalt$data/rss/RSSamps.dat') xtalkfile = iraf.osfn('pysalt$data/rss/RSSxtalk.dat') geomfile = iraf.osfn('pysalt$data/rss/RSSgeom.dat') elif infile[0] == 'S': gaindb = iraf.osfn('pysalt$data/scam/SALTICAMamps.dat') xtalkfile = iraf.osfn('pysalt$data/scam/SALTICAMxtalk.dat') geomfile = iraf.osfn('pysalt$data/scam/SALTICAMgeom.dat') #verify the file struct = saltio.openfits(rawpath + '/' + infile) struct.verify('exception') #check to see if detmode is there if not saltkey.found('DETMODE', struct[0]): return #reduce the file struct = prepare(struct, createvar=False, badpixelstruct=None) #reset the names in the structures for i in range(1, len(struct)): struct[i].name = struct[i].header['EXTNAME'] #gain correct the files usedb = True dblist = saltio.readgaindb(gaindb) log = open(logfile, 'a') ampccd = struct[0].header['NAMPS'] / struct[0].header['NCCDS'] struct = gain(struct, mult=True, usedb=usedb, dblist=dblist, ampccd=ampccd, log=None, verbose=verbose) struct = bias(struct, subover=True, trim=True, subbias=False, median=False, function='polynomial', order=5, rej_lo=3, rej_hi=3, niter=10, plotover=False, log=None, verbose=verbose) if struct[0].header[ 'CCDTYPE'] == 'OBJECT' and struct[0].header['EXPTIME'] > 90: struct = multicrclean(struct, crtype='median', thresh=5, mbox=5, bbox=25, bthresh=5, flux_ratio=0.2, \ gain=1, rdnoise=5, bfactor=2, fthresh=5, gbox=0, maxiter=5, log=None, verbose=verbose) pinfile = outpath + 'bxp' + infile saltio.writefits(struct, pinfile, clobber) saltred.saltmosaic(images=pinfile, outimages='', outpref=outpath + 'm', geomfile=geomfile, fill=True, interp=interp, cleanup=cleanup, clobber=clobber, logfile=logfile, verbose=verbose) profile = outpath + 'mbxp' + infile #remove intermediate steps if cleanup: if os.path.isfile(pinfile): os.remove(pinfile) return