{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Data preparation for 1DC How-tos" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "
\"Download
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial assumes that you have downloaded the data for the first CTA Data Challenge. If this is not the case, please read first [how to get the 1DC data](../1dc/getting_data.rst).\n", "\n", "Start by importing the relevant Python modules." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import gammalib\n", "import ctools\n", "import cscripts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now set the `CTADATA` and `CALDB` environment variables. Please adjust the path below so that it points to the relevant location." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "env: CTADATA=/project-data/cta/data/1dc\n", "env: CALDB=/project-data/cta/data/1dc/caldb\n" ] } ], "source": [ "%env CTADATA=/project-data/cta/data/1dc\n", "%env CALDB=/project-data/cta/data/1dc/caldb" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now prepare a dataset that comprises the Galactic Centre observations that have been performed during the Galactic Plane Scan. Start with selecting the observations." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "obsselect = cscripts.csobsselect()\n", "obsselect['inobs'] = '$CTADATA/obs/obs_gps_baseline.xml'\n", "obsselect['pntselect'] = 'CIRCLE'\n", "obsselect['coordsys'] = 'GAL'\n", "obsselect['glon'] = 0.0\n", "obsselect['glat'] = 0.0\n", "obsselect['rad'] = 3.0\n", "obsselect['tmin'] = 'NONE'\n", "obsselect['tmax'] = 'NONE'\n", "obsselect['outobs'] = 'obs.xml'\n", "obsselect.execute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now select the events with energies comprised between 1 and 100 TeV from the observations. " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "select = ctools.ctselect()\n", "select['inobs'] = 'obs.xml'\n", "select['ra'] = 'NONE'\n", "select['dec'] = 'NONE'\n", "select['rad'] = 'NONE'\n", "select['tmin'] = 'NONE'\n", "select['tmax'] = 'NONE'\n", "select['emin'] = 1.0\n", "select['emax'] = 100.0\n", "select['outobs'] = 'obs_selected.xml'\n", "select.execute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next step is to stack the selected events into a counts cube." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "binning = ctools.ctbin()\n", "binning['inobs'] = 'obs_selected.xml'\n", "binning['xref'] = 0.0\n", "binning['yref'] = 0.0\n", "binning['coordsys'] = 'GAL'\n", "binning['proj'] = 'CAR'\n", "binning['binsz'] = 0.02\n", "binning['nxpix'] = 300\n", "binning['nypix'] = 300\n", "binning['ebinalg'] = 'LOG'\n", "binning['emin'] = 1.0\n", "binning['emax'] = 100.0\n", "binning['enumbins'] = 20\n", "binning['outobs'] = 'cntcube.fits'\n", "binning.execute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now compute the corresponding stacked exposure cube, point spread function cube and background cube." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "expcube = ctools.ctexpcube()\n", "expcube['inobs'] = 'obs_selected.xml'\n", "expcube['incube'] = 'cntcube.fits'\n", "expcube['outcube'] = 'expcube.fits'\n", "expcube.execute()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "psfcube = ctools.ctpsfcube()\n", "psfcube['inobs'] = 'obs_selected.xml'\n", "psfcube['incube'] = 'NONE'\n", "psfcube['ebinalg'] = 'LOG'\n", "psfcube['emin'] = 1.0\n", "psfcube['emax'] = 100.0\n", "psfcube['enumbins'] = 20\n", "psfcube['nxpix'] = 10\n", "psfcube['nypix'] = 10\n", "psfcube['binsz'] = 1.0\n", "psfcube['coordsys'] = 'GAL'\n", "psfcube['proj'] = 'CAR'\n", "psfcube['xref'] = 0.0\n", "psfcube['yref'] = 0.0\n", "psfcube['outcube'] = 'psfcube.fits'\n", "psfcube.execute()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "bkgcube = ctools.ctbkgcube()\n", "bkgcube['inobs'] = 'obs_selected.xml'\n", "bkgcube['inmodel'] = '$CTOOLS/share/models/bkg_irf.xml'\n", "bkgcube['incube'] = 'cntcube.fits'\n", "bkgcube['outcube'] = 'bkgcube.fits'\n", "bkgcube['outmodel'] = 'bkgcube.xml' \n", "bkgcube.execute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now you are done. All data structures are prepared for the following tutorials." ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 2 }