Getting started

The standard HEAsoft build makes a Python 3 module based on the HEASP C++ classes described in the next chapter. The standard HEAsoft initialization script adds the location of the HEASP Python module to PYTHONPATH. To load the module use

UNIX> python3
>>>from heasp import *
If this produces name conflicts then loading the module by
UNIX> python3
>>>import heasp
requires heasp. in front of all commands. Since heasp C++ vectors are mapped to numpy arrays it is also a good idea to load the numpy module by
>>>from numpy import *

To set up an HEASP object first give a simple command such as

>>>sp = pha()
for a spectrum. This can then be read in and information about it displayed by
Alternatively, the object can be defined directly from a file by
>>>sp = pha("file1.pha")
Individual components of the object can be accessed by get methods. For instance:
>>>first = sp.getFirstChannel()
will place the first channel number in the variable first. There are corresponding set methods. For instance:
The components of each class are given in the appropriate chapter describing the C++ interface.

Components which are arrays can be loaded into numpy arrays. For instance:

>>>counts = sp.getPha()
Alternatively, a single element can be accessed:
Going the other way, a single element of the current contents of the PHA column can be replaced by e.g.:
and the entire array using e.g.:
Setting an individual element does not resize the array but setting the entire array does.

HEASARC Home | Observatories | Archive | Calibration | Software | Tools | Students/Teachers/Public

Last modified: Wednesday, 23-Mar-2022 21:09:02 EDT