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

Home » Public Forums » archive » NaN problems
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
NaN problems [message #43584] Thu, 21 April 2005 06:37 Go to next message
David Lopez Pons is currently offline  David Lopez Pons
Messages: 8
Registered: July 2003
Junior Member
Hi everybody.
I have a problem detecting NaN values. When I write:

err=findgen(10)-5
res=err^2.5
print,res

NaN NaN NaN NaN NaN
0.00000 1.00000 5.65685 15.5885 32.0000

Until here everything is OK, but now i want to look for Nan values in my
result so I write:

print,where(res EQ !values.f_nan)
-1

I can see the NaN values in res. Why they are not equal to !values.f_nan?
Re: NaN problems [message #43703 is a reply to message #43584] Sat, 23 April 2005 12:48 Go to previous messageGo to next message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
David Fanning wrote:

> Y.T. writes:
>
>> I don't have access to IDL on a win-box, but I have a (potentially
>> stupid) question: On that page of yours where you write
>>
>> IDL> print, array ne array
>> 0 0 0 0 0
>>
>> have you tried the converse, i.e.
>>
>> IDL> print, array eq array
>>
>> ?
>>
>> I am asking since, while it is true that a NaN is not equal to a NaN it
>> does not seem to follow (to my wrinkled brain) that a NaN is
>> necessarily UNequal to a NaN.
>>
>> In your version you test for the latter, and I'm kinda curious what
>> would happen if you tried the former...
>
> Well, looks like some things have changed since that
> article was written. Here is what I get in IDL 6.1 on Windows:
>
> IDL> a = [ 1.0, 2.0, !Values.F_NAN, 4.0, !Values.F_NAN ]
> IDL> print, a ne a
> 0 0 1 0 1
> % Program caused arithmetic error: Floating illegal operand
> IDL> print, a eq a
> 1 1 0 1 0
> % Program caused arithmetic error: Floating illegal operand
>
> Consistent, anyway. :-)
>
> Cheers,
>
> David

I got the same result without the warnings on the linux Version.
Probably we both should try it with the actual 6.1.1 version. For windows
it's a 2MB download and I don't know why it is for linux 60MB. ;-)

cheers

Reimar



--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
Re: NaN problems [message #43725 is a reply to message #43584] Fri, 22 April 2005 20:38 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Y.T. writes:

> I don't have access to IDL on a win-box, but I have a (potentially
> stupid) question: On that page of yours where you write
>
> IDL> print, array ne array
> 0 0 0 0 0
>
> have you tried the converse, i.e.
>
> IDL> print, array eq array
>
> ?
>
> I am asking since, while it is true that a NaN is not equal to a NaN it
> does not seem to follow (to my wrinkled brain) that a NaN is
> necessarily UNequal to a NaN.
>
> In your version you test for the latter, and I'm kinda curious what
> would happen if you tried the former...

Well, looks like some things have changed since that
article was written. Here is what I get in IDL 6.1 on Windows:

IDL> a = [ 1.0, 2.0, !Values.F_NAN, 4.0, !Values.F_NAN ]
IDL> print, a ne a
0 0 1 0 1
% Program caused arithmetic error: Floating illegal operand
IDL> print, a eq a
1 1 0 1 0
% Program caused arithmetic error: Floating illegal operand

Consistent, anyway. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: NaN problems [message #43777 is a reply to message #43584] Mon, 25 April 2005 16:51 Go to previous messageGo to next message
yp is currently offline  yp
Messages: 42
Registered: February 2005
Member
David Lopez Pons wrote:
> Hi everybody.
> I have a problem detecting NaN values. When I write:
>
> err=findgen(10)-5
> res=err^2.5
> print,res
>
> NaN NaN NaN NaN NaN
> 0.00000 1.00000 5.65685 15.5885 32.0000
>
> Until here everything is OK, but now i want to look for Nan values in
my
> result so I write:
>
> print,where(res EQ !values.f_nan)
> -1
>
> I can see the NaN values in res. Why they are not equal to
!values.f_nan?

Use
print,where(FINITE(res) EQ 0)

instead. FINITE returns 1 or 0 if the argument is True (Finite) or
False (NaN or Inf) respectively.
Alternatively you can use:
print,where(FINITE(res,/NAN) EQ 1)

yas
Re: NaN problems [message #43778 is a reply to message #43584] Mon, 25 April 2005 16:49 Go to previous messageGo to next message
yp is currently offline  yp
Messages: 42
Registered: February 2005
Member
David Lopez Pons wrote:
> Hi everybody.
> I have a problem detecting NaN values. When I write:
>
> err=findgen(10)-5
> res=err^2.5
> print,res
>
> NaN NaN NaN NaN NaN
> 0.00000 1.00000 5.65685 15.5885 32.0000
>
> Until here everything is OK, but now i want to look for Nan values in
my
> result so I write:
>
> print,where(res EQ !values.f_nan)
> -1
>
> I can see the NaN values in res. Why they are not equal to
!values.f_nan?

Use
print,where(FINITE(res) EQ 0)

instead. FINITE returns 1 or 0 if the argument is True (Finite) or
False (NaN or Inf) respectively.
Alternatively you can use:
print,where(FINITE(res,/NAN) EQ 1)

yas
Re: NAN Problem [message #69392 is a reply to message #43584] Thu, 14 January 2010 00:49 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
David Fanning schrieb:
> Folks,
>
> Consider this sequence of commands on my IDL 7.0.1
> LINUX version.
>
> IDL> a = Findgen(11)
> IDL> a[0] = !Values.F_NAN
> IDL> Print, Min(a), Max(a)
> NaN NaN
> IDL> b = Findgen(11)
> IDL> b[1] = !Values.F_NAN
> IDL> Print, Min(b), Max(b)
> 0.00000 10.00000
>
> What do you make of that? This is giving me a great
> deal of touble today while trying to elminate bad
> values from an image. :-(
>
> I have the same results with my Windows IDL 7.1.2
> version, except I do get a warning about a floating
> illegal operand with variable b, which I don't get
> on LINUX.
>
> Cheers,
>
> David
>
>
>

Hi David

For some reason the nan keyword was introduced

NAN

Set this keyword to cause the routine to check for occurrences of the
IEEE floating-point values NaN or Infinity in the input data. Elements
with the value NaN or Infinity are treated as missing data. (See Special
Floating-Point Values (Application Programming) for more information on
IEEE floating-point values.)

IDL> print, min(a,/nan)
1.00000
IDL> print, min(b,/nan)
0.00000


I try to avoid nan values.

Because not all operators do have the possibility to set nan operations
by a keyword. Frank has added some
http://www.fz-juelich.de/icg/icg-1/idl_icglib/idl_source/idl _work/fh_lib/f_ge.pro
functions because he likes nan.

cheers
Reimar
Re: NAN Problem [message #69394 is a reply to message #43584] Wed, 13 January 2010 16:15 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Jan 13, 10:00 pm, "R.G. Stockwell" <noem...@please.com> wrote:
> i swear i used to get nan as a the result of that.
> I do get a :
> % Program caused arithmetic error: Floating illegal operand
>
> after that min(b) call.  But now I am worried about how
> invalid that result is (and how diligent i have been in using
> nan keywords).

Same here. It is probably one of the reasons I once had some
difficulty writing a reader/writer to a file format (ISIS cubes, in
case anyone is interested) which has several special values, that
could be translated to NaN.
Re: NAN Problem [message #69395 is a reply to message #43584] Wed, 13 January 2010 16:00 Go to previous message
R.G.Stockwell is currently offline  R.G.Stockwell
Messages: 163
Registered: October 2004
Senior Member
"David Fanning" <news@dfanning.com> wrote in message
news:MPG.25b7d9955ac199e398969e@news.giganews.com...
> Folks,
>
> Consider this sequence of commands on my IDL 7.0.1
> LINUX version.
>
> IDL> a = Findgen(11)
> IDL> a[0] = !Values.F_NAN
> IDL> Print, Min(a), Max(a)
> NaN NaN
> IDL> b = Findgen(11)
> IDL> b[1] = !Values.F_NAN
> IDL> Print, Min(b), Max(b)
> 0.00000 10.00000
>
> What do you make of that?

HOLY CRAP!!!

i swear i used to get nan as a the result of that.
I do get a :
% Program caused arithmetic error: Floating illegal operand

after that min(b) call. But now I am worried about how
invalid that result is (and how diligent i have been in using
nan keywords).


cheers,
bob
Re: NAN Problem [message #69398 is a reply to message #43584] Wed, 13 January 2010 13:00 Go to previous message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Wed, 13 Jan 2010, David Fanning wrote:

> Consider this sequence of commands on my IDL 7.0.1
> LINUX version.
>
> IDL> a = Findgen(11)
> IDL> a[0] = !Values.F_NAN
> IDL> Print, Min(a), Max(a)
> NaN NaN
> IDL> b = Findgen(11)
> IDL> b[1] = !Values.F_NAN
> IDL> Print, Min(b), Max(b)
> 0.00000 10.00000
>
> What do you make of that? This is giving me a great
> deal of touble today while trying to elminate bad
> values from an image. :-(
>

The first array element causes the difference. You can reproduce the
results:

min=a[0]
max=a[0]
for j=1,10 do begin
if a[j] lt min then min=a[j]
if a[j] gt max then max=a[j]
endfor


lt and gt are not defined for NaNs, they always return 0:

x=0.0
y=!Values.F_NAN
help, x lt y, x eq y, x gt y

<Expression> BYTE = 0
<Expression> BYTE = 0
<Expression> BYTE = 0


regards,
lajos
Re: NAN Problem [message #69399 is a reply to message #43584] Wed, 13 January 2010 12:59 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Jan 13, 6:23 pm, David Fanning <n...@dfanning.com> wrote:
> Folks,
>
> Consider this sequence of commands on my IDL 7.0.1
> LINUX version.
>
>    IDL> a = Findgen(11)
>    IDL> a[0] = !Values.F_NAN
>    IDL> Print, Min(a), Max(a)
>            NaN   NaN
>    IDL> b = Findgen(11)
>    IDL> b[1] = !Values.F_NAN
>    IDL> Print, Min(b), Max(b)
>           0.00000   10.00000
>
> What do you make of that? This is giving me a great
> deal of touble today while trying to elminate bad
> values from an image. :-(
>
> I have the same results with my Windows IDL 7.1.2
> version, except I do get a warning about a floating
> illegal operand with variable b, which I don't get
> on LINUX.

Interesting. I found the same here, with 7.1.1 in Linux. I had never
noticed this behavior before.

I do not know how the min and max functions were implemented, but this
would be the result of one algorithms that could be used for it. Since
NaN does not compare larger or smaller than anything, the following
would produce the same result:

function min_test,a
res=a[0]
for i=1,n_elements(a)-1 do if a[i] lt res then res=a[i]
return,res
end

When the NaN is the first element, it will be set as the initial value
for the minimum, and since nothing is smaller, it will be kept as the
result. Conversely, if the first value is not NaN, no NaN value that
comes after will be smaller than it, so an NaN would not replace the
minimum.
Re: NAN Problem [message #69400 is a reply to message #43584] Wed, 13 January 2010 12:39 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
jeanh writes:

> heu, hum.... the help for min and max says "Note
> If the MIN function is run on an array containing NaN values and the NAN
> keyword is not set, an invalid result will occur."

I was sort of hoping the "invalid result" would make
itself known to me. :-(

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: NAN Problem [message #69402 is a reply to message #43584] Wed, 13 January 2010 12:28 Go to previous message
jeanh is currently offline  jeanh
Messages: 79
Registered: November 2009
Member
David Fanning wrote:
> Folks,
>
> Consider this sequence of commands on my IDL 7.0.1
> LINUX version.
>
> IDL> a = Findgen(11)
> IDL> a[0] = !Values.F_NAN
> IDL> Print, Min(a), Max(a)
> NaN NaN
> IDL> b = Findgen(11)
> IDL> b[1] = !Values.F_NAN
> IDL> Print, Min(b), Max(b)
> 0.00000 10.00000
>
> What do you make of that? This is giving me a great
> deal of touble today while trying to elminate bad
> values from an image. :-(
>
> I have the same results with my Windows IDL 7.1.2
> version, except I do get a warning about a floating
> illegal operand with variable b, which I don't get
> on LINUX.
>
> Cheers,
>
> David

hi,

heu, hum.... the help for min and max says "Note
If the MIN function is run on an array containing NaN values and the NAN
keyword is not set, an invalid result will occur."

Jean
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: NAN Problem
Next Topic: Re: aggregate pixel values within shapes or another raster

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

Current Time: Wed Oct 08 13:32:03 PDT 2025

Total time taken to generate the page: 0.00750 seconds