comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: dimensional headache
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: dimensional headache [message #43299] Wed, 06 April 2005 00:46
Andrew[2] is currently offline  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 Go to previous message
Andrew[2] is currently offline  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 Go to previous message
Andrew[2] is currently offline  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
Re: dimensional headache [message #43320 is a reply to message #43301] Sat, 02 April 2005 09:17 Go to previous message
Margrethe is currently offline  Margrethe
Messages: 4
Registered: March 2005
Junior Member
thank you! I will look into that!

M.
Re: dimensional headache [message #43321 is a reply to message #43320] Fri, 01 April 2005 16:10 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <1112374157.893164.86500@l41g2000cwc.googlegroups.com>,
"Margrethe" <margrethewold@hotmail.com> wrote:

> I'm developing a two-dimensional model and to save computational time
> I've tried to avoid for-loops whereever I could and used matrices
> instead. I thought I had it all figured out, but I'm doing something
> wrong...I'd be grateful if someone could tell me what's wrong with the
> following:

Have a look at the CONVOL and SHIFT functions. They mayallow you to do
what you need without loops.

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: texture map on cylindrical section
Next Topic: Re: calculating long term statistics on ALBEDO data

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:37:12 PDT 2025

Total time taken to generate the page: 0.00578 seconds