The following Python example reads a type II PHA file, rebins the channels in each spectrum by a factor of 2 and writes out the result.
# 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.getphas(i) groupInfo.load(2,spectrum.getNumberChannels()) status = spectrum.rebinChannels(groupInfo) output.push(spectrum) # write out the spectrum output.write("testout.pha")