Fix and improve hess tutorial
"from gammapy.cube import MapMaker, MapDataset, PSFKernel, MapMakerRing\n",
"from gammapy.cube.models import SkyModel, BackgroundModel\n",
"from gammapy.spectrum.models import PowerLaw\n",
+ "from gammapy.spectrum import CrabSpectrum\n",
"from gammapy.image.models import SkyPointSource\n",
"from gammapy.detect import compute_lima_on_off_image\n",
"from gammapy.scripts import SpectrumAnalysisIACT\n",
"exclusion_mask = images[\"counts\"].copy()\n",
"exclusion_mask.data = np.ones_like(exclusion_mask.data, dtype=bool)\n",
"\n",
- "model = PowerLaw(\n",
+ "model_pwl = PowerLaw(\n",
" index=2.6, amplitude=\"5e-11 cm-2 s-1 TeV-1\", reference=\"1 TeV\"\n",
")\n",
"\n",
"config = {\n",
" \"outdir\": \".\",\n",
" \"background\": {\"on_region\": on_region, \"exclusion_mask\": exclusion_mask},\n",
- " \"extraction\": {\"containment_correction\": True},\n",
- " \"fit\": {\"model\": model, \"fit_range\": [1, 10] * u.TeV},\n",
+ " \"extraction\": {\"containment_correction\": False},\n",
+ " \"fit\": {\"model\": model_pwl, \"fit_range\": [1, 10] * u.TeV},\n",
" \"fp_binning\": np.logspace(0, 1, 7) * u.TeV,\n",
"}\n",
"analysis = SpectrumAnalysisIACT(observations=observations, config=config)\n",
"metadata": {},
"outputs": [],
"source": [
- "print(analysis.fit.result[0])"
+ "plt.figure(figsize=(8, 6))\n",
+ "crab_ref = CrabSpectrum(\"hess_pl\").model\n",
+ "\n",
+ "dataset_fp = analysis.spectrum_result\n",
+ "\n",
+ "e_range = [1, 10] * u.TeV\n",
+ "ax_spectrum, ax_residuals = dataset_fp.peek()\n",
+ "crab_ref.plot(ax=ax_spectrum, energy_range=e_range, energy_power=2, label=\"H.E.S.S. 2006 PWL\")\n",
+ "\n",
+ "model.spectral_model.plot(ax=ax_spectrum, energy_range=e_range, energy_power=2, label=\"3D best fit model\")\n",
+ "ax_spectrum.legend()"
]
},
{
