Re: calculating an 3d array from N-BODY data [message #10844] |
Mon, 16 February 1998 00:00 |
J.D. Smith
Messages: 214 Registered: August 1996
|
Senior Member |
|
|
> Hi:
>
> I am trying to visualize data in 3D. I have it in the form of "x,y,x,mass" for
> each particle. Does anyone have a routine to create an array M(x,y,z) from this
> data ? The only methods I have come with are not very efficient.
>
> Thank you very much.
>
> I~nigo.
> --
I assume you've read in x,y,z,mass...
;;**************************************************
M=fltarr(nx,ny,nz)
;;rescale x,y,z onto [0...n[xyz]-1]
;;or maybe x,y,z onto [0....max(n[x,y,z])-1] (preserves aspect)
minx=min(x,max=maxx)
x=round(float(x-minx)/(maxx-minx)*(nx-1))
...
...
ind=nx*ny*z+nx*y+x & M(ind)=mass
;;**************************************************
That should do it.
Note that in this case for any points which fall in the same voxel (3d
pixel, of which there are nx*ny*nz), the *last* value in the list will
be used. This would be the case for non-uniform points (e.g. not on
some kind of grid), or undersampled points (e.g. not enough voxels in
array to accomodate all the points). If you would prefer to *average*
overlapping values, you'll have to sort them all first, and set the
overlappers specially as an extra step, like this:
;;**************************************************
s=sort(ind)
ind=ind(s) & mass=mass(s)
u=[-1,uniq(ind)] ; u is sorted ... which we take advantage of...
del=u-shift(u,1)-1
wh=where(del gt 0,cnt) ; where the delta between adjacent uniq's is not
1
if cnt ne 0 then begin
for i=0,cnt-1 do begin
j=wh(i)
M(ind(u(j)))=total(mass(u(j)-del(j):u(j)))/(del(j)+1.)
enfor
endif
;;***************************************************
This is a slow loop, compared to the above calculation, but that doesn't
much matter if there are only a few (<10%, say) same-voxel points. You
should therefore choose each array dimension to be on the order of the
cube root of the number of points, if possible.
JD
--
J.D. Smith |*| WORK: (607) 255-5842
Cornell University Dept. of Astronomy |*| (607) 255-4083
206 Space Sciences Bldg. |*| FAX: (607) 255-5875
Ithaca, NY 14853 |*|
|
|
|