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

Home » Public Forums » archive » replacing "NAN" values using interpolation in IDL
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
replacing "NAN" values using interpolation in IDL [message #82789] Thu, 17 January 2013 02:02 Go to next message
abc is currently offline  abc
Messages: 46
Registered: March 2011
Member
Dear all, I have an data array. I have many "NaN" values. I want to replace those "NaN" values by the nearby values either using interpolation. Is there any way to do that in IDL.

Thanks in advance
Re: replacing "NAN" values using interpolation in IDL [message #82951 is a reply to message #82789] Wed, 30 January 2013 01:18 Go to previous messageGo to next message
Carsten Lechte is currently offline  Carsten Lechte
Messages: 124
Registered: August 2006
Senior Member
On 30/01/13 03:37, Jeremy Bailin wrote:
> I must admit, the silliness factor is the main reason I use the "data
> EQ data" convention. :-)

Alas, no silliness without punishment: this method fails on windows
IDL <=5.6, see last entry on
<http://www.idlcoyote.com/math_tips/nans.html>. Fortunately, that
version is so old, that even MY place of employment has a newer one.


chl
Re: replacing "NAN" values using interpolation in IDL [message #82952 is a reply to message #82789] Tue, 29 January 2013 19:12 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeremy Bailin writes:

> I must admit, the silliness factor is the main reason I use the "data EQ
> data" convention. :-)

Ha, ha! I love this newsgroup. ;-)

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: replacing "NAN" values using interpolation in IDL [message #82953 is a reply to message #82789] Tue, 29 January 2013 18:37 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
> ; Dick prefers "Finite(data)" to "data EQ data" for finding non-NaN :-)

I must admit, the silliness factor is the main reason I use the "data EQ
data" convention. :-)

-Jeremy.
Re: replacing "NAN" values using interpolation in IDL [message #82954 is a reply to message #82789] Tue, 29 January 2013 16:47 Go to previous messageGo to next message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Dear idlhelp,

That's even easier, assuming that you mean that your data 'x' values are evenly spaced, and can be considered to be [0, 1, 2, ...]

Building on Jeremy's work:

; sample data
data = [0., !values.f_nan, 10., 15., !values.f_nan, !values.f_nan, 5., 4., 5.]

; figure out where there are NaNs and where the useful data are
; Dick prefers "Finite(data)" to "data EQ data" for finding non-NaN :-)
gooddata = where(Finite(data), ngooddata, comp=baddata, ncomp=nbaddata)

; interpolate at the locations of the bad data using the good data
if nbaddata gt 0 then data[baddata] = interpol(data[gooddata], gooddata, baddata)

Hope this helps!
-Dick

Dick Jackson Software Consulting
Victoria, BC, Canada
www.d-jackson.com

On Monday, January 28, 2013 9:27:36 AM UTC-8, idlhelp wrote:
> On Thursday, January 17, 2013 4:05:11 PM UTC+1, Jeremy Bailin wrote:
>
>> On 1/17/13 4:02 AM, idlhelp wrote:

>>> Dear all, I have an data array. I have many "NaN" values. I want to replace those "NaN" values by the nearby values either using interpolation. Is there any way to do that in IDL.
>>>
>>> Thanks in advance
>
>> Yes, there is.
>>
>> Oh, you want to know how? ;-)
>>
>> I would do something like this, if I had an array of locations x and a
>> data array data:
>>
>> ; sample data
>> x = [1., 2., 3., 5., 7., 7.5, 9., 12., 12.1]
>> data = [0., !values.f_nan, 10., 15., !values.f_nan, !values.f_nan, 5.,
>> 4., 5.]
>>
>> ; figure out where there are NaNs and where the useful data are
>> gooddata = where(data eq data, ngooddata, $
>> comp=baddata, ncomp=nbaddata)
>>
>> ; interpolate at the locations of the bad data using the good data
>> if nbaddata gt 0 then begin
>> data[baddata] = interpol(data[gooddata], x[gooddata], x[baddata])
>> endif
>
>> -Jeremy.
>
> Thanks Jeremy, but the problem I am having is that I don't have any sample data 'x'. I have only 'data' and want to use that 'data' file again for interpolating and replacing the NaN value. Any Idea how to do that.
>
> thanks
Re: replacing "NAN" values using interpolation in IDL [message #83869 is a reply to message #82951] Thu, 11 April 2013 07:31 Go to previous message
Chang Liao is currently offline  Chang Liao
Messages: 5
Registered: December 2012
Junior Member
On Wednesday, January 30, 2013 4:18:53 AM UTC-5, Carsten Lechte wrote:
> On 30/01/13 03:37, Jeremy Bailin wrote:
>
>> I must admit, the silliness factor is the main reason I use the "data
>
>> EQ data" convention. :-)
>
>
>
> Alas, no silliness without punishment: this method fails on windows
>
> IDL <=5.6, see last entry on
>
> <http://www.idlcoyote.com/math_tips/nans.html>. Fortunately, that
>
> version is so old, that even MY place of employment has a newer one.
>
>
>
>
>
> chl

Yh, I have read that article as well. This is a pretty interesting topic of handling NAN in data.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: SMOOTH not smoothing...
Next Topic: Re: run-time function creation

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

Current Time: Wed Oct 08 13:36:46 PDT 2025

Total time taken to generate the page: 0.00816 seconds