Re: dimensional headache [message #43299] |
Wed, 06 April 2005 00:46 |
Andrew[2]
Messages: 7 Registered: February 2005
|
Junior Member |
|
|
Hi again,
please ignore both of the previous posts by me. They dont work, DIST
was completly wrong. Dont know what I was thinking. Sorry. But you can
reduce what you do in the loops. For example the code below (and I made
sure this worked properly) runs in 16 milliseconds (pretty quick). Then
you can still do the rest of the code that I had before, or
alternatively your own code from your WhereToMulti statement.
t1=systime(/seconds)
d=findgen(160,160)
xgrid=findgen(160)
ygrid=findgen(160)
;i just assumed a central position here
xmod=79
ymod=79
dx=(xmod-xgrid)^2
dy=(ymod-ygrid)^2
for i=0,159 do for j=0,159 do d[i,j]=SQRT(dx[i]+dy[j])
t2=systime(/seconds)
print,t2-t1
Sorry about the dud answers before. I hope this one helps a bit even if
it didnt get rid of the loops.
Cheers
Andrew
|
|
|
Re: dimensional headache [message #43300 is a reply to message #43299] |
Wed, 06 April 2005 00:01  |
Andrew[2]
Messages: 7 Registered: February 2005
|
Junior Member |
|
|
Hi Margrethe,
I am not sure what some of the things you have in your code do (aka
calls to ther functions), nor do I know how easily you might be able to
modify them, but I had a crack at the code and made some reasonably
hefty assumptions. Some of this may be completly useless to you. The
distance array d works a treat though and lets you get away from the
whole sqrt, squared buisness. As for the rest of it, I am not sure
since I dont know if you are heavily restricted in your array sizes (I
also am not sure what are scalars and arrays in a couple of cases). I
also noticed in you second attempt at the code that their are still
what appear to be loop markers k and l. So i am not entirely sure what
will be applicable here. I would imagine that the [indx] markers can be
removed if I have stuck them in the wrong places for the things that
are scalars rather than arrays. I hope this helps in some small way.
;get the distance array first
d=SHIFT(DIST(160),xmod,ymod)
;don't take the wings of the psf into account
indx = where (d lt (3. * (fwhm/2.35) ) ,ct)
;only do the calculations where the above criteria has been met
IF (ct NE 0) THEN BEGIN
;assumes here that vel_p,vel_sys, and v_rad are all 160x160 arrays
;if vel_sys isnt then just remove the [indx] part
vel_p[indx] = ( vel_sys[indx] + v_rad[indx] )
;I assume the original psf returned a scalar value at the location i,j
;psf = gaussfunc(st_dev,xgrid(i),ygrid(j),xmod,ymod )
;not sure what do do here as I dont really know what psf returns
;can you return it as a 160x160 array if needed. yes?
;i assumed here that the xgrid and ygrid parameters can
;be merged and passed as the complete array size (im guessing)
psf[indx] = gaussfunc(st_dev,FINDGEN(160,160),xmod,ymod )
lineprof[indx] = lineprof[indx] + total ( psf[indx] * image[indx]
* $
exp( (vel - vel_p[indx])^2./(-2.*v2)) )
ENDIF
Cheers
Andrew
|
|
|
Re: dimensional headache [message #43301 is a reply to message #43300] |
Tue, 05 April 2005 23:57  |
Andrew[2]
Messages: 7 Registered: February 2005
|
Junior Member |
|
|
Hi again,
after a second look at your new code that you posted I think you can
get away with the following. This is assuming that it is the values in
d that are being returned incorrectly in your code
;get the distance array first
d=SHIFT(DIST(160),xmod,ymod)
then carry on from your WhereToMulti procedure (seems like a waste of a
nice WHERE statement however, which will give you the array locations
you want)
Cheers
Andrew
|
|
|
|
|