Re: Variable sized bins in histogram, or find a bounding lat/lon box [message #53451] |
Thu, 12 April 2007 12:28 |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
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
|
|
|
Re: Variable sized bins in histogram, or find a bounding lat/lon box [message #53455 is a reply to message #53451] |
Thu, 12 April 2007 06:59  |
yp
Messages: 42 Registered: February 2005
|
Member |
|
|
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!
|
|
|
Re: Variable sized bins in histogram, or find a bounding lat/lon box [message #53470 is a reply to message #53455] |
Wed, 11 April 2007 09:49  |
Matt[2]
Messages: 69 Registered: March 2007
|
Member |
|
|
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
|
|
|
Re: Variable sized bins in histogram, or find a bounding lat/lon box [message #53471 is a reply to message #53470] |
Wed, 11 April 2007 09:13  |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
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
> and the more I write and think about this, the more I think this might
> 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
>
|
|
|