Help with getting rid of a FOR loop [message #60490] |
Tue, 20 May 2008 15:19 |
nathan12343
Messages: 14 Registered: August 2007
|
Junior Member |
|
|
Hi, all
Recently, I've been going through some old code in an effort to make
it run a bit faster. My primary tool in this adventure has been the
elimination of unnecessary FOR loops - all this code was written
before I read David Fanning's article on 'The IDL Way'.
This particular piece of code is used to approximate the center to
limb variation in full-disk solar images. It identifies pixels that
are on the solar disk and assigns them a value according to whether
they're in between two radii given in a vector, r. This defines a set
of annuli which cover the solar disk, the number of which is given by
num. This information is stored in the mask array and returned.
Here's the actual code:
PRO generate_annuli,radius,xcenter,ycenter,num,mask
;radius - solar radius
;xcenter - x coord of solar disk center
;ycenter - y coord of solar disk center
;num - number of annuli for CLV approximation
;mask - the output mask
; No integer overflows
compile_opt IDL2
imsize=2048L ;images are 2048X2048
mu=reverse(findgen(num+1))/(num) ;Generates values for mu
r=radius*sqrt(1-mu^2) ;Inner radii for all the
annuli
xx=rebin(findgen(imsize),imsize,imsize) ;array of x indices
yy=transpose(xx) ;array of y indices
dist=sqrt((xx-xcenter)^2+(yy-ycenter)^2) ;array of radii
mask=fltarr(imsize,imsize)-1
FOR i=0,num-1 DO BEGIN
wh=where(dist GE r[i] and dist LE r[i+1])
mask[wh]=i
ENDFOR
END
I would like to find some way to get rid of the FOR loop at the end.
All I'm doing in that loop is going through the annuli one by one,
finding the pixels in that annuli, and setting the corresponding
pixels in mask to the correct mask value.
Thanks for any help anyone can provide!
Nathan Goldbaum
|
|
|