Load your data in jaxspec
¶
Most of the data you will use when manipulating X-ray spectra will be in the form of a PHA file. This file contains the measured spectra, the background spectra, and also links to the response matrix file and the ancillary response file.
Loading an instrumental setup¶
jaxspec
provides a simple way to load this data using the Observation.from_pha_file
function. If you only want to load the instrument related data (i.e. the response matrix and the ancillary response file), you can use the Instrument.from_ogip_file
function.
from jaxspec.data import Instrument
instrument = Instrument.from_ogip_file("data/PN.rmf", arf_path="data/PN.arf")
Instrument and observation objects are subclasses of xarray
's datasets, which mean they can be interactively explored when using jupyter notebooks.
instrument
<xarray.Instrument> Size: 19MB Dimensions: (instrument_channel: 4096, unfolded_channel: 2067) Coordinates: e_min_unfolded (unfolded_channel) float64 17kB 0.05 0.051 ... 15.98 15.99 e_max_unfolded (unfolded_channel) float64 17kB 0.051 0.052 ... 15.99 16.0 e_min_channel (instrument_channel) float64 33kB 0.0 0.00537 ... 20.48 e_max_channel (instrument_channel) float64 33kB 0.00537 0.01074 ... 20.48 Dimensions without coordinates: instrument_channel, unfolded_channel Data variables: redistribution (instrument_channel, unfolded_channel) float32 19MB <COO: nnz=929478, fill_value=0.0> area (unfolded_channel) float64 17kB 1.239 4.504 ... 1.693 1.671 Attributes: description: X-ray instrument response dataset
You can display insights about your instrumental setup with the following commands
import matplotlib.pyplot as plt
instrument.plot_redistribution()
plt.show()
import matplotlib.pyplot as plt
instrument.plot_area()
plt.show()
Loading a given observation¶
from jaxspec.data import Observation
observation = Observation.from_pha_file("data/PN_spectrum_grp20.fits")
observation
<xarray.Observation> Size: 273kB Dimensions: (instrument_channel: 4096, folded_channel: 1230) Coordinates: channel (instrument_channel) int64 33kB 0 1 2 ... 4093 4094 4095 grouped_channel (folded_channel) int64 10kB 0 1 2 3 ... 1227 1228 1229 Dimensions without coordinates: instrument_channel, folded_channel Data variables: counts (instrument_channel) int64 33kB 0 0 0 0 0 0 ... 0 0 0 0 0 folded_counts (folded_channel) int64 10kB 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 grouping (folded_channel, instrument_channel) bool 70kB <COO: nnz=4096, fill_value=False> quality (instrument_channel) int64 33kB 0 0 0 0 0 0 ... 0 0 0 0 0 exposure float64 8B 2.027e+04 backratio (instrument_channel) float64 33kB 0.2928 ... 0.2928 folded_backratio (folded_channel) float64 10kB 0.2928 0.2928 ... 0.2928 background (instrument_channel) int64 33kB 0 0 0 0 0 0 ... 0 0 0 0 0 folded_background (folded_channel) int64 10kB 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 Attributes: observation_file: data/PN_spectrum_grp20.fits background_file: data/PNbackground_spectrum.fits response_matrix_file: data/PN.rmf ancillary_response_file: data/PN.arf description: X-ray observation dataset
You can highlight the grouping bound to your observation, and understand how you photon are packed into new bins.
observation.plot_grouping()
plt.show()
Define an Observational Setup¶
The ObsConfiguration
is the key component of a jaxspec
inference problem. It will define a transfer matrix which carries the information about how your spectrum is folded through your instrument and binned with your observation. To build a folding matrix, you usually require an instrument and an observation, and add the energy band you consider.
from jaxspec.data import ObsConfiguration
folding_model = ObsConfiguration.from_instrument(instrument, observation, low_energy=0.5, high_energy=8)
You can also directly load it from a .pha file
folding_model = ObsConfiguration.from_pha_file('data/PN_spectrum_grp20.fits', low_energy=0.5, high_energy=8)
folding_model
<xarray.ObsConfiguration> Size: 854kB Dimensions: (folded_channel: 102, unfolded_channel: 2067) Coordinates: e_min_folded (folded_channel) float64 816B 0.5215 0.5572 ... 7.365 e_max_folded (folded_channel) float64 816B 0.5572 0.5926 ... 7.795 e_min_unfolded (unfolded_channel) float64 17kB 0.05 0.051 ... 15.99 e_max_unfolded (unfolded_channel) float64 17kB 0.051 0.052 ... 16.0 Dimensions without coordinates: folded_channel, unfolded_channel Data variables: transfer_matrix (folded_channel, unfolded_channel) float64 800kB <COO: nnz=50028, fill_value=0.0> area (unfolded_channel) float64 17kB 1.239 4.504 ... 1.671 exposure float64 8B 2.027e+04 folded_counts (folded_channel) int64 816B 265 227 196 209 ... 20 20 20 folded_backratio (folded_channel) float64 816B 2.049 2.049 ... 17.57 25.18 folded_background (folded_channel) int64 816B 23 27 22 18 ... 12 10 13 21 Attributes: observation_file: data/PN_spectrum_grp20.fits background_file: data/PNbackground_spectrum.fits response_matrix_file: data/PN.rmf ancillary_response_file: data/PN.arf description: X-ray instrument response dataset