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

Home » Public Forums » archive » Interpolation problem
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
Interpolation problem [message #36824] Mon, 03 November 2003 03:21 Go to next message
sdj is currently offline  sdj
Messages: 20
Registered: November 2003
Junior Member
Dear All,

I have a problem with interpolating data, neither of the IDL functions
INTERPOLATE/INTERPOL/BILINEAR seem to work.

I have a 2-d array on a regular grid with valid values which are all
+ve. Non valid values are set to -9999 and some 'intermediate' values
I
would like to interpolate are set to -1.
How can I interpolate over the x, y grid the 'intermediate' values set
to -1 without taking into account the non-valid values ?

I've tried the following, but it does not work (my output values are
exactly the same as my input values).

;a is a fltarr(x, y) -> 'a' being meteorological values at 'x' lon
;and 'y' lat
nx = n_elements(a(*, 0)) ; no. elements x
ny = n_elements(a(0, *)) ; no. elements y
d = where(a EQ -1, count1) ; find 1-d index of values to be
interpolated
xd = d mod nx ;x index of values to be interpolated
yd = d / nx ; y index of values to be interpolated

;I "try" to have the a(xd, yd) values interpolated, but my output
;values are exactly the same as my input values
int_val = INTERPOLATE(a, xd, yd, missing = -9999)

INTERPOL and BILINEAR don't work either, have you got any idea of how
to do this sort of operation ?

Thanks in advance for the help.

Best Regards,
Pepe
Re: Interpolation problem [message #36907 is a reply to message #36824] Tue, 04 November 2003 03:26 Go to previous message
sdj is currently offline  sdj
Messages: 20
Registered: November 2003
Junior Member
Thank you for the help, yes your program indeed does the trick.

The only minor thing I had to change was to set the valid data NE to
-1 AND NE to -9999 (see my original message), and then overwrite the
interpolated values of the -9999 indices with the original data.

Thus, I end up interpolating the missing values without taking into
account the non-valid ones.

PRO test2

; Make a data set
n = 100
data = SIN( FINDGEN(n,n)/n^2 )

; Missing data
mx = RANDOMU(1, n, /LONG) MOD n^2
data[mx] = -1

; Non-valid data
nv = RANDOMU(2, n, /LONG) MOD n^2
data[nv] = -9999

valid = WHERE(data NE -1 AND data NE -9999)
ix = valid MOD n
iy = valid / n

; Fill in missing data
TRIANGULATE,ix,iy,tr
new = TRIGRID(ix, iy, data[valid],tr, NX = n, NY = n)

;Reset non-valid values equal to -9999
new[nv] = data[nv]

Again, thanks for your help.

Hasta lluego,
Pepe

the_cacc@hotmail.com (trouble) wrote in message news:<5f9f0a23.0311031206.167c106a@posting.google.com>...
> sdj@tiscali.it (Pepe) wrote in message news:<56bc95a7.0311030321.42de483d@posting.google.com>...
>>
>> I have a 2-d array on a regular grid with valid values which are all
>> +ve. Non valid values are set to -9999 and some 'intermediate' values
>> I would like to interpolate are set to -1.
>
> It sounds like you may be mis-understanding the MISSING keyword in
> interpolate. In fact, you may want to be using different functions
> altogther: TRIANGULATE & TRIGRID.
>
> Try the program below and see if it's what you're looking for.
>
> Ciao.
>
> ;--------------------------------------------------
> PRO test
>
> ; Make a data set
> n = 100
> data = SIN( FINDGEN(n,n)/n^2 )
>
> ; Missing data
> mx = RANDOMU(1,n,/LONG) MOD n^2
> data[mx] = -1
> valid = WHERE(data NE -1)
> ix = valid MOD n
> iy = valid / n
>
> ; Fill in missing data
> TRIANGULATE,ix,iy,tr
> new = TRIGRID(ix,iy,data[valid],tr,NX=n,NY=n)
>
> ; Display.
> tvscl,data >0
> tvscl,new
>
> END
> ;------------------------------------------------
Re: Interpolation problem [message #36913 is a reply to message #36824] Mon, 03 November 2003 12:06 Go to previous message
the_cacc is currently offline  the_cacc
Messages: 104
Registered: October 2001
Senior Member
sdj@tiscali.it (Pepe) wrote in message news:<56bc95a7.0311030321.42de483d@posting.google.com>...
>
> I have a 2-d array on a regular grid with valid values which are all
> +ve. Non valid values are set to -9999 and some 'intermediate' values
> I would like to interpolate are set to -1.

It sounds like you may be mis-understanding the MISSING keyword in
interpolate. In fact, you may want to be using different functions
altogther: TRIANGULATE & TRIGRID.

Try the program below and see if it's what you're looking for.

Ciao.

;--------------------------------------------------
PRO test

; Make a data set
n = 100
data = SIN( FINDGEN(n,n)/n^2 )

; Missing data
mx = RANDOMU(1,n,/LONG) MOD n^2
data[mx] = -1
valid = WHERE(data NE -1)
ix = valid MOD n
iy = valid / n

; Fill in missing data
TRIANGULATE,ix,iy,tr
new = TRIGRID(ix,iy,data[valid],tr,NX=n,NY=n)

; Display.
tvscl,data >0
tvscl,new

END
;------------------------------------------------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Keywords/Parameters and Common Blocks
Next Topic: Keywords/Parameters and Common Blocks

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

Current Time: Wed Oct 08 13:07:55 PDT 2025

Total time taken to generate the page: 0.00388 seconds