comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » More histogram magic help please!
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: More histogram magic help please! [message #92960 is a reply to message #92952] Fri, 01 April 2016 15:35 Go to previous message
Yngvar Larsen is currently offline  Yngvar Larsen
Messages: 134
Registered: January 2010
Senior Member
On Friday, 1 April 2016 12:12:46 UTC+2, rj...@le.ac.uk wrote:
> I still haven't quite got my head around all the histogram magic that's possible but fairly sure it'll massively help me speed this up.
>
>
> for i=0L, n_elements(lons)-1 do begin
> for j=0L, n_elements(lats)-1 do begin
>
> find=where(longitude GE lons[i] and longitude LT lons[i]+1 AND $
> latitude GE lats[j] and latitude LT lats[j]+1)
>
> if find[0] NE -1 then assigned_value[find]=data[i,j]
>
> endfor
> endfor
>
> I have a large 2 million+ element 1D array that has a latitude/longitude associated with each point.
>
> I also have a second 2D gridded array and I want to work out which of the grid boxes each value of the large array falls into.
>
> I just can't seem to get the histogram syntax quite right!
>
> Thanks in advance

There are two cases:

1) Regular bin size

This is quite trivial:

dlon = lons[1]-lons[0]
dlat = lats[1]-lats[0]
ilon = (longitude-lons[0])/dlon
ilat = (latitude-lats[0])/dlat
assigned_value = data[ilon, ilat]

2) Irregular bin size

For binning into bins of different sizes, you want VALUE_LOCATE.

http://www.harrisgeospatial.com/docs/VALUE_LOCATE.html

ilon = value_locate(lons, longitude)
ilat = value_locate(lats, latitude)
assigned_value = data[ilon, ilat]

Neither of 1) and 2) try to detect out of bounds values, nor do they handle bins that cross the date line. This is left as an exercise to the reader :)

--
Yngvar
[Message index]
 
Read Message
Read Message
Previous Topic: Coyote Returns
Next Topic: JSON file manipulation in idl

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 17 15:34:03 PDT 2025

Total time taken to generate the page: 0.80044 seconds