Analyzing GRB 080916C

Alt text (NASA/Swift/Cruz deWilde)

To demonstrate the capabilities and features of 3ML in, we will go through a time-integrated and time-resolved analysis. This example serves as a standard way to analyze Fermi-GBM data with 3ML as well as a template for how you can design your instrument’s analysis pipeline with 3ML if you have similar data.

3ML provides utilities to reduce time series data to plugins in a correct and statistically justified way (e.g., background fitting of Poisson data is done with a Poisson likelihood). The approach is generic and can be extended. For more details, see the time series documentation.

[1]:
import warnings

warnings.simplefilter("ignore")
[2]:
%%capture
import matplotlib.pyplot as plt
import numpy as np

np.seterr(all="ignore")


from threeML import *
from threeML.io.package_data import get_path_of_data_file
[3]:

silence_warnings() %matplotlib inline from jupyterthemes import jtplot jtplot.style(context="talk", fscale=1, ticks=True, grid=False) set_threeML_style()

Examining the catalog

As with Swift and Fermi-LAT, 3ML provides a simple interface to the on-line Fermi-GBM catalog. Let’s get the information for GRB 080916C.

[4]:
gbm_catalog = FermiGBMBurstCatalog()
gbm_catalog.query_sources("GRB080916009")
05:16:35 INFO      The cache for fermigbrst does not yet exist. We will try to    get_heasarc_table_as_pandas.py:64
                  build it                                                                                         
                                                                                                                   
         INFO      Building cache for fermigbrst                                 get_heasarc_table_as_pandas.py:112
[4]:
Table length=1
nameradectrigger_timet90
objectfloat64float64float64float64
GRB080916009119.800-56.60054725.008861362.977

To aid in quickly replicating the catalog analysis, and thanks to the tireless efforts of the Fermi-GBM team, we have added the ability to extract the analysis parameters from the catalog as well as build an astromodels model with the best fit parameters baked in. Using this information, one can quickly run through the catalog an replicate the entire analysis with a script. Let’s give it a try.

[5]:
grb_info = gbm_catalog.get_detector_information()["GRB080916009"]

gbm_detectors = grb_info["detectors"]
source_interval = grb_info["source"]["fluence"]
background_interval = grb_info["background"]["full"]
best_fit_model = grb_info["best fit model"]["fluence"]
model = gbm_catalog.get_model(best_fit_model, "fluence")["GRB080916009"]
[6]:
model
[6]:
Model summary:

N
Point sources 1
Extended sources 0
Particle sources 0


Free parameters (5):

value min_value max_value unit
GRB080916009.spectrum.main.SmoothlyBrokenPowerLaw.K 0.012255 0.0 None keV-1 s-1 cm-2
GRB080916009.spectrum.main.SmoothlyBrokenPowerLaw.alpha -1.130424 -1.5 2.0
GRB080916009.spectrum.main.SmoothlyBrokenPowerLaw.break_energy 309.2031 10.0 None keV
GRB080916009.spectrum.main.SmoothlyBrokenPowerLaw.break_scale 0.3 0.0 10.0
GRB080916009.spectrum.main.SmoothlyBrokenPowerLaw.beta -2.096931 -5.0 -1.6


Fixed parameters (3):
(abridged. Use complete=True to see all fixed parameters)


Properties (0):

(none)


Linked parameters (0):

(none)

Independent variables:

(none)

Linked functions (0):

(none)

Downloading the data

We provide a simple interface to download the Fermi-GBM data. Using the information from the catalog that we have extracted, we can download just the data from the detectors that were used for the catalog analysis. This will download the CSPEC, TTE and instrument response files from the on-line database.

[7]:
dload = download_GBM_trigger_data("bn080916009", detectors=gbm_detectors)

Let’s first examine the catalog fluence fit. Using the TimeSeriesBuilder, we can fit the background, set the source interval, and create a 3ML plugin for the analysis. We will loop through the detectors, set their appropriate channel selections, and ensure there are enough counts in each bin to make the PGStat profile likelihood valid.

  • First we use the CSPEC data to fit the background using the background selections. We use CSPEC because it has a longer duration for fitting the background.

  • The background is saved to an HDF5 file that stores the polynomial coefficients and selections which we can read in to the TTE file later.

  • The light curve is plotted.

  • The source selection from the catalog is set and DispersionSpectrumLike plugin is created.

  • The plugin has the standard GBM channel selections for spectral analysis set.

[8]:
fluence_plugins = []
time_series = {}
for det in gbm_detectors:
    ts_cspec = TimeSeriesBuilder.from_gbm_cspec_or_ctime(
        det, cspec_or_ctime_file=dload[det]["cspec"], rsp_file=dload[det]["rsp"]
    )

    ts_cspec.set_background_interval(*background_interval.split(","))
    ts_cspec.save_background(f"{det}_bkg.h5", overwrite=True)

    ts_tte = TimeSeriesBuilder.from_gbm_tte(
        det,
        tte_file=dload[det]["tte"],
        rsp_file=dload[det]["rsp"],
        restore_background=f"{det}_bkg.h5",
    )

    time_series[det] = ts_tte

    ts_tte.set_active_time_interval(source_interval)

    ts_tte.view_lightcurve(-40, 100)

    fluence_plugin = ts_tte.to_spectrumlike()

    if det.startswith("b"):
        fluence_plugin.set_active_measurements("250-30000")

    else:
        fluence_plugin.set_active_measurements("9-900")

    fluence_plugin.rebin_on_background(1.0)

    fluence_plugins.append(fluence_plugin)
05:17:32 INFO      Auto-determined polynomial order: 0                                binned_spectrum_series.py:389
05:17:41 INFO      None 0-order polynomial fit with the mle method                               time_series.py:458
         INFO      Saved fitted background to n3_bkg.h5                                         time_series.py:1064
         INFO      Saved background to n3_bkg.h5                                         time_series_builder.py:471
         INFO      Successfully restored fit from n3_bkg.h5                              time_series_builder.py:171
         INFO      Interval set to 1.28-64.257 for n3                                    time_series_builder.py:290
05:17:42 INFO      Auto-probed noise models:                                                    SpectrumLike.py:490
         INFO      - observation: poisson                                                       SpectrumLike.py:491
         INFO      - background: gaussian                                                       SpectrumLike.py:492
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
05:17:44 INFO      Now using 120 bins                                                          SpectrumLike.py:1739
05:17:45 INFO      Auto-determined polynomial order: 1                                binned_spectrum_series.py:389
05:17:55 INFO      None 1-order polynomial fit with the mle method                               time_series.py:458
         INFO      Saved fitted background to n4_bkg.h5                                         time_series.py:1064
         INFO      Saved background to n4_bkg.h5                                         time_series_builder.py:471
         INFO      Successfully restored fit from n4_bkg.h5                              time_series_builder.py:171
         INFO      Interval set to 1.28-64.257 for n4                                    time_series_builder.py:290
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:490
         INFO      - observation: poisson                                                       SpectrumLike.py:491
         INFO      - background: gaussian                                                       SpectrumLike.py:492
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
05:17:57 INFO      Auto-determined polynomial order: 1                                binned_spectrum_series.py:389
05:18:07 INFO      None 1-order polynomial fit with the mle method                               time_series.py:458
         INFO      Saved fitted background to b0_bkg.h5                                         time_series.py:1064
         INFO      Saved background to b0_bkg.h5                                         time_series_builder.py:471
         INFO      Successfully restored fit from b0_bkg.h5                              time_series_builder.py:171
         INFO      Interval set to 1.28-64.257 for b0                                    time_series_builder.py:290
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:490
         INFO      - observation: poisson                                                       SpectrumLike.py:491
         INFO      - background: gaussian                                                       SpectrumLike.py:492
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
../_images/notebooks_grb080916C_12_42.png
../_images/notebooks_grb080916C_12_43.png
../_images/notebooks_grb080916C_12_44.png

Setting up the fit

Let’s see if we can reproduce the results from the catalog.

Set priors for the model

We will fit the spectrum using Bayesian analysis, so we must set priors on the model parameters.

[9]:
model.GRB080916009.spectrum.main.shape.alpha.prior = Truncated_gaussian(
    lower_bound=-1.5, upper_bound=1, mu=-1, sigma=0.5
)
model.GRB080916009.spectrum.main.shape.beta.prior = Truncated_gaussian(
    lower_bound=-5, upper_bound=-1.6, mu=-2.25, sigma=0.5
)
model.GRB080916009.spectrum.main.shape.break_energy.prior = Log_normal(mu=2, sigma=1)
model.GRB080916009.spectrum.main.shape.break_energy.bounds = (None, None)
model.GRB080916009.spectrum.main.shape.K.prior = Log_uniform_prior(
    lower_bound=1e-3, upper_bound=1e1
)
model.GRB080916009.spectrum.main.shape.break_scale.prior = Log_uniform_prior(
    lower_bound=1e-4, upper_bound=10
)

Clone the model and setup the Bayesian analysis class

Next, we clone the model we built from the catalog so that we can look at the results later and fit the cloned model. We pass this model and the DataList of the plugins to a BayesianAnalysis class and set the sampler to MultiNest.

[10]:
new_model = clone_model(model)

bayes = BayesianAnalysis(new_model, DataList(*fluence_plugins))

# share spectrum gives a linear speed up when
# spectrumlike plugins have the same RSP input energies
bayes.set_sampler("multinest", share_spectrum=True)
05:18:08 INFO      sampler set to multinest                                                bayesian_analysis.py:202

Examine at the catalog fitted model

We can quickly examine how well the catalog fit matches the data. There appears to be a discrepancy between the data and the model! Let’s refit to see if we can fix it.

[11]:
fig = display_spectrum_model_counts(bayes, min_rate=20, step=False)
../_images/notebooks_grb080916C_18_0.png

Run the sampler

We let MultiNest condition the model on the data

[12]:
bayes.sampler.setup(n_live_points=400)
bayes.sample()
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  400
 dimensionality =    5
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -3115.1088434063004      +/-  0.24836632544875722
 Total Likelihood Evaluations:        25762
 Sampling finished. Exiting MultiNest

05:18:25 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
GRB080916009...K (1.469 -0.006 +0.021) x 10^-2 1 / (cm2 keV s)
GRB080916009...alpha -1.002 +0.007 +0.05
GRB080916009...break_energy (2.00 -0.17 +0.08) x 10^2 keV
GRB080916009...break_scale (4.26 +0.17 +1.4) x 10^-1
GRB080916009...beta -2.016 -0.05 +0.027
Values of -log(posterior) at the minimum:

-log(posterior)
b0 -1056.063633
n3 -1029.690172
n4 -1021.792936
total -3107.546741
Values of statistical measures:

statistical measures
AIC 6225.263937
BIC 6244.496148
DIC 6196.952054
PDIC 2.308004
log(Z) -1352.874581

Now our model seems to match much better with the data!

[13]:
bayes.restore_median_fit()
fig = display_spectrum_model_counts(bayes, min_rate=20)
         INFO      fit restored to median of posterior                                          sampler_base.py:164
../_images/notebooks_grb080916C_22_1.png

But how different are we from the catalog model? Let’s plot our fit along with the catalog model. Luckily, 3ML can handle all the units for is

[14]:
conversion = u.Unit("keV2/(cm2 s keV)").to("erg2/(cm2 s keV)")
energy_grid = np.logspace(1, 4, 100) * u.keV
vFv = (energy_grid**2 * model.get_point_source_fluxes(0, energy_grid)).to(
    "erg2/(cm2 s keV)"
)
[15]:
fig = plot_spectra(bayes.results, flux_unit="erg2/(cm2 s keV)")
ax = fig.get_axes()[0]
_ = ax.loglog(energy_grid, vFv, color="blue", label="catalog model")
../_images/notebooks_grb080916C_25_2.png

Time Resolved Analysis

Now that we have examined fluence fit, we can move to performing a time-resolved analysis.

Selecting a temporal binning

We first get the brightest NaI detector and create time bins via the Bayesian blocks algorithm. We can use the fitted background to make sure that our intervals are chosen in an unbiased way.

[16]:
n3 = time_series["n3"]
[17]:
n3.create_time_bins(0, 60, method="bayesblocks", use_background=True, p0=0.2)
05:20:11 INFO      Created 15 bins via bayesblocks                                       time_series_builder.py:708

Sometimes, glitches in the GBM data cause spikes in the data that the Bayesian blocks algorithm detects as fast changes in the count rate. We will have to remove those intervals manually.

Note: In the future, 3ML will provide an automated method to remove these unwanted spikes.

[18]:
fig = n3.view_lightcurve(use_binner=True)
../_images/notebooks_grb080916C_30_0.png
[19]:
bad_bins = []
for i, w in enumerate(n3.bins.widths):
    if w < 5e-2:
        bad_bins.append(i)


edges = [n3.bins.starts[0]]

for i, b in enumerate(n3.bins):
    if i not in bad_bins:
        edges.append(b.stop)

starts = edges[:-1]
stops = edges[1:]


n3.create_time_bins(starts, stops, method="custom")
05:20:12 INFO      Created 12 bins via custom                                            time_series_builder.py:708

Now our light curve looks much more acceptable.

[20]:
fig = n3.view_lightcurve(use_binner=True)
../_images/notebooks_grb080916C_33_0.png

The time series objects can read time bins from each other, so we will map these time bins onto the other detectors’ time series and create a list of time plugins for each detector and each time bin created above.

[21]:
time_resolved_plugins = {}

for k, v in time_series.items():
    v.read_bins(n3)
    time_resolved_plugins[k] = v.to_spectrumlike(from_bins=True)
         INFO      Created 12 bins via custom                                            time_series_builder.py:708
         INFO      Interval set to 1.28-64.257 for n3                                    time_series_builder.py:290
         INFO      Created 12 bins via custom                                            time_series_builder.py:708
05:20:13 INFO      Interval set to 1.28-64.257 for n4                                    time_series_builder.py:290
         INFO      Created 12 bins via custom                                            time_series_builder.py:708
         INFO      Interval set to 1.28-64.257 for b0                                    time_series_builder.py:290

Setting up the model

For the time-resolved analysis, we will fit the classic Band function to the data. We will set some principled priors.

[22]:
band = Band()
band.alpha.prior = Truncated_gaussian(lower_bound=-1.5, upper_bound=1, mu=-1, sigma=0.5)
band.beta.prior = Truncated_gaussian(lower_bound=-5, upper_bound=-1.6, mu=-2, sigma=0.5)
band.xp.prior = Log_normal(mu=2, sigma=1)
band.xp.bounds = (None, None)
band.K.prior = Log_uniform_prior(lower_bound=1e-10, upper_bound=1e3)
ps = PointSource("grb", 0, 0, spectral_shape=band)
band_model = Model(ps)

Perform the fits

One way to perform Bayesian spectral fits to all the intervals is to loop through each one. There can are many ways to do this, so find an analysis pattern that works for you.

[23]:
models = []
results = []
analysis = []
for interval in range(12):
    # clone the model above so that we have a separate model
    # for each fit

    this_model = clone_model(band_model)

    # for each detector set up the plugin
    # for this time interval

    this_data_list = []
    for k, v in time_resolved_plugins.items():
        pi = v[interval]

        if k.startswith("b"):
            pi.set_active_measurements("250-30000")
        else:
            pi.set_active_measurements("9-900")

        pi.rebin_on_background(1.0)

        this_data_list.append(pi)

    # create a data list

    dlist = DataList(*this_data_list)

    # set up the sampler and fit

    bayes = BayesianAnalysis(this_model, dlist)

    # get some speed with share spectrum
    bayes.set_sampler("multinest", share_spectrum=True)
    bayes.sampler.setup(n_live_points=500)
    bayes.sample()

    # at this stage we coudl also
    # save the analysis result to
    # disk but we will simply hold
    # onto them in memory

    analysis.append(bayes)
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 107 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -787.96595981418716      +/-  0.17462588503363854
 Total Likelihood Evaluations:        17453
 Sampling finished. Exiting MultiNest

05:20:24 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (3.5 -0.5 +0.7) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-5.7 -1.3 +1.4) x 10^-1
grb.spectrum.main.Band.xp (3.2 -0.5 +0.9) x 10^2 keV
grb.spectrum.main.Band.beta -2.02 -0.5 +0.06
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval0 -285.739709
n3_interval0 -250.207549
n4_interval0 -267.955410
total -803.902668
Values of statistical measures:

statistical measures
AIC 1615.918650
BIC 1631.327467
DIC 1570.506120
PDIC 2.309255
log(Z) -342.209268
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -1947.9734117178666      +/-  0.22170649427592543
 Total Likelihood Evaluations:        23028
 Sampling finished. Exiting MultiNest

05:20:42 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (4.25 -0.17 +0.09) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-8.42 -0.32 +0.13) x 10^-1
grb.spectrum.main.Band.xp (5.68 -0.34 +0.5) x 10^2 keV
grb.spectrum.main.Band.beta -1.9982 +0.0016 +0.05
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval1 -675.900810
n3_interval1 -641.653319
n4_interval1 -644.455467
total -1962.009596
Values of statistical measures:

statistical measures
AIC 3932.132506
BIC 3947.541324
DIC 3876.730833
PDIC 2.625377
log(Z) -845.994104
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 115 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -913.84149353589510      +/-  0.21327288306383574
 Total Likelihood Evaluations:        19060
 Sampling finished. Exiting MultiNest

05:20:54 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (2.72 -0.4 +0.07) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha -1.04 -0.15 -0.05
grb.spectrum.main.Band.xp (4.6 -0.7 +2.8) x 10^2 keV
grb.spectrum.main.Band.beta -1.702 -0.012 +0.007
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval2 -324.699382
n3_interval2 -288.903951
n4_interval2 -311.336985
total -924.940319
Values of statistical measures:

statistical measures
AIC 1857.993952
BIC 1873.402769
DIC 1809.384910
PDIC 1.524203
log(Z) -396.876318
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 109 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -790.53471851516258      +/-  0.17979386318258817
 Total Likelihood Evaluations:        18333
 Sampling finished. Exiting MultiNest

05:21:05 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (3.00 -0.30 +0.6) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-9.1 -0.7 +1.2) x 10^-1
grb.spectrum.main.Band.xp (3.1 -0.7 +0.5) x 10^2 keV
grb.spectrum.main.Band.beta -2.05 +0.07 +0.23
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval3 -298.362009
n3_interval3 -242.166795
n4_interval3 -262.060694
total -802.589498
Values of statistical measures:

statistical measures
AIC 1613.292310
BIC 1628.701127
DIC 1570.589597
PDIC 1.935653
log(Z) -343.324866
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -2270.9893351436408      +/-  0.20068505577188064
 Total Likelihood Evaluations:        19612
 Sampling finished. Exiting MultiNest

05:21:17 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (2.06 -0.12 +0.08) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-9.76 -0.4 +0.22) x 10^-1
grb.spectrum.main.Band.xp (3.96 -0.31 +0.6) x 10^2 keV
grb.spectrum.main.Band.beta -1.97 -0.08 +0.07
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval4 -778.466491
n3_interval4 -757.154683
n4_interval4 -746.668395
total -2282.289569
Values of statistical measures:

statistical measures
AIC 4572.692452
BIC 4588.101270
DIC 4527.013163
PDIC 3.063199
log(Z) -986.278137
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -1578.5934655505241      +/-  0.19822710637227095
 Total Likelihood Evaluations:        20263
 Sampling finished. Exiting MultiNest

05:21:30 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (3.02 +0.09 +0.5) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-8.618 -0.014 +1.2) x 10^-1
grb.spectrum.main.Band.xp (3.47 -0.5 -0.10) x 10^2 keV
grb.spectrum.main.Band.beta -1.91 -0.20 +0.04
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval5 -537.162048
n3_interval5 -523.806225
n4_interval5 -527.260335
total -1588.228608
Values of statistical measures:

statistical measures
AIC 3184.570530
BIC 3199.979348
DIC 3143.019163
PDIC 4.169922
log(Z) -685.574431
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -1756.6589231758014      +/-  0.19908812375757584
 Total Likelihood Evaluations:        18967
 Sampling finished. Exiting MultiNest

05:21:43 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (1.956 -0.013 +0.16) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha -1.013 -0.015 +0.06
grb.spectrum.main.Band.xp (4.46 -0.6 +0.18) x 10^2 keV
grb.spectrum.main.Band.beta -2.384 -0.4 +0.029
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval6 -609.515396
n3_interval6 -584.375364
n4_interval6 -576.863409
total -1770.754169
Values of statistical measures:

statistical measures
AIC 3549.621652
BIC 3565.030469
DIC 3500.269731
PDIC 2.466741
log(Z) -762.907277
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -1941.3100768833663      +/-  0.19691423609493514
 Total Likelihood Evaluations:        19614
 Sampling finished. Exiting MultiNest

05:21:56 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (1.709 -0.022 +0.14) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha -1.025 -0.019 +0.05
grb.spectrum.main.Band.xp (4.06 -0.6 +0.10) x 10^2 keV
grb.spectrum.main.Band.beta -2.208 +0.009 +0.20
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval7 -661.982907
n3_interval7 -640.921430
n4_interval7 -650.070709
total -1952.975047
Values of statistical measures:

statistical measures
AIC 3914.063409
BIC 3929.472226
DIC 3867.690296
PDIC 2.541560
log(Z) -843.100254
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -2054.9489859688510      +/-  0.19166283059183892
 Total Likelihood Evaluations:        18922
 Sampling finished. Exiting MultiNest

05:22:08 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (1.55 -0.08 +0.16) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-8.4 -0.4 +0.7) x 10^-1
grb.spectrum.main.Band.xp (3.72 -0.5 +0.26) x 10^2 keV
grb.spectrum.main.Band.beta -2.29 -0.13 +0.18
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval8 -702.401377
n3_interval8 -698.539306
n4_interval8 -665.854308
total -2066.794991
Values of statistical measures:

statistical measures
AIC 4141.703297
BIC 4157.112115
DIC 4097.008212
PDIC 2.862848
log(Z) -892.453005
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -1878.8638767671787      +/-  0.14573996686635662
 Total Likelihood Evaluations:        12824
 Sampling finished. Exiting MultiNest

05:22:17 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (1.13 -0.35 +2.0) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-8.4 -1.9 +4) x 10^-1
grb.spectrum.main.Band.xp (1.1 -0.5 +0.4) x 10^2 keV
grb.spectrum.main.Band.beta -1.86 -0.34 +0.15
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval9 -648.474432
n3_interval9 -616.962398
n4_interval9 -616.253759
total -1881.690589
Values of statistical measures:

statistical measures
AIC 3771.494493
BIC 3786.903311
DIC 3653.406975
PDIC -93.749278
log(Z) -815.980214
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -1322.8720612186330      +/-  0.17245546107316020
 Total Likelihood Evaluations:        15193
 Sampling finished. Exiting MultiNest

05:22:27 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (2.03 -0.5 +0.15) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-7.37 -1.9 +0.35) x 10^-1
grb.spectrum.main.Band.xp (2.29 -0.15 +0.8) x 10^2 keV
grb.spectrum.main.Band.beta -2.02 -0.6 -0.08
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval10 -460.906917
n3_interval10 -437.832719
n4_interval10 -433.494214
total -1332.233849
Values of statistical measures:

statistical measures
AIC 2672.581012
BIC 2687.989830
DIC 2635.840637
PDIC 1.014367
log(Z) -574.516036
         INFO      Range 9-900 translates to channels 5-124                                    SpectrumLike.py:1247
         INFO      Now using 120 bins                                                          SpectrumLike.py:1739
         INFO      Range 9-900 translates to channels 5-123                                    SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      Range 250-30000 translates to channels 1-119                                SpectrumLike.py:1247
         INFO      Now using 119 bins                                                          SpectrumLike.py:1739
         INFO      sampler set to multinest                                                bayesian_analysis.py:202
 *****************************************************
 MultiNest v3.10
 Copyright Farhan Feroz & Mike Hobson
 Release Jul 2015

 no. of live points =  500
 dimensionality =    4
 *****************************************************
  analysing data from chains/fit-.txt ln(ev)=  -812.58736608024833      +/-  0.15061984174475224
 Total Likelihood Evaluations:        11932
 Sampling finished. Exiting MultiNest

05:22:36 INFO      fit restored to maximum of posterior                                         sampler_base.py:178
         INFO      fit restored to maximum of posterior                                         sampler_base.py:178
Maximum a posteriori probability (MAP) point:

result unit
parameter
grb.spectrum.main.Band.K (2.8 -0.8 +2.2) x 10^-2 1 / (cm2 keV s)
grb.spectrum.main.Band.alpha (-4.9 -2.5 +3.4) x 10^-1
grb.spectrum.main.Band.xp (1.28 -0.24 +0.20) x 10^2 keV
grb.spectrum.main.Band.beta -2.079 -0.5 +0.020
Values of -log(posterior) at the minimum:

-log(posterior)
b0_interval11 -292.336539
n3_interval11 -272.298236
n4_interval11 -255.910569
total -820.545344
Values of statistical measures:

statistical measures
AIC 1649.204001
BIC 1664.612819
DIC 1616.570143
PDIC -0.752131
log(Z) -352.902209

Examine the fits

Now we can look at the fits in count space to make sure they are ok.

[24]:
for a in analysis:
    a.restore_median_fit()
    _ = display_spectrum_model_counts(a, min_rate=[20, 20, 20], step=False)
         INFO      fit restored to median of posterior                                          sampler_base.py:164
         INFO      fit restored to median of posterior                                          sampler_base.py:164
05:22:37 INFO      fit restored to median of posterior                                          sampler_base.py:164
05:22:38 INFO      fit restored to median of posterior                                          sampler_base.py:164
         INFO      fit restored to median of posterior                                          sampler_base.py:164
05:22:39 INFO      fit restored to median of posterior                                          sampler_base.py:164
         INFO      fit restored to median of posterior                                          sampler_base.py:164
05:22:40 INFO      fit restored to median of posterior                                          sampler_base.py:164
05:22:41 INFO      fit restored to median of posterior                                          sampler_base.py:164
05:22:42 INFO      fit restored to median of posterior                                          sampler_base.py:164
         INFO      fit restored to median of posterior                                          sampler_base.py:164
05:22:43 INFO      fit restored to median of posterior                                          sampler_base.py:164
../_images/notebooks_grb080916C_41_12.png
../_images/notebooks_grb080916C_41_13.png
../_images/notebooks_grb080916C_41_14.png
../_images/notebooks_grb080916C_41_15.png
../_images/notebooks_grb080916C_41_16.png
../_images/notebooks_grb080916C_41_17.png
../_images/notebooks_grb080916C_41_18.png
../_images/notebooks_grb080916C_41_19.png
../_images/notebooks_grb080916C_41_20.png
../_images/notebooks_grb080916C_41_21.png
../_images/notebooks_grb080916C_41_22.png
../_images/notebooks_grb080916C_41_23.png

Finally, we can plot the models together to see how the spectra evolve with time.

[25]:
fig = plot_spectra(
    *[a.results for a in analysis[::1]],
    flux_unit="erg2/(cm2 s keV)",
    fit_cmap="viridis",
    contour_cmap="viridis",
    contour_style_kwargs=dict(alpha=0.1),
)
../_images/notebooks_grb080916C_43_13.png

This example can serve as a template for performing analysis on GBM data. However, as 3ML provides an abstract interface and modular building blocks, similar analysis pipelines can be built for any time series data.