[AstroPy] DS9 color tables in Python

Thomas Robitaille thomas.robitaille at gmail.com
Tue Mar 31 14:13:04 EDT 2015


Axel Donath has also coded up the ds9 colormaps in Python here:

http://nbviewer.ipython.org/gist/adonath/c9a97d2f2d964ae7b9eb

I feel like given that many people seem to have developed this, there's
no reason it can't be included in astropy.visualization. Maybe we could
have:

from astropy.visualization import colormaps as cm

then use cm.ds9.heat for example.

But first, it would be good to check whether this can't be instead
included in

http://jiffyclub.github.io/palettable/

which is a specialized library for colormaps (not sure if it's too
specific for that, will check with the author).

Cheers,
Tom

Megan Sosey wrote:
> 
> Via the intertubes
> 
>> On Mar 31, 2015, at 12:59 PM, "Megan Sosey" <sosey at stsci.edu> wrote:
>>
>> you can still feed ds9 your own colormap with  “cmap” , it expects a  valid colormap lookup table valid contrast values specifying level and intensity,
>> looking something like this, and described here http://tdc-www.harvard.edu/software/saoimage/saoimage.cmap.html   :  -cmap file  filename.lut
>>
>>
>> http://ds9.si.edu/ref/file.html#ColorLookupTable
>>
>> You can save the ds9 color table you like from the gui using the “Colormap parameters”  menu, here’s the one it saved for “heat”
>>
>>
>> # SAOimage color table
>>
>> PSEUDOCOLOR
>>
>> RED:
>>
>> (0,0)(0.34,1)(1,1)
>>
>> GREEN:
>>
>> (0,0)(1,1)
>>
>> BLUE:
>>
>> (0,0)(0.65,0)(0.98,1)(1,1)
>>
>>
>> If you want to translate that to matplotlib you can do this:
>>
>> Make a dictionary for the color translation:
>>
>> cdict= {'red':  ((0., 0, 0, 0),
>>                 (0.34, 1, 1, 1),
>>                 (1, 1, 1,1)),
>>
>>        'green': ((0,0,0,0),
>>                  (1,1,1,1)),
>>
>>        'blue': ((0,0,0,0),
>>                 (0.65,0,0,0),
>>                 (0.98,1,1,1),
>>                 (1,1,1,1))
>>                 }
>>
>> import matplotlib.pylab as plt
>> from matplotlib import colors
>>
>> test=colors.LinearSegmentedColormap('megan',cdict)
>>
>> plt.register_cmap(‘megan’,test)
>>
>>
>> plt.figure()
>> plt.imshow(data)
>> plt.set_cmap(‘megan’)
>>
>>
>> From: John Zuhone <jzuhone at gmail.com<mailto:jzuhone at gmail.com>>
>> Reply-To: Astronomical Python mailing list <astropy at scipy.org<mailto:astropy at scipy.org>>
>> Date: Tuesday, March 31, 2015 at 9:36 AM
>> To: Astronomical Python mailing list <astropy at scipy.org<mailto:astropy at scipy.org>>
>> Subject: Re: [AstroPy] DS9 color tables in Python
>>
>> It's definitely do-able, I did it for a couple of ds9 colormaps by hand for yt, actually. I can try seeing if I can script it up.
>>
>> On Tue, Mar 31, 2015 at 9:01 AM, Peter Teuben <teuben at astro.umd.edu<mailto:teuben at astro.umd.edu>> wrote:
>>> On 03/31/2015 08:25 AM, Thomas Robitaille wrote:
>>>> On 31 March 2015 at 14:00, Peter Weilbacher <pweilbacher at aip.de<mailto:pweilbacher at aip.de>> wrote:
>>>> Dear all,
>>>>
>>>> has anyone succeeded to set up DS9-like color tables for plotting in
>>>> Python? I'm specifically interested in "heat", "sls", "hsv", and "b".
>>>>
>>>> I know that matplotlib defines somewhat similar tables, but e.g.
>>>> "gist_heat" is just too different from DS9's (and skycat's) heat...
>>> If this doesn't exist, this might be a good addition to
>>> astropy.visualization or pyds9!
>>>
>>> Tom
>>
>> Since I had done something similar in a long ago past, I had a quick peek
>> at the source distro of ds9.   I was surprised to see this part documented
>> very lightly (if at all), but the "obvious" code to look at is in
>>    saods9/saotk/colorbar/default.C
>> where a series of
>>
>>  red.append(new LIColor(0,0));
>>  red.append(new LIColor(1,1));
>>
>>  green.append(new LIColor(0,0));
>>  green.append(new LIColor(1,1));
>>
>>  blue.append(new LIColor(0,0));
>>  blue.append(new LIColor(1,1));
>>
>> create a colortable.   The SLS color scheme, which happens to
>> be my favorite, does this in RGB space:
>>
>>  colors.append(new RGBColor(0.000000, 0.000000, 0.000000));
>>  colors.append(new RGBColor(0.043442, 0.000000, 0.052883));
>>  colors.append(new RGBColor(0.086883, 0.000000, 0.105767));
>>  colors.append(new RGBColor(0.130325, 0.000000, 0.158650));
>> ...
>>  colors.append(new RGBColor(1.000000, 1.000000, 1.000000));
>>  colors.append(new RGBColor(1.000000, 1.000000, 1.000000));
>>  colors.append(new RGBColor(1.000000, 1.000000, 1.000000));
>>
>> others are done programmatically (check out HSV )
>>
>> I NEMO and GIPSY these live as ascii tables with 256 entries of RGB
>> scaled 0..1, and I checked a few and the ds9 ones seem to match
>> the ones I see in GIPSY or NEMO. (NEMO/data/lut or GIPSY/dat/lut)
>>
>> The ds9 codebase also has some yacc & lex parsing, i'm not clear
>> if that's still used. Clearly the distribution doesn't contain these
>> LUT ascii type files. If we're interested in persuing this, we should
>> check with Bill Joye about the best approach to scrape it the right
>> way.
>>
>> My old notes from 2003 tell me that ds9 can read my LUT/RGB ascii tables,
>> but I cannot find this in the current ds9 (7.3.x)
>> http://carma.astro.umd.edu/nemo/man_html/lut.5.html
>>
>> peter
>>
>>
>>
>>
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org<mailto:AstroPy at scipy.org>
>> http://mail.scipy.org/mailman/listinfo/astropy
>>
>>
>>
>> --
>> John ZuHone
>>
>> Postdoctoral Researcher
>> NASA/Goddard Space Flight Center
>>
>> jzuhone at gmail.com<mailto:jzuhone at gmail.com>
>> john.zuhone at nasa.gov<mailto:john.zuhone at nasa.gov>
>> <Screen Shot 2015-03-31 at 12.58.23 PM.png>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy



More information about the AstroPy mailing list