SPEX user model support

The pyspextools module provides interface routines to create SPEX user models. There is a helper class for the SPEX ‘user’ and ‘musr’ models, which provides the opportunity for users to import their own models into SPEX.

SPEX user model interface module

This is a Python helper class for the development of user defined models in SPEX. The ‘user’ and ‘musr’ components in SPEX can calculate an additive and multiplicative model, respectively, based on a user program. See the SPEX manual for details: http://var.sron.nl/SPEX-doc/

The ‘user’ component can run an executable provided by the user. This module provides the class that helps to exchange the relevant information between SPEX and the user provided executable. Documentation for an example program is here: User model example.

SPEX output and executable input:

The SPEX user component will provide an energy grid and a list of model parameters to the executable through a text file, for example input-01-01.prm. Using this information, the user provided program should calculate the spectrum on the provided grid using the input parameters.

Executable output and SPEX input:

The spectrum (and the weights) can be written to the provided sener (and wener) arrays in this module. The write_spc function will write the calculated spectrum to an output file named, for example, output-01-01.spc. This file will be read again by the SPEX user model and the resulting values will be used in the SPEX fit.

class pyspextools.model.User[source]

Class structure to contain the input and output parameters of the user function.

Variables
  • npar (int) – Numper of model input parameters from SPEX.

  • par (numpy.ndarray) – Array containing the parameter values from SPEX (length npar).

  • neg (int) – Number of bins in the input energy grid from SPEX.

  • egb (numpy.ndarray) – Upper boundaries of the energy bins (length neg).

  • eg (numpy.ndarray) – Bin centroids of the energy bins (length neg).

  • deg (numpy.ndarray) – Bin widths of the energy bins (length deg).

  • sener (numpy.ndarray) – Spectrum or transmission (e.g. in ph/s/bin)

  • wener (numpy.ndarray) – If Delta E = average photon energy within the bin (keV) minus the bin centroid then wener = sener * Delta E

  • fprm (str) – Input file name from command line.

  • fspc (str) – Output file name from command line.

read_prm()[source]

Read the parameter file that SPEX creates at the beginning of the model evaluation. This is done automatically when the User class is initialised.

write_spc()[source]

Write the calculated spectrum to the output file for SPEX. Make sure that the sener and wener arrays are initialized and filled with a spectrum before calling this function.