4.1.40. User: User defined model

The user model provides an interface to create an additive model component calculated by a user program. The interface is rather simple and therefore very flexible. The interface uses a set of two ASCII files: input-?-?.prm and output-?-?.spc, where the ’?’ stands for the sector and component number of the user model component.

The input-?-?.prm is generated by the user model and contains the parameter values and the energy grid that SPEX uses to calculate the model. The file has a fixed structure:

  • The first line contains one integer number containing the number of parameters that the model needs to calculate (current maximum is 40).

  • On the second line the array of parameter values is listed (with the length indicated on the previous line.

  • On the third line, an integer value is shown which indicates the number of model bins SPEX has in its model grid.

  • On the following lines, the model grid points are shown in three columns. The first column contains the bin upper boundary (egb), the second column is the bin center (eg) and the third column is the full bin width (deg). The energy values are in keV.

The user program is supposed to read the input file and calculate the model spectrum for each energy bin on the grid. The spectrum array is called sener and has the same length as the energy grid and unit photons/s/bin. In addition, it is also possible to calculate the model for the emission weighted center of the bin. In that case the spectrum calculation is a bit more complicated, but it leads to better results. The user has the option of also calculating the weighted spectrum, which is the average photon energy E_{\mathrm{aver}} minus the bin centroid E_{\mathrm{centroid}} times the flux (F):

W = (E_{\mathrm{aver}} - E_{\mathrm{centroid}})  F

The W values end up in the wener array. If you do not use weighing by average photon energy, wener values can be 0.

The user program should create an output ASCII file named output-?-?.spc with the following structure:

  • On the first row, put the number of model bins. This should be the same number as written in the input-?-?.prm file.

  • Write the sener and wener values in two columns. The first column is the sener value in photons/s/bin and the second column is the wener value.

In How to use the SPEX user model some example user model programs can be found. The source code can be adapted to accommodate the user’s wishes.

The equivalent of user for multiplicative models is Musr: User defined multiplicative model.

The parameters of the model are:

exec : User executable, for example ’./model.py’ for a python script in the same directory where you run SPEX
npar : Number of free parameters in the model. Current maximum is 40.
p01...p40 : Model parameters of the user model.