Add FoVBackgroundMaker example
"outputs": [],
"source": [
"from gammapy.data import DataStore\n",
- "from gammapy.maps import WcsGeom, MapAxis\n",
- "from gammapy.cube import MapDatasetMaker, MapDataset, SafeMaskMaker\n",
+ "from gammapy.maps import WcsGeom, MapAxis, Map\n",
+ "from gammapy.cube import MapDatasetMaker, MapDataset, SafeMaskMaker, FoVBackgroundMaker\n",
"from gammapy.modeling.models import (\n",
" SkyModel,\n",
" PowerLawSpectralModel,\n",
"maker_safe_mask = SafeMaskMaker(methods=[\"offset-max\"], offset_max=offset_max)"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "circle = CircleSkyRegion(center=SkyCoord(\"83.63 deg\", \"22.14 deg\"), radius=0.2 * u.deg)\n",
+ "data = geom.region_mask(regions=[circle], inside=False)\n",
+ "exclusion_mask = Map.from_geom(geom=geom, data=data)\n",
+ "maker_fov = FoVBackgroundMaker(method=\"fit\", exclusion_mask=exclusion_mask)"
+ ]
+ },
{
"cell_type": "markdown",
"metadata": {},
" cutout = stacked.cutout(obs.pointing_radec, width=2 * offset_max)\n",
" # A MapDataset is filled in this cutout geometry\n",
" dataset = maker.run(cutout, obs)\n",
+ " # fit background model\n",
+ " dataset = maker_fov.run(dataset)\n",
+ " print(f\"Background norm obs {obs.obs_id}: {dataset.background_model.norm.value:.2f}\")\n",
" # The data quality cut is applied\n",
" dataset = maker_safe_mask.run(dataset, obs)\n",
" # The resulting dataset cutout is stacked onto the final one\n",
