Introduction to Sherpa, the CIAO modeling and fitting package
The CIAO 4 release includes a new, more powerful version of Sherpa, the CIAO modeling and fitting package. Sherpa enables the user to construct complex models from simple definitions and fit those models to data, using a variety of statistics and optimization methods.
This document provides an introduction to Sherpa; more information is available on the Sherpa website.
Sherpa is designed for use in a variety of modes: as a user-interactive application and in batch mode. The Sherpa command launches an interactive Python session (using the IPython interpreter), in which Sherpa commands (which are Python functions) can be used, as well as ChIPS commands (to create and modify plots); Crates commands for reading and writing files; as well as other Python functions. It is possible to write Python scripts that import the relevant Sherpa modules, and so run non-interactively.
The Sherpa session can be saved into a platform-independent state file. The session can then be restored at any time.
From the CIAO command line, type:
unix% sherpa [-x|-n|-b|-rcfile|-norcfile] <file>
Any or all of the following options which may be supplied when Sherpa is started:
- -x : launch Sherpa shell in separate display terminal.
- -n : prevents the Sherpa banner from being displayed on startup.
- -b : runs Sherpa in batch mode
- -rcfile : specify a specific .sherpa.rc file to use; refer to "ahelp sherparc" for details.
- -norcfile : do not load any .sherpa.rc file; overrides "-rcfile" if both are set.
- <file>: Python command file to execute
The "Starting Sherpa" thread has more details.
The Sherpa Resource File: .sherpa.rc
When Sherpa is started, it processes the $HOME/.sherpa.rc resource file. The resource file defines default behavior for the Sherpa commands and can be customized to the user's preferences; refer to "ahelp sherparc" for details.
To import the Sherpa, CRATES, and ChIPS modules in Python without using the "sherpa" startup script:
from sherpa.astro.ui import * from pychips.hlui import * from pycrates import *
You may also find it useful to load the numpy module
import numpy as np
There are several ways to access the Sherpa help files. Note that in the CIAO 4.10 release the Pyton docstrings are the preferred option, and that the ahelp pages for Sherpa commands are not guaranteed to be kept up to date.
Within the Sherpa application, the native Python help system can be used:
sherpa> help <command>
It is also possible to do a wildcard search for commands, by taking advantage of the native IPython support:
sherpa> plot* ? sherpa> *psf ?
Alternatively, the ahelp system can be used either directly:
sherpa> ahelp("<command>") sherpa> ,ahelp <command>
or by running the ahelp command-line program:
sherpa> !ahelp <command>
From the CIAO command line
Syntax, description and examples for a specific command:
unix% ahelp <command>
The ChIPS GUI
The ChIPS GUI can be used to modify any Sherpa plot. It is launched by right clicking on an existing ChIPS window and selecting "Launch GUI" or by running the show_gui command from within a ChIPS session. A Python terminal is built into the GUI, allowing access to ChIPS and other Python commands.
- the ability to edit the properties of an object, such as the symbol style of a curve or the font used for an axis label,
- zoom, pan, and select objects in the plot,
- update the plot ranges,
- move plot areas and annotations,
- resize plot areas, labels, and points,
- and an object tree which describes existing plot objects.
Futher information is available from the built-in help menu in the GUI and via "ahelp chipsgui".
Contributing to Sherpa
Development of Sherpa has moved to GitHub and can be found at https://github.com/sherpa/sherpa. Please consider contributing to Sherpa development - whether it is reporting bugs, providing documentation updates, fixing bugs, or adding new functionality. Using this repository, Sherpa can be installed outside of CIAO, and so used with Python packages that can not be installed into the CIAO environment.
Changes in CIAO 4.10
Changes have been made to fix problems Python 3.5 version of Sherpa. Use
% python --version
to check what version of Python is being used by CIAO, as CIAO 4.10 provides either Python 3.5.4 or 2.7.14.
The Pyton docstrings are the preferred means for documenting Sherpa's behavior. The ahelp files are still provided but are not guaranteed to be kept up to date. This means that the recommended command to use for help is now the Python help command, rather than ahelp, for Sherpa functions.
XSPEC models update
The XSPEC models have been updated to release 12.9.1n in CIAO 4.10. Support for the following models have been added to Sherpa: xsbtapec, xsbvtapec, xsbvvtapec, xscarbatm, xshatm, xsismabs, xsnlapec, xsslimbh, xssnapec, xstapec, xstbfeo, xstbgas, xstbpcf, xstbrel, xsvoigt, xsvtapec, xsvvtapec, and xsxscat.
These models are only documented using Python docstrings, and not in ahelp. Use the help command on the model instance for information, as shown in the following example:
sherpa> set_source(xsphabs.gal * xsbvtapec.src) sherpa> help(src) ...
Parameter names now match those of XSPEC
Over time the parameter names of some XSPEC models have changed - e.g. to support use in Python - so in CIAO 4.10 the Sherpa XSPEC interface has been updated to match the XSPEC names. The old names can still be used (they are aliased to the new name). As an example, the xsdisk model now uses the name 'CenMass' for the central mass parameter, but the old version ('NSmass') can still be used, as shown below:
sherpa> create_model_component('xsdisk', 'mdl') <XSdisk model instance 'xsdisk.mdl'> sherpa> mdl.cenmass.val 1.3999999999999999 sherpa> mdl.nsmass = 2 sherpa> mdl.cenmass.val 2.0
It is strongly suggested that code be updated to use the new names, as support for these aliases may be removed in a later release. The Python documentation for each model can be read to find out if a parameter contains an alias. The following table lists the parameters that have been changed.
|Model name||Old parameter name||New parameter name|
Note that the RoutG parameter for the xslaor model does not contain the alias, and so users of this model will need to replace 'RoutG' with 'Rout_G' (it is a case insensitive match).
The following routines have been added to the sherpa.astro.xspec module: get_xspath_manager, get_xspath_model, and set_xspath_manager.
See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.