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

Home » Public Forums » archive » Re: Arrays with NaN values
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
Re: Arrays with NaN values [message #41253] Mon, 04 October 2004 16:58 Go to next message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
David Fanning wrote:
>
> I think I would try something like this:
>
> index = Where(Finite(image) EQ 0, count)
> IF count NE 0 THEN image[index] = 0

Note that the first line could *not* be replaced by the (apparently
reasonable)

index = Where(NOT Finite(image), count)

because the NOT operator and the WHERE function do not play well
together. The reasons are explained here:

http://www.dfanning.com/code_tips/bitwiselogical.html

In IDL 6.0 the logical not operator, "~" operator was introduced to
avoid this problem, so the following would work

index = Where(~Finite(image), count)

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
Re: Arrays with NaN values [message #41258 is a reply to message #41253] Mon, 04 October 2004 13:35 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Julio writes:

> Man, your code worked fine!
> Very simple, very efficient...

Well, it has taken my years to learn to program in the
IDL Way. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
Re: Arrays with NaN values [message #41266 is a reply to message #41258] Mon, 04 October 2004 10:08 Go to previous messageGo to next message
julio is currently offline  julio
Messages: 31
Registered: December 2003
Member
Man, your code worked fine!
Very simple, very efficient...

Thanks
Julio

David Fanning <david@dfanning.com> wrote in message news:<MPG.1bca8c1aa16488e5989691@news.frii.com>...
> Julio writes:
>
>> Ok, David, but I'm using this code to put zeros in the place of Nan
>>
>> Image=(0*(where(float(finite Image[*,*],/Nan)))) + $
>> Image*(where(NOT float(finite *Image[*,*],/Nan))))
>>
>> I guess I'm not using "where" function correctly, once it doesn't
>> work.
>
> Humm. Well that code looks a little strange. :-)
>
> I think I would try something like this:
>
> index = Where(Finite(image) EQ 0, count)
> IF count NE 0 THEN image[index] = 0
>
> Cheers,
>
> David
Re: Arrays with NaN values [message #41272 is a reply to message #41266] Sun, 03 October 2004 22:22 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Julio writes:

> Ok, David, but I'm using this code to put zeros in the place of Nan
>
> Image=(0*(where(float(finite Image[*,*],/Nan)))) + $
> Image*(where(NOT float(finite *Image[*,*],/Nan))))
>
> I guess I'm not using "where" function correctly, once it doesn't
> work.

Humm. Well that code looks a little strange. :-)

I think I would try something like this:

index = Where(Finite(image) EQ 0, count)
IF count NE 0 THEN image[index] = 0

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
Re: Arrays with NaN values [message #41277 is a reply to message #41272] Sun, 03 October 2004 13:36 Go to previous messageGo to next message
julio is currently offline  julio
Messages: 31
Registered: December 2003
Member
Ok, David, but I'm using this code to put zeros in the place of Nan

Image=(0*(where(float(finite Image[*,*],/Nan)))) + $
Image*(where(NOT float(finite *Image[*,*],/Nan))))

I guess I'm not using "where" function correctly, once it doesn't
work.
What could be the problem? I must retain the array size, I just need
to change Nan for zeros or other value.

Regards,
Julio


David Fanning <david@dfanning.com> wrote in message news:<MPG.1bc94a59bb2414b998968f@news.frii.com>...
> Julio writes:
>
>> I need to manipulate arrays with some NaN values inside. How can I put
>> zero values in the place of the NaN values??
>
> Here is an article that describes how to find them, so
> you can change them:
>
> http://www.dfanning.com/tips/check_nan.html
>
> Cheers,
>
> David
Re: Arrays with NaN values [message #41286 is a reply to message #41277] Sat, 02 October 2004 23:30 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Julio writes:

> I need to manipulate arrays with some NaN values inside. How can I put
> zero values in the place of the NaN values??

Here is an article that describes how to find them, so
you can change them:

http://www.dfanning.com/tips/check_nan.html

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http:/www.dfanning.com/
Phone: 970-221-0438, IDL Book Orders: 1-888-461-0155
Re: Arrays with NaN values [message #41347 is a reply to message #41253] Tue, 05 October 2004 09:13 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Mark Hadfield wrote:
> David Fanning wrote:
>
>>
>> I think I would try something like this:
>>
>> index = Where(Finite(image) EQ 0, count)
>> IF count NE 0 THEN image[index] = 0
>
>
> Note that the first line could *not* be replaced by the (apparently
> reasonable)
>
> index = Where(NOT Finite(image), count)
>
> because the NOT operator and the WHERE function do not play well
> together. The reasons are explained here:
>
> http://www.dfanning.com/code_tips/bitwiselogical.html
>
> In IDL 6.0 the logical not operator, "~" operator was introduced to
> avoid this problem,

Man, the C-loving types really did a number on IDL. RSI musta hired a boatload of CS grads
from the same school or something to implement the OO stuff. :o) [and, just in case
anyone is irony impaired, yes, I am kidding]

> so the following would work
>
> index = Where(~Finite(image), count)

I realise "~" is a complement operator but when I look at the code above, I think "where
the elements of IMAGE are *approximately* finite" ..... huh?

Gosh, I have that old'n'crusty feeling coming on again. Back to DF's blog for some
restorative therapy......

paulv
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Map_grid options
Next Topic: General 3D graphics advise required

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

Current Time: Fri Oct 10 06:54:17 PDT 2025

Total time taken to generate the page: 1.11946 seconds