Exemple #1
0
def dobin(image,offset,bin,unit):
   """Combine all steps for reading a fits image and binning radially"""
   
   junk    = nlclib.createtempname() # list of pixel values with distances in arcsecs
   outdata = nlclib.createtempname() # binned data

   # read fits header to get crpix and cdelt
   crpix1 = crpix2 = -1
   cdelt1 = cdelt2 = -1
   header = iraf.imheader(image,Stdout=1)
   for line in header:
      if re.match(r'^CRPIX1',line):
         crpix1 = float(line.split()[2])
      elif re.match(r'^CRPIX2',line):
         crpix2 = float(line.split()[2])
      elif re.match(r'^CDELT1',line):
         cdelt1 = float(line.split()[2])
      elif re.match(r'^CDELT2',line):
         cdelt2 = float(line.split()[2])
   if crpix1 == -1 or crpix2 == -1:
      nlclib.error("Couldn't read crpix values!")
   if cdelt1 == -1 or cdelt2 == -1:
      nlclib.error("Couldn't read cdelt values!")

   # Add in offsets
   fac = abs(cdelt1)*3600 # convert pixel distances to arcsecs
   crpix1 = crpix1 - offset[0]/fac
   crpix2 = crpix2 + offset[1]/fac


   # figure out binning
   if unit == 'step':
      count = int((bin[1] - bin[0])/bin[2])
   elif unit == 'nbin':
      count = bin[2]
   if count < 0:
      nlclib.error('Number of bins is negative!')

   # get pixel values
   fp = open(junk,'w')
   x = iraf.listpixels(image,Stdout=1)
   for line in x:
      t = map(float,line.split())
      dist = fac*math.sqrt((t[0] - crpix1)**2 + (t[1] - crpix2)**2)
      fp.write('%f %f\n' %(dist,t[3]))
   fp.close()

   # bin data
   cmd = 'dobin in=%s bin=%f:%f:%d > %s' %(junk,bin[0],bin[1],count,outdata)
   os.system(cmd)
   nlclib.remove(junk)
   return outdata
Exemple #2
0
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))

if 'p' in step: # make plot
   nlclib.check_existance(outdata)
   nlclib.remove(outplot)

   default(width=2)
   winadj()
   for n,f in enumerate(outdata):
      data = getdata(f)
      plot(data[0],data[2],style='-',color=pycolors[n+1],
         logx=True,logy=True,text=None,limits=(0.8,35,0.01,1.1))
      #errorbar(data[0],data[2],yerr=data[3],size=3,color=pycolors[n+1])
      text(10,0.8,outplot)
      # find slope
      x = [math.log10(i) for i in data[0]]
      y = [math.log10(i) for i in data[2]]
      e = [0.43429*b/a for a,b in zip(data[2],data[3])]
      try:
         logmin = math.log10(xmin)
Exemple #3
0
os.system('%s/rotatevector.py in=%s fits=%s out=%s ext=%d cd=%s' %(path,
   infile,fits,blah,ext,cdFlag))

data1 = nlclib.readdata(infile)
data2 = nlclib.readdata(blah,dtype=float)

if len(data1) != len(data2):
   arg.error('Problem rotating vectors!')

fp = open(outfile,'w')
fp.write('#   x         y       Pol     dPol    Angle   dAngle     H        dH    Filename\n')
fp.write('#  (pix)    (pix)     (%)      (%)    (deg)    (deg)   (mag)     (mag)  (string)\n')

for l1,l2 in zip(data1,data2):
   fp.write('%8.3f  %8.3f  ' %(l2[0],l2[1])) # x,y from data2
   fp.write('%6s  %6s  ' %(l1[2],l1[3])) # pol,dpol from data1
   try:
      fp.write('%7.3f  %7s  ' %(l2[3],l1[5])) # angle from data2,dangle from data1
   except IndexError:
      fp.close()
      arg.error('Missing angle or delta angle for input file')
   try:
      fp.write('%7s  %7s  ' %(l1[6],l1[7])) # Hmag,dHmag from data1
      fp.write('%s\n'       %(l1[8]))       # filename from data1
   except IndexError:
      fp.write('%7s  %7s  ' %('0.00','0.00')) # Hmag,dHmag
      fp.write('%s\n'       %infile)          # filename      
fp.close()

nlclib.remove(blah)