Using SAOImage ds9
CIAO 4.2 Science Threads
Last Update: 25 Jan 2010 - reviewed for CIAO 4.2: no changes
The imaging application SAOImage ds9 is distributed with CIAO as the default imager. Developed independently of the software, ds9 contains some CIAO-specific support.
To introduce a few of the key features used in CIAO analysis ranging from simple (e.g. defining preferences) to complex (e.g. use of the XPA messaging system).
Read this thread if:
you would like to learn to display and work interactively with ACIS and HRC imaging and grating event files.
- Getting Started
- Coordinate Definitions: Image, Physical/Sky, Celestial, and WCS
- Command Line Arguments and Preferences
- Displaying an Event File in Different Coordinates
- Using Multiple Frames
- The Analysis Menu
- Running CIAO tasks from the Analysis menu
- XPA: Public Access to Data and Algorithms
- Figure 1: Image in (x,y) binned by a factor of 16
- Figure 2: An image in (detx,dety) binned by a factor of 4
- Figure 3: Displaying multiple frames
- Figure 4: X-ray image with contours
- Figure 5: X-ray and optical images with contours
- Figure 6: Images with contours and locked crosshairs
- Figure 7: Selecting the CIAO dax task menu
Sample ObsID used: 1712 (ACIS-S, 3C 273)
File types needed: evt2; asol1
Since ds9 and XPA can both be used independently of CIAO, it is possible that your system has a different version installed than the one that is packaged with CIAO. Also, in order to run CIAO scripts from ds9, the imager must have been launched from a term window already running CIAO. For these reasons, we recommend that you make sure CIAO is running in the current window before beginning any analysis task using ds9 or XPA. Otherwise, incompatibilities between the imager and the commands in the thread may arise.
Here we show that the ds9 accessed from the term window changes after starting CIAO:
unix% which ds9 /usr/local/bin/ds9 unix% ciao CIAO configuration is complete... CIAO 4.2 Monday, November 30, 2009 bindir : /soft/ciao/bin unix% which ds9 /soft/ciao/bin/ds9
The same applies to XPA:
unix% which xpaget /opt/local/bin/xpaget unix% ciao CIAO configuration is complete... CIAO 4.2 Monday, November 30, 2009 bindir : /soft/ciao/bin unix% which xpaget /soft/ciao/bin/xpaget
Any CIAO thread that refers to ds9 and/or XPA assumes that the version being used is the one packaged with CIAO.
When a CIAO release is being prepared, the most recent version of ds9 available is used in testing and then packaged with the software. Since updates to ds9 are released on a much shorter timescale than CIAO, users may wish to upgrade independently of CIAO to take advantage of new features and bug fixes.
If you wish to use a different version of ds9 than the one packaged with CIAO, please refer to this FAQ. It is not guaranteed that CIAO will work flawlessly with a newer release of ds9! It is possible that changes to the imager may cause unexpected problems in the CIAO software.
There are a few terms needed to discuss coordinate systems:
Image: image coordinates specify a location in an image. The lower left pixel of the array will have the image coordinates (1,1). Coordinates increase to the right in x and up in y. Note that the lower left corner of the array will have coordinates (0.5,0.5).
Physical/Sky: "sky" is shorthand for (x,y) coordinates, the system used most commonly in Chandra data analysis. Physical coordinates are the generalized system used by ds9. The sky coordinates of an event are defined as the point where an event crosses the imaginary tangent plane for a given pointing of the telescope's mirrors. This is calculated (by the CIAO tools reproject_events and acis_process_events / hrc_process_events) from knowledge of the location of the event on the detector, the location of the detector in the observatory, and the pointing of the telescope. For Chandra data, the range of sky coordinates is 0.5:8192.5 for ACIS, 0.5:32768.5 for HRC-I, and 0.5:65536.5 for HRC-S.
When saving regions in ds9, use CIAO formatted regions to ensure total compatibility with the CIAO tools. CIAO format regions are saved in physical coordinates by default. The CIAO and ds9 region formats section of the Using CIAO Regions thread has a discussion on the ASCII region types available for use. If necessary, it is possible to convert region formats/coordinate systems by loading one type (e.g. ds9 format in celestial coordinates) and saving it in a different format/coordinate system (e.g. CIAO format in physical coordinates).
Celestial: the celestial coordinate system is the standard method of measuring positions in the sky. The transformations from sky (x,y) to celestial (RA, Dec) are described at the end of the event file "columns" listing:
unix% dmlist acisf01712N003_evt2.fits cols ...cut... 8: EQPOS(RA ) = (+187.2768)[deg] +TAN[(-0.000136667)* (sky(x)-(+4096.50))] (DEC) (+2.0542 ) (+0.000136667) ( (y) (+4096.50))
The two systems are related by the aimpoint of the observation. When events are projected onto the celestial sphere, RA increases to the left (hence the minus sign in the definition) and Dec increases upward. In this example, the celestial coordinates of the reference pixel in degrees (J2000) are (187.2768,2.0542).
Although CIAO regions may be saved in celestial coordinates, only sexagesimal coordinates are currently supported (e.g. circle(17:46:14.065,-28:51:39,1.0')). Since some tools are not yet able to transform from celestial to sky coordinates, we recommend using the physical format.
WCS: the World Coordinate System (WCS) is a generalized name for the celestial coordinate system. The default celestial coordinate system in CIAO and ds9 is the J2000 system. A complete description of the WCS standard is given on the WCSTools home page.
The (x,y) coordinate system is related to the celestial coordinate system by specifying the (RA,Dec) of a reference pixel in the file's header. It is sometimes necessary to edit these header keywords to improve upon Chandra's pointing accuracy. For more information, see the Aspect caveats and the Improving the Astrometry of your Data: Correct for a Known Processing Offset thread.
For a detailed discussion of the relationships between Chandra instrument coordinate systems, see the Chandra Coordinate Systems: Imaging document (PS, 25pp).
Command line arguments may be used to perform a task when opening the application. For example, to specify log scaling when loading an event file:
unix% ds9 acisf01712N003_evt2.fits -log
A more involved example overlays a region onto the file, sends the image to the printer, and then closes ds9:
unix% ds9 acisf01712N003_evt2.fits -region sources.reg -print -exit
A short list of the available command line arguments can be found by typing "ds9 --help" in a term window. Detailed descriptions of the arguments are available from the Command Line Options section of the ds9 manual.
Preferences are user-defined default settings accessed from the "Edit → Preferences" menu. Dozens of settings are available for modification, such as:
- color scale
- display buffer size
- window layout
- region shape
- analysis file (see the Using Analysis Scripts section)
Most of the options are self-explanatory, but there is more information on each in the Preferences section of the ds9 manual. Note that under the "Information Panel" is an option to display "Detector" coordinates. This does not refer to the Chandra detector coordinates (i.e. det or tdet).
If these settings are changed and "Save Preferences" is chosen, the preferences are written to /home/username/.ds9.prf. The next time ds9 is started, this file is read and the preferences are used.
Important: as mentioned before, the preference files are generally not backward-compatible. This means a .ds9.prf created by a newer version of ds9 may react badly with the ds9 packaged in CIAO. Please reference the Preferences section of the ds9 manual for information on avoiding this problem when supporting multiple versions of ds9.
The most direct way of checking quality and content of an event file is to view it in ds9:
unix% ds9 acisf01712N003_evt2.fits &
The imager will display a 1k x 1k array of pixels by default (this may be changed in the preferences). The typical Chandra image will need to be binned to see the entire field of view. Using the "Bin" button or menu, try a binning factor of 16. If the Scale is also set to "Log", the image should look like Figure 1.
ds9 also has the ability to display any of the other columns stored in the event file, although it is only meaningful to use one of the spatial vector columns. In order to display the file in other coordinates, use the "Bin → Binning Parameters" menu to select the two columns to display. To create an image in detector coordinates (detx,dety), select them from the "Bin Columns" menus. Change "Block" to 4, select the "or center of data" button, and click "Apply". Figure 2 shows the results.
Displaying the event file in detector coordinates reveals details about how the observation was done. Bad columns (removed in the level=2 event file, so not visible here) are displayed as dark lines and point sources appear as limb-brightened squares due to the telescope dither.
Alternatively, one can display an event file in specific coordinates when calling ds9 from the command line. The syntax is similar to the CIAO binning syntax:
unix% ds9 "acisf01712N003_evt2.fits[bin=detx,dety]" &
The file is loaded into ds9 and displayed in detector coordinates.
ds9 allows the simultaneous viewing of multiple images through the use of frames, which are memory areas used to store images for viewing.
There are two ways to create multiple frames:
Specify all the filenames when starting ds9:
unix% ds9 acisf01712N003_evt2.fits -cmap b -scale log ../../315/primary/acisf00315N004_evt2.fits \ -cmap b -scale log /data/1838/primary/acisf01838N002_evt2.fits -cmap b -scale log &
Notice that the pathnames may be relative or absolute. Issuing this command created Figure 3.
Use the "Frame → New Frame" menu option. This process can be repeated to create as many frames as desired. To load the data, select the desired frame and then choose the file from the "File → Open..." dialog box.
Displaying multiple images can be helpful when trying to compare them. Images may be displayed side-by-side using the "Tile Frames" option or sequentially using the "Blink Frames" option, both found in the "Frame" menu. If the WCS info is defined for each system (or if they have the same image pixel scale), use "Frame → Match Frames" to align them for comparison.
The "Analysis" menu has several features which are useful in the analysis of Chandra data. The following examples illustrate how to apply contours, retrieve Digital Sky Survey data, perform comparative analysis of the two datasets, and define custom analysis functions. There is information on each of the commands used in these examples in the ds9 manual:
Each of the following examples assumes that an event file has been loaded into ds9:
unix% ds9 acisf01712N003_evt2.fits -scale log &
To apply contours to the data, open the "Contour Parameters" window from "Analysis → Contours Parameters". There are four parameters to adjust: the number of contours ("Contour Levels"), the smoothness of the contours, the flux at the lowest contour, and the flux at the highest contour. The flux at each contour is displayed in the "Levels" portion of the window. Be sure to click "Generate" whenever an adjustment is made to the contour parameters; this will recalculate the levels to be applied to the image.
In this example, four levels were created for the flux limits 5 to 365 at a smoothness of 5. Figure 4 shows the "Contour Parameters" window and the resulting contours on the image. Smoothing the contours can make the number of contours displayed less than the number generated.
It is also possible to access Digital Sky Survey (DSS) optical images matching your observation via the "Analysis → Image Servers" menu in ds9. There are several DSS server options; we used "SAO-DSS". The "SAO-DSS Server" window allows you to retrieve an optical image of the field of your observation and load it into a new frame. The default retrieval image size and (RA,Dec) is equal to the size and center of the field currently displayed. You may also want to use the menus in the dialog box to select a different server for quicker access from your location. In this example, none of the values determined by ds9 were changed before clicking on "Retrieve".
To overlay the X-ray contours on the optical image:
- Select the frame with the X-ray data in it.
- Use "Frame → Match Frames → WCS" to align the two images.
- To copy the contours, open the "Contour Parameters" dialog again and select "Copy Contours" from the "File" menu. Leave the window open, as it is needed in a future step.
- Select the frame with the optical data in it.
- Using the "File" menu of the "Contour Parameters" dialog, select "Paste Contours".
- Adjust the parameters in the "Contours Parameters" dialog box that pops up, if desired, then click "OK". In this example, the contour color was changed from green to red.
The final product should look similar to Figure 5. Adjust the contrast and the jet is identifiable in both the xray and optical image, extending a few arcseconds to the southwest (lower right).
The contours can also be saved to disk by choosing "Save Contours" from the "File" menu. They can then be loaded back into ds9 with the "Load Contours" option.
This image is used as the starting point for the next example (Locking Crosshairs), so do not exit ds9 if you are planning on continuing in the thread.
Having WCS defined for two images can be valuable in their simlutaneous analysis, as shown in the previous section where the images were matched via WCS. This information, combined with the "locking crosshairs" feature in ds9, can be used to examine the same region in several frames simultaneously.
Starting from the previous example, change the cursor to crosshair by means of the "Edit" menu. To lock the crosshairs into the same coordinate system for correlating features between the two images, go to "Frame → Lock Crosshairs → WCS". After locking crosshairs and zooming in on the central portion of the image, the display looks like Figure 6.
The "Load Analysis Commands..." function allows the user to define menu items which call scripts. The displayed file (and optionally regions) are exported to the script which is executed, returning the results to a ds9 text window.
This process requires two things: an analysis file which defines the menu item and the script which is called by the menu item. A shell script named "script.sh" is used for this example, but any type of script is possible.
Multiple menu items may be defined in a single analysis file. For each analysis menu item, four things must be given:
Menu label to be used A space-separated list of file templates Command type [menu | bind <event>] The command line for the analysis program
This is described in more detail in the Analysis section of the ds9 manual. The analysis file used in this example also includes a comment line:
#Define a menu item to call "script.sh" Get Counts in Regions *.fits *.fits.gz menu /workingpath/script.sh $filename $regions(source,ciao) $regions(background,ciao) | $text
where "/workingpath" is the path to the script. To define the menu item, create an analysis file containing this text. For this example, the file is saved as ciao.ds9:
unix% cat ciao.ds9 #Define a menu item to call "script.sh" Get Counts in Regions *.fits *.fits.gz menu script.sh $filename $regions(source,ciao) $regions(background,ciao) | $text
The final line defines the script's three input fields:
- $filename - the name of the event file
- $regions(source,ciao) - the source regions defined, in CIAO format
- $regions(background,ciao) - the background regions defined, in CIAO format
The script output is sent to $text, which will appear in a new ds9 window. More information on the analysis file variables is given in the Analysis section of the ds9 manual.
This analysis file can also be loaded automatically when ds9 is launched. To do so, either supply the pathname in the preferences or rename the file .ds9.ans and keep it in your home directory.
There is a suite of scripts, called dax, that allows users to run some common CIAO tasks from within ds9. The tasks in dax are implemented in the same manner as Analysis Scripts, and are automatically loaded from the file $ASCDS_INSTALL/config/ciao.ds9 when ds9 is launched from within CIAO.
The scripts are accesible from "Analysis → CIAO", as shown in Figure 7.
X Public Access (XPA) is a messaging system which provides communication between Unix programs. XPA allows users to interact with ds9 and CIAO through a set of access points; access points are simply keywords that allow command-line interaction with the application. 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. As a general rule, functions which are available in the ds9 GUI can be accessed through XPA.
For comparison, consider getting the crosshair coordinates from ds9 and inputting them to dmcoords (e.g. to find the off-axis angle).
unix% ds9 acisf01712N003_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.27699 username
Now that ds9 is running and linked to an XPA server, mark the desired point on the image with the crosshairs. Recall that the "Edit" menu is used to change the cursor.
xpaget is used to retrieve the cursor location, which is then input to the tool dmcoords (note that the "set" command syntax given is correct for the csh or tcsh shell):
unix% xpaget ds9 crosshair physical 4101.375 4066.5 unix% set x = `xpaget ds9 crosshair physical | cut -d" " -f2` unix% set y = `xpaget ds9 crosshair physical | cut -d" " -f3` unix% dmcoords infile=acisf01712N003_evt2.fits asolfile=pcadf077378077N003_asol1.fits opt=sky x=$x y=$y
The set commands are added to show the utility of xpaget; the values could simply be given directly to dmcoords as "x=4101.375 y=4066.5". The results are stored in the dmcoords parameter file:
unix% plist dmcoords Parameters for /home/username/cxcds_param/dmcoords.par infile = acisf01712N003_evt2.fits Input dataset/block specification asolfile = pcadf077378077N003_asol1.fits Input aspect solution file # # Position of photon in different coord systems # chip_id = 7 Chip ID number chipx = 188.7071503462198 Chip X [pixel] chipy = 390.1592564498173 Chip Y [pixel] tdetx = 4105.707150346219 TDETX [pixel] tdety = 2092.159256449817 TDETY [pixel] detx = 4067.131532836975 FPC X [pixel] dety = 4104.326797652676 FPC Y [pixel] x = 4101.375 Sky X [pixel] y = 4066.5 Sky Y [pixel] logicalx = 4101.375 X coordinate in binned image [pixel] logicaly = 4066.5 Y coordinate in binned image [pixel] ra = 12:29:06.264 RA [deg or hh:mm:ss] dec = +02:03:00.48 Dec [deg or dd:mm:ss] theta = 0.2492268040240001 Off axis angle [arcmin] phi = 165.0773142314044 Azimuthal angle [deg] order = 0 Grating order ...etc... unix% pget dmcoords theta 0.2492268040240001
The point at (4101.375,4066.5) has an off-axis angle of 0.25 arcmin.
To calculate the crosshair coordinates in degrees or sexagesimal format using XPA directly:
unix% xpaget ds9 crosshair wcs 187.2761 2.0501338 unix% xpaget ds9 crosshair wcs sexagesimal 12:29:06.263 +02:03:00.48
The results are the same coordinates reported by dmcoords. Note that to get (RA,Dec) in degrees with dmcoords, it is necessary to set celfmt=deg and re-run the tool.
XPA redirects ("%xpa()") also allow you to get information from ds9 and use it with the CIAO tools. This method differs from the previous example in that the values are automatically updated when the crosshairs are moved.
This example uses the XPA redirect to read the x and y coordinates of the crosshairs into dmcoords:
unix% ds9 acisf01712N003_evt2.fits & unix% punlearn dmcoords unix% pset dmcoords asolfile=pcadf077378077N003_asol1.fits unix% pset dmcoords infile="%xpa(ds9,file)" unix% pset dmcoords opt=sky unix% pset dmcoords x="%xpa(ds9,x)" unix% pset dmcoords y="%xpa(ds9,y)" # place the crosshairs at some location in the ds9 window unix% dmcoords mode=h verb=1 | grep SKY SKY(X,Y): 4101.38 4066.50 # move the crosshairs in ds9 unix% dmcoords mode=h verb=1 | grep SKY SKY(X,Y): 4087.75 4083.00
Since the x and y coordinates are set in the parameter file as redirects, the values are automatically updated when the crosshairs are moved. The parameter file looks like:
unix% plist dmcoords Parameters for /home/username/cxcds_param4/dmcoords.par infile = %xpa(ds9,file) -> acisf01712N003_evt2.fits[EVENTS] Input dataset/block specification asolfile = pcadf077378077N003_asol1.fits Input aspect solution file # # Position of photon in different coord systems # chip_id = 7 Chip ID number chipx = 209.3624694289583 Chip X [pixel] chipy = 384.4581321490172 Chip Y [pixel] tdetx = 4126.362469428958 TDETX [pixel] tdety = 2086.458132149017 TDETY [pixel] detx = 4087.76202058092 FPC X [pixel] dety = 4110.007783521776 FPC Y [pixel] x = %xpa(ds9,x) -> 4087.75 Sky X [pixel] y = %xpa(ds9,y) -> 4083 Sky Y [pixel] ...
Because the values are read from ds9, they are not available after ds9 has been closed:
unix% plist dmcoords Parameters for /home/username/cxcds_param4/dmcoords.par infile = %xpa(ds9,file) -> Input dataset/block specification asolfile = pcadf077378077N003_asol1.fits Input aspect solution file # # Position of photon in different coord systems # chip_id = 7 Chip ID number chipx = 209.3624694289583 Chip X [pixel] chipy = 384.4581321490172 Chip Y [pixel] tdetx = 4126.362469428958 TDETX [pixel] tdety = 2086.458132149017 TDETY [pixel] detx = 4087.76202058092 FPC X [pixel] dety = 4110.007783521776 FPC Y [pixel] x = %xpa(ds9,x) -> Sky X [pixel] y = %xpa(ds9,y) -> Sky Y [pixel] ...
|23 Dec 2004||updated for CIAO 3.2: version of ds9|
|23 Mar 2005||updated contours images to match ds9 v3.0b9|
|19 Dec 2005||updated for CIAO 3.3: ds9 v4.0b7 is packaged with CIAO 3.3, ds9 v4.0 region format is slightly different than v3.0; getcounts.sl has not yet been updated for CIAO 3.3/ds9 v4.0|
|01 Dec 2006||updated for CIAO 3.4: CIAO version in screen output|
|09 Jan 2007||created Using a newer version of ds9 subsection|
|08 Jan 2008||updated for CIAO 4.0: removed "Known Issues" section; ds9 v5.0 packaged with CIAO; filename and screen output updated for reprocessed data (version N003 event file); expanded XPA section|
|13 Jun 2008||updated image display to place figures inline with text|
|05 Jan 2009||updated for CIAO 4.1: ds9 v5.4 is packaged with CIAO; new section: dax: running CIAO tasks from the Analysis menu; ds9 and slsh have moved from /soft/ciao/ots to /soft/ciao/bin; "-xpa local" workaround no longer needed|
|20 Apr 2009||updated for CIAO 4.1.2: the asolfile parameter in dmcoords has changed from hidden to automatic (updated parameter file listing)|
|25 Jan 2010||reviewed for CIAO 4.2: no changes|