COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Variable sized bins in histogram, or find a bounding lat/lon box

• Email
• Follow

```All, ( well, JD mostly, but feel free to jump in. )

I'm trying to solve a problem that seems particularly suited to
histogram. The main idea is that I'm trying to find the surrounding 4
corner points of a given sample point within a semi-regular lat-lon
grid. (Note: not the 4 nearest-neighbors, they must be the closest 4
points in a rectangle that enclose the target point.)

I'll try to break it down to its most simple.  I know that I'll have
some number of latitudes and another number of longitudes that
represent the centers of grid-cells via their intersections. I don't
know that they will be evenly spaced (note: that seemed key in my
inability to come up with a fast solution).

lats = [10, 20, 25, 30, 40]
lons = [100, 120, 130, 135, 140, 155]

I'll also have a set of lat/lon points that do not fall on a regular
lat/lon grid.

target_lats = [ 10.5, 39.1,   29., ... ]
target_lons = [ 142.3, 130, 152.3, ... ]

I'd like to know the lat/lon values of the initial locations that
surround my target points.

So for the first target point [10.5, 142.3], I'd hope to return:

[20,140]   [20,155]

[10,140]   [10,155]

Or in fact, since I know the lats and lons are already sorted.
Returning, indices [0 & 4] would give me the information I'm after.

I think I can do this with two histograms one in lat one in lon.  It's
along the lines of ... if I can histogram the initial lats into a
histogram with no more than 1 element per bin.  And then histogram all
of my target_lats with the same histogram min, max, and binsize.  I
should through the beauty and horror of reverse indices, be able to
back out the indices of the target.  But I'm just not quite there in
full thought process.

Does anyone have a brilliant idea? I've had a sleep on this already
not be the best way to solve this problem.  I'm going to proceed with
a "where" solution which may be slow, but I understand it.  But as an
intellectual puzzle, I'd like to see how someone can bin data into
variable sized bins via histogram.  In the final breakdown, that's all
I'm trying to do right?

lats = [10, 20, 25, 30, 40]

Bins = [[-inf, 15], (15, 22.5], (22.5 , 27.5], (27.5, 35], (35, +Inf]]

Right?

Any help is appreciated,
Thanks.
Matt

--
Matthew Savoie  -  Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785   http://nsidc.org

```
 0
Reply savoie (90) 4/11/2007 2:19:06 PM

See related articles to this posting

```Because the grid is orthogonal and sorted, you could try

res1=value_locate(lats,target_lats)
res2=value_locate(lons,target_lons)

IDL> print,res1,res2
0           3           2
4           2           4

Is that what you need?

Ciao,
Paolo

Matt wrote:
> All, ( well, JD mostly, but feel free to jump in. )
>
> I'm trying to solve a problem that seems particularly suited to
> histogram. The main idea is that I'm trying to find the surrounding 4
> corner points of a given sample point within a semi-regular lat-lon
> grid. (Note: not the 4 nearest-neighbors, they must be the closest 4
> points in a rectangle that enclose the target point.)
>
> I'll try to break it down to its most simple.  I know that I'll have
> some number of latitudes and another number of longitudes that
> represent the centers of grid-cells via their intersections. I don't
> know that they will be evenly spaced (note: that seemed key in my
> inability to come up with a fast solution).
>
> lats = [10, 20, 25, 30, 40]
> lons = [100, 120, 130, 135, 140, 155]
>
>
> I'll also have a set of lat/lon points that do not fall on a regular
> lat/lon grid.
>
> target_lats = [ 10.5, 39.1,   29., ... ]
> target_lons = [ 142.3, 130, 152.3, ... ]
>
>
> I'd like to know the lat/lon values of the initial locations that
> surround my target points.
>
> So for the first target point [10.5, 142.3], I'd hope to return:
>
> [20,140]   [20,155]
>
> [10,140]   [10,155]
>
>
> Or in fact, since I know the lats and lons are already sorted.
> Returning, indices [0 & 4] would give me the information I'm after.
>
>
> I think I can do this with two histograms one in lat one in lon.  It's
> along the lines of ... if I can histogram the initial lats into a
> histogram with no more than 1 element per bin.  And then histogram all
> of my target_lats with the same histogram min, max, and binsize.  I
> should through the beauty and horror of reverse indices, be able to
> back out the indices of the target.  But I'm just not quite there in
> full thought process.
>
> Does anyone have a brilliant idea? I've had a sleep on this already
> not be the best way to solve this problem.  I'm going to proceed with
> a "where" solution which may be slow, but I understand it.  But as an
> intellectual puzzle, I'd like to see how someone can bin data into
> variable sized bins via histogram.  In the final breakdown, that's all
> I'm trying to do right?
>
>
> lats = [10, 20, 25, 30, 40]
>
> Bins = [[-inf, 15], (15, 22.5], (22.5 , 27.5], (27.5, 35], (35, +Inf]]
>
> Right?
>
>
> Any help is appreciated,
> Thanks.
> Matt
>
>
>
> --
> Matthew Savoie  -  Scientific Programmer
> National Snow and Ice Data Center
> (303) 735-0785   http://nsidc.org
>
```
 0
Reply pgrigis (171) 4/11/2007 4:13:09 PM

```On Apr 11, 10:13 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
> Because the grid is orthogonal and sorted, you could try
>
> res1=value_locate(lats,target_lats)
> res2=value_locate(lons,target_lons)
>
> IDL> print,res1,res2
>             0           3           2
>             4           2           4
>
> Is that what you need?

Wow, it's easy to find that solution now that I know the keyword
"value_locate".  That was incredibly helpful and exactly what I
needed.  I
just grepped my entire library of idl programs and I've never once
used that
routine.  Now that I've got a hammer, maybe everything will look like
a nail?

Thanks so much.

Matt

--
Matthew Savoie  -  Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785   http://nsidc.org

```
 0
Reply savoie (90) 4/11/2007 4:49:52 PM

```On Apr 11, 5:49 pm, "Matt" <sav...@nsidc.org> wrote:
> On Apr 11, 10:13 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
>
> > Because the grid is orthogonal and sorted, you could try
>
> > res1=value_locate(lats,target_lats)
> > res2=value_locate(lons,target_lons)
>
> > IDL> print,res1,res2
> >             0           3           2
> >             4           2           4
>
> > Is that what you need?
>
> Wow, it's easy to find that solution now that I know the keyword
> "value_locate".  That was incredibly helpful and exactly what I
> needed.  I
> just grepped my entire library of idl programs and I've never once
> used that
> routine.  Now that I've got a hammer, maybe everything will look like
> a nail?
>
> Thanks so much.
>
> Matt
>
> --
> Matthew Savoie  -  Scientific Programmer
> National Snow and Ice Data Center
> (303) 735-0785  http://nsidc.org

Be aware that lats, lons must be monotonically increasing/decreasing
vectors in this case!

```
 0

```On Wed, 11 Apr 2007 09:49:52 -0700, Matt wrote:

> On Apr 11, 10:13 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
>> Because the grid is orthogonal and sorted, you could try
>>
>> res1=value_locate(lats,target_lats)
>> res2=value_locate(lons,target_lons)
>>
>> IDL> print,res1,res2
>>             0           3           2
>>             4           2           4
>>
>> Is that what you need?
>
> Wow, it's easy to find that solution now that I know the keyword
> "value_locate".  That was incredibly helpful and exactly what I
> needed.  I
> just grepped my entire library of idl programs and I've never once
> used that
> routine.  Now that I've got a hammer, maybe everything will look like
> a nail?

Yep, value_locate is what you want.  Histogram works only with fixed bin
sizes, so you'd have to resort to rescaling either the bins or the data
points non homogenously to make the match.

JD

```
 0
Reply jdsmith (626) 4/12/2007 7:28:26 PM

4 Replies
38 Views

Similar Articles

12/6/2013 3:29:48 AM
page loaded in 55887 ms. (0)