Last modified: December 2021

Jump to: Description · Examples · ATTRIBUTES · Notes · Bugs

AHELP for CIAO 4.14 Sherpa


Context: modeling


Integrate a model across each bin (one dimensional).




Numerically integrate a one-dimensional model across each bin of a "histogram" dataset - that is one with low and high edges for each bin. The model to be integrated is supplied as an input to this model and any attribute changes must be made before this.


Example 1

>>> create_model_component("integrate1d", "mdl")
>>> print(mdl)

Create a component of the integrate1d model and display its default parameters. The output is:

   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   mdl.epsabs   frozen  2.22045e-16 -3.40282e+38  3.40282e+38           
   mdl.epsrel   frozen            0 -3.40282e+38  3.40282e+38           
   mdl.maxeval  frozen        10000 -3.40282e+38  3.40282e+38           

Example 2

The Integrate1D model lets you use a one-dimensional model which can only be evaluated at a point in a case where the dataset has a low and high edge for the independent axis - such as a Data1DInt object. The Scale1D model is used as an example of a model which only evaluates at a point (as it always returns the scale value), but in actual code you should use the Const1D model rather than apply Integrate1D to Scale1D. The evaluation of the `smdl` instance returns the `c0` parameter value (set to 10) at each point, whereas the `mdl` instance integrates this across each bin, and so returning the bin width times `c0` for each bin. Note that the tolerance for the integration:

>>> import numpy as np
>>> from sherpa.models.basic import Scale1D, Integrate1D
>>> xlo, xhi = [2, 5, 8], [4, 8, 12]
>>> imdl = Integrate1D(name='imdl')
>>> imdl.epsabs = np.finfo(np.float32).eps
>>> smdl = Scale1D(name='smdl')
>>> mdl = imdl(smdl)
>>> smdl.c0 = 10
>>> print(mdl)
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   smdl.c0      thawed           10 -3.40282e+38  3.40282e+38
>>> print(smdl(xlo, xhi))
[10. 10. 10.]
>>> print(mdl(xlo, xhi))
[20. 30. 40.]


The attributes for this object are:

Attribute Definition
epsabs The maximum absolute difference allowed when integrating the model. This parameter is always frozen.
epsrel The maximum relative difference allowed when integrating the model. This parameter is always frozen.
maxeval The maximum number of iterations allowed per bin. This parameter is always frozen.


If `imdl` is an instance of `Integrate1D` and `omdl` the model to integrate, then `imdl(omdl)` creates the integrated form. Note that changes to the `Integrate1D` parameters - such as `epsabs` - must be made before creating this integrated form. For example, to change the absolute tolerance to a value appropriate for 32-bit floats:

>>> imdl = Integrate1D(name='imdl')
>>> imdl.epsabs = np.finfo(np.float32).eps
>>> mdl = imdl(omdl)


See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.