binning a point clouds in the xy plane [message #87011] |
Thu, 19 December 2013 13:53  |
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   |
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   |
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   |
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 #87019 is a reply to message #87017] |
Fri, 20 December 2013 16:06   |
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.")
|
|
|
|