Fanning Software Consulting

Missing Contour Data

Facebook Twitter RSS Google+

QUESTION: I have missing data in my 2D array that I am trying to visualize as a color-filled contour plot. But, I can't seem to make the data appear to be missing. It is always assigned some color. What I really want are holes in my filled contour plot where the missing data looks like the background color. Is it possible to so this in IDL?

ANSWER: Yes, of course it is possible. And, it is incredibly easy to do, too. Let's start by creating a filled contour plot of data that is not missing.

   data = cgDemoData(2)
   cgLoadCT, 6, /Brewer, /Reverse
   cgContour, data, /FILL, /OUTLINE

You see the results in the figure below.

A normal filled contour plot.
A normal filled contour plot.
 

Now, let's create some missing contour values in the same data set. We will create 10 missing values. Note that our data array is already a floating point array. If it wasn't floating point, we would have to cast it to floating point data before setting the missing values to !Values.F_NaN.

   missingIndices = RandomU(-3L, 10) * 41 * 41L
   data[missingIndices] = !Values.F_NaN

What you do not want to do, is use the same command you used above with this data set that has missing values in it. In particular, you do not want to use the Fill keyword. Let's see what happens if you do.

   cgContour, data, /FILL, /OUTLINE
A filled contour plot with missing data using the /FILL keyword.
A filled contour plot with missing data using the /FILL keyword. The plot looks
strange! Some filled contours are missing. Others are wrong.
 

The correct thing to do here is to use the Cell_Fill keyword. This must always be used when you have missing data in your array.

   cgContour, data, /CELL_FILL, /OUTLINE

Now the data is drawn correctly and the missing values appear to be actually missing.

A filled contour plot with missing data shown missing.
A filled contour plot with missing data shown missing.
 

Version of IDL used to prepare this article: IDL 8.2.3.

Written: 15 February 2014