Chandra X-Ray Observatory
	(CXC)
Skip to the navigation links
Last modified: 13 March 2017

How can I assign XSPEC-style numbering to Sherpa model parameters for use in my script?


Model parameters are identified by names such as "abs1.nH" or "pl.gamma" in Sherpa, but sometimes it is useful to reference them by number instead - e.g., parameters 1, 2, 3, 4 - in order to easily manipulate them within a script. Model parameter names may be replaced by numbers in Sherpa as follows:

sherpa> load_data('pha.fits')
sherpa> set_model(xswabs.wabs1 * xspowerlaw.pow1)

sherpa> show_model()
apply_rmf(apply_arf((3709.22913978 * (xswabs.wabs1 * xspowerlaw.pow1))))
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   wabs1.nH     thawed            1            0       100000 10^22 atoms / cm^2
   pow1.PhoIndex thawed            1           -2            9           
   pow1.norm    thawed            1            0        1e+24      

sherpa> mdl = get_model()
sherpa> mdl.pars
         
(<Parameter 'nH' of model 'wabs1'>,
 <Parameter 'PhoIndex' of model 'pow1'>,
 <Parameter 'norm' of model 'pow1'>)


sherpa> parnums = (1, 2, 3)
sherpa> for par, parnum in zip(mdl.pars, parnums):
            par.name = parnum

sherpa> mdl.pars

(<Parameter '1' of model 'wabs1'>,
 <Parameter '2' of model 'pow1'>,
 <Parameter '3' of model 'pow1'>)

In this example, the "mdl" model parameters "nH", "PhoIndex", and "norm" are replaced with IDs "1","2", and "3", respectively.



Last modified: 13 March 2017
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-2017. All rights reserved.