Personal tools
You are here: Home / CarPy / Burns' Python Scripts / Modules / ReadSex

ReadSex

Routine for reading in sextractor output.

Python Source icon ReadSex.py — Python Source, 1 KB

File contents

#from basics import *
from string import split

INTKEYS = ["NUMBER","VECTOR_ASSOC"]

def readsex(filename,verb=0):
   fu = open(filename,"r")
   icol = []
   keys = []
   fmts = []
   data = {}
   n=0
   for l in fu.xreadlines():
     if l[0] == "#":
       w = split(l)
       icol.append(int(w[1])-1)
       keys.append(w[2])
       if w[2] in INTKEYS: fmts.append("%6d")
       elif w[2] == "FLAGS": fmts.append("%4d")
       elif w[2] == "CLASS_STAR": fmts.append("%5.2f")
       elif w[2] == "X_IMAGE": fmts.append("%9.3f")
       elif w[2] == "Y_IMAGE": fmts.append("%9.3f")
       else: fmts.append("%9.4f")
       data[w[2]] = []
       n+=1
     else:
       w = split(l)
       [data[keys[j]].append(w[j]) for j in range(n)]
   fu.close()
   if verb:
     print "Found Keys="
     print keys
     print "Number of Objects = %d" % ( len(data[keys[0]]))
   for k in keys: data[k] = [[float,int][k in INTKEYS](d) for d in data[k]]
   return (data,keys,icol,fmts)