Scripting ds9

Return to the DS9 Users Manual


Synopsis

Scripting with ds9 can be done in several ways: by invoking the GUI with a number of command-line options or via the XPA messaging system. A third option, Simple Application Messaging Protocol (SAMP), is introduced but not included in the examples.

To illustrate how to script ds9, we repeat the contours example with both methods,. The examples use Chandra data from an observation of the galaxy cluster Abell 2142 (ObsID 5005).

If you encounter any problems, please email ds9help @ cfa.harvard.edu.


Contents


Command-line Scripting

The ds9 Reference Manual has an extensive list of the available command line options. The most important thing to note is that the commands are executed one at a time in the order they are listed.

To create contours on a data image:

unix% ds9 acisf05005N002_evt2.fits -bin about 3800 3800 -bin factor 2 \
    -scale log -cmap b \ 
    -contour yes -contour limits 1 100 \
    -contour smooth 5 -contour nlevels 6 -contour save ds9.con &

This command line produces Figure 1.

The options direct ds9 to:

  1. -bin about 3800 3800 : center the image display at (x,y)=(3800,3800)
  2. -bin factor 2 : bin the data by a factor of 2
  3. -scale log : set the display to log scale
  4. -cmap b : use the "b" colormap
  5. -contour yes : display contours
  6. -contour limits 1 100 : set the minimum and maximum contour limits
  7. -contour smooth 5 : set contour smoothness to "5"
  8. -contour nlevels 6 : create six contour levels
  9. -contour save ds9.com : save the contours to the file "ds9.con"

If you wish to add options to the command line after it has been processed, the whole command must be run again from the beginning. It is, however, possible to interact with the ds9 GUI that has been created. For instance, instead of including the "-bin about 3800 3800" modifier, the image could be recentered in ds9 interactively.

The following command line builds on the previous example by retrieving a DSS image and copying the contours to the new frame:

unix% ds9 acisf05005N002_evt2.fits -bin about 3800 3800 -bin factor 2 \
    -scale log -cmap b \ 
    -contour yes -contour limits 1 100 \
    -contour smooth 5 -contour nlevels 6 -contour copy \
    -dsssao A2142 -cmap grey -contour paste \
    -frame first -match frames wcs &

The resulting image is shown in Figure 2.

The options which have been added from the previous command line are:

  1. -contour copy : copy the x-ray contours
  2. -dsssao A2142 : retrieve a DSS image of A2142 from the DSS-SAO server (there are also a "dsseso" and "dssstsci" options)
  3. -cmap grey : use the "grey" colormap in the DSS frame
  4. -contour paste : paste the x-ray contours onto the optical data
  5. -frame first : select the first ds9 frame
  6. -match frames wcs : match the WCS of the DSS frame to the current (x-ray) frame

At this point, we can end the ds9 session or modify the display interactively via the ds9 GUI.


XPA Scripting

X Public Access (XPA) is a messaging system which provides communication between Unix programs through a set of access points. The two most common actions are retrieving information (xpaget) and issuing commands (xpaset). For more information, see the XPA Messaging System page and the XPA Access Points section of the ds9 manual.

XPA commands may be issued one at a time from the terminal or collected in a script to run in batch mode. Unlike the command line syntax, there is no predetermined stopping point - commands may be sent to ds9 as long as the GUI is open.

First, open ds9 with the data file:

unix% ds9 acisf05005N002_evt2.fits &

The xpans name server is used to manage the names and ports of XPA access points. Use "xpaget xpans" to see the list of available access points:

unix% xpaget xpans
DS9 ds9 gs /tmp/.xpa/DS9_ds9.22972 username

Now that ds9 is running and linked to an XPA server, we can use xpaset to modify the display and add contours. (Refer to the XPA documentation for details on xpaset syntax.)

unix% xpaset -p ds9 bin about 3800 3800 
unix% xpaset -p ds9 bin factor 2 
unix% xpaset -p ds9 scale log 
unix% xpaset -p ds9 cmap b  
unix% xpaset -p ds9 contour yes 
unix% xpaset -p ds9 contour limits 1 100 
unix% xpaset -p ds9 contour smooth 5 
unix% xpaset -p ds9 contour nlevels 6 
unix% xpaset -p ds9 contour save xpa.con

This command line produces Figure 3.

The options direct ds9 to:

  1. xpaset -p bin about 3800 3800 : center the image display at (x,y)=(3800,3800)
  2. xpaset -p bin factor 2 : bin the data by a factor of 2
  3. xpaset -p scale log : set the display to log scale
  4. xpaset -p cmap b : use the "b" colormap
  5. xpaset -p contour yes : display contours
  6. xpaset -p contour limits 1 100 : set the minimum and maximum contour limits
  7. xpaset -p contour smooth 5 : set contour smoothness to "5"
  8. xpaset -p contour nlevels 6 : create six contour levels
  9. xpaset -p contour save xpa.com : save the contours to the file "xpa.con"

As long as the ds9 GUI remains open, we can continue to modify the display. Here we build on the previous example by retrieving a DSS image and copying the contours to the new frame:

unix% xpaset -p ds9 contour copy 
unix% xpaset -p ds9 dsssao A2142 
unix% xpaset -p ds9 cmap grey
unix% xpaset -p ds9 contour paste 
unix% xpaset -p ds9 frame first
unix% xpaset -p ds9 match frames wcs

The resulting image is shown in Figure 2.

The options which have been added from the previous command line are:

  1. xpaset -p contour copy : copy the x-ray contours
  2. xpaset -p dsssao A2142 : retrieve a DSS image of A2142 from the DSS-SAO server (there are also a "dsseso" and "dssstsci" options)
  3. xpaset -p cmap grey : use the "grey" colormap in the DSS frame
  4. xpaset -p contour paste : paste the x-ray contours onto the optical data
  5. xpaset -p frame first : select the first ds9 frame
  6. xpaset -p match frames wcs : match the WCS of the DSS frame to the current (x-ray) frame

At this point, we can end the ds9 session, issue further XPA commands, or modify the display interactively via the ds9 GUI.


SAMP: Simple Application Messaging Protocol

A third method of scripting ds9 is via SAMP, a messaging protocol that enables astronomy software tools to interoperate and communicate. SAMP is also used by such applications as TOPCAT, an interactive graphical viewer and editor for tabular data and Aladin, an interactive software sky atlas.

Information on the ds9 SAMP implementation is available in the ds9 Reference Manual.


History

21 Sep 2009 Original version

Return to the DS9 Users Manual