Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: 14 December 2010

URL: http://cxc.harvard.edu/sherpa/about.html

About Sherpa


Sherpa is the CIAO modeling and fitting application made available by the Chandra X-ray Center (CXC). It can be used for analysis of images, spectra and time series from many telescopes, including optical telescopes such as Hubble. Sherpa is flexible, modular and extensible. It has an IPython user interface and it is also an importable Python module. Sherpa models, optimization and statistic functions are available via both C++ and Python for software developers wishing to link such functions directly to their own compiled code.

The CIAO 4.3 Sherpa release supports fitting of 1-D X-ray spectra from Chandra and other X-ray missions, as well as 1-D non-X-ray data, including ASCII data arrays, radial profiles, and lightcurves. The options for grating data analysis include fitting the spectrum with multiple response files required for overlapping orders in LETG observations. Modeling of 2-D spatial data is fully supported, including the PSF and exposure maps. User specified models can be added to Sherpa with advanced "user model" functionality.

Features

Python environment

Sherpa is an importable module for the Python scripting language, providing users with the ability to write their own Python scripts for use in Sherpa. This easily allows for creating complex analysis and modeling functions, building batch-mode analysis, and extending the provided functionality to meet required needs.

Startup Options

There are five command-line options which may be specified when Sherpa is started:

  • -x : launch chips/sherpa shell in separate display terminal.
  • -b : run in batch mode
  • -n : do not print banner
  • -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.

The same options may be used with ChIPS.

The Sherpa and ChIPS applications use the $HOME/.ipython-ciao/ directory to store configuration information. The first time Sherpa or ChIPS is started you will see a message asking whether you want to update your ipythonrc-sherpa or ipythonrc-chips file.

unix% ciao
unix% sherpa

 ATTENTION: Out of date IPython profile for Sherpa found in:
           /home/username/.ipython-ciao

           Local version (40201) vs latest (40301).
           Update to latest? [Y/N] :

Unless you have manually changed your $HOME/.ipython-ciao/ipythonrc-sherpa(or -chips) file, it is safe to answer "Y" here. The outdated file is renamed with a timestamp to preserve it.

Accessing and manipulating data structures

In addition to the normal mode of loading data from files, Sherpa allows you to manipulate the data arrays internally at the Python prompt and then "re-load" them before fitting and modeling further. The resulting data may be manipulated without writing it to a file, making it easy to incorporate into scripts.

The analysis of data from modern instruments requires a flexible modeling and fitting system. The Sherpa infrastructure provides the user with an environment to develop complex and sophisticated analysis that goes beyond the default Sherpa functionality. Examples of user-contributed Python packages which extend Sherpa's functionality are Cosmocalc, Datastack, Deproject, and the standalone Sherpa application.

User Interface

There are many functions available for accessing internal data, model data, fit and projection results, plotting objects, etc., in a Sherpa session. These provide the user with easy access and interaction with the system required by modern data analysis. Examples of such functions include:

	show_data
	show_bkg
	show_model
	show_filter
	show_fit
	show_all
	get_arf 
        get_rmf 
        get_response
        get_bkg_scale
        get_backscal
	get_conf_results
	get_data_plot_prefs
	get_delchi_plot
	get_curve_xrange
	get_curve_yrange
        set_plot_title
        set_plot_xlabel
        set_plot_ylabel
	

The much longer list of get*, set*, show*, etc., functions may be accessed by typing, e.g., "*get*?" at the Sherpa prompt.

Optimization methods

There are three optimization methods available in Sherpa: "levmar", a modification of the Levenberg-Marquardt algorithm which uses the LMDIF algorithm; "neldermead", A Nelder-Mead Simplex direct search; and "moncar", a Monte Carlo method - differential evolution - based on the paper by Hedar & Fukushima. These algorithms are robust and show very good convergence required by modern data analysis.

The Primini and Sigma-rejection iterative fitting methods in Sherpa allow the chosen optimization method to be called multiple times during a fit, instead of just once, until the fit can no longer be improved. The Primini method re-calculates statistical errors using the best-fit model parameters from the previous fit, while the Sigma-rejection method excludes poorly fit data points at each successive fit.

Statistics

There are several choices of fit statistic in Sherpa, including cash (maximum likelihood) and many options of weighted χ2 statistics. The full list includes:

	  cash
	  cstat
	  χ2 statistics:
            chi2/leastsq
            chi2constvar (CHI PARENT | CVAR)
            chi2datavar (CHI DVAR)
            chi2gehrels (CHI GEHRELS)
            chi2modvar (CHI MVAR)
            chi2xspecvar
	

Descriptions of all available fit statistics are provided on the Sherpa Statistics page.

The Sherpa interface also provides an easy way to define new statistics required for analysis by the user. The load_user_stat function accommodates user-defined functions for a statistic and statistical errors, in addition to defining a list of model parameters and hyperparameters for prior distributions (if prior desired).

Parameter Uncertainties and Confidence Regions

Confidence, Covariance, and Projection, based on the CIAO 3.4 algorithm, calculate the confidence range for the best-fit model parameters; interval-projection and region-projection provide a way to visualize the model constraints on the best-fit parameter values. The results are easily accessible with the user functions get_conf_results, get_proj_results, and get_covar_results.

The following computationally intensive functions are parallelized to make use of multi-core systems (i.e., laptops or desktops with 2 or 4 cores), providing users with such systems significant improvements in efficiency compared to previous releases of Sherpa. Each function has a "numcores" option to specify the number of cores to use in parallelization; the default is to use all cores available.


Models

Sherpa in CIAO 4.3 allows the user to define customized models and provides several flexible options for defining complex model expressions for fitting data.

Complex model expressions which apply response matrices, or PSFs, to some model components, while not applying the response or the PSF to the rest of the model expression, may be defined with the set_full_model and set_bkg_full_model functions. This allows for including both convolved and unconvolved model components in a single model expression for fitting source and/or background data.

It is possible to simultaneously fit multiple data sets with each independent source model convolved by a different PSF model.

The Sherpa table model supports additive and multiplicative XSpec-style table models, as well as linear interpolation of data points on the data set grid from the model grid supplied from file.

The add_model function may be used to register a user-defined Sherpa model class as a Sherpa model type, to create instances of models that are recognized automatically in Sherpa model expressions.

The paramprompt command of Sherpa 3.4 is now available in Sherpa 4.3 to control whether Sherpa prompts the user for initial parameter values when a model component is created. If parameter prompting is turned on, the user is queried for the initial value of each model component parameter when it is established.

There are plotting functions available for visualizing the contribution of individual model components to a fit of a multi-component model to data. These functions can accept one or multiple Sherpa model components. Similarly, users can view 2D model components in DS9.

Fitting

The Primini and Sigma-rejection iterative fitting methods of Sherpa in CIAO 3.4 are now available in 4.2. The following functions are available for iterative fitting in Sherpa: set_iter_method, get_iter_method_name, list_iter_methods, get_iter_method_opt, and set_iter_method_opt.

The fit_bkg function is available for fitting only background data sets when fitting with PHA spectral data. The function's list of arguments is the same as the fit function. (This function provides functionality equivalent to the Sherpa 3.4 BFIT command.)

The functions calc_stat_info and get_stat_info implement functionality similar to the GOODNESS command from Sherpa 3.4. Goodness-of-fit statistics usually returned by a Sherpa fit are now also calculated separately; it is no longer necessary to perform a new fit just to return the goodness-of-fit information.

Filtering and Grouping Data

The following grouping functions are avaible for grouping PHA channel data to match functionality provided in Sherpa 3.4. These functions use the CIAO group module to group data in various ways:


Saving the Sherpa Session

save_all command saves all the settings which define the current Sherpa session to an ASCII file. The resulting file can be read into a future Sherpa session to recreate the data, models, filter, grouping and quality flags, statistic and method used at that time.

The save command creates a binary file that can be restored in Sherpa with the restore.

Missing or changed functionality with respect to Sherpa 3.4

Commands and algorithms

Initial model parameter values are not automatically guessed in Sherpa 4 as they were in Sherpa 3.4; the guess is available for this purpose, but only for simple (i.e. single-component) models. This command makes an initial guess at parameter values to ensure convergence, but users should check that the initial range of parameter values (soft limits) is sensible for their data.

Certain keywords such as "data", "model", "fit", and "bkg" cannot be used as data set IDs, nor can model names be set to known Python function names (e.g., "abs").

Statistics

The "bayes" statistic is not implemented.

Fitting

Multiplication of two integrated models, each with its own normalization, is not handled correctly. It results in incorrect fit parameters and an incorrect number of counts in fake_pha simulations.

User interface

There is no interface to the GUIDE atomic transition catalog.

Plotting

Sherpa and ChIPS no longer have the ability to do surface plots of 2-D data. However, the support for contour plots is improved in the new version of ChIPS.

Plotting model-fitted spectra in photon flux units: there is no function in Sherpa 4.3 equivalent to the Sherpa 3.4 function "lplot UFIT", which plots fitted data in photon flux units; see Sherpa Plotting FAQs #2 for a Sherpa 4.3 routine which mimics its behaviour.


Last modified: 14 December 2010
Smithsonian Institute Smithsonian Institute

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