[AstroPy] Image combine

Perry Greenfield perry@stsci....
Wed Mar 7 07:30:51 CST 2012

Hi Jose,

Anytime you iterate over every pixel in a loop, you are going to find  
that it is very slow. You want to be operating on at least 1000 pixels  
at a time (ideally more than 10,000) to avoid numpy overhead. Using  
masks to do the sigma clipping would be much faster (though not as  
optimized as doing it in C as others mention).


On Mar 7, 2012, at 3:43 AM, Jose Miguel Ibáñez wrote:

> Hi !
> Right Kathleen, I mostly refer to the rejection, masking, scaling ...
> algorithms; the idea is to avoid to install all the PyRAF staff only
> because the nice iraf.imcombine task.
> I have tried to implement some of those features, but for the moment
> the main problem is that my routine is extremely slow (~2min)
> following the next schema:
> import numpy as np
> ndim = 2048
> cube = np.random.rand(32,ndim, ndim)
> result = np.zeros([ndim, ndim], np.float32)
> def combine(cube, result):
>    for ii in range(ndim):
>        for jj in range(ndim):
>            result[ii, jj] = my_sigma_clip(cube[:,ii,jj])
>    return result
> However, the next numpy sentence is very fast (less than 1 second )
>>> median_result = np.median(cube,0)

More information about the AstroPy mailing list