Spectrum exampleThe following Python example reads a type II PHA file, rebins the channels in each spectrum by a factor of 2, multiplies the spectrum values by 1.5, and writes out the result.
import os
from heasp import *
# read the spectrum
spectra = phaII("testin.pha")
# loop round the spectra in the file
# rebinning by a factor of 2 then placing
# in the output spectra
output = phaII()
Nspectra = spectra.getNumberSpectra()
groupInfo = grouping()
for i in xrange(Nspectra):
spectrum = spectra.getphasElement(i)
groupInfo.load(2,spectrum.getNumberChannels())
status = spectrum.rebinChannels(groupInfo, "PROPAGATE")
spectrum *= 1.5
output.push(spectrum)
# write out the spectrum
phafile = "testout.pha"
if (os.path.exists(phafile)): os.remove(phafile)
status = output.write(phafile)
if status != 0: print("Failed to write testout.pha: status = ", status)
HEASARC Home | Observatories | Archive | Calibration | Software | Tools | Students/Teachers/Public Last modified: Friday, 14-Mar-2025 15:41:24 EDT |


