More histogram magic help please! [message #92952] |
Fri, 01 April 2016 03:12  |
rjp23
Messages: 97 Registered: June 2010
|
Member |
|
|
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
|
|
|
Re: More histogram magic help please! [message #92960 is a reply to message #92952] |
Fri, 01 April 2016 15:35  |
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
|
|
|