Commits

Sam Skillman committed 5bd2ed6

Moving stuff around, renaming

  • Participants
  • Parent commits 5f03899

Comments (0)

Files changed (2)

File rad_prof2d.py

-import numpy as np
-
-def radial(image,x,y):
-    yind,xind = np.indices(image.shape)
-    dist = np.sqrt((xind-x)**2+(yind-y)**2)
-    return dist    
-
-''' Do a radial profile of image 'im' centered on (cx,cy), weighted by
-image 'weight'.  imwidth can be used to rescale the returned radius
-array by some physically relevant distance in units of fraction of the
-image width.  if average is False, it will return a straight sum of
-the radial bins, and not average them either by pixel number or the
-weight field.
-'''
-def rprof(im,cx,cy,weight=None,imwidth=1.0,average=True):
-    r = radial(im,cx,cy)
-    ind = np.argsort(r.flat) # indices for sorted radii (need to use with im)
-    sr = r.flat[ind] # the sorted radii
-    sim = im.flat[ind] # image values sorted by radii
-    if average:
-        if weight is not None:
-            sw = weight.flat[ind] # weight values sorted by radii
-            sim *= sw
-    ri = sr.astype(np.int16) # integer part of radii (bin size = 1)
-    # The particularly tricky part, must average values within each radii bin
-    # Start by looking for where radii change values
-    deltar = ri[1:] - ri[:-1] # assume all radii represented (more work if not)
-    rind = np.where(deltar)[0] # location of changed radius
-    nr = rind[1:] - rind[:-1] # number of pixels in radius bin
-    if average:
-        if weight is not None:
-            cssw = np.cumsum(sw, dtype=np.float64)
-    csim = np.cumsum(sim, dtype=np.float64) # cumulative sum for increasing radius
-    # total in one bin is simply difference between cumulative sum for adjacent bins
-    tbin = csim[rind[1:]] - csim[rind[:-1]] # sum for image values in radius bins
-
-    maxr = np.max(r)*(imwidth)/(im.shape[0])
-    rad = np.linspace(0.0,maxr,num=tbin.shape[0])
-
-    if average:
-        if weight is not None:
-            twbin = cssw[rind[1:]] - cssw[rind[:-1]]
-            return rad, tbin/twbin
-        radialprofile = tbin/nr # compute average for each bin
-    else:
-        radialprofile = tbin
-
-    return rad, radialprofile
+import numpy as np
+
+def radial(image,x,y):
+    yind,xind = np.indices(image.shape)
+    dist = np.sqrt((xind-x)**2+(yind-y)**2)
+    return dist    
+
+''' Do a radial profile of image 'im' centered on (cx,cy), weighted by
+image 'weight'.  imwidth can be used to rescale the returned radius
+array by some physically relevant distance in units of fraction of the
+image width.  if average is False, it will return a straight sum of
+the radial bins, and not average them either by pixel number or the
+weight field.
+'''
+def rprof2d(im,cx,cy,weight=None,imwidth=1.0,average=True):
+    r = radial(im,cx,cy)
+    ind = np.argsort(r.flat) # indices for sorted radii (need to use with im)
+    sr = r.flat[ind] # the sorted radii
+    sim = im.flat[ind] # image values sorted by radii
+    if average:
+        if weight is not None:
+            sw = weight.flat[ind] # weight values sorted by radii
+            sim *= sw
+    ri = sr.astype(np.int16) # integer part of radii (bin size = 1)
+    # The particularly tricky part, must average values within each radii bin
+    # Start by looking for where radii change values
+    deltar = ri[1:] - ri[:-1] # assume all radii represented (more work if not)
+    rind = np.where(deltar)[0] # location of changed radius
+    nr = rind[1:] - rind[:-1] # number of pixels in radius bin
+    if average:
+        if weight is not None:
+            cssw = np.cumsum(sw, dtype=np.float64)
+    csim = np.cumsum(sim, dtype=np.float64) # cumulative sum for increasing radius
+    # total in one bin is simply difference between cumulative sum for adjacent bins
+    tbin = csim[rind[1:]] - csim[rind[:-1]] # sum for image values in radius bins
+
+    maxr = np.max(r)*(imwidth)/(im.shape[0])
+    rad = np.linspace(0.0,maxr,num=tbin.shape[0])
+
+    if average:
+        if weight is not None:
+            twbin = cssw[rind[1:]] - cssw[rind[:-1]]
+            return rad, tbin/twbin
+        radialprofile = tbin/nr # compute average for each bin
+    else:
+        radialprofile = tbin
+
+    return rad, radialprofile