How to make IDL faster [message #36775] |
Tue, 28 October 2003 21:35  |
parkkw
Messages: 4 Registered: October 2003
|
Junior Member |
|
|
Hello
I write message first time.
If I want to compare trmm satellite data with ground point data,
I used to this line.
geo(0,207,2985) : trmm latitute
geo(1,*,*) : trmm longitute
lat : ground location(latitute)
lon : ground location(longitute)
rain : automatic weather system rainfall data
highf(0,207,2985) : trmm brightness temperature data
for i=0,207 do begin
for j=1200,1700 do begin
for k=0,di(0)-1 do begin
if geo(0,i,j) gt lat(k)-0.04 and geo(0,i,j) lt lat(k)+0.04 and $
geo(1,i,j) gt lon(k)-0.04 and geo(1,i,j) lt lon(k)+0.04 then begin
printf,lun3,loc(k),lon(k),lat(k),rain1(k),rain(k),highf(0,i, j)
endif
endfor
endfor
endfor
When I caculate 26 trmm data, I wait almost 2hour.
How can I change this program?
Help me.
|
|
|
|
|
Re: How to make IDL faster [message #36862 is a reply to message #36775] |
Wed, 29 October 2003 16:35   |
parkkw
Messages: 4 Registered: October 2003
|
Junior Member |
|
|
parkkw@mail1.pknu.ac.kr (Park Kyung Won) wrote in message news:<eceee805.0310282135.5448e3af@posting.google.com>...
> Hello
> I write message first time.
> If I want to compare trmm satellite data with ground point data,
> I used to this line.
>
> geo(0,207,2985) : trmm latitute
> geo(1,*,*) : trmm longitute
> lat : ground location(latitute)
> lon : ground location(longitute)
> rain : automatic weather system rainfall data
> highf(0,207,2985) : trmm brightness temperature data
>
> for i=0,207 do begin
> for j=1200,1700 do begin
> for k=0,di(0)-1 do begin
>
> if geo(0,i,j) gt lat(k)-0.04 and geo(0,i,j) lt lat(k)+0.04 and $
> geo(1,i,j) gt lon(k)-0.04 and geo(1,i,j) lt lon(k)+0.04 then begin
> printf,lun3,loc(k),lon(k),lat(k),rain1(k),rain(k),highf(0,i, j)
> endif
>
> endfor
> endfor
> endfor
>
> When I caculate 26 trmm data, I wait almost 2hour.
> How can I change this program?
> Help me.
Thank you for your answer.
I have mistake.
geo(0,*,*) : trmm latitute
geo(1,*,*) : trmm longitute
lat : ground location(latitute)
lon : ground location(longitute)
rain : automatic weather system rainfall data
highf(0,207,2985) : trmm brightness temperature data
k : number of ground station
|
|
|
Re: How to make IDL faster [message #36865 is a reply to message #36775] |
Wed, 29 October 2003 13:28   |
Ken Knapp
Messages: 14 Registered: April 2003
|
Junior Member |
|
|
My two cents:
Only loop over the rainfall data (k). Use rebin and reform to create
large (and constant) arrays, then simply difference the arrays to find
where the lat and lon matchup:
nelem = 207
nscan = 2985
trmmlat = reform(geo(0,*,*))
trmmlon = reform(geo(1,*,*))
trmmtb = reform(highf(0,*,*))
for k=0,di(0)-1 do begin
;remap the 1 lat value to match the trmmlat coordinates
lat = rebin(reform([lat(k)]),1,1),nelem,nscan)
lon = rebin(reform([lon(k)]),1,1),nelem,nscan)
match = where(abs(lat-trmmlat) lt 0.04 and $
abs(lon-trmmlon) lt 0.04,nmatch)
if (nmatch gt 0) then begin
for im=0,nmatch-1 do begin
print,loc(k),lon(k),lat(k),rain1(k),$
rain(k),trmmtb(match(im))
endfor
endif
endfor
Park Kyung Won wrote:
> Hello
> I write message first time.
> If I want to compare trmm satellite data with ground point data,
> I used to this line.
>
> geo(0,207,2985) : trmm latitute
> geo(1,*,*) : trmm longitute
> lat : ground location(latitute)
> lon : ground location(longitute)
> rain : automatic weather system rainfall data
> highf(0,207,2985) : trmm brightness temperature data
>
> for i=0,207 do begin
> for j=1200,1700 do begin
> for k=0,di(0)-1 do begin
>
> if geo(0,i,j) gt lat(k)-0.04 and geo(0,i,j) lt lat(k)+0.04 and $
> geo(1,i,j) gt lon(k)-0.04 and geo(1,i,j) lt lon(k)+0.04 then begin
> printf,lun3,loc(k),lon(k),lat(k),rain1(k),rain(k),highf(0,i, j)
> endif
>
> endfor
> endfor
> endfor
>
> When I caculate 26 trmm data, I wait almost 2hour.
> How can I change this program?
> Help me.
|
|
|
Re: How to make IDL faster [message #36867 is a reply to message #36775] |
Wed, 29 October 2003 11:42   |
mchinand
Messages: 66 Registered: September 1996
|
Member |
|
|
In article <4a097d6a.0310291118.2ceed6d5@posting.google.com>,
M. Katz <MKatz843@onebox.com> wrote:
>
> if geo(0,i,j) gt lat(k)-0.04 and geo(0,i,j) lt lat(k)+0.04 and $
> geo(1,i,j) gt lon(k)-0.04 and geo(1,i,j) lt lon(k)+0.04
>
> to this
>
> if (abs(geo(0,i,j) - lat(k)) LT 0.04) and $
> (abs(geo(1,i,j) - lon(k)) LT 0.04) then . . .
>
> Here I am thinking that you minimize the number of times you have to
> go to the geo() array and get the (0,i,j) element.
>
> M. Katz
Do both conditional clauses always get evaluated, even if the first one is false? If so,
it might be faster to add a second if statement:
if (abs(geo(0,i,j) - lat(k)) LT 0.04) then $
if (abs(geo(1,i,j) - lon(k)) LT 0.04) then print, loc(k), etc...
I haven't tried this on a large dataset, but it might be worth investigating.
--Mike
--
Michael Chinander
m-chinander@uchicago.edu
Department of Radiology
University of Chicago
|
|
|
Re: How to make IDL faster [message #36868 is a reply to message #36775] |
Wed, 29 October 2003 11:18   |
MKatz843
Messages: 98 Registered: March 2002
|
Member |
|
|
> for i=0,207 do begin
> for j=1200,1700 do begin
> for k=0,di(0)-1 do begin
>
> if geo(0,i,j) gt lat(k)-0.04 and geo(0,i,j) lt lat(k)+0.04 and $
> geo(1,i,j) gt lon(k)-0.04 and geo(1,i,j) lt lon(k)+0.04 then begin
> printf,lun3,loc(k),lon(k),lat(k),rain1(k),rain(k),highf(0,i, j)
> endif
>
> endfor
> endfor
> endfor
>
> How can I change this program?
> Help me.
This is minor, but you can get a small speed advantage by taking out
the begin...end where possible. For example your code could be
for i=0,207 do $
for j=1200,1700 do $
for k=0,di(0)-1 do $
if geo(0,i,j) gt lat(k)-0.04 and geo(0,i,j) lt lat(k)+0.04 and $
geo(1,i,j) gt lon(k)-0.04 and geo(1,i,j) lt lon(k)+0.04 $
then printf,lun3,loc(k),lon(k),lat(k),rain1(k),rain(k),highf(0,i, j)
It makes a small difference but it can help. You have to use
begin...end only when there is more than one line of code to execute.
Here, you can string them together.
You could change
if geo(0,i,j) gt lat(k)-0.04 and geo(0,i,j) lt lat(k)+0.04 and $
geo(1,i,j) gt lon(k)-0.04 and geo(1,i,j) lt lon(k)+0.04
to this
if (abs(geo(0,i,j) - lat(k)) LT 0.04) and $
(abs(geo(1,i,j) - lon(k)) LT 0.04) then . . .
Here I am thinking that you minimize the number of times you have to
go to the geo() array and get the (0,i,j) element.
M. Katz
|
|
|
|