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

Home » Public Forums » archive » Re: BYTSCL and NAN keyword
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: BYTSCL and NAN keyword [message #38269] Tue, 02 March 2004 15:48 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kenneth P. Bowman writes:

> Sure there are, 2^8 different ways.

Yes, but all currently used to represent one of the
256 numbers. :-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: BYTSCL and NAN keyword [message #38270 is a reply to message #38269] Tue, 02 March 2004 15:18 Go to previous messageGo to next message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <MPG.1aae762bf27e19ee9896c4@news.frii.com>,
David Fanning <david@dfanning.com> wrote:

> Ken, they are *bytes*. They only have 8 little thingamajigs.
> There is not too much room for creativity here! :-)

Sure there are, 2^8 different ways.

Ken
Re: BYTSCL and NAN keyword [message #38272 is a reply to message #38270] Tue, 02 March 2004 14:07 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
JD Smith writes:

> I even go so far as to check if there are any
> non-finite values and use:
>
> b=bytscl(a,NAN=self.non_finite,TOP=254)+self.non_finite?self .finite:1

There you go! I should have known JD could still
work magic no matter how limited his materials. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: BYTSCL and NAN keyword [message #38273 is a reply to message #38272] Tue, 02 March 2004 13:32 Go to previous messageGo to next message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Tue, 02 Mar 2004 10:26:19 -0700, Kenneth Bowman wrote:

> In article <MPG.1aae6fc4ef56f7829896c3@news.frii.com>,
> David Fanning <david@dfanning.com> wrote:
>
>> Well, NANs are definitely floats (that is, they have a float-type
>> bit pattern). So it seems reasonable to me that if you are
>> trying to stuff it into a byte (which can only have values between
>> 0 and 255, that 0 is a good choice. (The only possible other
>> choice is 255, but that just turns your problem on its head.)
>>
>> I think what I would do is locate the NANs and save their
>> indices. Then scale my data into 255 colors (0 to 254), leaving
>> color index 255 for the NAN color (whatever that is). This will
>> take a couple of steps, but that's what IDL programs are for. :-)
>
> Right, I understand all that. I'm just trying to understand what the
> NAN keyword is good for.
>
> If you could say NAN = 255 (or 19, or whatever), instead of just /NAN,
> it would be of some use. That way the value that NANs become in the
> output could be distinguished from valid data.
>
> As it is, the NAN keyword is only of use if you are happy with NANs
> turning into valid data in the output (i.e., indistinguishable from
> small valid values).
>
> I have to consider this an error in the way the handling of NANs was
> implemented in BYTSCL.


IDL> print,bytscl([!VALUES.F_NAN,0.,10.,100.])
0 0 0 0
% Program caused arithmetic error: Floating illegal operand
IDL> print,bytscl([!VALUES.F_NAN,0.,10.,100.],/NAN)
0 0 25 255

What it's good for is ensuring that the rest of your finite values are
scaled appropriately. The problem, of course, is that:

IDL> print,max([!VALUES.F_NAN,0.,10.,100.])
NaN

so, absent the /NAN, this becomes the maximum value to scale the array
to, with the obvious deleterious side effect that all scaled values
are now NaN (think of NaN like a virus, infecting everything it
touches). Since there's no byte value representing NaN, as there is a
float value, they had to pick something, so they picked 0b, which
seems as good as anything else. Any value you pick would be
degenerate with real data.

If you'd like to separate out the NaN's, I'd use:

b=bytscl(a,/NAN,TOP=254)+finite(a)

Now 0 is definitely a NaN, and 1-255 is real data. Yes, there is a
duplicate check for NaN's implicit here. If you rescale the image
many times without changing the data, you might cache finite(a) for a
bit of speedup. I even go so far as to check if there are any
non-finite values and use:

b=bytscl(a,NAN=self.non_finite,TOP=254)+self.non_finite?self .finite:1

The reason? Adding /NaN slows most functions down by about a factor
of 2.

JD
Re: BYTSCL and NAN keyword [message #38276 is a reply to message #38273] Tue, 02 March 2004 09:39 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Kenneth Bowman <k-bowman@null.tamu.edu> writes:

> Has anyone else noticed this problem with BYTSCL and the NAN keyword?
>
> The BYTSCL function scales integers and floats into bytes between 0 and
> 255 (or the value set by the TOP keyword). If the NAN keyword is set,
> NANs in the input array are set to 0 in the output array. But 0 falls
> into the valid range for good values (0 to TOP)!
...

How about this non-WHERE approach?
bb = bytscl(x, ...) + (finite(x) EQ 0)*255b

Craig



--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: BYTSCL and NAN keyword [message #38278 is a reply to message #38276] Tue, 02 March 2004 09:45 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kenneth Bowman writes:

> Right, I understand all that. I'm just trying to understand what the
> NAN keyword is good for.
>
> If you could say NAN = 255 (or 19, or whatever), instead of just /NAN,
> it would be of some use. That way the value that NANs become in the
> output could be distinguished from valid data.
>
> As it is, the NAN keyword is only of use if you are happy with NANs
> turning into valid data in the output (i.e., indistinguishable from
> small valid values).
>
> I have to consider this an error in the way the handling of NANs was
> implemented in BYTSCL.

Ken, they are *bytes*. They only have 8 little thingamajigs.
There is not too much room for creativity here! :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: BYTSCL and NAN keyword [message #38279 is a reply to message #38276] Tue, 02 March 2004 09:26 Go to previous messageGo to next message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <MPG.1aae6fc4ef56f7829896c3@news.frii.com>,
David Fanning <david@dfanning.com> wrote:

> Well, NANs are definitely floats (that is, they have a float-type
> bit pattern). So it seems reasonable to me that if you are
> trying to stuff it into a byte (which can only have values between
> 0 and 255, that 0 is a good choice. (The only possible other
> choice is 255, but that just turns your problem on its head.)
>
> I think what I would do is locate the NANs and save their
> indices. Then scale my data into 255 colors (0 to 254), leaving
> color index 255 for the NAN color (whatever that is). This will
> take a couple of steps, but that's what IDL programs are for. :-)

Right, I understand all that. I'm just trying to understand what the
NAN keyword is good for.

If you could say NAN = 255 (or 19, or whatever), instead of just /NAN,
it would be of some use. That way the value that NANs become in the
output could be distinguished from valid data.

As it is, the NAN keyword is only of use if you are happy with NANs
turning into valid data in the output (i.e., indistinguishable from
small valid values).

I have to consider this an error in the way the handling of NANs was
implemented in BYTSCL.

Ken
Re: BYTSCL and NAN keyword [message #38280 is a reply to message #38279] Tue, 02 March 2004 09:18 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kenneth Bowman writes:

> Has anyone else noticed this problem with BYTSCL and the NAN keyword?
>
> The BYTSCL function scales integers and floats into bytes between 0 and
> 255 (or the value set by the TOP keyword). If the NAN keyword is set,
> NANs in the input array are set to 0 in the output array. But 0 falls
> into the valid range for good values (0 to TOP)!
>
> Because it is not possible to set NANs to a value outside the valid
> range (greater than TOP), it is not possible to distinguish missing from
> valid data.
>
> As best I can tell, the only solution is to not use the NAN keyword and
> scale the valid data only by using WHERE to find all the valid values.
> Am I missing something obvious? (Quite possible, I admit.)

Well, NANs are definitely floats (that is, they have a float-type
bit pattern). So it seems reasonable to me that if you are
trying to stuff it into a byte (which can only have values between
0 and 255, that 0 is a good choice. (The only possible other
choice is 255, but that just turns your problem on its head.)

I think what I would do is locate the NANs and save their
indices. Then scale my data into 255 colors (0 to 254), leaving
color index 255 for the NAN color (whatever that is). This will
take a couple of steps, but that's what IDL programs are for. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: BYTSCL and NAN keyword [message #38281 is a reply to message #38280] Tue, 02 March 2004 09:13 Go to previous messageGo to next message
Edd Edmondson is currently offline  Edd Edmondson
Messages: 50
Registered: January 2003
Member
Kenneth Bowman <k-bowman@null.tamu.edu> wrote:
> Has anyone else noticed this problem with BYTSCL and the NAN keyword?

> The BYTSCL function scales integers and floats into bytes between 0 and
> 255 (or the value set by the TOP keyword). If the NAN keyword is set,
> NANs in the input array are set to 0 in the output array. But 0 falls
> into the valid range for good values (0 to TOP)!

> Because it is not possible to set NANs to a value outside the valid
> range (greater than TOP), it is not possible to distinguish missing from
> valid data.

> As best I can tell, the only solution is to not use the NAN keyword and
> scale the valid data only by using WHERE to find all the valid values.
> Am I missing something obvious? (Quite possible, I admit.)

Yes, remember the NaN locations *before* you BYTSCL. Use
http://www.dfanning.com/tips/check_nan.html
to do this.

Then afterwards you can do something to the BYTSCLd array to put the NaNs
back in appropriately.

--
Edd
Re: BYTSCL and NAN keyword [message #38352 is a reply to message #38276] Wed, 03 March 2004 07:26 Go to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <ond67vf8sb.fsf@cow.physics.wisc.edu>,
Craig Markwardt <craigmnet@REMOVEcow.physics.wisc.edu> wrote:

> How about this non-WHERE approach?
> bb = bytscl(x, ...) + (finite(x) EQ 0)*255b

Clever idea (JD also)! The logical not operator (~) will work as well

bb = BYTSCL(x, ..., /NAN) + BYTE(255*(~FINITE(co)))

While not mandatory, the BYTE function ensures that the result bb is
type BYTE (since FINITE returns a LONG).

Ken
Re: BYTSCL and NAN keyword [message #38363 is a reply to message #38269] Tue, 02 March 2004 17:44 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <MPG.1aaecb44b5ab2a789896c6@news.frii.com>,
David Fanning <david@dfanning.com> wrote:

> Yes, but all currently used to represent one of the
> 256 numbers. :-(

You can have the last word.

Ken
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: 2D-fit
Next Topic: FastDL: An MPI interface for IDL

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

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

Total time taken to generate the page: 0.00755 seconds