Fanning Software Consulting

Using Brewer Color Tables with New Graphics

QUESTION: Question? I like the new graphics routines introduced in IDL 8. But I miss being able to use the Brewer color tables with my images. Is there an easy way to use these Brewer color tables?

ANSWER: Yes, the Coyote Library routine, CTLoad, is already enabled to create Brewer color tables in a form you can use in the new IDL 8 graphics. Use the RGB_TABLE keyword to return a Brewer color table in the [256,3] form needed for the graphics functions. For example, to show an image using Brewer color table 4, you would type code similar to this.

   IDL> file = Filepath('worldelv.dat', SUBDIRECTORY = ['examples', 'data'])
   IDL> world = Read_Binary(file, DATA_DIMS = [360,360])   
   IDL> CTLoad, 4, /BREWER, /REVERSE, RGB_TABLE=ct
   IDL> img = Image(world, RGB_TABLE=ct) 

You will see something that looks similar to the figure below.

An image shown with a Brewer color table.
An image displayed with a Brewer color table.
 

But, unfortunately, things aren't as smooth if you want to change the color table later. You could try something like this, but you get an error.

    IDL> CTLoad, 18, /BREWER, /REVERSE, RGB_TABLE=nct
   IDL> img.RGB_TABLE=nct
        % IDLITDATAIDLPALETTE::SETDATA: Data must be a 3xN or 4xN array. 

This is so even when ct and nct are exactly the same size and shape!

    IDL> Help, ct, nct         CT              BYTE      = Array[256, 3]
        NCT             BYTE      = Array[256, 3] 

For goodness only knows what reason, you have to transpose the color table when you are trying to change it.

   IDL> img.RGB_TABLE=Transpose(nct) 

As it turns out, the miracle is that the first color table loaded properly! I knew about this once and had forgotten it. While TVLCT requires a 256x3 array, all object graphic routines require a 3x256 array. I've added a new keyword, ROW, to CTLoad so that if it is set, the color table array is transposed to row vectors before it is returned. That way, it will be suitable for all new graphics routines.

Update: Brewer Color Tables Available in IDL 8.2.1

As of IDL 8.2.1, the IDL color tools LoadCT and XLoadCT now support Brewer color tables directly.

Version of IDL used to prepare this article: IDL 8.0

Google
 
Web Coyote's Guide to IDL Programming