<div dir="ltr">On Tue, Apr 5, 2016 at 9:48 AM, mpc <span dir="ltr"><<a href="mailto:matt.p.conte@gmail.com" target="_blank">matt.p.conte@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The idea is that I want to thin a large 2D buffer of x,y,z points to a given<br>
resolution by dividing the data into equal sized "cubes" (i.e. resolution is<br>
number of cubes along each axis) and averaging the points inside each cube<br>
(if any).<br></blockquote><div><br></div><div>are the original x,y,z points aranged along a nice even grid? or arbitrarily spaced?<br><br></div><div>if the former, I have Cython code that does that :-) I could dig it up, haven't used it in a while. or scikit.image might have something.<br><br></div><div>If the latter, then Ben is right -- you NEED a spatial index -- scipy.spatial.kdtree will probably do what you want, though it would be easier to use a sphere to average over than a cube.<br><br></div><div>Also, maybe Kernel Density Estimation could help here????<br></div><div><br><a href="https://jakevdp.github.io/blog/2013/12/01/kernel-density-estimation/">https://jakevdp.github.io/blog/2013/12/01/kernel-density-estimation/</a><br><br></div><div>Otherwise, you could use Cython to write a non-vectorized version of your below code -- it would be order NM where N is the number of "cubes" and M is the number of original points. I think, but would be a lot faster than the pure python.<br><br></div><div>-CHB<br><br></div>Here is where you would do the cython:<br>    while x_idx < max_x:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
        y_idx = min_y<br>
        while y_idx < max_y:<br>
            z_idx = min_z<br>
            while z_idx < max_z:<br>
                inside_block_points = np.where((x_buffer >= x_idx) &<br>
                                                             (x_buffer <=<br>
x_idx + x_block) &<br>
                                                             (y_buffer >=<br>
y_idx) &<br>
                                                             (y_buffer <=<br>
y_idx + y_block) &<br>
                                                             (z_buffer >=<br>
z_idx) &<br>
                                                             (z_buffer <=<br>
z_idx + z_block))<br></blockquote><div><br></div><div>instead of where, you could loop through all your points and find the ones inside your extents.<br></div><br></div><div class="gmail_quote">though now that I think about it -- you are mapping arbitrary points to a regular grid, so you only need to go through the points once, assigning each one to a bin, and then compute the average in each bin.<br><br></div><div class="gmail_quote">Is this almost a histogram?<br><br></div><div class="gmail_quote">-CHB<br><br></div><br clear="all"><br>-- <br><div class="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>