Masked arrays

Tommy Grav tgrav at mac.com
Wed May 10 14:05:40 EDT 2006


I am trying to get the flux of a star in an image. I have been using  
numpy
and pyfits and have the code.

def distance(im,xc,yc):
     (rows,cols) = im.shape
     dist = zeros([rows,cols]).astype(Float64)
     for row in range(rows):
         for col in range(cols):
             dist[row,col] = sqrt(((row + 0.5) - yc)**2 + ((col +  
0.5) - xc)**2)
     return dist

def apphot(im,x,y,r):
     dist = distance(im,x,y)
     appmask = where(dist <= r,1,0)
     fluxim = where(appmask,im,0)
     appflux = sum(sum(fluxim))
     skymask = where(dist > r, 1,0)
     skyim = where(skymask,im,0)
     sky = mean(skyim)
     print skyim
     print sky

     return 1

Output:
 > array (20,20) , type = f, has 400 elements
 > [ 45.89742126, 45.92555847, 45.8874054 , 45.88538208, 45.88244934,  
45.9353241 ,
        36.75245361, 29.85816345, 27.53547668, 22.93712311, 22.93178101,
        22.93699799, 22.91038208, 27.4988739 , 29.84021606, 36.71789551,
        45.86646729, 45.86741638, 45.85328979, 45.823349  ,]

where im is a ndarray, x and y are the position of the star and r is
the radius of the aperture. I calculate the flux inside the aperture,
but when I want to calculate the mean of the pixels outside the
aperture I run into problems as the pixels values inside the aperture
is 0 and is still considered in the mean calculation. Is there a way to
do this without using masked arrays? How would I use a masked array
to do it?

Cheers
Tommy


tgrav at mac.com
http://homepage.mac.com/tgrav/

"Any intelligent fool can make things bigger,
more complex, and more violent. It takes a
touch of genius -- and a lot of courage --
to move in the opposite direction"
                          -- Albert Einstein


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060510/81568f0d/attachment.html>


More information about the Python-list mailing list