[AstroPy] PyFits too slow
Jose Miguel Ibáñez
ppmime at gmail.com
Fri Jun 26 07:10:30 EDT 2009
Great !!! now it is really fast and powerful !!
I will follow your advices and read the docs and tutorials.
Thanks !
2009/6/26 Derek Homeier <derek at astro.physik.uni-goettingen.de>
> On 26 Jun 2009, at 11:32, Johann Cohen-Tanugi wrote:
>
> this is very very bad : have a look at the numpy tutorials or user's
>> guide. You are not making use of vectorization....
>>
>> Johann
>>
>> Jose Miguel Ibáñez wrote:
>>
>>> Hello !
>>>
>>> I am trying to iterate through the pixels of an FITS image read
>>> previusly with PyFits,
>>> but it is too slow (more that 1CPU minute), so my question is if is
>>> there any other way to do that in a
>>> more efficient/fast way.
>>>
>>> That's the code I'm using:
>>> ------------------------------------------------------------------
>>> f=pyfits.open('/tmp/c1.fits',memmap=1)
>>> b=numpy.zeros([2048,2048],dtype='float32')
>>> cdata=f[0].data.copy()
>>> f.close()
>>> print 'start loop...'
>>> for i in range(0,2048):
>>> for j in range(0,2048):
>>> if cdata[i,j]<1 or cdata[i,j]>100000:
>>> b[i,j]=1
>>>
>>
> Correct; basically the numpy way to achieve what you want to do would look
> like
>
> b[ (cdata<1) | (cdata>1.e5) ] = 1
>
> and should take fractions of a second. As Johann said, read the tutorials
> to get
> familiar with the basic operations.
>
> Cheers,
> Derek
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20090626/63d0b9d2/attachment.html>
More information about the AstroPy
mailing list