def bin_(self): """Overloaded method. """ evt_header = self.event_file.hdu_list['PRIMARY'].header num_chans = evt_header['DETCHANS'] total_time = self.event_file.total_good_time() binning = numpy.linspace(-0.5, num_chans -0.5, num_chans+1) n, bins = numpy.histogram(self.event_data['PHA'], bins=binning) primary_hdu = self.build_primary_hdu() data = [numpy.arange(num_chans), n/total_time, numpy.sqrt(n)/total_time ] spec_hdu = xBinTableHDUPHA1(data) spec_hdu.setup_header(self.event_file.primary_keywords()) irf_name = evt_header['IRFNAME'] keywords = [('EXPOSURE', total_time, 'exposure time'), ('RESPFILE', irf_file_path(irf_name, 'rmf')), ('ANCRFILE', irf_file_path(irf_name, 'arf'))] spec_hdu.setup_header(keywords) hdu_list = fits.HDUList([primary_hdu, spec_hdu]) hdu_list.info() logger.info('Writing binned PHA1 data to %s...' % self.get('outfile')) hdu_list.writeto(self.get('outfile'), clobber=True) logger.info('Done.')
def __init__(self, file_path, **kwargs): """ """ xspec.AllData.clear() self.count_spectrum = xBinnedCountSpectrum(file_path) irf_name = self.count_spectrum.primary_header_keyword('IRFNAME') self.spectrum = xspec.Spectrum(file_path) self.spectrum.response = irf_file_path(irf_name, 'rmf') self.spectrum.response.arf = irf_file_path(irf_name, 'arf') self.spectrum.ignore('**-%f' % kwargs['emin']) self.spectrum.ignore('%f-**' % kwargs['emax']) self.model = xspec.Model(kwargs['model']) xspec.Fit.perform()