Example #1
0
   for i in reversed(range(len(data[0]))):
      if data[2][i] <= 0:
         del(data[0][i])
         del(data[1][i])
         del(data[2][i])
         del[data[3][i]]
      else:
         data[2][i] = data[2][i]/maxy
         data[3][i] = data[3][i]/(maxy*math.sqrt(data[1][i])) #std.dev. mean
   return data

### Start Program ###

arg = ReadCmd(spec)
image   = arg.getliststr('in',exist=True)
bin     = arg.getlistfloat('bin',length=3)
unit    = arg.getstr('unit',option=['nbin','step'])
offset  = arg.getlistfloat('offset',length=2)
outplot = arg.getstr('out')
junk    = arg.getlistfloat('range',length=2)
xmin = junk[0]
xmax = junk[1]
step    = arg.getstr('step',option=['b','p'])

if 'b' in step: # do binning
   outdata = []

   from pyraf import iraf

   for i in image:
      outdata.append(dobin(i,offset,bin,unit))
Example #2
0
import nlclib
from readcmd import ReadCmd

spec = """# Grid a data set
          in     = ???  # Input file
          xrange = ???  # Range in x (min,max)
          yrange = ???  # Range in y (min,max)
          bins   = 10   # Number of bins (can be x,y)
          xcol   = 1    # Column with x values
          ycol   = 2    # Column with y values
          out    = ???  # Output fits image
          norm   = None # Normalize by sum, max, or none (no normalization)"""

spec = ReadCmd(spec)
inFile  = spec.getstr('in')
rangex  = spec.getlistfloat('xrange',length=2)
rangey  = spec.getlistfloat('yrange',length=2)
nbins   = spec.getlistint('bins',length=[1,2])
xcol    = spec.getint('xcol',min=1) - 1
ycol    = spec.getint('ycol',min=1) - 1
outFile = spec.getstr('out',exist=False)
norm    = spec.getstr('norm',option=['sum','none','max'],ignorecase=True)

if norm is None:
   norm = 'none'

if len(nbins) == 1: #by default make x and y the same size
   nbins.append(nbins[0])

import pyfits
import numpy as np
Example #3
0
   tmpstep  = [0.5,0.5,1, 2, 5, 5, 5,20, 30, 60,300,300, 300, 600,1200, 3600]
   
   ralabel = map(lambda a: a/3600.,tmplabel) # convert to hours
   stepra  = map(lambda a: a/3600.,tmpstep)  # convert to hours

   tmp = abs(maxra - minra)
   guess = tmp/6. # aim for about 6 labels
   diff  = [abs(guess-a) for a in ralabel]
   idx   = diff.index(min(diff))
   
   return stepra[idx],ralabel[idx]
 
if __name__ == "__main__":
   arg = ReadCmd(spec)
   image      = arg.getstr('in',exist=True)
   rangex     = arg.getlistfloat('xrange',length=2)
   rangey     = arg.getlistfloat('yrange',length=2)
   tmplength  = arg.getfloat('length')
   tmpra      = arg.getlistfloat('ra',length=2)
   tmpdec     = arg.getlistfloat('dec',length=2)
   outfile    = arg.getstr('out',exist=False)

   import worldpos
   wcs = worldpos.wcs(image)
   if wcs.header['rot'] != 0:
      error('WIP cannot handle rotations!')
      
   if len(rangex) == 0:
      xmin = 0.5
      xmax = naxis1 + 0.5
   else:
Example #4
0
      dAv = None
   return Av,dAv
   
def rjce(intrinsic, magj, sigmaj, magh, sigmah, magks, sigmaks):
   """Compute extinction using RJCE (Majewski TODO)"""
   
   return None,None

if __name__ == "__main__":
   arg = ReadCmd(spec)
   infile  = arg.getstr("in",exist=True)
   outfile = arg.getstr("out",exist=False)
   intrinsic = {}
   intrinsic['k1']  = 1./arg.getfloat("avaj")
   intrinsic['k2']  = 1./arg.getfloat("avah")
   intrinsic['jh']  = arg.getlistfloat("jh")
   intrinsic['hk']  = arg.getlistfloat("hk")
   intrinsic['cov'] = arg.getfloat("cov")
   intrinsic['method'] =  arg.getstr("method",option=['jh','hk','nicer','rjce'])

   from numpy import loadtxt,savetxt,sqrt

   data = loadtxt(infile,dtype=str)
   d    = data[:,2:8].astype(float)
   if intrinsic['method'] == 'jh' or intrinsic['method'] == 'hk':
      Av,dAv = nice(intrinsic, d[:,0],d[:,1],d[:,2],d[:,3],d[:,4],d[:,5])
   elif intrinsic['method'] == 'nicer':
      Av,dAv = nicer(intrinsic,d[:,0],d[:,1],d[:,2],d[:,3],d[:,4],d[:,5])
   elif intrinsic['method'] == 'rjce':
      Av,dAv = rjce(intrinsic, d[:,0],d[:,1],d[:,2],d[:,3],d[:,4],d[:,5])
   else:
Example #5
0
    ralabel = map(lambda a: a / 3600., tmplabel)  # convert to hours
    stepra = map(lambda a: a / 3600., tmpstep)  # convert to hours

    tmp = abs(maxra - minra)
    guess = tmp / 6.  # aim for about 6 labels
    diff = [abs(guess - a) for a in ralabel]
    idx = diff.index(min(diff))

    return stepra[idx], ralabel[idx]


if __name__ == "__main__":
    arg = ReadCmd(spec)
    image = arg.getstr('in', exist=True)
    rangex = arg.getlistfloat('xrange', length=2)
    rangey = arg.getlistfloat('yrange', length=2)
    tmplength = arg.getfloat('length')
    tmpra = arg.getlistfloat('ra', length=2)
    tmpdec = arg.getlistfloat('dec', length=2)
    outfile = arg.getstr('out', exist=False)

    import worldpos
    wcs = worldpos.wcs(image)
    if wcs.header['rot'] != 0:
        error('WIP cannot handle rotations!')

    if len(rangex) == 0:
        xmin = 0.5
        xmax = naxis1 + 0.5
    else:
Example #6
0
          ylabel = None      # Y-axis label"""

def error(text):
   """Write out error message and quit"""
   sys.stderr.write("### Fatal Error! %s\n" %text)
   sys.exit()

arg = ReadCmd(spec)
infile   = arg.getstr('in',exist=True)
xcol     = arg.getlistint('xcol',min=1)
ycol     = arg.getlistint('ycol',min=1)
dxcol    = arg.getlistint('dxcol',min=1)
dycol    = arg.getlistint('dycol',min=1)
style    = arg.getliststr('style')
color    = arg.getliststr('color')
limits   = arg.getlistfloat('limits',length=4)
out      = arg.getstr('out')
xlab     = arg.getstr('xlabel')
ylab     = arg.getstr('ylabel')
mytext   = arg.getliststr('text')
mytitle  = arg.getstr('title')
mywidth  = arg.getliststr('width')
legloc   = arg.getlistfloat('legend',length=2)

nx       = len(xcol)
ny       = len(ycol)
ndx      = len(dxcol)
ndy      = len(dycol)
nstyle   = len(style)
ncolor   = len(color)
ntext    = len(mytext)