Re: colormaps and file formats

From: Derrick Snowden (Derrick.Snowden AT noaa.gov)
Date: Wed Jan 12 2005 - 16:25:14 MST


Thanks to Mark, Dave and James for answering some of my questions and for code
fragments. Attached is a Python conversion utility to convert GMT *.cpt
color palette files into a format NCL and PyNGL can use. It also allows for
linear interpolation in the colorspace to change the length of the new
colormap. I haven't tested the HSV functionality, but from my reading of the
code James Boyle provided, the program will detect an HSV color model in a
*.cpt file and convert it to an RGB color model. As Dave recommended, I
currently ignore the background, foreground and no data colors specified in
the *.cpt file.

For you NCLers not familiar with Python, at the *nix command line type
$> ./cpt2rgb.py -h

or

$> python cpt2rgb.py -h

for some instructions. Let me know if you find a bug, I certainly haven't
tested it exhaustively. Also, I wasn't overly careful with checking for
errors in file io or imports so you may need to install a few Python
packages.

-Derrick

PS: The RGB values in the output file are currently limited to 0-255, even
though NCL can accept 0-65535. Also, after interpolation, the results are
downcast as integers so the floats are truncated (i.e. 126.350 becomes 126).
Hopefully this doesn't cause problems but it's easily fixed if it does.

On Wed January 12 2005 03:39 pm, David Ian Brown wrote:
> Mark, Derrick,
>
> Actually, although it has never been properly documented, you can set
> an environment
> variable called 'NCARG_COLORMAP_PATH' with a colon-separated list of
> directories that
> will cause NCL/PyNGL to search for colormaps in these directories and
> load them. It will
> look for any files with extensions '.rgb', '.gp', or '.ncmap' and try
> to interpret them as colormaps
> when a workstation is first created. Note, however, that this path
> actually replaces the default path
> so it should always include $NCARG_ROOT/lib/ncarg/colormaps as one of
> its directories.
>
> Derrick, see below. I have tried to answer some of your questions.
> -dave
>
> On Jan 12, 2005, at 10:20 AM, Mark J. Stevens wrote:
> > Hi,
> >
> > I have written a function that is included in contributed.ncl that
> > allows you
> > to "roll your own" colormaps with your own rgb file. To use this
> > here is an example. The rgb file and a ncl script for viewing the
> > colors
> > are attached.
> >
> > example of use in ncl script:
> > .....
> > cmap = RGBtoCmap("blueyellowred.rgb")
> > gsn_define_colormap(wks,cmap)
> > ....
> >
> > I use to use GMT in grad school, I think you could easily modify those
> > rgb files to use with ncl.
> >
> > Mark Stevens
> >
> > On Wednesday 12 January 2005 07:51 am, Derrick Snowden wrote:
> >> Hi all,
> >>
> >> I'm interested in writing a conversion script to convert GMT style
> >> *.cpt
> >> colormap files to a file format useable by NCL and PyNGL. First of
> >> all,
> >> has anyone already done this? If so are you willing to share? There
> >> are
> >> some good default colormaps in GMT and there is a great site
> >> (cpt-city at
> >> http://craik.shef.ac.uk/cpt-city/index.html) with hundreds of user
> >> contributed extensions. A script to go between these different file
> >> formats would be very useful. I have a few questions as I'm getting
> >> started...
> >>
> >> 1. NCL/PyNGL ships with colormaps in the
> >> $NCARG_ROOT/lib/ncarg/colormaps
> >> directory. In my installation, I have *.ncmap, *.gp and *.rgb files.
> >> For
> >> some colormaps there are multiple file type versions of the same map.
> >> Which is the preferred file format and why? Is there a trick to the
> >> format
> >> or are they just rgb (0-255) triplets on each line?
>
> .ncmap files come from the ncview application. The .rgb and .gp files
> are originally from
> other applications, I forget which (IDL maybe is one).
> These formats are similar enough that NCL reads them all using a single
> routine.
> Basically, it ignores any line of the file where the first non-space
> character is anything other than a digit.
> There is no trick to the format. It is just, as you suggest, rgb
> triplets.
> The range can be either 0-255 or 0-65535.
>
> >> 2. If I remember correctly, the first entry in the colormap is the
> >> default
> >> background color, and the second entry is the default foreground
> >> color.
> >> Which index entry provides the default color for the various fill
> >> colors
> >> such as the land fill and the inland waters filll? I constantly
> >> screw that
> >> up. If one uses the resource gsnSpreadColors = True, are the
> >> foreground/background colors used or not?
>
> Up to 254 colors will be read from the colormap file. Indexes 0 and 1,
> background and foreground,
> must be defined separately, using wkBackgroundColor and
> wkForegroundColor. So the
> colors read from the colortable file are assigned indexes starting from
> 2, and
> the gsnSpreadColors functionality ignores background and foreground.
>
> >> 3. Where, other than $NCARG_ROOT/lib/ncarg/colormaps, can these files
> >> be
> >> stored so they are available in scripts? If I'm using a network
> >> installation of ncl and don't have write permission in the directory
> >> above?
>
> See above.
>
> >> 4. What is a good rule of thumb for the length of a colormap, given
> >> that
> >> one can interpolate etc? (For this purpose I am talking about
> >> colormaps
> >> used for continuous variables not categorical variables.)
>
> For NCL, each color that you want in the colormap must be specified
> explicitly. There is
> currently no interpolation of colors such as GMT provides.
> Hope this helps.
> -dave
>
> >> Thanks for any help you can give...
> >>
> >> Best,
> >> Derrick
> >
> > --
> > Mark J. Stevens
> > Climate and Global Dynamics Division
> > NCAR Mesa Laboratory, Room 320c
> > ph: 303-497-1707 stevens@ucar.edu
> > http://www.cgd.ucar.edu/~stevens
> > <show_colors.ncl><blueyellowred.rgb>___________________________________
> > ____________
> > ncl-talk mailing list
> > ncl-talk@ucar.edu
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
Derrick Snowden
PhOD/AOML/NOAA
4301 Rickenbacker Causeway
Miami, FL 33149
Office: 305.361.4322  Fax: 305.361.4392


_______________________________________________ ncl-talk mailing list ncl-talk@ucar.edu http://mailman.ucar.edu/mailman/listinfo/ncl-talk



This archive was generated by hypermail 2b29 : Thu Jan 13 2005 - 13:34:26 MST