[AstroPy] Image combine

Eduardo Bañados Torres eebanado at uc.cl
Wed Mar 7 04:16:10 EST 2012


Hi all,

I started to write a imcombine-like routine but it still needs a lot
of improvements.

The main features are mean or median combination, image scaling (mean,
median or mode. You can also choose the image section for computing
the statistics) and sigma-clipping.

The normal mean/median combinations are very fast.
For scaling using the mode, I had to write my own method which is not
really optimal (I have some ideas to improve it but I haven't had
time)
but is faster than scipy.stats.mode

One big problem is that combinations using sigma-clipping are hundreds
times slower than the no-clipped methods, mainly due to the use of
numpy masked arrays which are too slow! If someone knows a faster way
for the sigma-clipping please let me know :)

If you think this can be useful, I'd be happy to share it and get some
feedback. So drop me a line if you want me to email you the code, in
the meantime I will comment it.

Cheers,

Eduardo

On Wed, Mar 7, 2012 at 10:13 AM, Alexander Wagner
<alexander.y.wagner at googlemail.com> wrote:
>
> If you can turn my_sigma_clip into a ufunc, you could do
>
> my_sigma_clip.reduce(cube, axis=0)
>
> http://docs.scipy.org/doc/numpy/user/c-info.ufunc-tutorial.html
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduce.html
>
> Best wishes,
> Alex
>
>
> On 7/03/12 5:43 PM, 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)
>> So, I'd also like to find out where is the point of that difference.
>>
>>
>> As Erik suggests, I think that kind of combine-like routines should be
>> in the next coming astropy package, maybe with the effort of all of
>> us.
>> So Kathleen, I encourage you to continue with your adventure at Gemini
>> and let us know about your progress.
>>
>> Cheers,
>> Jose
>>
>>
>>
>> 2012/3/6 Kathleen Labrie<klabrie at gemini.edu>:
>>> Hi,
>>>
>>> I think Jose mostly refer to the rejection, masking, scaling, weighing
>>> algorithms that iraf imcombine offers.    I agree the arithmetic is easy
>>> enough to do with numpy and pyfits, even the median.  It's the rest
>>> of imcombine that can get tricky (and bloated).
>>>
>>> For the record, here at Gemini, we will soon embark it that foolish adventure
>>> of trying to reproduce at least some of the imcombine features (but only
>>> the ones we need due to time and resource constraints).   We are still
>>> at the point of defining which features we really need though, so I don't
>>> think it will help Jose much for now.
>>>
>>> I am very interested to hear if someone has written some code for a
>>> imcombine-like routine.
>>>
>>> Cheers,
>>> Kathleen
>>>
>>> On Mar 6, 2012, at 8:52 AM, Erik Tollerud wrote:
>>>
>>>> I'm not aware of a function that does it exactly with the interface of
>>>> imcombine, but it can be done pretty easily with pyfits:
>>>>
>>>> import pyfits
>>>>
>>>> f1 = pyfits.open('filename1')
>>>> f2 = pyfits.open('filename2')
>>>>
>>>> h1 = f1[0].header
>>>> im1 = f1[0].data
>>>> im2 = f2[0].data
>>>>
>>>> newimage = im1 + im2
>>>>
>>>> newhdu = pyfits.PrimaryHDU(data=newimage,header=h1)
>>>> newhdu.writeto('newfilename')
>>>>
>>>>
>>>> That example is specific to addition, of course (the im1 + im2 part,
>>>> but it should be clear how to generalize it to other arithmetic
>>>> operations.
>>>>
>>>>
>>>> 2012/3/6 Jose Miguel Ibáñez<ppmime at gmail.com>:
>>>>> Hello everyone,
>>>>>
>>>>> does anyone know of an implementation of the iraf.imcombine task in
>>>>> python+numpy ? (of course, not using pyraf.imcombine call)
>>>>>
>>>>>
>>>>> Thanks !
>>>>> Jose
>>>>> _______________________________________________
>>>>> AstroPy mailing list
>>>>> AstroPy at scipy.org
>>>>> http://mail.scipy.org/mailman/listinfo/astropy
>>>>
>>>>
>>>> --
>>>> Erik Tollerud
>>>> _______________________________________________
>>>> AstroPy mailing list
>>>> AstroPy at scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/astropy
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> http://mail.scipy.org/mailman/listinfo/astropy
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy



-- 
Eduardo Bañados Torres



More information about the AstroPy mailing list