Introduction to ChIPS, CIAO's plotting package.
ChIPS (Chandra Imaging and Plotting System) is the plotting package of CIAO and can be used interactively or be driven by a script to create plots on the screen and in hardcopy form. It is embedded within Sherpa, is used by applications such as Prism and Filtwin for displaying data, and can be used to create plots from S-Lang.
ChIPS is designed so that plots can be built up interactively in small steps and can easily be refined, saved, printed, and restored. It is particularly flexible at creating plots from tables, but also allows users to generate plots of selected columns from an image or event file. The S-Lang programming language can be used to manipulate - or create - data for plotting.
The ChIPS command language - not including the S-Lang functions - provides the ability to create and manipulate plots but no data-manipulation capabilities, other than to read in data from a file. The S-Lang programming language provides the functions needed to create and manipulate data and to interact with ChIPS.
Welcome to ChIPS, version CIAO3.1 Copyright (C) 1999-2003, Smithsonian Astrophysical Observatory chips>
- and leaves you at an interactive prompt at which you can enter any valid ChIPS, as discussed above.
There are two ways to start ChIPS and get it to execute a pre-determined set of commands. If the ASCII file plot.chp contains text that could be entered at the ChIPS prompt then it can be processed by saying:
unix% chips plot.chp
This will cause ChIPS to evaluate all the commands in plot.chp and then leave you at the interactive prompt. If you want ChIPS to exit after processing the commands either add a QUIT statement to the end of the file or use the "-batch" command-line option and say
unix% chips --batch plot.chp
New to CIAO 3.0 is the ability to use the store files - created with the STORE command - in this way.
If you want to evaluate a S-Lang script - which can define useful functions or run through a set of commands - then you have to use the "-slscript" option:
unix% chips --slscript plot.sl
Here the contents of plot.sl must be valid S-Lang code: variables must be pre-declared (unless you have set the _auto_declare variable to 1 at the start of the script) and statements require the closing semi-colon, but S-lang statements can be split across more than one line. After processing the S-Lang file the interactive prompt will be displayed (the "-batch" option can be used to cause ChIPS to exit after processing the files).
Any ChIPS resource file will be loaded before any command-line file (either ChIPS or S-Lang format) is loaded.
You can load in both ChIPS and S-Lang files at the same time using
unix% chips --slscript plot.sl plot.chp
This evaluates the file plot.sl and then the file plot.chp. Multiple S-Lang files can be specified using "-slscript" but only one ChIPS command file. In fact, the command-line processing stops after the first ChIPS command file is found.
Note that the files can be called anything you like: we use the convention that the extensions "chp" and "sl" indicate ChIPS and S-Lang files respectively.
It also allows you to save the current plot to a file using the STORE command; the resulting file can be loaded into a new ChIPS session using the RESTORE command. This provides easy editing of plots across multiple runs of ChIPS and the ability to easily send actual plots - including the data - to colleagues rather than just a postscript version.
For those occasions when no X-window output is required - for instance when running a script in the background - "batch" mode can be switched on. If a script calls "BATCH ON" or ChIPS is started with the -batch command-line option
chips> clear chips> limits 0 10 0.01 10 chips> log y chips> ylabel "The Y axis" chips> ylabel size 1.5 chips> ylabel green
This is often the desired behaviour, but it can cause problems if the plot contains many data points (since it will take a long time to re-draw the plot) or if the flickering of the contents of the plot window is a nuisance.
The automatic redrawing can be turned off by calling
before creating the plot and then calling
once the plot has finished. If you wish to keep the redraw mode turned off but want to update the window with the current plot contents then call
Note that Sherpa sets the redraw mode to OFF when started (or its S-Lang module is loaded). The S-Lang routines chips_redraw() and chips_auto_redraw() can be used to set and find the current value of the redraw mode.
So,
chips> redraw off chips> clear chips> limits 0 10 0.01 10 chips> log y chips> ylabel "The Y axis" chips> ylabel size 1.5 chips> ylabel green chips> redraw on
creates the same plot as above but without the plot window being updated until the "REDRAW ON" command is called.
ChIPS converts double-precision numbers to floating-point values before plotting them, which can cause problems for values that are either too large or too small. The allowed range is approximately 1e-38 to 3e38 (for both positive and negative values).
The S-Lang functions chips_get_xrange() and chips_set_xrange() can be used to set and get the X-axis limits for a plot. Similarly named functions exist for the Y and Z axes.
If SPLIT is called and a plot (or even multiple plots) already exist then the contents will remain, as long as the total number of plots in the SPLIT call is at least as large as the existing number of plots. This is shown in the following example, where the first plot remains even after 5 new panes are added to the display.
chips> clear chips> limits 0 10 10 20 chips> axes red chips> ylabel "y axis 1" chips> ylabel size 1.5 chips> split 2 3
When ChIPS commands are entered they are assumed to be for the current "working" pane. This can be found out by using the INFO command, which lists details of all the drawing panels and their contents, as well as indicating the currently selected drawing area. The "D" command or S-Lang function "chips_set_pane()" can be used to switch to different drawing areas (also called panes). The S-Lang function "chips_get_pane()" can be used to find out what the currently selected pane is.
chips> clear chips> split 3 1 chips> d 2 axes red chips> info Drawing Area #1 (Location: 0.15 0.4 0.1 0.9) (Limits : -0.05 1.05 -0.05 1.05) (Axes : fouraxes color: defaultcolor width: 1) Drawing Area #2 << CURRENT DRAWING AREA (Location: 0.4 0.65 0.1 0.9) (Limits : -0.05 1.05 -0.05 1.05) (Axes : fouraxes color: red width: 1) Drawing Area #3 (Location: 0.65 0.9 0.1 0.9) (Limits : -0.05 1.05 -0.05 1.05) (Axes : fouraxes color: defaultcolor width: 1)
Here this shows that there are three drawing areas (or panes) and that the second one is the currently-selected area (since we explicitly prefaced the call to AXES with "D 2"). The output also lists information such as the axes limits and the location of each pane in the window. Although not shown here, the INFO command will also list plotted datasets and lines - again indicating the currently selected curve. Some of this information can be accessed from S-Lang; see "ahelp /chips_get/" and "ahelp /chips_set/" for a list of these functions.
chips> clear chips> info Drawing Area #1 << CURRENT DRAWING AREA (Location: 0.15 0.9 0.1 0.9) (Limits : -0.05 1.05 -0.05 1.05) (Axes : fouraxes color: defaultcolor width: 1) chips> location 0.15 0.9 0.35 0.9 chips> drawarea 0.15 0.9 0.1 0.3 chips> info Drawing Area #1 (Location: 0.15 0.9 0.35 0.9) (Limits : -0.05 1.05 -0.05 1.05) (Axes : fouraxes color: defaultcolor width: 1) Drawing Area #2 << CURRENT DRAWING AREA (Location: 0.15 0.9 0.1 0.3) (Limits : -0.05 1.05 -0.05 1.05) (Axes : fouraxes color: defaultcolor width: 1)
In this example we used LOCATION to re-size the original drawing area to cover roughly 2/3 of the window (along the Y dimension) and then the DRAWAREA command to create a much smaller window below it. Drawing areas can even overlap as shown by the following example (we use the SPLIT command to create 3 panes and then resize them, alternatively the second and third panes could have been created using the DRAWAREA command):
chips> clear chips> split 1 3 chips> location 0.15 0.9 0.35 0.9 chips> d 2 location 0.15 0.9 0.1 0.3 chips> d 3 location 0.4 0.7 0.2 0.4
require("chips");
This is not necessary if you have already loaded the "sherpa" module. A side effect of loading ChIPS is that the Varmm library is also loaded and the ChIPS resource file is evaluated, if it exists.
Once the "chips" module is loaded then the S-Lang functions - such as chips_clear() - can be used. Use
to list these functions. The chips_eval() function can be used to run ChIPS commands which do not have a S-Lang version.
() = curve( x, y ); () = curve( x, y, yerr ); () = curve( x, y, yerrlo, yerrhi ); () = curve( x, y, xerrlo, xerrhi, yerrlo, yerrhi );
As an example, the following S-Lang code uses a mixture of ChIPS and S-Lang commands to create a plot of sin(x):
% ensure ChIPS commands are available require("chips"); % create the data to be plotted variable x = [1:10:0.02]; variable y = sin(x); % ensure plot will not be created until the "redraw" call () = chips_auto_redraw(0); % set up the limits of the plot () = chips_set_xrange( 0.5, 10.5 ); () = chips_set_yrange( -1.2, 1.2 ); % draw the data as a line connecting the points rather % than the default setting (crosses) chips.symbolstyle = _chips->none; chips.curvestyle = _chips->simpleline; () = curve( x, y ); % set up the axis labels () = chips_eval("xlabel 'X Axis'"); () = chips_eval("ylabel 'Y Axis'"); () = chips_eval("xlabel size 1.5"); () = chips_eval("ylabel size 1.5"); % create the plot chips_redraw();
If this code is saved to a file called "plot1.sl" then it can be evaluated by:
unix% slsh plot1.sl
Whilst it does create the plot, the window is destroyed immediately since the S-Lang script finishes after the call to chips_redraw().
A simple solution is to add code that extends the life of the program - perhaps
sleep(30);
to make the program last for 30 seconds longer, or
variable buffer; () = printf( "Enter return to exit the program: " ); () = fgets( &buffer, stdin );
which will wait until the user hits the return key.
An alternate solution is to create a hardcopy version of the plot rather than an X-windows display. This can be achieved by replacing the call to chips_redraw() by
which will create a postscript file called plot1.ps.
chips> set_state_defaults("chips") chips> print(chips) curvestyle = 2 symbolstyle = 2 linestyle = 6 curvecolor = 3 symbolcolor = 3 linecolor = 3 linewidth = 1 symbolsize = 3 font = 3 undo = 1 savevars = 1 colorsys = rgb pagewidth = 8 pagelen = 8 unit = inch tmpdir = /tmp tmpdata = /tmp/.chips.data.username.fits padfactor = 0.05 fullautolimits = 0 lowerloglimit = 0.01 mingridsize = 50
Many of the fields are direct counterparts to the plot attributes set using ChIPS commands such as curve, plot, symbol, and line. The following table lists the field, a description, and the default value:
Field Name | Description | Default |
curvestyle | curve style | _chips-![]() |
symbolstyle | symbol style | _chips-![]() |
linestyle | line style | _chips-![]() |
curvecolor | color of curve | _chips-![]() |
symbolcolor | color of symbols | _chips-![]() |
linecolor | color of lines | _chips-![]() |
linewidth | width of line | 1.0 |
symbolsize | size of symbols | 3.0 |
font | font used for text | _chips-![]() |
undo | turns undo on/off | 1 (i.e. on) |
savevars | see "Saving temporary files" section | 1 (i.e. on) |
colorsys | color system for plotting | rgb |
pagewidth | x dimension of the hardcopy plot | 8.0 |
pagelen | y dimension of the hardcopy plot | 8.0 |
unit | unit for pagewidth and pagelen | inch |
tmpdir | location of temporary files (see "Saving temporary files" section) | $ASCDS_WORK_PATH |
tmpdata | name of temporary files (see "Saving temporary files" section) | ![]() ![]() |
padfactor | padding for plots | 0.05 |
fullautolimits | if on, includes labels and lines in calculating auto limits | 0 (i.e. off) |
lowerloglimit | lower limit threshold for log scales | 0.01 |
mingridsize | size of the interpolated data grid (see "Plotting contours" section) | 50 |
The allowable options for the relevant fields are discussed in the "Attribute values" section.
If data is uniform, chips.mingridsize is not used in linear scale. In log scale, it is used only if the data grid supplied by user is smaller than the current chips.mingridsize setting; this determination is done independently for X and Y coordinates.
The value of chips.mingridsize may be set at the prompt. After doing so, change from linear to log scale and back (or vice-versa) to recalculate the grid. Note that the appearance of the contours may not be accurate because of the interpolation.
(the trailing semi-colon is only needed if used in S-Lang code rather than entered at the ChIPS prompt).
Attribute type | Attribute values |
Color | _chips-![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Curve Styles | _chips-![]() ![]() ![]() ![]() |
Line Styles | _chips-![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Symbol Styles | _chips-![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Font Names | _chips-![]() ![]() ![]() ![]() ![]() |
Color Systems | _chips-![]() ![]() ![]() |
Units | _chips-![]() ![]() ![]() |
For the color values, the S-Lang functions chips_color_name() and chips_color_value() are also available to help convert between text (e.g. "RED") and numeric (e.g. 6) forms.
It is important to note that the ChIPS state object is currently not saved by the STORE command. So, after using the RESTORE command, data will be drawn correctly but the values of the ChIPS state object will not be changed.
The resource file must be in one of the following locations:
The search stops when the first match is made and ChIPS is launched, even if the chosen resource file contains an error.
The following is an example $HOME/.chipsrc file that causes any application that starts ChIPS to print two messages and set a number of plot defaults:
message("Starting to process .chipsrc") chips.curvecolor = _chips->blue chips.symbolcolor = _chips->red chips.linecolor = _chips->green chips.curvestyle = _chips->histo chips.symbolstyle = _chips->diamond chips.font = _chips->italic message("Finished processing .chipsrc")
After this file is read, any columns plotted from prism, for example, will consist of red diamonds connected by a blue line using the histogram (step) mode, and the axis labels will be italic.
Although the first and last lines of the above example create screen output for demonstrative purposes, it is recommended that the .chipsrc file does not contain any command that creates either text or graphical output.
So, if /home/ciaouser/slang/setup_chips.sl contained
% set up the fields of the ChIPS % - this is a S-Lang file so all statements need to end in ; chips.curvecolor = _chips->blue; chips.symbolcolor = _chips->red; chips.linecolor = _chips->green; chips.curvestyle = _chips->histo; chips.symbolstyle = _chips->diamond; chips.font = _chips->italic; % define some useful functions define xaxis(label) { variable oldval = chips_auto_redraw(0); () = chips_eval( "xlabel '" + string(label) + "'" ); () = chips_eval( "xlabel size 1.5" ); () = chips_auto_redraw(oldval); } define yaxis(label) { variable oldval = chips_auto_redraw(0); () = chips_eval( "ylabel '" + string(label) + "'" ); () = chips_eval( "ylabel size 1.5" ); () = chips_auto_redraw(oldval); }
then this could be made available to ChIPS by adding the line
to your .chipsrc file. Note that we use the full path to the file so it can be found wherever ChIPS is started from. See "ahelp chips_eval" for more details on the "xaxis()" function.
For a full list of ChIPS commands and S-Lang functions use "ahelp -c chips".
Examples:
unix% chips Welcome to ChIPS, version CIAO3.1 Copyright (C) 1999-2003, Smithsonian Astrophysical Observatory chips> info Drawing Area #1 << CURRENT DRAWING AREA (Location: 0.15 0.9 0.1 0.9) (Limits : -0.05 1.05 -0.05 1.05) (Axes : fouraxes color: defaultcolor width: 1) chips>
Here we used the INFO command to display the current plot settings. As no plots have been created it lists the default settings.
chips> curve "lc.fits[cols time,rate]" chips> red
Plotting two columns from a FITS file
The CURVE
command is used here to plot the RATE
column against the TIME column from the
file lc.fits.
The column selection is made using the Data Model
syntax (see "ahelp dmcols"); in fact
any valid Data Model "virtual file" syntax
("ahelp dmsyntax")
can be used to filter the file before it is
displayed.
Once the data is displayed the look of the plot can be manipulated using commands such as RED. See the following example for further details.
chips> x = [1:10:0.1] chips> y = sin(x) chips> chips.curvecolor = _chips->red chips> chips.curvestyle = _chips->simpleline chips> curve( x, y ) 0
The "0" after the curve command
indicates that it was a success; it can be
avoided by saying "() curve(...)"
as shown below.
This plot may also be created using ChIPS commands to alter the attributes of the curve:
chips> set_state_defaults("chips") chips> clear chips> () = curve( x, y ) chips> simpleline chips> red
The main difference between the two approaches is that values in the ChIPS state object are persistent, meaning that they will be used as the defaults for any new plotting objects that are subsequently created, whilst the ChIPS commands like RED only refer to the current plot item.
These examples would produce the same results if the ChIPS CURVE command had been used - i.e. "curve x x y" - rather than the S-Lang "curve()" function.
() = chips_eval( "title 'Plot title'" ); () = chips_eval( "title size 1.5" );
See "ahelp chips_eval" for more information on this.
unix% ( setenv CHIPSRC /dev/null; chips )
and for ksh:
unix% ( export CHIPSRC=/dev/null; chips )
The command-line options for ChIPS - which can also be listed by entering "chips -help" - are:
Option | Description |
-batch | Runs in batch mode: the ChIPS welcome message is not displayed, any supplied code is run as if "BATCH ON" were specified, and ChIPS exits after evalulating the code. |
-h, -help, or -help | Lists the command-line options. |
-nosession | Do not attatch this ChIPS to the current CIAO session. |
-slscript ![]() ![]() |
Evaluates the S-Lang code in ![]() ![]() |
-xpa ![]() ![]() |
Sets the XPA access point of ChIPS to
![]() ![]() |
See the section titled "The command line" in the main discussion for more details on how ChIPS and S-Lang code can be automatically executed by ChIPS using these options.
ChIPS has an XPA access point which can be used to control its behaviour. This is used by the CIAO session handling ("ahelp session") to provide an integrated analysis environment.
The default name is "chips", with further instances being called "chips2", "chips3", ...(the "-xpa" command-line option can be used to override this naming scheme). ChIPS understands the following commands when sent via XPA:
unix% xpaget prism cmd: Any valid ChIPS command options: see ChIPS documentation for each command exit: Exit the current application options: None quit: Synonym for "exit"
If you have a ChIPS program running then the following will clear its display, set the plot limits to 0-10 on both axes, and draw a line between (1,1) and (8,9):
unix% xpaaccess chips yes unix% xpaset -p chips "cmd clear" unix% xpaset -p chips "cmd limits 0 10 0 10" unix% xpaset -p chips "cmd line 1 1 8 9"
You can also send in any S-Lang command you can enter at the ChIPS prompt. For example:
unix% xpaset -p chips "cmd () = chips_set_xrange(0,9)"
The '() ' is needed to avoid the return value
being printed in the ChIPS terminal window.
It is not possible to use the xpaget command to get information from ChIPS. Sending a command like "INFO" via XPA results in the output being printed to the ChIPS terminal window.
cxchelp@head.cfa.harvard.edu