Analyzing GRB 080916C with Fermi-GBM
(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")
[4]:
| name | ra | dec | trigger_time | t90 |
|---|---|---|---|---|
| object | float64 | float64 | float64 | float64 |
| GRB080916009 | 119.800 | -56.600 | 54725.0088613 | 62.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]:
| 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)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 2) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 3) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
The TTE file /home/runner/work/threeML/threeML/docs/md_docs/slow_execute/glg_tte_n3_bn080916009_v01.fit.gz contains duplicate time tags and is thus invalid. Contact the FSSC
The TTE file /home/runner/work/threeML/threeML/docs/md_docs/slow_execute/glg_tte_n3_bn080916009_v01.fit.gz was not sorted in time but contains no duplicate events. We will sort the times, but use caution with this file. Contact the FSSC.
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 2) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 3) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 2) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 3) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
The TTE file /home/runner/work/threeML/threeML/docs/md_docs/slow_execute/glg_tte_n4_bn080916009_v01.fit.gz was not sorted in time but contains no duplicate events. We will sort the times, but use caution with this file. Contact the FSSC.
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 2) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 3) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 2) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 3) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
The TTE file /home/runner/work/threeML/threeML/docs/md_docs/slow_execute/glg_tte_b0_bn080916009_v01.fit.gz contains duplicate time tags and is thus invalid. Contact the FSSC
The TTE file /home/runner/work/threeML/threeML/docs/md_docs/slow_execute/glg_tte_b0_bn080916009_v01.fit.gz was not sorted in time but contains no duplicate events. We will sort the times, but use caution with this file. Contact the FSSC.
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 1) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 2) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
The default choice for MATRIX extension failed:KeyError("Extension ('MATRIX', 3) not found.")available: None 'EBOUNDS' 'SPECRESP MATRIX' 'SPECRESP MATRIX' 'SPECRESP MATRIX'
No TLMIN keyword found. This DRM does not follow OGIP standards. Assuming TLMIN=1
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
)
We have set the min_value of GRB080916009.spectrum.main.SmoothlyBrokenPowerLaw.break_energy to 1e-99 because there was a postive transform
We have set the min_value of GRB080916009.spectrum.main.SmoothlyBrokenPowerLaw.break_energy to 1e-99 because there was a postive transform
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)
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)
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)= -3126.2708578670727 +/- 0.24828908419842016
Total Likelihood Evaluations: 23306
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| GRB080916009...K | (1.453 -0.008 +0.009) x 10^-2 | 1 / (keV s cm2) |
| GRB080916009...alpha | -1.010 +0.033 +0.11 | |
| GRB080916009...break_energy | (1.69 -0.08 +0.04) x 10^2 | keV |
| GRB080916009...break_scale | (4.1 +0.6 +2.2) x 10^-1 | |
| GRB080916009...beta | -1.889 -0.09 -0.015 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3 | -1030.143256 |
| n4 | -1023.404689 |
| b0 | -1063.910695 |
| total | -3117.458639 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 6245.087733 |
| BIC | 6264.319943 |
| DIC | 6217.662427 |
| PDIC | 1.619943 |
| log(Z) | -1357.722183 |
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)
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")
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)
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)
[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")
Now our light curve looks much more acceptable.
[20]:
fig = n3.view_lightcurve(use_binner=True)
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)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.267000198364258)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
Minimum MC energy (5.0) is larger than minimum EBOUNDS energy (4.369999885559082)
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)
We have set the min_value of Band.xp to 1e-99 because there was a postive transform
We have set the min_value of Band.xp to 1e-99 because there was a postive transform
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)
*****************************************************
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)= -788.03588434186815 +/- 0.17429941592113973
Total Likelihood Evaluations: 16947
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (3.7 -0.7 +0.4) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-5.3 -1.7 +1.1) x 10^-1 | |
| grb.spectrum.main.Band.xp | (3.02 -0.28 +1.1) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -2.04 -0.5 +0.09 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval0 | -250.010269 |
| n4_interval0 | -267.956415 |
| b0_interval0 | -285.622815 |
| total | -803.589499 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 1615.292312 |
| BIC | 1630.701129 |
| DIC | 1571.068722 |
| PDIC | 2.614604 |
| log(Z) | -342.239636 |
*****************************************************
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)= -1959.6789593701772 +/- 0.23178431420391898
Total Likelihood Evaluations: 22893
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (4.121 -0.016 +0.10) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-8.62 -0.14 +0.10) x 10^-1 | |
| grb.spectrum.main.Band.xp | (5.893 -0.4 -0.005) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -1.876 +0.004 +0.024 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval1 | -642.498969 |
| n4_interval1 | -645.248652 |
| b0_interval1 | -684.133317 |
| total | -1971.880937 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 3951.875189 |
| BIC | 3967.284007 |
| DIC | 3896.236762 |
| PDIC | 3.164944 |
| log(Z) | -851.077758 |
*****************************************************
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)= -908.32279773776133 +/- 0.19065339078451504
Total Likelihood Evaluations: 19050
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (2.652173328570218 +0 +0.6) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | -1.021 -0.019 +0.13 | |
| grb.spectrum.main.Band.xp | (4.97 -1.8 -0.15) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -1.798 -0.030 +0.13 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval2 | -288.603432 |
| n4_interval2 | -311.788502 |
| b0_interval2 | -324.149689 |
| total | -924.541622 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 1857.196559 |
| BIC | 1872.605376 |
| DIC | 1805.461402 |
| PDIC | 2.309097 |
| log(Z) | -394.479579 |
*****************************************************
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)= -789.02152766085123 +/- 0.17897855911961469
Total Likelihood Evaluations: 16706
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (2.93 -0.20 +0.5) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-9.2 -0.4 +1.1) x 10^-1 | |
| grb.spectrum.main.Band.xp | (3.3 -0.7 +0.5) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -2.19 +/- 0.17 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval3 | -242.435059 |
| n4_interval3 | -262.396339 |
| b0_interval3 | -298.331994 |
| total | -803.163392 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 1614.440098 |
| BIC | 1629.848916 |
| DIC | 1569.279496 |
| PDIC | 2.341636 |
| log(Z) | -342.667696 |
*****************************************************
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)= -2276.5328333822758 +/- 0.20478216682870309
Total Likelihood Evaluations: 19761
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (2.34 +0.04 +0.18) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-8.958 +0.006 +0.5) x 10^-1 | |
| grb.spectrum.main.Band.xp | (3.09 -0.4 -0.05) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -1.86 -0.04 +0.07 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval4 | -758.574637 |
| n4_interval4 | -745.712808 |
| b0_interval4 | -778.198732 |
| total | -2282.486176 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 4573.085667 |
| BIC | 4588.494485 |
| DIC | 4533.162795 |
| PDIC | 2.618732 |
| log(Z) | -988.685647 |
*****************************************************
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)= -1594.4679652071159 +/- 0.22181514322867346
Total Likelihood Evaluations: 20972
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (2.252 -0.012 +0.07) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | -1.155 -0.008 +0.012 | |
| grb.spectrum.main.Band.xp | (6.9 -1.1 +0.5) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -2.066 -0.12 +0.032 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval5 | -527.436356 |
| n4_interval5 | -542.002045 |
| b0_interval5 | -540.803650 |
| total | -1610.242051 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 3228.597416 |
| BIC | 3244.006233 |
| DIC | 3168.703224 |
| PDIC | 1.615955 |
| log(Z) | -692.468639 |
*****************************************************
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)= -1754.9750846963125 +/- 0.19089396677139278
Total Likelihood Evaluations: 20748
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (1.98 -0.15 +0.11) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-10.0 -0.6 +0.4) x 10^-1 | |
| grb.spectrum.main.Band.xp | (4.3 -0.4 +1.0) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -2.28 -0.5 +0.10 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval6 | -584.208006 |
| n4_interval6 | -576.605474 |
| b0_interval6 | -609.412676 |
| total | -1770.226156 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 3548.565626 |
| BIC | 3563.974444 |
| DIC | 3501.526201 |
| PDIC | 3.491485 |
| log(Z) | -762.175995 |
*****************************************************
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)= -1938.7750082691430 +/- 0.18896288847341852
Total Likelihood Evaluations: 21295
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (1.68 -0.12 +0.08) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | -1.04 -0.05 +0.04 | |
| grb.spectrum.main.Band.xp | (4.3 -0.4 +0.9) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -2.27 -0.4 +0.12 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval7 | -641.065712 |
| n4_interval7 | -650.271022 |
| b0_interval7 | -662.272747 |
| total | -1953.609480 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 3915.332275 |
| BIC | 3930.741092 |
| DIC | 3869.080489 |
| PDIC | 3.420394 |
| log(Z) | -841.999288 |
*****************************************************
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)= -2053.8721623474894 +/- 0.18718261875967865
Total Likelihood Evaluations: 19370
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (1.52 -0.11 +0.13) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-8.6 -0.5 +0.7) x 10^-1 | |
| grb.spectrum.main.Band.xp | (3.8 -0.4 +0.6) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -2.30 -0.4 +0.14 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval8 | -698.372327 |
| n4_interval8 | -666.356520 |
| b0_interval8 | -702.153576 |
| total | -2066.882424 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 4141.878162 |
| BIC | 4157.286979 |
| DIC | 4098.065321 |
| PDIC | 3.254902 |
| log(Z) | -891.985347 |
*****************************************************
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)= -1879.1325224008456 +/- 0.14849091866822617
Total Likelihood Evaluations: 12515
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (1.07 -0.29 +1.2) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-8.8 -1.7 +3.3) x 10^-1 | |
| grb.spectrum.main.Band.xp | (1.1 +/- 0.4) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -1.86 -0.23 +0.11 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval9 | -616.948905 |
| n4_interval9 | -616.279812 |
| b0_interval9 | -648.375953 |
| total | -1881.604670 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 3771.322654 |
| BIC | 3786.731471 |
| DIC | 3723.844077 |
| PDIC | -22.844815 |
| log(Z) | -816.096885 |
*****************************************************
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)= -1321.7271731863170 +/- 0.16431638328924769
Total Likelihood Evaluations: 16480
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (2.00 -0.33 +0.6) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-7.5 -1.2 +1.7) x 10^-1 | |
| grb.spectrum.main.Band.xp | (2.3 -0.5 +0.6) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -1.95 -0.4 +0.11 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval10 | -437.622196 |
| n4_interval10 | -433.328768 |
| b0_interval10 | -460.947412 |
| total | -1331.898376 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 2671.910066 |
| BIC | 2687.318884 |
| DIC | 2634.475554 |
| PDIC | 0.539537 |
| log(Z) | -574.018818 |
*****************************************************
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)= -813.01887148242065 +/- 0.15093285126540171
Total Likelihood Evaluations: 11693
Sampling finished. Exiting MultiNest
Maximum a posteriori probability (MAP) point:
| result | unit | |
|---|---|---|
| parameter | ||
| grb.spectrum.main.Band.K | (3.1 -1.2 +1.0) x 10^-2 | 1 / (keV s cm2) |
| grb.spectrum.main.Band.alpha | (-4.5 -3.1 +1.1) x 10^-1 | |
| grb.spectrum.main.Band.xp | (1.22 -0.24 +0.4) x 10^2 | keV |
| grb.spectrum.main.Band.beta | -2.07 -0.6 +0.23 |
Values of -log(posterior) at the minimum:
| -log(posterior) | |
|---|---|
| n3_interval11 | -272.501196 |
| n4_interval11 | -255.703189 |
| b0_interval11 | -292.320842 |
| total | -820.525227 |
Values of statistical measures:
| statistical measures | |
|---|---|
| AIC | 1649.163769 |
| BIC | 1664.572587 |
| DIC | 1618.151565 |
| PDIC | 0.772099 |
| log(Z) | -353.089610 |
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)
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),
)
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.