def mkheader(file,keyword,value,comment,verbose,logfile): """create keyword with mkheader IRAF tool i.e. without opening the whole file""" status = 0 message = 'SALTKEY.MKHEADER: Created keyword ' + keyword + ' in ' + file try: tmpfile, status = saltio.tmpfile('.',False,logfile) tmp, status = saltio.openascii(tmpfile,'w',logfile) tmp.write('%-8s= \'%-18s\' / %-s\n' % (keyword,value,comment)) status = saltio.closeascii(tmp,logfile) iraf.noao.artdata.mkheader(file,tmpfile,append='y',verbose='n') saltio.delete(tmpfile,False,logfile) saltprint.log(logfile,message,verbose) except: message = 'ERROR -- SALTKEY.MKHEADER: Cannot edit keyword ' + keyword message += ' in ' + file status = saltprint.err(logfile,message) return status
def salthtml(propcode,scamobslog,rssobslog, hrsobslog, htmlpath,nightlog,readme,clobber,logfile,verbose): # set up filenames = [] proposers = [] propids = [] instrumes = [] objects = [] ras = [] decs = [] detmodes = [] ccdtypes = [] ccdsums = [] gainsets = [] rospeeds = [] filters = [] gratings = [] gr_angles = [] ar_angles = [] time_obss = [] date_obss = [] exptimes = [] hours = [] filename = {} proposer = {} propid = {} instrume = {} object = {} ra = {} dec = {} detmode = {} ccdsum = {} ccdtype = {} gainset = {} rospeed = {} filter = {} grating = {} gr_angle = {} ar_angle = {} time_obs = {} exptime = {} status=0 # test the logfile logfile = saltio.logname(logfile) # log the call saltprint.line(logfile,verbose) history = 'SALTHTML -- ' history += 'scamobslog='+scamobslog+' ' history += 'rssobslog='+rssobslog+' ' history += 'htmlpath='+htmlpath+' ' history += 'nightlog='+nightlog+' ' history += 'readme='+readme+' ' yn = 'n' if (clobber): yn = 'y' history += 'clobber='+yn+' ' history += 'logfile='+logfile+' ' yn = 'n' if (verbose): yn = 'y' history += 'verbose='+yn saltprint.log(logfile,history,verbose) # start time saltprint.time('\nSALTHTML -- started at',logfile,verbose) saltprint.log(logfile,' ',verbose) # are the arguments defined if (status == 0): pids,status = saltio.argunpack('propcode',propcode ,logfile) if (status == 0): status = saltio.argdefined('scamobslog',scamobslog,logfile) if (status == 0): status = saltio.argdefined('rssobslog',rssobslog,logfile) if (status == 0): status = saltio.argdefined('htmlpath',htmlpath,logfile) # check htmlpath exists, ends with a "/" and convert to absolute path if (status == 0): htmlpath, status = saltio.abspath(htmlpath,logfile) # check observation log files exist if (status == 0 and scamobslog.upper() != 'NONE'): status = saltio.fileexists(scamobslog,logfile) if (status == 0 and rssobslog.upper() != 'NONE'): status = saltio.fileexists(rssobslog,logfile) # read observation logs for obslog in [scamobslog, rssobslog, hrsobslog]: if (status == 0 and obslog.upper() != 'NONE'): struct,status = saltio.openfits(obslog,logfile) if (status == 0 and obslog.upper() != 'NONE'): obstab,status = saltio.readtab(struct[1],obslog,logfile) if (status == 0 and obslog.upper() != 'NONE'): status = saltio.closefits(struct,logfile) if (status == 0 and obslog.upper() != 'NONE'): filenames.extend(obstab.field('filename')) objects.extend(obstab.field('object')) ras.extend(obstab.field('ra')) decs.extend(obstab.field('dec')) instrumes.extend(obstab.field('instrume')) proposers.extend(obstab.field('proposer')) propids.extend(obstab.field('propid')) ccdtypes.extend(obstab.field('ccdtype')) ccdsums.extend(obstab.field('ccdsum')) gainsets.extend(obstab.field('gainset')) rospeeds.extend(obstab.field('rospeed')) detmodes.extend(obstab.field('detmode')) filters.extend(obstab.field('filter')) time_obss.extend(obstab.field('time-obs')) date_obss.extend(obstab.field('date-obs')) exptimes.extend(obstab.field('exptime')) if (obslog == rssobslog): gratings.extend(obstab.field('grating')) gr_angles.extend(obstab.field('gr-angle')) ar_angles.extend(obstab.field('ar-angle')) else: for i in range(len(filenames)): gratings.append(' ') gr_angles.append(0.) ar_angles.append(0.) # Create the list of proposals if (status == 0): pids,status=saltio.cleanpropcode(pids, propids, logfile) # date of observations date, caldate = salttime.date_obs2yyyymmdd(date_obss[0]) # sort into chronological order for i in range(len(filenames)): hours.append(salttime.time_obs2hr(time_obss[i])) if (hours[i] < 12.): hours[i] += 24 filename[str(hours[i])] = filenames[i] object[str(hours[i])] = objects[i] ra[str(hours[i])] = ras[i] dec[str(hours[i])] = decs[i] instrume[str(hours[i])] = instrumes[i] proposer[str(hours[i])] = proposers[i] propid[str(hours[i])] = propids[i] ccdsum[str(hours[i])] = ccdsums[i].replace(' ','x') ccdtype[str(hours[i])] = ccdtypes[i] gainset[str(hours[i])] = gainsets[i] rospeed[str(hours[i])] = rospeeds[i] detmode[str(hours[i])] = detmodes[i] filter[str(hours[i])] = filters[i] time_obs[str(hours[i])] = time_obss[i] grating[str(hours[i])] = gratings[i] gr_angle[str(hours[i])] = gr_angles[i] ar_angle[str(hours[i])] = ar_angles[i] exptime[str(hours[i])] = exptimes[i] if (instrume[str(hours[i])] == 'SALTICAM'): instrume[str(hours[i])] = 'SCM' if ('Video Mode' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'VI' if ('Slot Mode' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'SL' if ('Frame Transfer' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'FT' if ('Normal' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'IM' if ('Bright' in gainset[str(hours[i])]): gainset[str(hours[i])] = 'BR' if ('Faint' in gainset[str(hours[i])]): gainset[str(hours[i])] = 'FA' if ('Fast' in rospeed[str(hours[i])]): rospeed[str(hours[i])] = 'FA' if ('Slow' in rospeed[str(hours[i])]): rospeed[str(hours[i])] = 'SL' if ('OBJECT' not in ccdtype[str(hours[i])].upper() and 'UNKNOWN' in proposer[str(hours[i])].upper()): proposer[str(hours[i])] = '' hours.sort() # create HTML directory in datapath and define html files docpath = htmlpath + 'doc/' if (status == 0 and not os.path.exists(docpath)): status = saltio.createdir(docpath,False,logfile) htmlfile = docpath + 'ObservationSequence' + date +'.html' notefile = docpath + 'CapeTownNotes' + date + '.html' nlogfile = docpath + 'AstronomersLog' + date + '.html' plogfile = docpath + 'PipelineLog' + date + '.html' elogfile = docpath + 'EnvironmentLog' + date + '.html' dlogfile = docpath + 'InstrumentDiagnostics' + date + '.html' # Copy css and banner images to the doc directory if (status == 0): status=saltio.copy(iraf.osfn('pipetools$html/style.css'),docpath,False,logfile) status=saltio.copy(iraf.osfn('pipetools$html/style_home.css'),docpath,False,logfile) status=saltio.copy(iraf.osfn('pipetools$html/header_salt.jpg'),docpath,False,logfile) # write observation log html file if (status == 0): status = writeobslog(htmlfile,filename,object,ra,dec,instrume,detmode,filter,ccdsum, gainset,rospeed,grating,gr_angle,ar_angle,exptime,time_obs,proposer, propid,hours,date,caldate,clobber,logfile,verbose,status) # write readme html file if (status == 0): status = writecapetownnotes(notefile,readme,date,caldate,clobber,logfile,verbose,status) # write nightlog html file if (status == 0): status = writenightlog(nlogfile,nightlog,date,caldate,clobber,logfile,verbose,status) # write pipeline log html file if (status == 0): status = writepipelog(plogfile,date,caldate,clobber,logfile,verbose,status) # write environment log html file if (status == 0): status = writeenvlog(elogfile,date,caldate,clobber,logfile,verbose,status) # write instrument diagnostics html file if (status == 0): status = writediaglog(dlogfile,date,caldate,clobber,logfile,verbose,status) # copy html files to PI directories if (status == 0): saltprint.log(logfile,' ',verbose) for pids in set(propids): for pid in pids.split(','): pid = pid.strip().upper() pidpath = htmlpath + pid if (os.path.exists(pidpath)): if (os.path.exists(pidpath+'/doc')): for file in glob.glob(pidpath+'/doc/*'): status = saltio.delete(file,False,logfile) status = saltio.deletedir(pidpath+'/doc',logfile) status = saltio.copydir(docpath,pidpath+'/doc',verbose,logfile) if (status == 0): infile, status = saltio.openascii(pidpath+'/doc/CapeTownNotes'+date+'.html','r',logfile) if (status == 0): saltio.delete(pidpath+'/doc/CapeTownNotes'+date+'.html',False,logfile) if (status == 0): outfile, status = saltio.openascii(pidpath+'/doc/CapeTownNotes'+date+'.html','w',logfile) if (status == 0): for line in infile: #line = line.replace('SALT user','Dr ' + string.capwords(pi.lower())) #line = line.replace('yourname',pi) line = line.replace('yyyymmdd',date) outfile.write(line) status = saltio.closeascii(outfile,logfile) # end time if (status == 0): saltprint.time('\nSALTHTML -- completed at',logfile,verbose) else: saltprint.time('\nSALTHTML -- aborted at',logfile,verbose)
def writeobslog(htmlfile,filename,object,ra,dec,instrume,detmode,filter, ccdsum,gainset,rospeed,grating,gr_angle,ar_angle,exptime, time_obs,proposer,propid,hours,date,caldate,clobber,logfile,verbose,status): # overwrite observation log html file if (status == 0 and os.path.isfile(htmlfile) and clobber): status = saltio.delete(htmlfile,False,logfile) elif (status == 0 and os.path.isfile(htmlfile) and not clobber): message = 'ERROR: SALTHTML -- file ' + htmlfile + ' exists. Use clobber=y' status = saltprint.err(logfile,message) # open observation log html file if (status == 0): line = ' ' saltprint.log(logfile,'SALTHTML -- creating ObservationSequence' + date + '.html',verbose) outfile, status = saltio.openascii(htmlfile,'w',logfile) # write html header if (status == 0): status = htmlheader(outfile,date,caldate,'ObservationLog',-1,logfile) # write table headings if (status == 0): outfile.write("%14s %12s %10s %9s %3s %2s %7s %3s %2s %2s %6s %5s %6s %6s %8s %15s %16s \n" % ('file'.ljust(14), 'object'.ljust(12), 'ra2000'.rjust(10), 'dec2000'.rjust(9), 'ins'.ljust(3), 'md'.ljust(2), 'filter'.rjust(7), 'bin'.rjust(3), 'gn'.rjust(2), 'sp'.rjust(2), 'grat'.rjust(6), 'gr-ang'.ljust(6), 'ar-ang'.ljust(6), 'exp'.rjust(6), 'UT'.rjust(8), 'Code'.ljust(15), 'PI'.ljust(16))) for i in range(140): outfile.write('-') outfile.write('\n') # write table for i in hours: outfile.write("%15s %12s %10s %9s %3s %2s %7s %3s %2s %2s %6s %5.2f %6.2f %6.1f %8s %15s %16s\n" % (filename[str(i)].replace('.fits','')[:13].ljust(13), object[str(i)][:12].ljust(12), ra[str(i)][:10].ljust(10), dec[str(i)][:9].ljust(9), instrume[str(i)][:3].ljust(3), detmode[str(i)][:2].ljust(2), filter[str(i)][:7].rjust(7), ccdsum[str(i)][:3].rjust(3), gainset[str(i)][:2].rjust(2), rospeed[str(i)][:2].rjust(2), grating[str(i)][:6].ljust(6), gr_angle[str(i)], ar_angle[str(i)], exptime[str(i)], time_obs[str(i)][:8].ljust(8), propid[str(i)][:15].ljust(15), proposer[str(i)][:16].ljust(16))) # write html foolter if (status == 0): status = htmlfooter(outfile,logfile) return status