Re: Arrays with NaN values [message #41253] |
Mon, 04 October 2004 16:58  |
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 #41266 is a reply to message #41258] |
Mon, 04 October 2004 10:08   |
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   |
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   |
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 #41347 is a reply to message #41253] |
Tue, 05 October 2004 09:13  |
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
|
|
|