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

Home » Public Forums » archive » IDL puzzle
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
IDL puzzle [message #1410] Sat, 20 November 1993 09:24
wolff is currently offline  wolff
Messages: 3
Registered: November 1993
Junior Member
I have an IDL puzzle for those interested.....

Suppose that you have data located via lat/lon, and want to average the
data into a larger grid. For example, compute the average rain rate in
N [deg] x N [deg] boxes over the area of the Amazon Basin given data
from a network of gauges.

The data is stored in the following arrays:

x = site_lat = fltarr(1000)
y = site_lon = fltarr(1000)
z = site_rate = fltarr(1000)


In IDL, an easy, but incredibly slow way to do this would be in a loop
such as the following (other variables added for clarity):

grid_size = 0.5

lat1 = -28
lat2 = -18
lon1 = -55
lon2 = -40

lon_pts = 0.
lat_pts = 0.
new_pts = 0

lon_pts = float(lon2-lon1)/grid_size
lat_pts = float(lat2-lat1)/grid_size
new_pts = lon_pts*lat_pts

count_0 = intarr(new_pts) ; # of non-zero rainrates reported
count = intarr(new_pts) ; Total number of rainrates reported
sum = fltarr(new_pts) ; Sum of rainrate reports
cavg = fltarr(new_pts) ; Conditional average (Avg Rain when raining)
uavg = fltarr(new_pts) ; Unconditional average (include 0's in avg)

ipts = 0
i=0.
j=0.
k=0


print,'Computing the rain averages over the new grid.....'
for i=float(lon1), float(lon2-grid_size), grid_size do begin
print,i
for j=float(lat1), float(lat2-grid_size), grid_size do begin
for k=0,num_sites-1 do begin
xx = x(k)
yy = y(k)
zz = z(k)
if( (xx ge i and xx lt i+grid_size) and $
(yy ge j and yy lt j+grid_size) ) then begin

if(zz lt flagged_data) then begin
sum(ipts) = sum(ipts) + zz
count(ipts) = count(ipts) + 1
if(zz lt 0.1) then count_0(ipts) = count_0(ipts) + 1
endif
endif
endfor
ipts = ipts + 1
endfor
endfor



I suppose there is a much faster way to do this. Using the where function?
I am somewhat new to IDL so would appreciate any tricks you may know of
to speed things up.


Thanks,

Dave
David B. Wolff
NASA/GSFC/910.1
Greenbelt, MD 20771 USA
wolff@echo.gsfc.nasa.gov
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: HDF's Vdata
Next Topic: Converting HPGL to IDL PS file

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

Current Time: Wed Oct 08 16:01:21 PDT 2025

Total time taken to generate the page: 0.00762 seconds