Exploring the Athena X-IFU WHIM Data Challenge

One task for Athena X-IFU will be measuring the Warm-Hot Intergalactic Medium (WHIM) via absorption spectroscopy. While WHIM itself does not emit X-rays, it will produce absorption lines in the X-ray spectra of bright Gamma-ray Burst (GRB) afterglows. This is important for solving the missing baryon problem.

How well Athena will be able to measure the WHIM depends on how well it is going to be able to identify lines in GRB afterglows. To this purpose, the Athena X-IFU WHIM Data Challenge was called into existence. The point here is figure out the best way to identify lines and their redshift, and find the method that has the highest detection probability for the weak lines expected from WHIM.

Exploring the Simulations

Let's first actually look at the data, so that we can set up an appropriate model.

Imports


In [1]:
%matplotlib notebook
import matplotlib.pyplot as plt
import seaborn as sns

import glob

import numpy as np
import pandas as pd

import sherpa.astro.ui
import astropy.io.fits as fits

datadir = "../data/"


WARNING: imaging routines will not be available, 
failed to import sherpa.image.ds9_backend due to 
'RuntimeErr: DS9Win unusable: Could not find ds9 on your PATH'
WARNING: failed to import WCS module; WCS routines will not be available
WARNING: failed to import sherpa.astro.xspec; XSPEC models will not be available

Before we do anything clever, I want to have a look at the FITS files so that I know what's going on:


In [2]:
import sherpa

In [3]:
sherpa.__version__


Out[3]:
'4.9.0'

In [4]:
hdulist = fits.open("../data/47.pha")
hdulist


Out[4]:
[<astropy.io.fits.hdu.image.PrimaryHDU object at 0x11682aef0>, <astropy.io.fits.hdu.table.BinTableHDU object at 0x11683c828>]

In [5]:
hdr = hdulist[0].header

In [6]:
hdr


Out[6]:
SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                   16 / number of bits per data pixel                  
NAXIS   =                    0 / number of data axes                            
EXTEND  =                    T / FITS dataset may contain extensions            
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 

What's in the data extension?


In [7]:
hdulist[1].header


Out[7]:
XTENSION= 'BINTABLE'           / binary table extension                         
BITPIX  =                    8 / 8-bit bytes                                    
NAXIS   =                    2 / 2-dimensional binary table                     
NAXIS1  =                    8 / width of table in bytes                        
NAXIS2  =                29874 / number of rows in table                        
PCOUNT  =                    0 / size of special data area                      
GCOUNT  =                    1 / one data group (required keyword)              
TFIELDS =                    2 / number of fields in each row                   
TTYPE1  = 'CHANNEL '           / label for field   1                            
TFORM1  = 'J       '           / data format of field: 4-byte INTEGER           
TTYPE2  = 'COUNTS  '           / label for field   2                            
TFORM2  = 'J       '           / data format of field: 4-byte INTEGER           
EXTNAME = 'SPECTRUM'           / name of this binary table extension            
TELESCOP= 'ATHENA  '                                                            
INSTRUME= 'XIFU    '                                                            
FILTER  = 'NONE    '                                                            
EXPOSURE=               75500.                                                  
AREASCAL=                   1.                                                  
BACKFILE= 'none    '                                                            
BACKSCAL=                   1.                                                  
CORRFILE= 'none    '                                                            
CORRSCAL=                   1.                                                  
RESPFILE= 'athena_xifu_rmf_highres_v20150609.rmf'                               
ANCRFILE= 'athena_xifu_sixte_1469_onaxis_v20150402.arf'                         
HDUCLASS= 'OGIP    '                                                            
HDUCLAS1= 'SPECTRUM'                                                            
HDUVERS = '1.2.1   '                                                            
CHANTYPE= 'PI      '                                                            
DETCHANS=                29874                                                  
CREATOR = '{fits_write_pha_file} v{1.0.0}'                                      
HDUCLAS2= 'TOTAL   '                                                            
HDUCLAS3= 'COUNTS  '                                                            
GROUPING=                    0                                                  
AREAFILE= 'none    '                                                            
POISSERR=                    T / Poisson errors appropriate?                    
STAT_ERR=                    F / Assume statistical errors?                     
SYS_ERR =                   0. / no global systematic error                     

In [8]:
hdulist[1].columns


Out[8]:
ColDefs(
    name = 'CHANNEL'; format = 'J'
    name = 'COUNTS'; format = 'J'
)

Hmm, so it doesn't look like I have energy information for each bin. Maybe the ARF/RMF files do?


In [9]:
arf_hdulist = fits.open(datadir+"athena_xifu_sixte_1469_onaxis_v20150402.arf")

In [10]:
arf_hdulist.info()


Filename: ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
No.    Name         Type      Cards   Dimensions   Format
  0  PRIMARY     PrimaryHDU       8   ()      
  1  SPECRESP    BinTableHDU     31   29874R x 3C   [D, D, D]   

In [11]:
e_low = arf_hdulist[1].data.field("ENERG_LO")
e_high = arf_hdulist[1].data.field("ENERG_HI")

What about the RMF?


In [12]:
rmf_hdulist = fits.open(datadir+"athena_xifu_rmf_highres_v20150609.rmf")

In [13]:
rmf_hdulist.info()


Filename: ../data/athena_xifu_rmf_highres_v20150609.rmf
No.    Name         Type      Cards   Dimensions   Format
  0  PRIMARY     PrimaryHDU       8   ()      
  1  EBOUNDS     BinTableHDU     32   29874R x 3C   [J, D, D]   
  2  MATRIX      BinTableHDU     46   29874R x 6C   [D, D, J, J, J, 92D]   

In [14]:
rmf_hdulist[1].header


Out[14]:
XTENSION= 'BINTABLE'           / binary table extension                         
BITPIX  =                    8 / 8-bit bytes                                    
NAXIS   =                    2 / 2-dimensional binary table                     
NAXIS1  =                   20 / width of table in bytes                        
NAXIS2  =                29874 / number of rows in table                        
PCOUNT  =                    0 / size of special data area                      
GCOUNT  =                    1 / one data group (required keyword)              
TFIELDS =                    3 / number of fields in each row                   
TTYPE1  = 'CHANNEL '           / label for field   1                            
TFORM1  = 'J       '           / data format of field: 4-byte INTEGER           
TTYPE2  = 'E_MIN   '           / label for field   2                            
TFORM2  = 'D       '           / data format of field: 8-byte DOUBLE            
TTYPE3  = 'E_MAX   '           / label for field   3                            
TFORM3  = 'D       '           / data format of field: 8-byte DOUBLE            
EXTNAME = 'EBOUNDS '           / name of this binary table extension            
TELESCOP= 'ATHENA  '                                                            
INSTRUME= 'XIFU    '                                                            
FILTER  = 'NONE    '                                                            
CHANTYPE= 'PI      '                                                            
DETCHANS=                29874                                                  
HDUCLASS= 'OGIP    '                                                            
HDUCLAS1= 'RESPONSE'                                                            
HDUCLAS2= 'EBOUNDS '                                                            
HDUVERS = '1.2.0   '                                                            
ORIGIN  = 'ECAP    '                                                            
VERSION =             20150609 / Version number                                 
TUNIT2  = 'keV     '                                                            
TUNIT3  = 'keV     '                                                            
HISTORY file written by fits_write_rmf.sl                                       
CHECKSUM= 'aqnjbokiaokiaoki'   / HDU checksum updated 2015-06-09T11:52:53       
DATASUM = '403690390'          / data unit checksum updated 2015-06-09T11:52:51 
FWHM    =              2.50000 / Resolution in eV below 7.0 keV                 

In [15]:
rmf_data = rmf_hdulist[2].data

In [16]:
rmf_data.columns


Out[16]:
ColDefs(
    name = 'ENERG_LO'; format = 'D'; unit = 'keV'
    name = 'ENERG_HI'; format = 'D'; unit = 'keV'
    name = 'N_GRP'; format = 'J'
    name = 'F_CHAN'; format = 'J'
    name = 'N_CHAN'; format = 'J'
    name = 'MATRIX'; format = '92D'; dim = '(92)'
)

In [17]:
datadir = "../data/"
datafiles = glob.glob(datadir+"*.pha")
print(datafiles)


['../data/01.pha', '../data/02.pha', '../data/03.pha', '../data/04.pha', '../data/05.pha', '../data/06.pha', '../data/07.pha', '../data/08.pha', '../data/09.pha', '../data/10.pha', '../data/11.pha', '../data/12.pha', '../data/13.pha', '../data/14.pha', '../data/15.pha', '../data/16.pha', '../data/17.pha', '../data/18.pha', '../data/19.pha', '../data/20.pha', '../data/21.pha', '../data/22.pha', '../data/23.pha', '../data/24.pha', '../data/25.pha', '../data/26.pha', '../data/27.pha', '../data/28.pha', '../data/29.pha', '../data/30.pha', '../data/31.pha', '../data/32.pha', '../data/33.pha', '../data/34.pha', '../data/35.pha', '../data/36.pha', '../data/37.pha', '../data/38.pha', '../data/39.pha', '../data/40.pha', '../data/41.pha', '../data/42.pha', '../data/43.pha', '../data/44.pha', '../data/45.pha', '../data/46.pha', '../data/47.pha', '../data/48.pha', '../data/49.pha', '../data/50.pha']

Sherpa model of the data

Let's build a simple sherpa model of a galactic abundance and a power law:


In [18]:
sherpa.astro.ui.load_data("../data/47.pha")


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field

In [19]:
d = sherpa.astro.ui.get_data()

In [20]:
arf = d.get_arf()

In [21]:
arf


Out[21]:
<DataARF data set instance '../data/athena_xifu_sixte_1469_onaxis_v20150402.arf'>

In [22]:
rmf = d.get_rmf()

In [23]:
rmf

In [24]:
for i,f in enumerate(datafiles):
    sherpa.astro.ui.load_data(id="%i"%(i+1), filename=datadir+f)


read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
read ARF file ../data/../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field

In [25]:
d1 = sherpa.astro.ui.get_data("1")

In [26]:
energy = d1.get_x()

In [27]:
plt.figure()
plt.plot(energy, d1.counts, label="HEG P1", alpha=0.9,
         c=sns.color_palette()[0], linestyle="steps-mid")

plt.xlim(0.5, 0.68)


Out[27]:
(0.5, 0.68)

Line Search Strategy

In the original document, the line search strategy is between 250 and 584 eV for the OVII line and 250 to 754 eV for the OVII and OVIII line. They use Gaussian statistics, i.e. rebin the data, which we are not going to do.

Question: Do I need to worry about over-sampling?

The authors then do a blind fit to the continuum, followed by a blind line search in the range between $0 \leq z \leq 0.1$, considering the simple case of a WHIM line in the nearby IGM. The search is performed using Protassov et al (2002), searching at every energy for a line and producing a posterior predictive p-value for each line energy in its rest frame $E_0$ shifted to $(1+z)E_0$ while oversampling the detector resolution. They produce a new fit for each energy and test for the presence of a line using a significance test.

Question: What are the priors used in the original approach?

Why this approach is not ideal

  • number of trials explodes!
  • can only find lines at fixed redshift intervals, but redshift is a continuous number!
  • cannot efficiently deal with multi-line inference!

Can we build a better model?

We're going to stick this into ShiftyLines and see what happens! But first, let's look at the relevant energy ranges:


In [28]:
len(e_low)


Out[28]:
29874

In [29]:
x_min = 0.25
x_max = 0.754

d = sherpa.astro.ui.get_data("47")

plt.figure()
plt.plot(e_low, d.counts, alpha=0.9,
         c=sns.color_palette()[0], linestyle="steps-mid")

plt.xlim(x_min, x_max)


Out[29]:
(0.25, 0.754)

I have no idea whether there's a line in there. I know that there are different simulations (1) for a single line search versus two line search, (2) different equivalent widths, and (3) different starting fluxes of the GRB. And apparently also for different exposure times.

Let's plot all spectra, just so I know what I'm dealing with, including the two lines of interest:


In [30]:
0.574*(1.0-0.1)


Out[30]:
0.5166

In [31]:
o_lines = [0.574, 0.654]

In [32]:
plt.figure()

for i,f in enumerate(datafiles):
    d = sherpa.astro.ui.get_data("%i"%(i+1))
    plt.plot(e_low, d.counts, label="HEG P1", alpha=0.9,
             c=sns.color_palette()[0], linestyle="steps-mid")
    
for l in o_lines:
    plt.vlines(l/(1.0 + 0.07), 0, 7000, lw=2, color="black")

plt.xlim(x_min, x_max)


Out[32]:
(0.25, 0.754)

According to the document, the lines are at different redshifts, so fine.

First Attempt

The first attempt to run this with 2 lines on the first spectrum:


In [33]:
sample = np.loadtxt("../../atrytone/data/47_posterior_sample.txt")

The $log(Z) = -2580.20885111$.

The Columns in the Sample File

  • 0: background
  • 1: noise_L
  • 2: noise_sigma
  • 3: number of parameters (I think)
  • 4: number of possible Redshifts
  • 5: log-amplitude hyper mean
  • 6: log-amplitude hyper sigma
  • 7: width hyper mean
  • 8: width hyper sigma
  • 9: threshold parameter
  • 10: number of Doppler shifts
  • 11: Doppler shift
  • 12-XX: parameters for the lines, one per Doppler shift and per line
  • XX-end: posterior sample spectrum

Let's plot the number of Doppler shifts:


In [34]:
plt.figure()
plt.hist(sample[:,10], bins=50);



In [35]:
plt.figure()
plt.hist(sample[:,11], bins=30)


Out[35]:
(array([  1.,   0.,   0.,   0.,   3.,   0.,   1.,   5.,   6.,   2.,  13.,
         48.,  26.,  27.,  39.,  43.,  41.,  46.,  39.,  25.,  22.,   7.,
          7.,   5.,   4.,  26.,   2.,   1.,   2.,   1.]),
 array([ 0.0808045 ,  0.08082568,  0.08084686,  0.08086804,  0.08088922,
         0.0809104 ,  0.08093158,  0.08095276,  0.08097394,  0.08099512,
         0.0810163 ,  0.08103748,  0.08105866,  0.08107984,  0.08110102,
         0.0811222 ,  0.08114338,  0.08116456,  0.08118574,  0.08120692,
         0.0812281 ,  0.08124928,  0.08127046,  0.08129164,  0.08131282,
         0.081334  ,  0.08135518,  0.08137636,  0.08139754,  0.08141872,
         0.0814399 ]),
 <a list of 30 Patch objects>)

In [36]:
x_min = 0.25
x_max = 0.75

In [111]:
min_ind = e_low.searchsorted(x_min)
max_ind = e_low.searchsorted(x_max)

e_low_small = e_low[min_ind:max_ind]
e_high_small = e_high[min_ind:max_ind]

Simulation 01

Let's start with simulation 1.

$log(z) =


In [38]:
# the data
d = sherpa.astro.ui.get_data("1")

In [39]:
sample = np.loadtxt("../../atrytone/data/01_posterior_sample.txt")
print("There are %i samples in the posterior."%len(sample))


There are 409 samples in the posterior.

In [40]:
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8,4))
ax1.hist(sample[:,10], bins=50);
ax1.set_title("Number of Doppler Shifts")

ax2.hist(sample[sample[:,11] != 0.0,11], bins=30)
ax2.set_xlabel("Doppler Shift")
ax2.set_ylabel("p(Doppler Shift)")

plt.figure(figsize=(8,4))
plt.plot(e_low, d.counts, 
         c="black", linestyle="steps-mid")
    
for s in sample[-20:]:
    plt.plot(e_low_small, s[-len(e_low_small)-5:-5], lw=1, 
             c=sns.color_palette()[0], alpha=0.3)
    
plt.xlim(x_min, x_max)
plt.ylim(0, 400)


Out[40]:
(0, 400)

What's the probability of having a Doppler shift in this source?


In [41]:
len(sample[sample[:,10]!= 0.0,11])/len(sample[:,10])


Out[41]:
0.2616136919315403

What are the amplitudes?


In [42]:
istart = 12
ndoppler = 1

nd1 = len(sample[sample[:,10]!=0.0, 10])

amplitudes = np.zeros((nd1, len(o_lines)))


for i in range(len(o_lines)):
    amplitudes[:,i] = sample[sample[:,istart+i*ndoppler]!=0.0, istart+i*ndoppler]

In [43]:
fig, axes = plt.subplots(1,2, figsize=(8,4))

axes = np.hstack(axes)

for i in range(len(o_lines)):
    a = amplitudes[:,i]
    axes[i].hist(a, bins=30)
    axes[i].set_title(o_lines[i])


What are the means and standard deviations of the amplitudes?


In [44]:
for i in range(amplitudes.shape[1]):
    print("Mean for amplitude for line at %.5f is %.5f +/- %.5f"%(o_lines[i], 
                                                                  np.mean(amplitudes[:,i]), 
                                                                  np.std(amplitudes[:,i])))


Mean for amplitude for line at 0.57400 is -4.32944 +/- 2.98967
Mean for amplitude for line at 0.65400 is -5.62011 +/- 3.13360

We have to compute the equivalent width of the two lines. For that, we're going to need (1) The Doppler shift of the line, (2) the shifted mean of the line, (3) the width and amplitude of the line, (4) the background

The Columns in the Sample File

  • 0: background
  • 1: noise_L
  • 2: noise_sigma
  • 3: number of parameters (I think)
  • 4: number of possible Redshifts
  • 5: log-amplitude hyper mean
  • 6: log-amplitude hyper sigma
  • 7: width hyper mean
  • 8: width hyper sigma
  • 9: threshold parameter
  • 10: number of Doppler shifts
  • 11: Doppler shift
  • 12-XX: parameters for the lines, one per Doppler shift and per line
  • XX-end: posterior sample spectrum

In [45]:
ndoppler = 1

In [46]:
import scipy.special

def gaussian_cdf(x, x0, gamma):
    c = 0.5*(1. + scipy.special.erf((x-x0)/(gamma*np.sqrt(2.))))
    return c

This is the factor for converting keV into Angstrom


In [47]:
cfac = 12.3984191

In [135]:
import astropy.units as u

In [137]:
k = 42. * u.keV

In [140]:
k.to(u.Angstrom, equivalencies=u.spectral())


Out[140]:
$0.29520046 \; \mathrm{\mathring{A}}$

In [207]:
def equivalent_widths(e_low_small, e_high_small, s, o_lines, cfac = 12.3984191):
    
    e_mid_small = e_low_small + (e_high_small - e_low_small)/2.0
    
    e_low_small = e_low_small * u.keV
    e_mid_small = e_mid_small * u.keV
    e_high_small = e_high_small * u.keV
    
    e_low_ang = e_low_small.to(u.Angstrom, equivalencies=u.spectral())
    e_mid_ang = e_mid_small.to(u.Angstrom, equivalencies=u.spectral())
    e_high_ang = e_high_small.to(u.Angstrom, equivalencies=u.spectral())
    
    #e_low_ang = np.array([e.to(u.Angstrom, equivalencies=u.spectral()) for e in e_low_small])
    #e_mid_ang = np.array([e.to(u.Angstrom, equivalencies=u.spectral()) for e in e_mid_small])
    #e_high_ang = np.array([e.to(u.Angstrom, equivalencies=u.spectral()) for e in e_high_small])
    
    # constant background
    bkg = s[0]
    
    # threshold parameter for positive/negative sign
    thr = s[9]

    # number of doppler shifts in this model
    nd = s[10]
    
    # value of the doppler shift (will be zero if nd is zero)
    dop = s[11]

    ew = np.zeros(len(o_lines))

    if nd > 0:
        lpos_kev = np.zeros(len(o_lines))
        lpos_ang = np.zeros(len(o_lines))
        amps = np.zeros(len(o_lines))
        widths = np.zeros(len(o_lines))
        widths_ang = np.zeros(len(o_lines))
        sign = np.zeros(len(o_lines))
        test = np.zeros(len(o_lines))
        lpos_kev = o_lines * u.keV
        lpos_ang = lpos_kev.to(u.Angstrom, equivalencies=u.spectral()) * (1. + dop)
        for i in range(len(o_lines)):
            #lpos[i] = o_lines[i]*1./(1.0+dop)
            #lpos_kev[i] = o_lines[i] * u.keV
            #lpos_ang[i] = lpost_kev[i].to(u.Angstrom, equivalencies=u.spectral())
            amps[i] = np.exp(s[istart+i*ndoppler])
            widths[i] = np.exp(s[istart+i*ndoppler+2])

            sign[i] = s[istart+i*ndoppler+4]

        widths = widths * u.keV
        widths_ang = widths.to(u.keV, equivalencies=u.spectral())

        for i in range(len(o_lines)):
            bkg_model = np.zeros_like(e_mid_ang.value) + bkg
            line_model = amps[i]*scipy.stats.norm(lpos_ang[i].value, widths_ang[i].value).pdf(e_mid_ang.value)
            total_model = bkg_model + line_model
            
            ew[i] = np.sum((-e_high_ang.value + e_low_ang.value) * np.abs(total_model - bkg_model)/bkg_model)
            
    return ew
            
            
#            ew[i] = (amps[i]/bkg)*gaussian_cdf(x_max, lpos[i], widths[i])

In [208]:
def equivalent_widths_old(s, o_lines, cfac = 12.3984191, x_max=0.68):
    # background flux
    bkg = s[0]
    
    # threshold parameter for positive/negative sign
    thr = s[9]

    # number of doppler shifts in this model
    nd = s[10]
    
    # value of the doppler shift (will be zero if nd is zero)
    dop = s[11]

    ew = np.zeros(len(o_lines))

    if nd > 0:
        lpos = np.zeros(len(o_lines))
        amps = np.zeros(len(o_lines))
        widths = np.zeros(len(o_lines))
        sign = np.zeros(len(o_lines))
        test = np.zeros(len(o_lines))
        for i in range(len(o_lines)):
            lpos[i] = o_lines[i]*1./(1.0+dop)
            amps[i] = np.exp(s[istart+i*ndoppler])
            widths[i] = np.exp(s[istart+i*ndoppler+2])
            sign[i] = s[istart+i*ndoppler+4]

        lpos_angstrom = cfac/lpos
        widths_angstrom = cfac/widths

        for i in range(len(o_lines)):
            ew[i] = (amps[i]/bkg)*gaussian_cdf(x_max, lpos[i], widths[i])

    return ew

In [209]:
print(sample[2,10:20])
equivalent_widths(e_low_small, e_high_small, sample[2], o_lines)


[   0.       0.       0.       0.       0.       0.       0.       0.
  116.897  117.753]
Out[209]:
array([ 0.,  0.])

In [210]:
ew = np.array([equivalent_widths(e_low_small, e_high_small, s, o_lines) for s in sample])
ew_old = np.array([equivalent_widths_old(s, o_lines, cfac = 12.3984191, x_max=0.68) for s in sample])

In [211]:
ew


Out[211]:
array([[  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.18265535e-17,   2.43294324e-01],
       [  4.19431938e+00,   1.32082029e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  4.86127081e-02,   4.83711330e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  6.89991038e+00,   6.75402345e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.27535695e+01,   7.50827883e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.03121869e+01,   6.41318712e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.57664980e+00,   2.21809807e+00],
       [  6.89991038e+00,   6.75402345e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.75738078e-06,   5.41194894e-10],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.25513582e-02,   2.32857688e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  5.04378238e-04,   6.75266835e-05],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  4.67673392e-02,   8.54461049e-02],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.58922137e+00,   4.87571622e-02],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  5.30099932e-07,   2.32089045e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.19741525e-01,   8.79729877e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.27535695e+01,   7.50827883e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.68777300e+00,   7.14820385e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.47738443e+00,   3.83371152e-02],
       [  5.27351290e-02,   2.25378833e-02],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  6.72790151e+00,   6.70379145e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.15111414e+01,   1.03518511e+01],
       [  0.00000000e+00,   0.00000000e+00],
       [  4.91147485e-01,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.52677503e+01,   0.00000000e+00],
       [  2.18671171e-10,   2.43091651e-08],
       [  0.00000000e+00,   0.00000000e+00],
       [  5.02559952e-10,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  3.51399869e-07,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   9.78431933e-04],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  3.66247272e-03,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   2.63767047e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   4.08491127e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.26328472e+01,   9.02673122e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  6.89991038e+00,   6.75402345e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   8.44313931e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.18671171e-10,   2.43091651e-08],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.12422215e+00,   3.19509526e-04],
       [  3.11206076e+01,   1.00435967e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.18357607e-01,   2.77142892e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.11221664e+01,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.41424701e+00,   2.50005246e-01],
       [  8.31431704e-06,   7.33807865e-10],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.03121869e+01,   6.41318712e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.68777300e+00,   7.14820385e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.68777300e+00,   7.14820385e+00],
       [  1.66899713e-06,   1.10777951e-06],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  3.68843098e-04,   1.89061302e-04],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.13757089e+00,   8.61642651e-03],
       [  7.69800868e+00,   4.24907645e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  4.49171494e-07,   1.84393188e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  6.51993834e-01,   3.81929071e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  5.04378238e-04,   6.75266835e-05],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  4.04217926e-04,   7.96604939e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.41993299e+01,   7.22819851e-01],
       [  5.04378238e-04,   6.75266835e-05],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.43268030e-02,   7.59757286e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   1.39531691e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.68777300e+00,   7.14820385e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.11221664e+01,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.27535695e+01,   7.50827883e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.15234174e+00,   6.37202910e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.77861810e-02,   8.02874856e-02],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  4.49171494e-07,   1.84393188e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   1.91192572e-07],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.53463908e+00,   4.23982037e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.18671171e-10,   2.43091651e-08],
       [  1.60180169e-13,   4.23466127e-05],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.13757089e+00,   8.61642651e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.77861810e-02,   8.02874856e-02],
       [  6.44585031e+00,   1.33625433e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.51987817e+00,   7.89613336e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.74555826e-09,   9.58010113e-17],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.26595386e+00,   1.61888210e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.68203740e-04,   1.88329176e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.37483705e-03,   8.23042360e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.13757089e+00,   8.61642651e-03],
       [  1.55979520e-01,   2.34845523e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.18265535e-17,   2.43294324e-01],
       [  8.64820302e-05,   5.12552235e-05],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  3.40883626e-04,   8.12105894e-05],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   6.83531707e-02],
       [  2.65795541e-07,   1.20882049e-17],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.18357607e-01,   2.77142892e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.41487363e-02,   5.56857634e-03],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.03121869e+01,   6.41318712e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.78390207e+01,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  4.91147485e-01,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  1.15234174e+00,   6.37202910e-01],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  3.40883626e-04,   8.12105894e-05],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  2.65795541e-07,   1.20882049e-17],
       [  1.26595386e+00,   1.61888210e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00],
       [  7.92733237e+00,   2.46180269e-12],
       [  0.00000000e+00,   0.00000000e+00]])

In [212]:
fig, axes = plt.subplots(1, 2, figsize=(8,4))

for i, l in enumerate(o_lines):
    axes[i].hist(np.log(ew[ew[:,i]!= 0.0,i]), bins=30)
    print(np.median(ew[ew[:,i]!= 0.0,i]))
    axes[i].set_title(l)


/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
0.491147484908
0.184393187649

In [213]:
for i in range(len(o_lines)):
    print("Equivalent width for line %.3f: %.5f +/ %.6f" %(o_lines[i], 
                                                           np.median(ew[ew[:,i]!= 0.0,i]), 
                                                           np.std(ew[ew[:,i]!= 0.0,i])))
    print("Equivalent width for line %.3f: %.5f +/ %.6f" %(o_lines[i], 
                                                           np.median(ew_old[ew_old[:,i]!= 0.0,i]), 
                                                           np.std(ew_old[ew_old[:,i]!= 0.0,i])))


Equivalent width for line 0.574: 0.49115 +/ 6.126249
Equivalent width for line 0.574: 0.93446 +/ 4.451956
Equivalent width for line 0.654: 0.18439 +/ 2.656471
Equivalent width for line 0.654: 0.27709 +/ 8.122545

Let's make a function of this:


In [214]:
def plot_ew(sample, o_lines):
    # calculate equivalent widths
    ew = np.array([equivalent_widths_old(s, o_lines) for s in sample])
    
    fig, axes = plt.subplots(1, 2, figsize=(8,4))

    for i, l in enumerate(o_lines):
        axes[i].hist(np.log(ew[ew[:,i]!= 0.0,i]), bins=30)
        print(np.median(ew[ew[:,i]!= 0.0,i]))
        axes[i].set_title(l)
        
    for i in range(len(o_lines)):
        print("Equivalent width for line %.3f: %.5f +/ %.6f" %(o_lines[i], 
                                                               np.median(ew[ew[:,i]!= 0.0,i]), 
                                                               np.std(ew[ew[:,i]!= 0.0,i])))
        
    return fig, axes

In [215]:
_, _ = plot_ew(sample, o_lines)


/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
0.934457806514
0.277092576762
Equivalent width for line 0.574: 0.93446 +/ 4.451956
Equivalent width for line 0.654: 0.27709 +/ 8.122545

Let's make a function of all of it:


In [219]:
def plot_all(nsim, datadir="../data/"):
    
    # the rest energies of the two lines
    o_lines = [0.574, 0.654]
    
    # make a string for the correct data file to load
    if nsim < 10:
        dataid = "0" + str(nsim)
    else:
        dataid = str(nsim)
        
    datafile = datadir + dataid + ".pha"

    # use sherpa to load the data
    sherpa.astro.ui.load_data(id="%i"%nsim, filename=datafile)
    
    # get the data
    d = sherpa.astro.ui.get_data("%i"%nsim)
    
    # get the posterior sample
    sample = np.loadtxt(datadir+"%s_posterior_sample.txt"%dataid)
    print("There are %i samples in the posterior."%len(sample))

    # compute the fraction of samples that have a Doppler shift
    p_doppler = len(sample[sample[:,10]!= 0.0,11])/len(sample[:,10])
    doppler_mean = np.mean(sample[sample[:,10]!= 0.0,11])
    doppler_std = np.std(sample[sample[:,10]!= 0.0,11])
    print("The probability that there is a signal in the data is %.4f"%p_doppler)
    print("The estimate for the Doppler shift is %.3f +/- %.3f"%(doppler_mean, doppler_std))

    # plot the number of Doppler shifts and the posterior distribution
    # of the Doppler shift itself if it's not zero (i.e. doesn't exist)
    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8,4))
    ax1.hist(sample[:,10], bins=50);
    ax1.set_title("Number of Doppler Shifts")

    ax2.hist(sample[sample[:,11] != 0.0,11], bins=30)
    ax2.set_xlabel("Doppler Shift")
    ax2.set_ylabel("p(Doppler Shift)")

    # plot posterior samples of the light curve
    plt.figure(figsize=(8,4))
    plt.plot(e_low, d.counts, 
             c="black", linestyle="steps-mid")

    for s in sample:
        plt.plot(e_low_small, s[-len(e_low_small)-5:-5], lw=1, 
                 c=sns.color_palette()[0], alpha=0.3)

    # set some sane y axis limits.
    s = sample[0, -len(e_low_small)-5:-5]
    y_min = 0
    y_max = np.max(s) + 20.0
    plt.xlim(x_min, x_max)
    plt.ylim(y_min, y_max)

    # let's also plot the posteriors of the amplitudes
    
    # these are the needed indices
    istart = 12
    ndoppler = 1

    # the number of samples where there is a Doppler shift
    nd1 = len(sample[sample[:,10]!=0.0, 10])

    # empty array for the amplitudes
    amplitudes = np.zeros((nd1, len(o_lines)))

    # get the amplitudes out of the posterior sample
    for i in range(len(o_lines)):
        amplitudes[:,i] = sample[sample[:,istart+i*ndoppler]!=0.0, istart+i*ndoppler]

    # make a plot of the amplitudes
    fig, axes = plt.subplots(1,2, figsize=(8,4))

    axes = np.hstack(axes)

    for i in range(len(o_lines)):
        a = amplitudes[:,i]
        axes[i].hist(a, bins=30)
        axes[i].set_title(o_lines[i])
        
    # print the mean and standard deviation of the amplitudes.
    for i in range(amplitudes.shape[1]):
        print("Mean for amplitude for line at %.5f is %.5f +/- %.5f"%(o_lines[i], 
                                                                      np.mean(amplitudes[:,i]), 
                                                                      np.std(amplitudes[:,i])))

    # compute the equivalent widths
    ew = np.array([equivalent_widths_old(s, o_lines) for s in sample])

    # plot the equivalent widths
    _, _ = plot_ew(sample, o_lines)
    
    return

In [220]:
plot_all(1)


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
There are 409 samples in the posterior.
The probability that there is a signal in the data is 0.2616
The estimate for the Doppler shift is 0.054 +/- 0.033
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
Mean for amplitude for line at 0.57400 is -4.32944 +/- 2.98967
Mean for amplitude for line at 0.65400 is -5.62011 +/- 3.13360
0.934457806514
0.277092576762
Equivalent width for line 0.574: 0.93446 +/ 4.451956
Equivalent width for line 0.654: 0.27709 +/ 8.122545

Simulation 02

$log(z) = -1714.44199708$


In [221]:
plot_all(2)


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
There are 402 samples in the posterior.
The probability that there is a signal in the data is 0.7338
The estimate for the Doppler shift is 0.077 +/- 0.014
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
Mean for amplitude for line at 0.57400 is -3.77464 +/- 1.10960
Mean for amplitude for line at 0.65400 is -6.65646 +/- 3.00591
1.67254012234
0.120395517445
Equivalent width for line 0.574: 1.67254 +/ 4.453931
Equivalent width for line 0.654: 0.12040 +/ 59.266591

Simulation 03

$log(z) = -1604.30562265$


In [222]:
plot_all(3)


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
There are 417 samples in the posterior.
The probability that there is a signal in the data is 0.0959
The estimate for the Doppler shift is 0.049 +/- 0.027
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
Mean for amplitude for line at 0.57400 is -7.34212 +/- 4.68466
Mean for amplitude for line at 0.65400 is -6.39125 +/- 2.72544
0.216961577255
0.75970542062
Equivalent width for line 0.574: 0.21696 +/ 6.259423
Equivalent width for line 0.654: 0.75971 +/ 0.926321

Simulation 04

$log(z) = $


In [223]:
plot_all(4)


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
There are 405 samples in the posterior.
The probability that there is a signal in the data is 1.0000
The estimate for the Doppler shift is 0.081 +/- 0.000
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
Mean for amplitude for line at 0.57400 is -2.23029 +/- 0.13860
Mean for amplitude for line at 0.65400 is -6.96896 +/- 3.99049
1.60346796155
0.0377719765161
Equivalent width for line 0.574: 1.60347 +/ 0.213056
Equivalent width for line 0.654: 0.03777 +/ 10.545330

Simulation 05

failed


In [224]:
plot_all(5)


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
There are 430 samples in the posterior.
The probability that there is a signal in the data is 0.9860
The estimate for the Doppler shift is 0.081 +/- 0.003
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
Mean for amplitude for line at 0.57400 is -3.48270 +/- 0.62102
Mean for amplitude for line at 0.65400 is -5.75041 +/- 2.66470
1.15311573973
0.212030999156
Equivalent width for line 0.574: 1.15312 +/ 0.321785
Equivalent width for line 0.654: 0.21203 +/ 90.297120

Simulation 06


In [226]:
plot_all(6)


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
There are 415 samples in the posterior.
The probability that there is a signal in the data is 1.0000
The estimate for the Doppler shift is 0.081 +/- 0.000
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)
Mean for amplitude for line at 0.57400 is -1.21062 +/- 0.08272
Mean for amplitude for line at 0.65400 is -3.95582 +/- 2.20836
1.47168355503
0.203283889498
Equivalent width for line 0.574: 1.47168 +/ 0.124565
Equivalent width for line 0.654: 0.20328 +/ 0.155826

Simulation 07


In [227]:
plot_all(7)


read ARF file ../data/athena_xifu_sixte_1469_onaxis_v20150402.arf
WARNING: '../data/athena_xifu_rmf_highres_v20150609.rmf' is not a filename or  MATRIX column not a variable length field
There are 467 samples in the posterior.
The probability that there is a signal in the data is 0.1199
The estimate for the Doppler shift is 0.045 +/- 0.027
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py:524: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)