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

Home » Public Forums » archive » binning a point clouds in the xy plane
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
binning a point clouds in the xy plane [message #87011] Thu, 19 December 2013 13:53 Go to next message
Nafiseh Masoumzadeh is currently offline  Nafiseh Masoumzadeh
Messages: 10
Registered: June 2013
Junior Member
Hello,

I have three vectors, x, y, z having same size which I want to bin x and y and have average value of z corresponding to bin. and then get resample data in point clouds as an output.

rebin or reform are supposed to do it, but I couldn't find how, however I've studied http://www.idlcoyote.com/tips/rebin_magic.html. The example in this link for me it is more like to mask your data but I want to have an avarage of one of my vector z in bin x-y plane.

regards,
Nafiseh
Re: binning a point clouds in the xy plane [message #87012 is a reply to message #87011] Thu, 19 December 2013 14:13 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Nafiseh Masoumzadeh writes:

> I have three vectors, x, y, z having same size which I want to bin x and y and have average value of z corresponding to bin. and then get resample data in point clouds as an output.
>
> rebin or reform are supposed to do it, but I couldn't find how, however I've studied http://www.idlcoyote.com/tips/rebin_magic.html. The example in this link for me it is more like to mask your data but I want to have an avarage of one of my vector z in bin x-y plane

I would use HIST_ND with the REVERSE_INDICES keyword to bin the data in
X and Y. Then, I would loop through each bin and with the output from
REVERSE_INDICES find the Z values falling in each bin and average those.

You can find NIST_ND in the Public directory of the Coyote Library, and
you might find cgReverseIndices handy for returning the indices of the Z
values in each bin:

http://www.idlcoyote.com/idldoc/cg/cgreverseindices.html

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: binning a point clouds in the xy plane [message #87014 is a reply to message #87011] Thu, 19 December 2013 16:11 Go to previous messageGo to next message
Nafiseh Masoumzadeh is currently offline  Nafiseh Masoumzadeh
Messages: 10
Registered: June 2013
Junior Member
Thanks a lot,

it is really a brilliant idea. :)

I have just problem with cgReverseIndices to find indices of avg z values.

here is the code;

readcol, 'sampledata.txt', x, y, z

hist_xy=hist_nd(transpose([[x],[y]]),[0.05,0.05],$
min=[min(x),min(y)],max=[max(x),max(y)],reverse_indices=ri)

avg_hist_xyz=make_array(size(hist_xy,/DIMENSIONS),VALUE=!VAL UES.F_NAN)

for j=0,n_elements(hist_xy)-1 do if ri[j+1] gt ri[j] then $
avg_hist_xyz[j]=mean(z[ri[ri[j]:ri[j+1]-1]])

;;;;;;;;;;;;;;; I am not sure how to use correctly "cgReverseIndices"
indicesz = cgReverseIndices( avg_hist_xyz[ri], 4, COUNT=cnt) ?????
help, indicesz ?????


regards,
Nafiseh
Re: binning a point clouds in the xy plane [message #87015 is a reply to message #87014] Thu, 19 December 2013 16:20 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Nafiseh M writes:

> Thanks a lot,
>
> it is really a brilliant idea. :)
>
> I have just problem with cgReverseIndices to find indices of avg z values.
>
> here is the code;
>
> readcol, 'sampledata.txt', x, y, z
>
> hist_xy=hist_nd(transpose([[x],[y]]),[0.05,0.05],$
> min=[min(x),min(y)],max=[max(x),max(y)],reverse_indices=ri)
>
> avg_hist_xyz=make_array(size(hist_xy,/DIMENSIONS),VALUE=!VAL UES.F_NAN)
>
> for j=0,n_elements(hist_xy)-1 do if ri[j+1] gt ri[j] then $
> avg_hist_xyz[j]=mean(z[ri[ri[j]:ri[j+1]-1]])
>
> ;;;;;;;;;;;;;;; I am not sure how to use correctly "cgReverseIndices"
>
> help, indicesz ?????

I would use it like this:

for j=0,n_elements(hist_xy)-1 do begin
indicesz = cgReverseIndices(ri, j, COUNT=cnt)
if cnt gt 0 then avg_hist[j] = Median(z[indicesz])
endfor

I would use Median rather than Mean so I wasn't being confused by
outliers, but you should decide what is best for you.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: binning a point clouds in the xy plane [message #87017 is a reply to message #87015] Fri, 20 December 2013 15:03 Go to previous messageGo to next message
Nafiseh Masoumzadeh is currently offline  Nafiseh Masoumzadeh
Messages: 10
Registered: June 2013
Junior Member
thanks a lot for the answer,

But I thought with indicesz, i would have my new x and y for mean z values. I cannot figure it how can I calculate them?

when I write
print, indicesz
I will get just some number which I don't know what are they.
Re: binning a point clouds in the xy plane [message #87018 is a reply to message #87011] Fri, 20 December 2013 15:01 Go to previous messageGo to next message
Nafiseh Masoumzadeh is currently offline  Nafiseh Masoumzadeh
Messages: 10
Registered: June 2013
Junior Member
thank you,


But I thought with indicesz, i would have my new x and y for mean z values. I cannot figure it how can I calculate them?
Re: binning a point clouds in the xy plane [message #87019 is a reply to message #87017] Fri, 20 December 2013 16:06 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Nafiseh M writes:

> thanks a lot for the answer,
>
> But I thought with indicesz, i would have my new x and y for mean z values. I cannot figure it how can I calculate them?

Are you talking about how you calculate the new X and Y vectors that
describe the binned data? I think I would do it like this. Given that
you have this (and note I'm leaving out the max values since they will
not be used if you are specifying the bin size, as you are):

hist_xy=hist_nd(transpose([[x],[y]]),[0.05,0.05],$
min=[min(x),min(y)], reverse_indices=ri)

I would do this, where I add half a bin size to put the X and Y vector
values in the center of the bin:

dims = Size(hist_xy, /Dimensions)
xvector = Findgen(dims[0])*0.05 + Min(x) + 0.025
yvector = Findgen(dims[1])*0.05 + Min(y) + 0.025

> when I write
> print, indicesz
> I will get just some number which I don't know what are they.

They are the indices of the Z values that were placed into that bin.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: binning a point clouds in the xy plane [message #87302 is a reply to message #87019] Thu, 23 January 2014 07:48 Go to previous message
Nafiseh Masoumzadeh is currently offline  Nafiseh Masoumzadeh
Messages: 10
Registered: June 2013
Junior Member
hello again,

I have a problem that my final result for my sample data in IDl, it is the same if i use this code in Matlab

http://www.mathworks.com/matlabcentral/fileexchange/41386-bi nning-a-point-cloud-3d-scattered-data-in-the-x-y-plane/all_f iles

or maybe it is not a good example to test how much the code written in Idl is correct?

for example my data have 10 elements, after bin i will get 9 elements and by using MATLAB code, I will get 8 elements.

regards,
Nafiseh
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Bar plotting in IDL
Next Topic: Color bar colors not matching Image colors

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

Current Time: Wed Oct 08 13:36:49 PDT 2025

Total time taken to generate the page: 0.00671 seconds