add example in the notebook
"metadata": {},
"outputs": [],
"source": [
- "filename = \"$GAMMAPY_DATA/cta-caldb/Prod5-South-20deg-AverageAz-14MSTs37SSTs.180000s-v0.1.fits.gz\"\n",
+ "irf_filename = \"$GAMMAPY_DATA/cta-caldb/Prod5-South-20deg-AverageAz-14MSTs37SSTs.180000s-v0.1.fits.gz\"\n",
"\n",
"pointing = SkyCoord(0.0, 0.0, frame=\"galactic\", unit=\"deg\")\n",
"livetime = 1 * u.hr"
"metadata": {},
"outputs": [],
"source": [
- "irfs = load_cta_irfs(filename)\n",
+ "irfs = load_cta_irfs(irf_filename)\n",
"location = observatory_locations['cta_south']\n",
"\n",
"observation = Observation.create(\n",
"metadata": {},
"outputs": [],
"source": [
- "events.table.meta[\"OBJECT\"] = dataset.models[0].name"
+ "events.table.meta[\"OBJECT\"] = dataset.models[0].name\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "We have to add the path to the IRF file in the metadata (this will be used later to create the index files linking events and irfs)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "events.table.meta[\"IRF_FILE\"] = irf_filename\n"
]
},
{
"cell_type": "markdown",
- "id": "874b911e",
"metadata": {},
"source": [
"Let's write the event list and its GTI extension to a FITS file. We make use of `fits` library in `astropy`:"
"\n",
" sampler = MapDatasetEventSampler(random_state=idx)\n",
" events = sampler.run(dataset, observation)\n",
+ " events.table.meta[\"IRF_FILE\"] = irf_filename\n",
" events.table.write(\n",
" f\"./event_sampling/events_{idx:04d}.fits\", overwrite=True\n",
" )"
"id": "bbf88446",
"metadata": {},
"source": [
- "For completeness, `data_store` is a `~gammapy.data.Datastore` object. You can find more information about it [here](https://docs.gammapy.org/dev/tutorials/data/cta.html#Datastore)."
+ "Then you can create the obervations from the Datastore:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "observations = data_store.get_observations()\n",
+ "observations[0].peek()"
]
},
{
"id": "38a38c6a",
"metadata": {},
"source": [
+ "For completeness, `data_store` is a `~gammapy.data.Datastore` object. You can find more information about it [here](https://docs.gammapy.org/dev/tutorials/data/cta.html#Datastore).\n",
+ "\n",
"## Exercises\n",
"- Try to sample events for an extended source (e.g. a radial gaussian morphology);\n",
"- Change the spatial model and the spectrum of the simulated Sky model;\n",
