[AstroPy] DS9 color tables in Python

Marshall Perrin mperrin at stsci.edu
Tue Mar 31 12:35:59 EDT 2015


I implemented the ds9_b colormap a while ago.  I hereby contribute the following code snippet to the community in the public domain - reuse freely as you desire.


# A Pythoninc re-implementation of DS9's colormap 'B'.
colormap_ds9_b = matplotlib.colors.LinearSegmentedColormap('DS9_B',
        {'red':   ((0.0, 0.0, 0.0),
                   (0.25, 0.0, 0.1),
                   (0.50, 1.0,1.0),
                   (0.75, 1.0, 1.0),
                   (1.0, 1.0, 1.0)),
         'green': ((0.0, 0.0, 0.0),
                   (0.25, 0.0, 0.0),
                   (0.50, 0.0, 0.0),
                   (0.75, 1.0, 1.0),
                   (1.00, 1.0, 1.0)),
         'blue':  ((0.00, 0.0, 0.0),
                   (0.25, 1.0, 1.0),
                   (0.50, 0.0, 0.0),
                   (0.75, 0.0, 0.0),
                   (1.00, 1.0, 1.0))
        })





On Mar 31, 2015, at 7:26 AM, John Zuhone <jzuhone at gmail.com<mailto:jzuhone at gmail.com>> wrote:

For the curious, the relevant Matplotlib bit that yt uses to import colormaps is here:

https://bitbucket.org/yt_analysis/yt/src/9ac515b537a3f2da0b70601f782fdb7dde4716dd/yt/visualization/color_maps.py?at=yt

I'd be happy to PR something like it up for AstroPy, if that's what we want.

On Tue, Mar 31, 2015 at 10:17 AM, John Zuhone <jzuhone at gmail.com<mailto:jzuhone at gmail.com>> wrote:
So I'm able to do it in yt, which is probably just a short step from doing it in AstroPy, since it's just NumPy and Matplotlib calls:

http://nbviewer.ipython.org/gist/jzuhone/3472085f67e41f20e00f

CIAO (Chandra software) contains all of the ds9 colormaps, so I extracted "sls.lut" from there and just read it in.

Does anyone know if there are any licensing issues with the ds9 colormaps?

Tom, where would something like this go in astropy.visualization?

On Tue, Mar 31, 2015 at 9:36 AM, John Zuhone <jzuhone at gmail.com<mailto:jzuhone at gmail.com>> wrote:
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>



--
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>



--
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>
_______________________________________________
AstroPy mailing list
AstroPy at scipy.org<mailto:AstroPy at scipy.org>
http://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150331/00b98677/attachment.html>


More information about the AstroPy mailing list