Add sed likelihood profile plot to spectrum analysis tutorial
"source": [
"## Compute Flux Points\n",
"\n",
- "To round up out analysis we can compute flux points by fitting the norm of the global model in energy bands. We'll use a fixed energy binning for now."
+ "To round up our analysis we can compute flux points by fitting the norm of the global model in energy bands. We'll use a fixed energy binning for now."
]
},
{
"outputs": [],
"source": [
"# Define energy binning\n",
- "ebounds = [0.3, 1.1, 3, 10.1, 30] * u.TeV\n",
+ "e_min, e_max = stacked_obs.lo_threshold.to_value(\"TeV\"), 30\n",
+ "ebounds = np.logspace(np.log10(e_min), np.log10(e_max), 15) * u.TeV\n",
"\n",
"stacked_obs = extraction.spectrum_observations.stack()\n",
"\n",
"outputs": [],
"source": [
"fpe = FluxPointEstimator(\n",
- " obs=stacked_obs, groups=seg.groups, model=joint_result[0].model\n",
+ " obs=stacked_obs, groups=seg.groups, model=joint_result[0].model, norm_min=0.2, norm_max=10\n",
")\n",
"flux_points = fpe.run()"
]
"metadata": {},
"outputs": [],
"source": [
- "flux_points.plot()\n",
"flux_points.table_formatted"
]
},
"cell_type": "markdown",
"metadata": {},
"source": [
- "The final plot with the best fit model and the flux points can be quickly made like this"
+ "Now we plot the flux points and their likelihood profiles. For the plotting of upper limits we choose a threshold of TS < 4."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "flux_points.table[\"is_ul\"] = flux_points.table[\"ts\"] < 4\n",
+ "ax = flux_points.plot(energy_power=2, flux_unit=\"erg-1 cm-2 s-1\", c=\"darkorange\")\n",
+ "flux_points.to_sed_type(\"e2dnde\").plot_likelihood(ax=ax)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "The final plot with the best fit model, flux points and residuals can be quickly made like this"
]
},
{
" energy_power=2,\n",
" flux_unit=\"erg-1 cm-2 s-1\",\n",
" fig_kwargs=dict(figsize=(8, 8)),\n",
- " point_kwargs=dict(color=\"red\"),\n",
")\n",
"\n",
"ax0.set_xlim(0.4, 50)"
"source": [
"# Start exercises here"
]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## What next?\n",
- "\n",
- "In this tutorial we learned how to extract counts spectra from an event list and generate the corresponding IRFs. Then we fitted a model to the observations and also computed flux points.\n",
- "\n",
- "Here's some suggestions where to go next:\n",
- "\n",
- "* if you want think this is way too complicated and just want to run a quick analysis check out [this notebook](spectrum_pipe.ipynb)\n",
- "* if you interested in available fit statistics checkout [gammapy.stats](https://docs.gammapy.org/dev/stats/index.html)"
- ]
}
],
"metadata": {
