About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: 9 July 2009

URL: http://cxc.harvard.edu/chips4.1/gallery/contours.sl.html

Gallery: Contours (S-Lang)

Examples


A simple contor plot

Contour plots are used to draw contours of 2D images which can be read from a FITS file, a two-dimensional array, or given as a set of (x, y, z) points. In this example the data is read from a file, where the image represents the statistic values from a fit of a thermal plasma model to a galaxy cluster spectrum (i.e. the results of a region-projection call in Sherpa).

[ChIPS output]
Postscript version
add_contour("contours.fits",[53.6454,57.5304,63.1794],{"wcs","params"});

add_vline(6.72,{"style","dot"});
add_hline(0.79,{"style","dot"});

limits(X_AXIS,4.0,13.0);
limits(Y_AXIS,0.0,2.0);

set_plot_xlabel("kT_x (keV)");
set_plot_ylabel("Abundance");

The add_contour call is used to create the contour plot; in this example we give it the file name, an array of contour values, and tell it to use the coordinate information in the image to label the axes.

If the contour levels were not given then ChIPS would have created a set of levels based on the data range of the image; the levels used are accessible via the levels field of the object returned by get_contour, as shown below. For more information see the Controlling the contour levels (S-Lang or Python) section of the "Introduction to contours" thread.

The image being displayed contains coordinate information to map from pixel location to "physical" space; in this case the X axis refers to the temperature of a Mekal plasma model (kTx) and the Y axis the abundance of the model, as shown by the dmlist output:

chips> !dmlist contours.fits cols  
 
--------------------------------------------------------------------------------
Columns for Image Block cont.dat_IMAGE
--------------------------------------------------------------------------------
 
ColNo  Name                 Unit        Type             Range
   1   cont.dat_IMAGE[21,21]              Real8(21x21)   -Inf:+Inf            
 
--------------------------------------------------------------------------------
Physical Axis Transforms for Image Block cont.dat_IMAGE
--------------------------------------------------------------------------------
 
Group# Axis# 
   1   1,2    params(kTx      ) = (+3.7250) +(+0.550)* ((#1)-(+0.50))
                    (Abundance)   (-0.050 )  (+0.10 )  ((#2) (+0.50))
 
--------------------------------------------------------------------------------
World Coordinate Axis Transforms for Image Block cont.dat_IMAGE
--------------------------------------------------------------------------------
 
Group# Axis# 

If the plot had been created by saying

chips> add_contour("contours.fits",[53.6454,57.5304,63.1794]);

then the axes would have been labelled using logical coordinates, going from 1 to 21 on both axes in this case.

The add_vline and add_hline calls create a vertical and horizontal line respectively; these lines will extend to the edge of the plot whatever limits are chosen for the axes. Note that the coordinate values used in these calls refer to the params coordinate system, so the call limits(X_AXIS,4,13) refers to 4 to 13 keV in this case.

The preferences for contours can be found by using the get_preference call:

chips> get_preference("contour");
contour.stem           : ctr
contour.color          : default
contour.thickness      : 1
contour.levels         : []
contour.numlevels      : 5
contour.style          : solid 
contour.algorithm      : marching 
contour.mode           : nice 
contour.interval       : 10
contour.depth          : default

The settings for the current contour can be found by using the get_contour routine:

chips> get_contour;
algorithm = 1
color = default
depth = 100
id = None
interval = 10.0
levels = [53.645400000000002, 57.5304, 63.179400000000001]
mode = arbitrary
numlevels = 5
stem = None
style = solid
thickness = 1.0
wcs = params

Two sets of contours in the same plot

In this example, two contours are added to the same plot. The same image is used, since the contours are used to identify different sets of levels (the solid contours represent the one, two, and three-sigma levels whereas the red dotted contours are the 90 and 99 percent confidence limits), but the images could have been different.

[ChIPS output]
Postscript version
add_contour("contours.fits",[53.6454,57.5304,63.1794],{"wcs","params"});
add_contour("contours.fits",[55.9554,60.5554],{"wcs","params","style","dot","color","red"});

limits(X_AXIS,4.0,14.0);
limits(Y_AXIS,0.0,2.0);

add_point(6.72,0.79,{"size",7.0});

add_label(11.0,1.8,"1,2,3 \sigma"R);
add_label(11.0,1.67,"90, 99%",{"color","red"});

current_label("all");
set_label({"size",14.0});

% Place a region behind the labels to highlight them
variable xr = [10.8,12.8,12.8,10.8];
variable yr = [1.63,1.63,1.91,1.91];
add_region(xr,yr,{"fill.style","solid","fill.color","gray","edge.style","noline","depth",50});

set_plot_xlabel("kT_x (keV)");
set_plot_ylabel("Abundance");

As with the first example, the levels are explicitly given and the "params" coordinate conversion is used to label the axes.

Two labels are created, and then they are both changed to use a size of 14 by setting the label currency to all. In order to make the labels stand out a filled region is added to the plot, with a depth of 50 so that it appears behind the labels (since the default depth of items is 100).

The info and info_current routines can be used to find out what ChIPS objects are in use:

chips> info;
Window [win1]
  Frame [frm1]
    Plot [plot1]   (0.20,0.20)  .. (0.90,0.90)
      Border bottom [bx1]  top [bx2]  left [by1]  right [by2]
      X Axis [ax1]
      Y Axis [ay1]
      Contour [ctr1]
      Contour [ctr2]
      Point [pnt1]
      Label [lbl1]
      Label [lbl2]
      Region [reg1]

chips> info_current();
Window [win1]
  Frame [frm1]
    Plot [plot1]
      X Axis [ax1]
      Y Axis [ay1]
      Contour [ctr2]
      Point [pnt1]
      Label [lbl1]
      Label [lbl2]
      Region [reg1]
    Coord Sys [Data]
    Coord Sys ID [plot1_ax1ay1]

Changes in CIAO 4.1

  1. The region fill is now controlled by the fill.style attribute rather than fill.visible, since it is now possible to fill regions with patterns rather than just a solid fill. In this case "fill.visible", 1 has been replaced by "fill.style", "solid".


Contouring an image using the WCS information

This example shows how a contour can be displayed using Right Ascension and Declination rather than "sky" or image coordinates.

[ChIPS output]
Postscript version
add_contour("a2142_smoothed.fits",[4.0,11.0,18.0,25.0,32.0,39.0,46.0,53.0]);

reverse_axes(X_AXIS);
set_xaxis({"tickformat","ra"});
set_yaxis({"tickformat","dec"});

set_plot_title("Abell 2142");
set_plot_xlabel("Right Ascension");
set_plot_ylabel("Declination");
set_plot({"leftmargin",0.25});
set_yaxis({"offset.perpendicular",80});

Since the image contains WCS information, as shown by the dmlist call below, the axes are automatically labelled using this coordinate system. To get sexagesimal format for the axis labels, we change the tickformat attribute of the axes to the values "ra" and "dec", and we reverse the X axis - using reverse_axes - to ensure the correct orientation of the plot.

chips> !dmlist a2142_smoothed.fits cols
 
--------------------------------------------------------------------------------
Columns for Image Block CONVOLVE
--------------------------------------------------------------------------------
 
ColNo  Name                 Unit        Type             Range
   1   CONVOLVE[366,366]                 Real4(366x366) -Inf:+Inf            
 
--------------------------------------------------------------------------------
Physical Axis Transforms for Image Block CONVOLVE
--------------------------------------------------------------------------------
 
Group# Axis# 
   1   1,2    sky(x) = (+3109.50) +(+4.0)* ((#1)-(+0.50))
                 (y)   (+2939.50)  (+4.0)  ((#2) (+0.50))
 
--------------------------------------------------------------------------------
World Coordinate Axis Transforms for Image Block CONVOLVE
--------------------------------------------------------------------------------
 
Group# Axis# 
   1   1,2    EQPOS(RA ) = (+239.5378)[deg] +TAN[(-0.000136667)* (sky(x)-(+4096.50))]
                   (DEC)   (+27.2755 )           (+0.000136667)  (   (y) (+4096.50)) 

Although the axes are labelled in sexagesimal format, only decimal format values can be used to specify a position: e.g. to change the axis range or to position a line or label. The get_plot_xrange and get_plot_yrange() routines can be useful to find out the current axis ranges; in this case the output is

chips> get_plot_xrange;
[239.64835574248269, 239.52515467429311]
chips> get_plot_yrange;
[27.175012726625269, 27.280674036873435]
Last modified: 9 July 2009


The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.