{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# GBM Spectral Catalog Files\n",
"\n",
"GBM provides standard spectral fits for each GRB triggered on-board. These spectral fits are hosted in FITS format at HEASARC as \"SCat\" (Spectral Catalog) files. The SCat files contain the spectral fit data, including fit parameters, uncertainties, fluxes/fluences, fit statistic, covariance. The files also contain metadata about the detectors and data that were used in the fit. All of this information can be easily accessed using the `Scat` class.\n",
"\n",
"We can read a SCat FITS file via the normal method in the Data Tools:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"glg_scat_all_bn170817529_flnc_comp_v02.fit\n"
]
}
],
"source": [
"from gbm import test_data_dir\n",
"# import the Scat class\n",
"from gbm.data import Scat\n",
"\n",
"# read a SCat file\n",
"scat = Scat.open(test_data_dir+'/glg_scat_all_bn170817529_flnc_comp_v02.fit')\n",
"print(scat)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can quickly determine the number of detectors used in the spectral fit(s) and the number of spectral fits provided in the file:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of detectors used: 4\n",
"Number of spectral fits: 1\n"
]
}
],
"source": [
"print('Number of detectors used: {}'.format(scat.num_detectors))\n",
"print('Number of spectral fits: {}'.format(scat.num_fits))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can acces the list of model fits by:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scat.model_fits"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `GbmModelFit` class contains the all of the relevant info for a fit. Let's look at a few properties contained in this class:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Fit time range: -0.192 - 0.064\n",
"Fit Statistic: Castor C-STAT\n",
"Stat/DoF: 479.62/479\n",
"Model name: Comptonized, Epeak\n",
"Parameter names: ['Amplitude', 'Epeak', 'Index', 'Pivot E =fix']\n"
]
}
],
"source": [
"one_fit = scat.model_fits[0]\n",
"print('Fit time range: {0} - {1}'.format(*one_fit.time_range))\n",
"print('Fit Statistic: {}'.format(one_fit.stat_name))\n",
"print('Stat/DoF: {0:.2f}/{1}'.format(one_fit.stat_value, one_fit.dof))\n",
"print('Model name: {}'.format(one_fit.name))\n",
"print('Parameter names: {}'.format(one_fit.parameter_list()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the actual fit data, they are stored as `Parameter` objects, which group together the fit value, uncertainty, and metadata such as the parameter name and units. If you want to quickly see the fit information, you can simply print the `GbmModelFit` object:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Comptonized, Epeak\n",
" Amplitude: 0.03 +/- 0.02\n",
" Epeak: 215.09 +/- 54.22\n",
" Index: 0.14 +/- 0.59\n",
" Pivot E =fix: 1.00e+02 +/- 0.00e+00\n"
]
}
],
"source": [
"print(one_fit)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Otherwise, you can directly access the parameter fit info by attributes and methods of the `Parameter` class:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Name: Epeak\n",
"Value: 215.09434509277344\n",
"1-sigma uncert: (54.219116, 54.219116)\n",
"1-sigma range: (160.87522888183594, 269.31346130371094)\n"
]
}
],
"source": [
"epeak = one_fit.parameters[1]\n",
"print('Name: {}'.format(epeak.name))\n",
"print('Value: {}'.format(epeak.value))\n",
"print('1-sigma uncert: {}'.format(epeak.uncertainty))\n",
"print('1-sigma range: {}'.format(epeak.one_sigma_range()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For each fit, the photon and energy fluxes and fluences are also recorded, and those are stored as special `Parameter` objects as well:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Photon Flux: 2.81 +/- 0.44 ph/cm^2/s\n",
"Energy Fluence: 1.40e-07 +/- 3.03e-08 erg/cm^2\n"
]
}
],
"source": [
"print(one_fit.photon_flux)\n",
"print(one_fit.energy_fluence)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"As for the detector metadata used in the fits, they are stored in `DetectorData` objects:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[, , , ]\n"
]
}
],
"source": [
"print(scat.detectors)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can access various properties stored in these objects:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"BGO_00: energy range: (284.65, 40108.0) keV, # channel range: (3, 124)\n",
"NAI_01: energy range: (8.501, 903.45) keV, # channel range: (5, 124)\n",
"NAI_02: energy range: (9.119, 902.57) keV, # channel range: (5, 124)\n",
"NAI_05: energy range: (8.698, 909.58) keV, # channel range: (5, 124)\n"
]
}
],
"source": [
"for det in scat.detectors:\n",
" print('{0}: energy range: {1} keV, # channel range: {2}'.format(det.detector, det.energy_range, det.channel_range))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For each detector, the deconvolved photon counts, errors, and detector-convolved photon model are stored as well. These can be used for making the model count rate plots. For example:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1.96157284e-02, 1.99605655e-02, 2.02203058e-02, 2.04198491e-02,\n",
" 2.05748081e-02, 2.06954200e-02, 2.07886994e-02, 2.08651833e-02,\n",
" 2.09236853e-02, 2.09595580e-02, 2.09755581e-02, 2.09734701e-02,\n",
" 2.09545959e-02, 2.09202804e-02, 2.08671484e-02, 2.07942519e-02,\n",
" 2.07068976e-02, 2.06062403e-02, 2.04924233e-02, 2.03650203e-02,\n",
" 2.02121083e-02, 2.00296603e-02, 1.98248476e-02, 1.96060352e-02,\n",
" 1.94124747e-02, 1.92341618e-02, 1.90395378e-02, 1.88379139e-02,\n",
" 1.86298881e-02, 1.84038971e-02, 1.81599278e-02, 1.79103129e-02,\n",
" 1.76558699e-02, 1.73842870e-02, 1.70959160e-02, 1.68044139e-02,\n",
" 1.65107511e-02, 1.62022281e-02, 1.58796720e-02, 1.55573804e-02,\n",
" 1.52229378e-02, 1.48775103e-02, 1.45354364e-02, 1.41847273e-02,\n",
" 1.38267530e-02, 1.34753715e-02, 1.31187867e-02, 1.27577381e-02,\n",
" 1.24046309e-02, 1.20481234e-02, 1.16888676e-02, 1.13384118e-02,\n",
" 1.09861176e-02, 1.06325680e-02, 1.02785071e-02, 9.92442667e-03,\n",
" 9.57103912e-03, 9.21891443e-03, 8.86891689e-03, 8.52157827e-03,\n",
" 8.18584766e-03, 7.85366166e-03, 7.52549898e-03, 7.20197801e-03,\n",
" 6.87657017e-03, 6.55738916e-03, 6.24498492e-03, 5.93968714e-03,\n",
" 5.64196613e-03, 5.35207335e-03, 5.07042184e-03, 4.79209516e-03,\n",
" 4.52288752e-03, 4.26308904e-03, 4.00841329e-03, 3.76371294e-03,\n",
" 3.52911279e-03, 3.30090406e-03, 3.07974149e-03, 2.86927028e-03,\n",
" 2.66939658e-03, 2.47712969e-03, 2.29281047e-03, 2.11906387e-03,\n",
" 1.95566076e-03, 1.80015434e-03, 1.65265775e-03, 1.51324435e-03,\n",
" 1.38190738e-03, 1.25858490e-03, 1.14318531e-03, 1.03555166e-03,\n",
" 9.35497112e-04, 8.42794776e-04, 7.57185626e-04, 6.78389741e-04,\n",
" 6.06101414e-04, 5.39377157e-04, 4.78061469e-04, 4.22516343e-04,\n",
" 3.72365321e-04, 3.27230984e-04, 2.86408875e-04, 2.49648612e-04,\n",
" 2.16978922e-04, 1.87817757e-04, 1.61900462e-04, 1.38990174e-04,\n",
" 1.18824362e-04, 1.01168524e-04, 8.57760242e-05, 7.24279816e-05,\n",
" 6.08285809e-05, 5.08733683e-05, 4.23745478e-05, 3.51066883e-05,\n",
" 2.89300351e-05, 2.37133027e-05, 1.93576161e-05, 1.57395298e-05,\n",
" 1.27308667e-05, 1.02440299e-05, 8.20066271e-06, 6.52375820e-06,\n",
" 5.15691772e-06, 3.84230407e-06, 2.66911161e-06, 3.89260578e-07],\n",
" dtype=float32)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# convolved photon model counts for detector n1\n",
"scat.detectors[1].photon_model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This finishes the brief intro to the `Scat` class. Onwards to [simulations!](./Simulations.ipynb)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}