Galaxy Cluster Seminar PyXspec

Galaxy Cluster Seminar
Bonn - 24.4.2014
PyXspec
Gerrit Schellenberger
Image courtesy of
C. Carreau and ESA
Spectral Fitting
pyXspec
● Xspec integration in Python comes with Heasoft
● (Almost) all Xspec commands available
Advantages
● Easy scripting without tcl
● Quick help and autocomplete using ipython
● Tasks can be stored in functions (e.g. freezing certain paramters...)
● Results can directly be used for further investigation with other Python modules
(e.g. halo mass function, plotting, ciao-tools)
Disadvantages
● Python knowledge is required
● For small tests (without existing routines) classic Xspec might be faster
PyXspec – How To Start?
Start:
● Source heasoft (6.12+)
source /vol/software/software/astro/heasoft/heasoft-init.sh 6.15
●
●
Start Python (only 2.7)
[/usr/bin/][i]python
Import the xspec module
> import xspec
Load Data:
● Default loading
> spec = xspec.Spectrum(''spectrum.pha'')
spec is now a data object with attributes (e.g. ignore, header-keywords...)
● With grouping parameters
> xspec.AllData(''2:2 spectrum.pha'')
can be dynamic with strings
> xspec.AllData(group+“:“+source+'' ''+filename)
PyXspec – How To Start?
Load Model
> m = xspec.Model(''phabs*apec'')
● Or with name and source:
> m = xspec.Model(''phabs*apec'',''Cluster'',1)
● Set the values
> m.apec.kT.values = 3.0
> m.phabs.nH.frozen = True
> m.show()
Fit the model to the data
> xspec.Fit.nIterations = 1000
> xspec.Fit.statMethod = ''chi''
> xspec.Fit.perform()
Plot the Fit
> xspec.Plot.device = "/xs"
> xspec.Plot.xAxis = "keV"
> xspec.Plot.add = True
> xspec.Plot.xLog = True
> xspec.Plot.yLog = True
> xspec.Plot("data delchi")
> xspec.Plot.show()
PyXspec - Teaser
PyXspec – Manual
http://heasarc.gsfc.nasa.gov/xanadu/xspec/python/html/quick.html
http://heasarc.gsfc.nasa.gov/xanadu/xspec/python/html/extended.html