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

Home » Public Forums » archive » Re: help on optimization
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: help on optimization [message #76683] Thu, 23 June 2011 08:19
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
I would approach this by:

1. Calculate the radius r.
2. Sort by radius.
3. Use TOTAL(/CUMULATIVE) to get the cumulative mass profile at each particle, in sorted radius order.
4. Use VALUE_LOCATE to find where in the radial-sorted-list-of-particles the endpoints of the bins are.
5. Subtract the cumulative total values at each bin edge to get the total mass in each bin, which you can compare directly to the cumulative mass to that point from the cumulative total.

-Jeremy.
Re: help on optimization [message #76684 is a reply to message #76683] Thu, 23 June 2011 05:47 Go to previous message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Thu, 23 Jun 2011 14:44:06 +0200, Wox <spam@nomail.com> wrote:


> xgaspos=file_gaspos[0,*]
> ygaspos=file_gaspos[1,*]
>
> for i=0,nhalos do begin
> ;Distance of particles to the halo
> dis2=(xrand[i]-xgaspos)^2+(yrand[i]-ygaspos)^2
>
> ;histogram distances within 10Mpc
> hist =histogram(dis2[ind_gas],binsize=bin_mpc,$
> max=10000,reverse_indices=ri)
>
> gasmass=file_gasmass[ind_gas]
> for ll=0,n_elements(hist)-1 do $
> if ri[ll] eq ri[ll+1] then gasm[ll]=0 $
> else gasm[ll]=total(gasmass[ ri[ ri[ll]:ri[ll+1]-1 ] ])
>
> ymin_r_gas+=total(gasm,/cumul,/pres) ; Sigma(<r)
> yplot_gas+=gasm ; Sigma(r)
> endfor

This should be removed of course:
gasmass=file_gasmass[ind_gas]
Re: help on optimization [message #76685 is a reply to message #76684] Thu, 23 June 2011 05:44 Go to previous message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Thu, 23 Jun 2011 02:38:00 -0700 (PDT), stefania
<stefania.giodini@gmail.com> wrote:

> Any help/idea/feedback will be very useful!


1. I don't think the preselection speeds things up, so skip it.

2. Avoid using WHERE by specifying a MAX in histogram (use 100^ to
avoid SQRT).

3. Remove some redundancy in total / cumulative total.


xgaspos=file_gaspos[0,*]
ygaspos=file_gaspos[1,*]

for i=0,nhalos do begin
;Distance of particles to the halo
dis2=(xrand[i]-xgaspos)^2+(yrand[i]-ygaspos)^2

;histogram distances within 10Mpc
hist =histogram(dis2[ind_gas],binsize=bin_mpc,$
max=10000,reverse_indices=ri)

gasmass=file_gasmass[ind_gas]
for ll=0,n_elements(hist)-1 do $
if ri[ll] eq ri[ll+1] then gasm[ll]=0 $
else gasm[ll]=total(gasmass[ ri[ ri[ll]:ri[ll+1]-1 ] ])

ymin_r_gas+=total(gasm,/cumul,/pres) ; Sigma(<r)
yplot_gas+=gasm ; Sigma(r)
endfor


4. You can think of calculating "dis" outside the loop but it depends
on how many columns file_gaspos has (memory issues). Assume xrand en
yrand are row vectors:

dis=sqrt((rebin(xrand,nhalos,np,/sample)-rebin(file_gaspos[0 ,*],nhalos,np,/sample))^2+$

(rebin(yrand,nhalos,np,/sample)-rebin(file_gaspos[1,*],nhalo s,np,/sample))^2)

You can also devide nhalos in smaller chunks. However you still need
to do the histogram and mass summation for each column separatly.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: help on optimization
Next Topic: New Graphics Reference Arrow

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

Current Time: Wed Oct 08 11:42:19 PDT 2025

Total time taken to generate the page: 0.00408 seconds