SPEX 4.0 documentation

Contents:

  • News
  • Install
    • Conda/Mamba
    • Install packages
    • Activate Python
    • Compile from source
    • Run in Docker
  • Using SPEX
    • General examples
      • How to run SPEX
      • How to convert spectra to SPEX format
    • Analysis threads
      • Fitting a CCD spectrum
      • Modeling particle background
      • Fitting interstellar dust absorption
      • Import UV/Optical data
      • PION setup for AGN warm absorber
      • PION setup for emission and absorption features in AGN
      • Fitting two different spectra simultaneously
      • How to use the SPEX user model
        • Use any Xspec model in SPEX
        • Use local Xspec model ismabs in SPEX
    • Performance
      • Optimizing model performance
    • Exercises
      • Powerlaw
      • Powerlaw with a Gaussian line
      • Statistics, binning and more
      • Stellar Spectra
      • Supernova remnants
      • Relativistic lines
      • AGN winds
  • Command syntax
    • Abundance: standard abundances
    • Aerror: Estimate atomic data errors for model parameters
    • Ascdump: ascii output of plasma and spectral properties
    • Ascdump output table properties
    • Bin: rebin the spectrum
    • Calculate: evaluate the spectrum
    • Comp: create, delete and relate spectral components
    • Data: read response file and spectrum
    • DEM: differential emission measure analysis
    • Distance: set the source distance
    • Egrid: define model energy grids
    • Elim: set flux energy limits
    • Error: Calculate the errors of the fitted parameters
    • Fit: spectral fitting
    • Ibal: set type of ionisation balance
    • Ignore: ignoring part of the spectrum
    • Ion: select ions for the plasma models
    • Log: Making and using command files
    • Menu: Menu settings
    • Model: show the current spectral model
    • Multiply: scaling of the response matrix
    • Obin: optimal rebinning of the data
    • Par: Input and output of model parameters
    • Plot: Plotting data and models
    • Quit: finish the program
    • Rbin: optimal rebinning of the data and response, including saving
    • Reset: Reset the data and/or model
    • Sector: creating, copying and deleting of a sector
    • Shiftplot: shift the plotted spectrum for display purposes
    • Simulate: Simulation of data
    • Step: Grid search for spectral fits
    • Syserr: systematic errors
    • System: call system executables
    • Use: reuse part of the spectrum
    • Var: various settings for the plasma models
    • Vbin: variable rebinning of the data
    • Watch: track time and subroutines
  • Spectral models
    • Absm: Morrison & McCammon absorption model
    • Amol: interstellar dust absorption model
    • APEC: collisional ionisation equilibrium model (External)
    • Bb: blackbody model
    • Cf: isobaric cooling flow differential emission measure model
    • Cie: collisional ionisation equilibrium model
    • Clus: projected cluster model
    • Comt: comptonisation model
    • CX: model for charge exchange plasmas
    • Dabs: dust absorption model
    • Dbb: disk blackbody model
    • Delt: delta line model
    • Dem: differential emission measure model
    • Dust: dust scattering model
    • Ebv: Galactic interstellar extinction model
    • Etau: simple transmission model
    • Euve: EUVE absorption model
    • File: model read from a file
    • Gain: Modify the energy scale of the model to compensate instrumental gain errors
    • Gaus: gaussian line model
    • Hot: collisional ionisation equilibrium absorption model
    • Hyd: model with user-own hydrodynamical simulation
    • Knak: segmented power law transmission model
    • Laor: relativistic line broadening model
    • Line: transmission model for a single spectral line
    • Lpro: spatial broadening model
    • Mbb: modified blackbody model
    • Musr: User defined multiplicative model
    • Neij: non-equilibrium ionisation jump model
    • Pdem: DEM models
    • Pion: SPEX photoionised plasma model
    • Pow: power law model
    • Reds: redshift model
    • Refl: reflection model
    • Rrc: radiative recombination continuum model
    • Slab: thin slab absorption model
    • Spei: relativistic line broadening model
    • Spln: spline continuum model
    • SSD: Shakura-Sunyaev disk model
    • Tpho: Time-dependent, non-equilibrium, photoionised plasma model
    • User: User defined model
    • Vblo: rectangular velocity broadening model
    • Vcom: Compton shoulder broadening model
    • Vgau: gaussian velocity broadening model
    • Vpro: velocity profile broadening model
    • Warm: continuous photoionised absorption model
    • Wdem: power law differential emission measure model
    • Xabs: photoionised absorption model
  • Plotting reference
    • Plot devices
    • Plot types
    • Plot colours
    • Plot line types
    • Plot text
    • Plot captions
    • Plot symbols
    • Plot axis units and scales
    • Plot asciidump file format
  • Spextools
    • Trafo
    • Stepcontour
    • Xabsinput
    • Hydro driver
    • Rgsvprof
    • RGS_fluxcombine
    • RGS_fmat
    • Uvtospex
    • Calling SPEX from Fortran
  • Python API Interface
    • Basic usage of PYSPEX
    • Basic PYSPEX commands
      • Data related commands
      • Model related commands
      • Ascdump commands
      • Optimization & Simulation commands
      • Plot commands
      • Log commands
      • Reset command
    • Jupyter Notebooks
    • Astropy units and tables
    • Spex class structure
    • Data class structure
    • Model class structures
    • Optimization & Simulation functions
    • Plot functions
    • Ascdump class
    • Logging commands
  • Fortran API Interface
  • Help & troubleshooting
    • Commandline help
    • Solving SPEX problems
    • Find known issues
    • Report issues
  • SPEX Theory
    • SPEX Atomic Code & Tables
      • The SPEX Atomic Code & Tables (SPEXACT)
      • Plasma model in SPEX 3.0
      • Absorption model theory
      • Atomic database for the absorbers
      • Non-equilibrium ionisation (NEI) calculations
      • Non-thermal electron distributions
      • Supernova remnant model theory
    • SPEX 2 notation of atomic transitions
    • Modelling and fitting
      • Calculating models on grids
      • Different types of spectral components
      • Sectors and regions
      • Spectral Fitting
      • Testing model significance
    • Optimal definition of respons matrices
    • Definition of the micro-turbulent velocity in SPEX
    • Supernova remnant model theory
  • Changelog
  • Credits
Theme by the Executable Book Project
Contents
  • Data
    • Data delete
    • Data save
  • Binning and data selection
    • Data selection
    • Systematic errors

Data related commands¶

The commands in this section are all related to the data structures within SPEX. They deal with spectral data and responses, simulation of data, etc.

Data¶

Loading spectral data and responses in SPEX is done with the data command. Data can be added by loading a .res and .spo file that contain the response and spectral information for an instrument. The PYSPEX command is:

where resfile is the response file and spofile the spectrum file. Note that this command needs the full filename (and if necessary the path to the file) including the extension. This is the only difference with the SPEX syntax. Example:

>>> s.data('xifu.res','xifu.spo')

Data delete¶

Deleting a loaded spectrum and response is done in SPEX with the data delete instrument #i command. In PYSPEX, this command is:

where ins is the instrument number to be deleted. For example:

>>> s.data_del(1)

Data save¶

Simulated spectra can be saved as a .spo file. In SPEX, this is done using the data save #i <spofile> command. In PYSPEX, the command is:

where ins is the instrument number of the data to be saved, spofile is the name of the output .spo file. Again note that you should give the full file name, including the .spo extension. Optionally, you can tell the command that existing files may be overwritten. For example:

>>> s.data_save(1,'sim.spo',overwrite=True)

or simply:

>>> s.data_save(1,'sim.spo')

if the file does not exist yet.

Binning and data selection¶

Unlike some other fitting packages, SPEX rebins the spectra within the program. The easiest binning method is to just rebin with a certain integer factor. This is the bin command in SPEX. In addition, SPEX contains a binning method based on the bin statistics (vbin) and an optimal binning algorithm (obin) which takes the instrument resolution into account.

Binning with factor

Binning with an integer factor is done with the bin command:

In this example, we bin the spectrum with a factor of 5 between 0.3 and 10 keV:

>>> s.bin(1,1,0.3,10.,5,'kev')

Variable binning

Variable binning is done with the vbin command:

In this example, we bin the spectrum with a minimum factor of 3 and a minimum signal-to-noise ratio of 25 between 0.3 and 10 keV:

>>> s.vbin(1,1,0.3,10.,3,25.,'kev')

Optimal binning

The optimal binning algorithm bins based on the instrument resolution and statistics:

In this example, we optimally bin the spectrum between 0.3 and 10 keV:

>>> s.obin(1,1,0.3,10.,'kev')

Data selection¶

Selecting data is done using the use and ignore commands. By default, the bin selection in the .spo file is loaded, which should use all the good bins.

Use function

Example:

>>> s.use(1,1,0.3,10.,'kev')

Ignore function

Example:

>>> s.ignore(1,1,0.0,0.3,'kev')
>>> s.ignore(1,1,10.,100.,'kev')

Systematic errors¶

If needed, the error bars on the source and background spectrum can be enlarged by the syserr command:

Warning

To use this function, you need to know what you are doing statistically. In many cases, this function would produce wrong results.

previous

Basic PYSPEX commands

next

Model related commands

By NWO-I/SRON Space Research Organisation Netherlands
© Copyright 1992-2026, NWO-I/SRON Space Research Organisation Netherlands, CC-BY-4.0.