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

Skip the navigation links
Last modified: December 2008

URL: http://cxc.harvard.edu/sherpa4.1/fit.py.html
AHELP for Sherpa 4.1

fit

Context: py.sherpa

Synopsis

Perform a fit using current optimization method and fit statistic.

Syntax

fit( [ id, [otherids], outfile="fit.out", clobber=True])

Description

The fit() function fits the defined model(s) to the data set(s) by data ID. It may be called with no arguments, in which case a fit is done simultaneously on all data sets for which the user has defined a model to be fit.

If a background file and background responses are defined for the dataset which is being fit, the background is automatically fit as well.

  • id, otherids - the id(s) of the data set(s) to use; default is to fit all datasets for which a model has been defined
  • outfile - name of the file in which to store parameter values and fit statistic after a fit (e.g., "fit.out")
  • clobber - a Boolean switch which indicates whether or not the 'outfile' should be overwritten, if the file already exists; default=True

The fit is done with the specified optimization method and statistic; the default values are levmar and chi2gehrels, respectively. The fit proceeds until it converges to within the set tolerance or hits the maximum number of iterations. The resulting best fit parameters and final statistic value are displayed to the user. The best-fit parameters are accessible with get_fit_results().

Example 1

sherpa> fit("src")

A single data set can be fit using its data set ID number or string.

Example 2

sherpa> fit()

The fit() function called with no arguments will simultaneously fit all data sets to which models have been assigned.

Example 3

sherpa> fit(3, outfile="fit_info.out", clobber=True)

In this example, data set 3 will be fit, and the fit parameter values and statistic will be stored in the file "fit_info.out" after the fit evaluation. This file will be overwritten if it already exists.

Example 4

sherpa> fit("leg_m1","leg_p1")

When multiple data sets are indicated, a simultaneous fit is performed and the statistics value is summed over all the data sets. For example, one may wish to simultaneously fit a source and background data set, multiple spectral orders of PHA grating data, etc. In this example, the LEG +1 and -1 spectral orders of an HRC-S/LETG grating data set are fit simultaneously by data ID:

        sherpa> fit("leg_m1","leg_p1")
	     LevMar:
	     Initial fit statistic = 21857.8
	     Final fit statistic   = 6662.04 at function evaluation 52
	     Data points           = 3162
	     Degrees of freedom    = 3158
	     Probability [Q-value] = 9.26899e-252
	     Reduced statistic     = 2.10958
	     Change in statistic   = 15195.8
	     bpow.phoindx1   1           
	     bpow.breake    0.763347    
	     bpow.phoindx2   1.79799     
	     bpow.norm      0.0294637
 
        sherpa> print get_fit_results()
	     methodname = LevMar
	     succeeded  = True
	     parnames   = ('bpow.phoindx1', 'bpow.breake', 'bpow.phoindx2', 'bpow.norm')
	     parvals    = (1.00000005713, 0.763346621728, 1.79799457922, 0.0294636807334)
	     covarerr   = None
	     statval    = 6662.04434909
	     istatval   = 21857.8439964
	     dstatval   = 15195.7996473
	     numpoints  = 3162
	     dof        = 3158
	     qval       = 9.26899264507e-252
	     rstat      = 2.10957705798
	     message    = relative error between two consecutive
	     iterates is at most xtol=1.19209e-07
	     nfev       = 52         
          

Bugs

See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

Last modified: December 2008



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.