X
106 Rate this article:
No rating

INTERNAL: How can ENVI use NaN as a value in Band Math or in Masking?

Anonym

In many processing paths, it is useful to use IEEE standard Inf and NaN values. For example, using NaN as a minimum or maximum value when building a mask, using this as a value in Band Math, or perhaps converting NaN's to 0's or any other user-defined value.
The easiest way to generate a mask of NaN or Inf values is directly from the Mask Definition dialog, by selecting Options > Mask "NaN"/ "Inf" Values. Though it is an often overlooked feature in ENVI, another option is to use the idl function FINITE to work with NaN and Inf values in Band Math. For example, the expression:

finite(b1,/infinity)

will return a mask image with 1's present where the data has Inf values and 0's where the data are real numbers. To generate a similar result based on NaNs:

finite(b1,/nan)

will return a mask where 1's indicate where the data had NaN values and 0's for all non-NaN data values.

If the reverse is desired, it could be achieved using:

(finite(b1,/nan) eq 0b)

as the expression. This would produce a mask band where 1's represent pixels having real number values in the original data and 0's represent pixels with NaN values.

Using these expressions in combination, it is possible to preserve the original data values and replace NaN or Inf values with a specific number. For example:

(9999 * finite(b1, /nan)) + ( finite(b1) * (b1 > (-1e+34) ) )

will produce a result where all non-NaN data values are preserved and all pixels with NaN values are assigned the value 9999.

Alternately, you can change an original data value to a NaN:

((b1) * (b1 ne 9999)) / (b1 ne 9999)

The above expression works because the numerator of the expression retains original data values where they are not equal to 9999 and places 0's where it is equal to 9999. The denominator of the expression also produces a binary image that when divided into the numerator, results in NaN wherever b1 is dividing a 0 value by a 0 value.