Getting startedThe 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 heasprequires 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 >>>sp.read("file1.pha") >>>sp.disp()Alternatively, the object can be defined directly from a file by >>>sp = pha("file1.pha") >>>sp.disp()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: >>>sp.setFirstChannel(0)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: >>>sp.getPhaElement(5)Going the other way, a single element of the current contents of the PHA column can be replaced by e.g.: >>>sp.setPhaElement(5,0.4)and the entire array using e.g.: sp.setPha(array([0.1,0.2,0.3,0.4,0.5]))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, 28-Aug-2024 16:49:33 EDT |