[Thread Prev][Thread Next][Index]

Re: [ferret_users] how to count the number of irregularly-spaced observations in each gridbox



Billy,
You could try something along the lines of

!put points into 1x1 bins on (0,2]x(0,2]

! here are the points we want to bin

let xvals=zsequence({ 0.1, 2.0, 0.2 })
let yvals=zsequence({ 0.1, 2.0, 0.2 })

! Define our bounds Note promotion to 2D

let xl= i[i=1:2]-1+0*xvals
let xh= i[i=1:2]+0*xvals
let yl= j[j=1:2]-1+0*xvals
let yh= j[j=1:2]+0*xvals

let isinboxx = if ( xvals le xh and xvals gt xl ) then 1 else 0
let isinboxy = if ( yvals le yh and yvals gt yl ) then 1 else 0

let isinbothboxes = isinboxx*isinboxy
let numinbox = isinbothboxes[z=@sum]

list numinbox

            VARIABLE : ISINBOTHBOXES[Z=@SUM]
             SUBSET   : 2 by 2 points (X-Y)
             Z        : 0.5 to 3.5
             1      2    
             1      2
 1   / 1:  2.000  0.000
 2   / 2:  0.000  1.000

Russ

On Thursday 01 September 2011 15:23, William S. Kessler wrote:
> I have a long list of data triplets (x,y,value) that I am putting on a  
> regular grid. No problem doing that, but how can I count the number of  
> data points that fall in each gridbox?
> 
> I want to end up with a gridded field whose values are the number of  
> the original (x,y) points within each box.
> 
> It seems like a simple task, but I can't think of a way to do it  
> without a (double) repeat loop, or sorting and writing data out  
> (twice). Ugly.
> 
> Anyone have a straightforward way to do this?
> 
> Frustratingly, the function SCAT2GRID_BIN_XY produces the bin-average.  
> To do that it must compute the number of points in each bin. That  
> number should be available to the user.
> 
> Thanks ... Billy K
> 


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement