#!/opt/anaconda/bin/python import numpy as np import string import getopt import os from sys import argv, exit # Version number and date versNum = "0.0.0" versDate = "2018-08-24" # Global Defaults # Runtime flags Verbose = False # Verbose debugging output on/off #---------------------------------------------------------------- # # printUsage - print a simple usage message # def printUsage(): print "\nUsage: createtab.py outfile" print "\nWhere:" print " outfile = name of output file" print "\nOptions:" print " -v print verbose debugging info during execution" print " -V print version info and exit\n" #---------------------------------------------------------------- # # # Main Program starts here... # # Parse the command-line arguments (GNU-style getopt) try: opts, files = getopt.gnu_getopt(argv[1:],'vV',['verbose','version',]) except getopt.GetoptError, err: print "\n** ERROR: %s" % (err) printUsage() exit(2) if len(opts)==0 and len(files)==0: printUsage() exit(1) for opt, arg in opts: if opt in ('-v','--verbose'): Verbose = True elif opt in ('-V','--version'): print "createtab.py v%s [%s]" % (versNum, versDate) exit(0) numFiles = len(files) if numFiles != 1: printUsage() exit(1) infile = files[0] s = np.genfromtxt(infile,dtype="string") MAXLINES = len(s) bfilters = ["SDT_Uspec","U-BESSEL", "B-BESSEL", "V-BESSEL", "g-SLOAN", "r-SLOAN"] rfilters = ["V-BESSEL", "R-BESSEL", "I-BESSEL", "r-SLOAN", "i-SLOAN", "z-SLOAN", "Y-FAN", "F972N20", "TiO_784", "CN_817"] #rfilters = ["V-BESSEL", "R-BESSEL", "I-BESSEL", "r-SLOAN", "i-SLOAN", "z-SLOAN", "Y-FAN", "F972N20", "TiO784", "CN817"] cam = [] fil = [] mnth = [] fname = [] ngood = [] nacc = [] ntot = [] du = [] for i in range(len(s)): inext = 3 cam.append(string.split(s[i,0],"_")[1]) nf = string.split(s[i,0],"_")[2] if nf == "SDT" or nf == "TiO" or nf == "CN": nfil = string.join(string.split(s[i,0],"_")[2:4],"_") fil.append(nfil) inext = 4 else: fil.append(nf) dte = string.split((string.split(s[i,0],"_")[inext]),".")[0] mnth.append(dte) fname.append(s[i,0]) ngood.append(s[i,2]) nacc.append(s[i,4]) ntot.append(s[i,10]) # create a list of unique dates if dte not in du: du.append(dte) # add one more item, to handle a missing file, such as when the list of flats in any given # filter does not exist for the particular date. cam.append('-') fil.append('-') mnth.append('-') fname.append('-') ngood.append('-99') nacc.append('-99') ntot.append('-99') # now populate the table with ngood(nacc) and the filename # for each unique date, # for each camera+filter # write out the ngood, nacc and filename F = open("flatsum.out","w") # LBC Blue linec = "|*LBC-Blue*|||||||\n" line = "| *date* | *SDT_USpec* | *U-BESSEL* | *B-BESSEL* | *V-BESSEL* | *g-SLOAN* | *r-SLOAN* |\n" F.write(linec) F.write(line) for m in du: #for each unique date, find the set of filenames and numbers (good, acc) nind = [n for n in range(len(s)) if mnth[n] == m and cam[n] == "B"] line3 = "|*%s*| " % (m) F.write(line3) for bfil in bfilters: if len([f for f in nind if fil[f] == bfil])==1: bf = [f for f in nind if fil[f] == bfil][0] else: bf = MAXLINES if int(nacc[bf]) > 0: line3a = " [[%%ATTACHURL%%/%s][%s(%s)]] |" % (fname[bf],ngood[bf],nacc[bf]) elif int(nacc[bf]) <= 0: line3a = " |" F.write(line3a) F.write("\n") F.write("\n\n") # LBC Red linec = "|*LBC-Red*|||||||||||\n" line = "| *date* | *V-BESSEL* | *R-BESSEL* | *I-BESSEL* | *r-SLOAN* | *i-SLOAN* | *z-SLOAN* | *Y-FAN* | *F972N20* | *TiO_784* | *CN_817* |\n" F.write(linec) F.write(line) for m in du: #for each unique date, find the set of filenames and numbers (good, acc) nind = [n for n in range(len(s)) if mnth[n] == m and cam[n] == "R"] line3 = "|*%s*| " % (m) F.write(line3) for rfil in rfilters: if len([f for f in nind if fil[f] == rfil])==1: rf = [f for f in nind if fil[f] == rfil][0] else: rf = MAXLINES if int(nacc[rf]) > 0: line3a = " [[%%ATTACHURL%%/%s][%s(%s)]] |" % (fname[rf],ngood[rf],nacc[rf]) elif int(nacc[rf]) <= 0: line3a = " |" F.write(line3a) F.write("\n") F.write("\n\n") F.close()