Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.bak file does not contain PHA data array #76

Open
makenziewortley opened this issue Nov 8, 2024 · 3 comments
Open

.bak file does not contain PHA data array #76

makenziewortley opened this issue Nov 8, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@makenziewortley
Copy link

makenziewortley commented Nov 8, 2024

When using .pha, .bak and .rsp files generated from the "Reduction_And_Export_Tutorial.ipynb" tutorial, XSPEC cannot read the .bak file correctly. The error is as follows:

***XSPEC Error: data file missing required entries: file does not contain PHA data array

However, the .pha and .rsp files load correctly.

I have tried adding the background file name into the 'BACKFILE' header of the .pha file, but the same issue occurs when loading in the data to XSPEC. It loads the .pha file fine, but gives the same error message in reference to the background.
I have tried this with my own files, on XSPEC from the terminal and using PyXspec but have not been able to solve the problem. It seems related to the .bak file not saving properly.

Here is the exact output from loading the .pha and .bak individually (where my_second_custom.pha does not have the updated 'BACKFILE' header):

XSPEC12>data my_second_custom.pha

1 spectrum in use

Spectral Data File: my_second_custom.pha Spectrum 1
Net count rate (cts/s) for Spectrum:1 4.307e+03 +/- 4.613e+01
Assigned to Data Group 1 and Plot Group 1
Noticed Channels: 1-121
Telescope: GLAST Instrument: GBM Channel Type: PHA
Exposure Time: 2.024 sec
Using fit statistic: chi
No response loaded.

***Warning! One or more spectra are missing responses,
and are not suitable for fit.
XSPEC12>backgrnd my_second_custom.bak

***XSPEC Error: data file missing required entries: file does not contain PHA data array

Here is the output when I load a .pha with the 'BACKFILE' header updated (to 'my_first_custom.bak'):

XSPEC12>data my_first_custom.pha

***XSPEC Error: data file missing required entries: file does not contain PHA data array

1 spectrum in use

***Warning! One or more spectra are missing responses,
and are not suitable for fit.

If anyone has any suggestions, it would be very much appreciated. Please ask me for any clarification if required, I am a new PhD student and am new to GDT-core so please bear with me.

@sumanbala2210-USRA
Copy link
Contributor

sumanbala2210-USRA commented Nov 18, 2024

Hi,
Can you please specify which version of Heasoft, XSPEC and GDT you are using?
You can find the GDT version as;

$ python
>>> import gdt.core
>>> gdt.core.__version__

'X,X,X'

@makenziewortley
Copy link
Author

Hi,
Sure, I'm using the following versions:
GDT: '2.1.0'
XSPEC: '12.14.1'
Heasoft: '6.34'

Thanks!

@makenziewortley
Copy link
Author

makenziewortley commented Nov 20, 2024

Hi, I've come up with a solution that works for me. It seems the issue was that the BackgroundSpectrum data being created by to_bak is not readable by XSPEC. My solution for this is creating a TimeEnergyBins object from the attributes of the BackgroundRates object created. You can then use Phaii.from_data to create the Phaii object, on which you can then use to_pha and then continue to save this data as a .bak file. This is readable by XSPEC, and produces the same plots (with the same background) as the spectra created in the tutorial using the original BackgroundRates object. Here's how it works with the tutorial:

bkgd = backfitter.interpolate_bins(phaii.data.tstart, phaii.data.tstop)

counts = bkgd.counts
tstart = bkgd.tstart
tstop = bkgd.tstop
exposure = bkgd.exposure
emin = bkgd.emin
emax = bkgd.emax
te_bins = TimeEnergyBins(counts, tstart, tstop, exposure, emin, emax)
gti = Gti.from_list([(src_time)])

back_bins, back_gti = to_TEbins(bkgd, src_time)
background_data = Phaii.from_data(back_bins, back_gti)
bak = background_data.to_pha(time_range=src_time, energy_range=erange)

bak.write(directory='./', filename='my_first_custom.bak', overwrite=True)

Hope that makes sense, please let me know if I should clarify anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants