Adapt image analysis tutorial
" MapDatasetMaker,\n",
" PSFKernel,\n",
" MapDataset,\n",
- " MapMakerRing,\n",
- " RingBackgroundEstimator,\n",
+ " MapDatasetMaker,\n",
+ " MapDatasetOnOff,\n",
+ " RingBackgroundMaker,\n",
")\n",
"from gammapy.modeling.models import (\n",
" SkyModel,\n",
"metadata": {},
"outputs": [],
"source": [
- "geom_image = geom.to_image()\n",
+ "geom_image = geom.to_image().to_cube([energy_axis.squash()])\n",
"\n",
"regions = CircleSkyRegion(center=spatial_model.position, radius=0.3 * u.deg)\n",
"\n",
"exclusion_mask = Map.from_geom(geom_image)\n",
"exclusion_mask.data = geom_image.region_mask([regions], inside=False)\n",
- "exclusion_mask.plot();"
+ "exclusion_mask.sum_over_axes().plot();"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "ring_bkg = RingBackgroundEstimator(r_in=\"0.3 deg\", width=\"0.3 deg\")"
+ "ring_maker = RingBackgroundMaker(r_in=\"0.3 deg\", width=\"0.3 deg\", exclusion_mask=exclusion_mask)"
]
},
{
"outputs": [],
"source": [
"%%time\n",
- "im = MapMakerRing(\n",
- " geom=geom,\n",
- " offset_max=3.0 * u.deg,\n",
- " exclusion_mask=exclusion_mask,\n",
- " background_estimator=ring_bkg,\n",
- ")\n",
+ "stacked_on_off = MapDatasetOnOff.create(geom=geom_image)\n",
"\n",
"for obs in observations:\n",
- " im._get_obs_maker(obs)\n",
- "\n",
- "images = im.run_images(observations)"
+ " dataset = maker.run(obs)\n",
+ " dataset_image = dataset.to_image()\n",
+ " dataset_on_off = ring_maker.run(dataset_image)\n",
+ " stacked_on_off.stack(dataset_on_off)"
]
},
{
"tophat.normalize(\"peak\")\n",
"\n",
"lima_maps = compute_lima_on_off_image(\n",
- " images[\"on\"],\n",
- " images[\"off\"],\n",
- " images[\"exposure_on\"],\n",
- " images[\"exposure_off\"],\n",
+ " stacked_on_off.counts,\n",
+ " stacked_on_off.counts_off,\n",
+ " stacked_on_off.acceptance,\n",
+ " stacked_on_off.acceptance_off,\n",
" tophat,\n",
")"
]
"ax2 = plt.subplot(222, projection=excess_map.geom.wcs)\n",
"\n",
"ax1.set_title(\"Significance map\")\n",
- "significance_map.plot(ax=ax1, add_cbar=True)\n",
+ "significance_map.get_image_by_idx((0,)).plot(ax=ax1, add_cbar=True)\n",
"\n",
"ax2.set_title(\"Excess map\")\n",
- "excess_map.plot(ax=ax2, add_cbar=True);"
+ "significance_map.get_image_by_idx((0,)).plot(ax=ax2, add_cbar=True)"
]
},
{
