An Example Analysing NuSTAR Data

In this tutorial, we will go through the steps of analyzing NuSTAR observation of the AGN in center of SWIFT J2127.4+5654 with obsid = 60001110002 using heasoftpy.

The first thing we need is to import the heasoftpy package.

The first three lines are needed in case heasoftpy is not installed yet. We add the folder containing heasoftpy to sys.path so we can import it.

Next, we want to download the data. If you have the data downloaded, you can move the observation folder to the same place as this notebook.

We can use either wget (linux) or curl (mac) to download the data

wget -q -nH -r -l0 -c -N -np -R 'index*' -erobots=off --retr-symlinks --cut-dirs=6 https://heasarc.gsfc.nasa.gov/FTP/nustar/data/obs/00/6//60001110002/
curl -s --remote-name https://heasarc.gsfc.nasa.gov/FTP/nustar/data/obs/00/6//60001110002/

Next, we use nupipeline to process the data (see detail here).

As we show in the Getting Started tutorial, we can either call hsp.nupipeline or create an instance of hsp.HSPTaks. Here, we use the latter

Note that to run nupipeline, only three parameters are needed: indir, outdir and steminput. By default, calling the task will also query for other parameters. We can instruct the task to use default values by setting noprompt=True.

Also, because nupipeline takes some time to run (several to tens of minutes), we will also request the output to printed on screen as the task runs by using verbose=True.

For the purposes of illustrations in this tutorial, we will focus on the FMPA instrument.

If we use outdir='60001110002_p/event_cl', the call may look something like:

After running for some time, and if things run smoothly, we will get a message like:

=============================================================================================
nupipeline_0.4.9: Exit with no errors - Fri Nov 26 13:53:29 EST 2021

=============================================================================================
=============================================================================================

A return code of 0, indicates that the task run with success!

The main cleaned event files are: nu60001110002A01_cl.evt and nu60001110002B01_cl.evt for NuSTAR modules A and B, respectively.


Note that the same results can acheived by using the parameters as attributes of the tasks:

nupipeline = hsp.HSPTask('nupipeline')

nupipeline.indir = obsid
nupipeline.outdir = obsid + '_p/event_cl'
nupipeline.steminput = 'nu' + obsid
nupipeline(noprompt=True, verbose=True)

Extracting a light curve

Now that we have data processed, we can proceed and extract a light curve for the source. For this, we use nuproducts (see nuproducts for details)

First, we need to create a source and background region files.

The source regions is a circle centered on the source with a radius of 150 arcseconds, while the background region is an annulus with an inner and outer radii of 180 and 300 arcseconds, respectively.

listing the content of the output directory 60001110002_p/lc, we see that the task has created a source and background light cruves (nu60001110002A01_sr.lc and nu60001110002A01_bk.lc) along with the corresponding spectra.

The task also generates .flc file, which contains the background-subtracted light curves.

We can proceed in different ways. We may for example use fits libraries in astropy to read this fits file directly, or we can use ftlist to dump the content of that file to an ascii file before reading it (we use option=T to list the table content).

Again, we could also have used task attributes as input parameters:

ftlist = hsp.HSPTask('ftlist')
ftlist.infile = '60001110002_p/lc/nu60001110002A01.flc'
ftlist.outfile = '60001110002_p/lc/nu60001110002A01.txt'
out = ftlist(option='T')