def createmasterflatname(infiles, flatkeys): """Create the name for the master flat file based on its parameters. The format for hte name is [S/P][YYYYMMDD]Flat[MODE][BINNING][GAINSET][ROSPEED][FILTER].fits where the following abbreviations are used: [S/P]--Scam or RSS [YYYYMMDD]--obsdate of the data or most common obsdate if multiple dates [MODE]--Mode of the observations: Normal: NM Framte Transfer: FT Slot Mode: SL Drift Scanning: DS [BINNING]--CCD binning in XBINxYBIN [GAINSET]--Gain setting Bright: BR Faint: FA [ROSPEED]--Read out speed FAST: FA SLOW: SL [FILTER]--Filter used """ #setup the in the instrument instr = saltstring.makeinstrumentstr(flatkeys[0]) #setup the obsdate--assumes fixed naming scheme obsdate = saltstring.makeobsdatestr(infiles) #if len(obsdate)<4: obsdate='' print obsdate #set the mode string mdstr = saltstring.makedetmodestr(flatkeys[1]) #set binning binstr = saltstring.makebinstr(flatkeys[2]) #set gain gnstr = saltstring.makegainstr(flatkeys[3]) #set readout rostr = saltstring.makereadoutstr(flatkeys[4]) fltstr = flatkeys[5].strip() if flatkeys[6].count('SKY'): skystr = 'Sky' else: skystr = '' flatname = '%s%s%sFlat%s%s%s%s%s.fits' % (instr, obsdate, skystr, mdstr, binstr, gnstr, rostr, fltstr) return flatname
def createmasterflatname(infiles, flatkeys): """Create the name for the master flat file based on its parameters. The format for hte name is [S/P][YYYYMMDD]Flat[MODE][BINNING][GAINSET][ROSPEED][FILTER].fits where the following abbreviations are used: [S/P]--Scam or RSS [YYYYMMDD]--obsdate of the data or most common obsdate if multiple dates [MODE]--Mode of the observations: Normal: NM Framte Transfer: FT Slot Mode: SL Drift Scanning: DS [BINNING]--CCD binning in XBINxYBIN [GAINSET]--Gain setting Bright: BR Faint: FA [ROSPEED]--Read out speed FAST: FA SLOW: SL [FILTER]--Filter used """ #setup the in the instrument instr=saltstring.makeinstrumentstr(flatkeys[0]) #setup the obsdate--assumes fixed naming scheme obsdate=saltstring.makeobsdatestr(infiles) #if len(obsdate)<4: obsdate='' print obsdate #set the mode string mdstr=saltstring.makedetmodestr(flatkeys[1]) #set binning binstr=saltstring.makebinstr(flatkeys[2]) #set gain gnstr=saltstring.makegainstr(flatkeys[3]) #set readout rostr=saltstring.makereadoutstr(flatkeys[4]) fltstr=flatkeys[5].strip() if flatkeys[6].count('SKY'): skystr='Sky' else: skystr='' flatname='%s%s%sFlat%s%s%s%s%s.fits' % (instr, obsdate, skystr, mdstr, binstr, gnstr, rostr, fltstr) return flatname
def createmasterbiasname(infiles, biaskeys, x1=5, x2=13): """Create the name for the master bias file based on its parameters. The format for hte name is [S/P][YYYYMMDD]Bias[DETNAM][BINNING][GAINSET][ROSPEED].fits where the following abbreviations are used: [H]--Scam or RSS [YYYYMMDD]--obsdate of the data or most common obsdate if multiple dates [DETNAM]--Detector Name Blue: B Red: R [BINNING]--CCD binning in XBINxYBIN [AMPS]--Number of Amps Bright: BR Faint: FA Parameters: x1: Place to start to extract obsdate x2: Place to stop to extract obsdate """ #setup the in the instrument #setup the obsdate--assumes fixed naming scheme obsdate=saltstring.makeobsdatestr(infiles, x1=x1, x2=x2) #if len(obsdate)<4: obsdate='' #set the mode string #mdstr=saltstring.makedetmodestr(biaskeys[2]) detstr='B' instr='H' ampstr='A2' if biaskeys[1]=='08443-03-01': detstr='R' instr='R' ampstr='A4' #set binning binstr=saltstring.makebinstr(biaskeys[3]) #set the AMP string biasname='%s%sBias%s%s%s.fits' % (instr, obsdate, detstr, binstr, ampstr) return biasname
def createmasterbiasname(infiles, biaskeys, x1=5, x2=13): """Create the name for the master bias file based on its parameters. The format for hte name is [S/P][YYYYMMDD]Bias[DETNAM][BINNING][GAINSET][ROSPEED].fits where the following abbreviations are used: [H]--Scam or RSS [YYYYMMDD]--obsdate of the data or most common obsdate if multiple dates [DETNAM]--Detector Name Blue: B Red: R [BINNING]--CCD binning in XBINxYBIN [AMPS]--Number of Amps Bright: BR Faint: FA Parameters: x1: Place to start to extract obsdate x2: Place to stop to extract obsdate """ #setup the in the instrument #setup the obsdate--assumes fixed naming scheme obsdate = saltstring.makeobsdatestr(infiles, x1=x1, x2=x2) #if len(obsdate)<4: obsdate='' #set the mode string #mdstr=saltstring.makedetmodestr(biaskeys[2]) detstr = 'B' instr = 'H' ampstr = 'A2' if biaskeys[1] == '08443-03-01': detstr = 'R' instr = 'R' ampstr = 'A4' #set binning binstr = saltstring.makebinstr(biaskeys[3]) #set the AMP string biasname = '%s%sBias%s%s%s.fits' % (instr, obsdate, detstr, binstr, ampstr) return biasname
def salteditkey(images,outimages,outpref, keyfile, recfile=None,clobber=False,logfile='salt.log',verbose=True): with logging(logfile,debug) as log: # Check the input images infiles = saltio.argunpack ('Input',images) # create list of output files outfiles=saltio.listparse('Outfile', outimages, outpref,infiles,'') #verify that the input and output lists are the same length saltio.comparelists(infiles,outfiles,'Input','output') #is key file defined saltio.argdefined('keyfile',keyfile) keyfile = keyfile.strip() saltio.fileexists(keyfile) # if the data are the same, set up to use update instead of write openmode='copyonwrite' if (infiles!=outfiles): openmode='copyonwrite' # determine the date of the observations obsdate=saltstring.makeobsdatestr(infiles, 1,9) if len(obsdate)!=8: message = 'Either FITS files from multiple dates exist, ' message += 'or raw FITS files exist with non-standard names.' log.warning(message) # FITS file columns to record keyword changes fitcol = [] keycol = [] oldcol = [] newcol = [] # Set up the rules to change the files keyedits=readkeyfile(keyfile, log=log, verbose=verbose) #now step through the images for img, oimg in zip(infiles, outfiles): #determine the appropriate keyword edits for the image klist=[] for frange in keyedits: if checkfitsfile(img, frange, keyedits[frange]): klist.append(keyedits[frange][3]) if klist: #open up the new files struct = saltio.openfits(img,mode=openmode) struct.verify('fix') for kdict in klist: for keyword in kdict: #record the changes value=kdict[keyword] fitcol.append(img) keycol.append(keyword) newcol.append(value) try: oldcol.append(struct[0].header[keyword].lstrip()) except: oldcol.append('None') #update the keyword if saltkey.found(keyword, struct[0]): try: saltkey.put(keyword,value,struct[0]) message='\tUpdating %s in %s to %s' % (keyword, os.path.basename(img), value) log.message(message, with_header=False, with_stdout=verbose) except Exception, e: message = 'Could not update %s in %s because %s' % (keyword, img, str(e)) raise SaltError(message) else: try: saltkey.new(keyword.strip(),value,'Added Comment',struct[0]) message='\tAdding %s in %s to %s' % (keyword, os.path.basename(img), value) log.message(message, with_header=False, with_stdout=verbose) except Exception,e : message = 'Could not update %s in %s because %s' % (keyword, img, str(e)) raise SaltError(message) #updat the history keywords #fname, hist=history(level=1, wrap=False, exclude=['images', 'outimages', 'outpref']) #saltkey.housekeeping(struct[0],'SAL-EDT', 'Keywords updated by SALTEDITKEY', hist) #write the file out if openmode=='update': saltio.updatefits(struct) message = 'Updated file ' + os.path.basename(oimg) else: saltio.writefits(struct, oimg, clobber) message = 'Created file ' + os.path.basename(oimg) log.message(message, with_header=False, with_stdout=True) struct.close()