Re: help needed to make the program run faster [message #93656 is a reply to message #93626] |
Thu, 22 September 2016 14:17   |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Sunday, September 11, 2016 at 10:58:46 PM UTC-5, sid wrote:
> On Friday, September 9, 2016 at 2:42:00 PM UTC+5:30, Markus Schmassmann wrote:
>> On 09/09/2016 08:04 AM, sid wrote:
>>> I need to read 500 fits files and do analysis for all this,
>>>
>>> So im doing like this,
>>>
>>> file=file_search('*.fts')
>>> nn=n_elements(file)
>>> for ii=0,nn-1 do begin
>>> img=readfits(file(ii),h)
>>> ----
>>> ---some analysis----
>>>
>>> endfor
>>> end
>>>
>>> in the analysis part also i have some for loops so the program takes so much time to process this job.
>>>
>>> So can anybody let me know whether any other faster methods are there to do this.
>> Hi Sid,
>>
>> - use PROFILER and/or TIC & TOC to figure out what part of your code is slow
>> - remove loops by vectorising
>> - if all fits-images have the same dimensions and header structures you
>> can put all into one array and then do analysis on all images at once, e.g.:
>>
>> file=file_search('*.fts')
>> nn=n_elements(file)
>> img0=readfits(file(0),h0)
>> img=fltarr([size(img0,/dim),nn])
>> img[*,*,0]=temporary(img0)
>> h=strarr([size(h0,/dim),nn])
>> h[*,0]=temporary(h0)
>> for i=1,nn-1 do begin
>> img[*,*,i]=readfits(file(i),hi)
>> h[*,i]=hi
>> endfor
>>
>> ---some analysis----
>>
>> - not knowing what analysis you do it is difficult to tell how to speed
>> it up, but using, WHERE, SORT, UNIQ, HISTOGRAM, VALUE_LOCATE and the
>> like sometimes makes it a lot faster
>>
>> Good luck, Markus
>>
>>
>> [1] http://www.harrisgeospatial.com/docs/PROFILER.html
>> [2] http://www.idlcoyote.com/code_tips/slowloops.html
>> [3] http://www.harrisgeospatial.com/docs/WHERE.html
>> [4] http://www.harrisgeospatial.com/docs/SORT.html
>> [5] http://www.harrisgeospatial.com/docs/UNIQ.html
>> [6] http://www.harrisgeospatial.com/docs/HISTOGRAM.html
>> [7] http://www.harrisgeospatial.com/docs/VALUE_LOCATE.html
>
> Thanks for the info,
> Actually the main problem im facing is im using where function and
> for example if im searching where(image(*,i) gt threshold,count=c)
> for some rows counts will be zero,
> so in that case im using if statement, that way my program becomes much slow.
> Is there any way to get out of this problem.
>
> thanks
Sometimes you can use masks instead of where to speed things up... but again, it depends what exactly you are doing with it. For example, to double every pixel that is greater than the threshold:
positive_mask = image gt threshold
image += image * positive_mask
-Jeremy.
|
|
|