Setup

⚠️ WARNING! ⚠️ BXA requires a working form of PyXspec and/or Sherpa.

Make sure either of these are installed before doing the exercises! Also note the exercises were written for BXA v4.0.5 - if some commands are not working as expected, check which version you are running.


For PyXspec users

First, install PyXspec: We advise using a conda environment (e.g. with Miniconda) to ensure no conflicts occur when installing the Python packages required for BXA. If you have not created a dedicated BXA conda environment before:
  • Create a new conda environment:
    $ conda create -n xspecbxa python=3.8 
  • Activate the new environment:
    $ conda activate xspecbxa 
  • Install BXA:
    • With Anaconda:
      $ conda install -c conda-forge bxa 
    • With pip (see warning below):
      $ pip install requests corner astropy h5py cython scipy tqdm pandas
      $ pip install bxa
       
Once the install process has finished, check everthing is installed and works as required: 
  • Check PyXspec works:
    $ python -c 'import xspec'  
  • Check UltraNest works:
    $ python -c 'import ultranest'  
  • Check BXA works:
    $ python -c 'import bxa.xspec as bxa'  
If no error messages come up from these commands, BXA and PyXspec should work.

For Sherpa users

  • First, install CIAO and Sherpa in a conda environment:
    https://cxc.cfa.harvard.edu/ciao/download/
  • Once the install process has finished, check Sherpa works:
    $ conda activate ciao-environment-name
    $ sherpa

    If there are no errors, Sherpa should be working as expected.
Then install BXA inside the CIAO conda environment:
  • Activate the environment:
    $ conda activate ciao-environment-name  
  • Install BXA:
    • With Anaconda:
      $ conda install -c conda-forge bxa  
    • With pip (see warning below):
      $ pip install requests corner astropy h5py cython scipy tqdm pandas
      $ pip install bxa
       
Once the install process has finished, check everthing works as required: 
  • Check UltraNest works:
    $ python -c 'import ultranest'  
  • Check BXA works:
    $ python -c 'import bxa.sherpa as bxa'  
If no error messages come up from these commands, BXA should work with Sherpa.

*⚠️ Warning!
Installing packages with conda and pip can lead to package conflicts, such as:
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

If this occurs, from inside your conda environment use:
pip uninstall ultranest
conda install -c conda-forge ultranest
 

Download spectra

If you don't have your own, download the following spectral data to use with the tutorial, simulated from the X-ray space telescopes NuSTAR and Chandra.




The zip file contains:

  • nustar_src.pha: NuSTAR source + background spectrum
  • nustar.rmf: NuSTAR response file
  • nustar.arf: NuSTAR effective area file
  • nustar_bkg.pha: NuSTAR background spectrum
  • chandra_src.pi: Chandra source + background spectrum
  • chandra.rmf: Chandra response file
  • chandra.arf: Chandra effective area file
  • chandra_bkg.pi: Chandra background spectrum

For an explanation of the roles each of these files plays, see the CXC X-ray Primer.


Depending on the fitting method being used, make sure to bin your spectra appropriately before fitting (see Exercise 0.1).