Commit 11528349b3c7fb03f6dbb3c302073505d6f473f5

Authored by Jürgen Knödlseder
1 parent 81c78263

Add Jupyter notebook for the connection of observations with models

doc/source/users/tutorials/howto/howto_advanced_python_fitting.ipynb
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 "cell_type": "raw", 11 "cell_type": "raw",
12 "metadata": {}, 12 "metadata": {},
13 "source": [ 13 "source": [
14 - "<div align=\"right\"><a href=\"../../../_downloads/advanced-python-fitting.ipynb\" download=\"advanced-python-fitting.ipynb\"><img src=\"../../../_static/download-notebook.jpg\" alt=\"Download Notebook\" height=\"40\"></a></div>" 14 + "<div align=\"right\"><a href=\"../../../_downloads/howto_advanced_python_fitting.ipynb\" download=\"howto_advanced_python_fitting.ipynb\"><img src=\"../../../_static/download-notebook.jpg\" alt=\"Download Notebook\" height=\"40\"></a></div>"
15 ] 15 ]
16 }, 16 },
17 { 17 {
doc/source/users/tutorials/howto/howto_combine_observations.ipynb
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 "cell_type": "raw", 11 "cell_type": "raw",
12 "metadata": {}, 12 "metadata": {},
13 "source": [ 13 "source": [
14 - "<div align=\"right\"><a href=\"../../../_downloads/combining-observations.ipynb\" download=\"combining-observations.ipynb\"><img src=\"../../../_static/download-notebook.jpg\" alt=\"Download Notebook\" height=\"40\"></a></div>" 14 + "<div align=\"right\"><a href=\"../../../_downloads/howto_combine_observations.ipynb\" download=\"howto_combine_observations.ipynb\"><img src=\"../../../_static/download-notebook.jpg\" alt=\"Download Notebook\" height=\"40\"></a></div>"
15 ] 15 ]
16 }, 16 },
17 { 17 {
doc/source/users/tutorials/howto/howto_connect_irfs.rst
@@ -66,7 +66,7 @@ observation definition XML file: @@ -66,7 +66,7 @@ observation definition XML file:
66 <parameter name="EventList" file="south.fits"/> 66 <parameter name="EventList" file="south.fits"/>
67 <parameter name="Calibration" database="prod2" response="South_0.5h"/> 67 <parameter name="Calibration" database="prod2" response="South_0.5h"/>
68 </observation> 68 </observation>
69 - </observation_list> 69 + </observation_list>
70 70
71 Each observation now has a ``Calibration`` parameter with the attributes 71 Each observation now has a ``Calibration`` parameter with the attributes
72 ``database`` and ``response``. 72 ``database`` and ``response``.
doc/source/users/tutorials/howto/howto_connect_models.ipynb 0 → 100644
  1 +{
  2 + "cells": [
  3 + {
  4 + "cell_type": "markdown",
  5 + "metadata": {},
  6 + "source": [
  7 + "# How to connect observations to specific models?"
  8 + ]
  9 + },
  10 + {
  11 + "cell_type": "raw",
  12 + "metadata": {},
  13 + "source": [
  14 + "<div align=\"right\"><a href=\"../../../_downloads/howto_connect_models.ipynb\" download=\"combining-observations.ipynb\"><img src=\"../../../_static/download-notebook.jpg\" alt=\"Download Notebook\" height=\"40\"></a></div>"
  15 + ]
  16 + },
  17 + {
  18 + "cell_type": "markdown",
  19 + "metadata": {},
  20 + "source": [
  21 + "In the previous examples there was always a single background model component to describe the residual particle background in the various dataset. This implies that the spatial and spectral shape of the background distribution is assumed to be identical for all observations. This is fine in a simulation, but for a real life situation this assumption will probably not hold.\n",
  22 + "\n",
  23 + "Start by importing the gammalib, ctools, and cscripts Python modules."
  24 + ]
  25 + },
  26 + {
  27 + "cell_type": "code",
  28 + "execution_count": 1,
  29 + "metadata": {},
  30 + "outputs": [],
  31 + "source": [
  32 + "import gammalib\n",
  33 + "import ctools\n",
  34 + "import cscripts"
  35 + ]
  36 + },
  37 + {
  38 + "cell_type": "markdown",
  39 + "metadata": {},
  40 + "source": [
  41 + "## Simulating the dataset\n",
  42 + "\n",
  43 + "Let’s start with creating a pointing definition ASCII file for two 30 min pointings near the Crab."
  44 + ]
  45 + },
  46 + {
  47 + "cell_type": "code",
  48 + "execution_count": 2,
  49 + "metadata": {},
  50 + "outputs": [],
  51 + "source": [
  52 + "f = open('pnt.def', 'wb')\n",
  53 + "f.write('name,ra,dec,duration\\n')\n",
  54 + "f.write('Crab,83.63,21.51,1800.0\\n')\n",
  55 + "f.write('Crab,83.63,22.51,1800.0\\n')\n",
  56 + "f.close()"
  57 + ]
  58 + },
  59 + {
  60 + "cell_type": "markdown",
  61 + "metadata": {},
  62 + "source": [
  63 + "Inspect the file that you just created. For that purpose let's create a `peek()` function that will also be used later to display XML files."
  64 + ]
  65 + },
  66 + {
  67 + "cell_type": "code",
  68 + "execution_count": 3,
  69 + "metadata": {},
  70 + "outputs": [
  71 + {
  72 + "name": "stdout",
  73 + "output_type": "stream",
  74 + "text": [
  75 + "name,ra,dec,duration\n",
  76 + "Crab,83.63,21.51,1800.0\n",
  77 + "Crab,83.63,22.51,1800.0\n"
  78 + ]
  79 + }
  80 + ],
  81 + "source": [
  82 + "def peek(filename):\n",
  83 + " f = open(gammalib.expand_env(filename), 'r')\n",
  84 + " for line in f:\n",
  85 + " print(line.rstrip())\n",
  86 + " f.close()\n",
  87 + "peek('pnt.def')"
  88 + ]
  89 + },
  90 + {
  91 + "cell_type": "markdown",
  92 + "metadata": {},
  93 + "source": [
  94 + "A pointing definition file is an ASCII file in Comma Separated Values (CSV) format that specifies one pointing per row. The file provides the `name` of the observation, the Right Ascension `ra` and Declination `dec` of the pointing, and its `duration`. Additional optional columns are possible (defining for example the energy range or the Instrument Response Function), but for this simulation the provided information is sufficient.\n",
  95 + "\n",
  96 + "Now transform the pointing definition file into an observation definition XML file using the csobsdef script."
  97 + ]
  98 + },
  99 + {
  100 + "cell_type": "code",
  101 + "execution_count": 4,
  102 + "metadata": {},
  103 + "outputs": [],
  104 + "source": [
  105 + "obsdef = cscripts.csobsdef()\n",
  106 + "obsdef['inpnt'] = 'pnt.def'\n",
  107 + "obsdef['outobs'] = 'obs.xml'\n",
  108 + "obsdef['caldb'] = 'prod2'\n",
  109 + "obsdef['irf'] = 'South_0.5h'\n",
  110 + "obsdef.execute()"
  111 + ]
  112 + },
  113 + {
  114 + "cell_type": "markdown",
  115 + "metadata": {},
  116 + "source": [
  117 + "Let's peek the resulting observation definition XML file"
  118 + ]
  119 + },
  120 + {
  121 + "cell_type": "code",
  122 + "execution_count": 5,
  123 + "metadata": {},
  124 + "outputs": [
  125 + {
  126 + "name": "stdout",
  127 + "output_type": "stream",
  128 + "text": [
  129 + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
  130 + "<observation_list title=\"observation list\">\n",
  131 + " <observation name=\"Crab\" id=\"000001\" instrument=\"CTA\" statistic=\"cstat\">\n",
  132 + " <parameter name=\"Pointing\" ra=\"83.63\" dec=\"21.51\" />\n",
  133 + " <parameter name=\"GoodTimeIntervals\" tmin=\"0\" tmax=\"1800\" />\n",
  134 + " <parameter name=\"TimeReference\" mjdrefi=\"51544\" mjdreff=\"0.5\" timeunit=\"s\" timesys=\"TT\" timeref=\"LOCAL\" />\n",
  135 + " <parameter name=\"Deadtime\" deadc=\"0.98\" />\n",
  136 + " <parameter name=\"Calibration\" database=\"prod2\" response=\"South_0.5h\" />\n",
  137 + " </observation>\n",
  138 + " <observation name=\"Crab\" id=\"000002\" instrument=\"CTA\" statistic=\"cstat\">\n",
  139 + " <parameter name=\"Pointing\" ra=\"83.63\" dec=\"22.51\" />\n",
  140 + " <parameter name=\"GoodTimeIntervals\" tmin=\"1800\" tmax=\"3600\" />\n",
  141 + " <parameter name=\"TimeReference\" mjdrefi=\"51544\" mjdreff=\"0.5\" timeunit=\"s\" timesys=\"TT\" timeref=\"LOCAL\" />\n",
  142 + " <parameter name=\"Deadtime\" deadc=\"0.98\" />\n",
  143 + " <parameter name=\"Calibration\" database=\"prod2\" response=\"South_0.5h\" />\n",
  144 + " </observation>\n",
  145 + "</observation_list>\n"
  146 + ]
  147 + }
  148 + ],
  149 + "source": [
  150 + "peek('obs.xml')"
  151 + ]
  152 + },
  153 + {
  154 + "cell_type": "markdown",
  155 + "metadata": {},
  156 + "source": [
  157 + "The file contains two observations which distinguish by the `id` attributes `000001` and `000002`, which are **unique to each observation for a given instrument**. The `id` attribute can therefore be used to uniquely identify a CTA observation.\n",
  158 + "\n",
  159 + "The value of the `id` attributes can be controlled by adding specific values to the pointing definition file, but if the values are missing - which is the case in the example - they simply count from `000001` upwards.\n",
  160 + "\n",
  161 + "Feed now the observation definition XML file into the ctobssim tool to simulate the event data."
  162 + ]
  163 + },
  164 + {
  165 + "cell_type": "code",
  166 + "execution_count": 6,
  167 + "metadata": {},
  168 + "outputs": [],
  169 + "source": [
  170 + "obssim = ctools.ctobssim()\n",
  171 + "obssim['inobs'] = 'obs.xml'\n",
  172 + "obssim['rad'] = 5.0\n",
  173 + "obssim['emin'] = 0.1\n",
  174 + "obssim['emax'] = 100.0\n",
  175 + "obssim['inmodel'] = '$CTOOLS/share/models/crab_2bkg.xml'\n",
  176 + "obssim['outevents'] = 'obs_2bkg.xml'\n",
  177 + "obssim.execute()"
  178 + ]
  179 + },
  180 + {
  181 + "cell_type": "markdown",
  182 + "metadata": {},
  183 + "source": [
  184 + "This will produce the two event files `sim_events_000001.fits` and `sim_events_000002.fits` on disk. Note that a specific model was used to simulate the data and peeking that model definiton file shows that it contains two different background components with a different power law `Prefactor` and `Index`. Both background components also have an `id` attribute which is used to tie them to the two observations. In other words, `Background_000001` will be used for the observation with identifier `000001` and `Background_000002` will be used for the observation with identifier `000002`."
  185 + ]
  186 + },
  187 + {
  188 + "cell_type": "code",
  189 + "execution_count": 7,
  190 + "metadata": {},
  191 + "outputs": [
  192 + {
  193 + "name": "stdout",
  194 + "output_type": "stream",
  195 + "text": [
  196 + "<?xml version=\"1.0\" standalone=\"no\"?>\n",
  197 + "<source_library title=\"source library\">\n",
  198 + " <source name=\"Crab\" type=\"PointSource\">\n",
  199 + " <spectrum type=\"PowerLaw\">\n",
  200 + " <parameter name=\"Prefactor\" scale=\"1e-16\" value=\"5.7\" min=\"1e-07\" max=\"1000.0\" free=\"1\"/>\n",
  201 + " <parameter name=\"Index\" scale=\"-1\" value=\"2.48\" min=\"0.0\" max=\"+5.0\" free=\"1\"/>\n",
  202 + " <parameter name=\"PivotEnergy\" scale=\"1e6\" value=\"0.3\" min=\"0.01\" max=\"1000.0\" free=\"0\"/>\n",
  203 + " </spectrum>\n",
  204 + " <spatialModel type=\"PointSource\">\n",
  205 + " <parameter name=\"RA\" scale=\"1.0\" value=\"83.6331\" min=\"-360\" max=\"360\" free=\"0\"/>\n",
  206 + " <parameter name=\"DEC\" scale=\"1.0\" value=\"22.0145\" min=\"-90\" max=\"90\" free=\"0\"/>\n",
  207 + " </spatialModel>\n",
  208 + " </source>\n",
  209 + " <source name=\"Background_000001\" type=\"CTAIrfBackground\" instrument=\"CTA\" id=\"000001\">\n",
  210 + " <spectrum type=\"PowerLaw\">\n",
  211 + " <parameter name=\"Prefactor\" scale=\"1.0\" value=\"0.5\" min=\"1e-3\" max=\"1e+3\" free=\"1\"/>\n",
  212 + " <parameter name=\"Index\" scale=\"1.0\" value=\"0.2\" min=\"-5.0\" max=\"+5.0\" free=\"1\"/>\n",
  213 + " <parameter name=\"PivotEnergy\" scale=\"1e6\" value=\"1.0\" min=\"0.01\" max=\"1000.0\" free=\"0\"/>\n",
  214 + " </spectrum>\n",
  215 + " </source>\n",
  216 + " <source name=\"Background_000002\" type=\"CTAIrfBackground\" instrument=\"CTA\" id=\"000002\">\n",
  217 + " <spectrum type=\"PowerLaw\">\n",
  218 + " <parameter name=\"Prefactor\" scale=\"1.0\" value=\"2.0\" min=\"1e-3\" max=\"1e+3\" free=\"1\"/>\n",
  219 + " <parameter name=\"Index\" scale=\"1.0\" value=\"-0.2\" min=\"-5.0\" max=\"+5.0\" free=\"1\"/>\n",
  220 + " <parameter name=\"PivotEnergy\" scale=\"1e6\" value=\"1.0\" min=\"0.01\" max=\"1000.0\" free=\"0\"/>\n",
  221 + " </spectrum>\n",
  222 + " </source>\n",
  223 + "</source_library>\n"
  224 + ]
  225 + }
  226 + ],
  227 + "source": [
  228 + "peek('$CTOOLS/share/models/crab_2bkg.xml')"
  229 + ]
  230 + },
  231 + {
  232 + "cell_type": "markdown",
  233 + "metadata": {},
  234 + "source": [
  235 + "## Analysing the data\n",
  236 + "\n",
  237 + "Now run a maximum likelihood fit of the model to the simulated data"
  238 + ]
  239 + },
  240 + {
  241 + "cell_type": "code",
  242 + "execution_count": 8,
  243 + "metadata": {},
  244 + "outputs": [],
  245 + "source": [
  246 + "like = ctools.ctlike()\n",
  247 + "like['inobs'] = 'obs_2bkg.xml'\n",
  248 + "like['inmodel'] = '$CTOOLS/share/models/crab_2bkg.xml'\n",
  249 + "like['outmodel'] = 'crab_results.xml'\n",
  250 + "like.run()"
  251 + ]
  252 + },
  253 + {
  254 + "cell_type": "markdown",
  255 + "metadata": {},
  256 + "source": [
  257 + "and inspect the model fitting results"
  258 + ]
  259 + },
  260 + {
  261 + "cell_type": "code",
  262 + "execution_count": 9,
  263 + "metadata": {},
  264 + "outputs": [
  265 + {
  266 + "name": "stdout",
  267 + "output_type": "stream",
  268 + "text": [
  269 + "=== GModels ===\n",
  270 + " Number of models ..........: 3\n",
  271 + " Number of parameters ......: 14\n",
  272 + "=== GModelSky ===\n",
  273 + " Name ......................: Crab\n",
  274 + " Instruments ...............: all\n",
  275 + " Instrument scale factors ..: unity\n",
  276 + " Observation identifiers ...: all\n",
  277 + " Model type ................: PointSource\n",
  278 + " Model components ..........: \"PointSource\" * \"PowerLaw\" * \"Constant\"\n",
  279 + " Number of parameters ......: 6\n",
  280 + " Number of spatial par's ...: 2\n",
  281 + " RA .......................: 83.6331 [-360,360] deg (fixed,scale=1)\n",
  282 + " DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1)\n",
  283 + " Number of spectral par's ..: 3\n",
  284 + " Prefactor ................: 5.72600803344134e-16 +/- 7.26125051929832e-18 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient)\n",
  285 + " Index ....................: -2.46250488685583 +/- 0.0107342940426319 [-0,-5] (free,scale=-1,gradient)\n",
  286 + " PivotEnergy ..............: 300000 [10000,1000000000] MeV (fixed,scale=1000000,gradient)\n",
  287 + " Number of temporal par's ..: 1\n",
  288 + " Normalization ............: 1 (relative value) (fixed,scale=1,gradient)\n",
  289 + "=== GCTAModelIrfBackground ===\n",
  290 + " Name ......................: Background_000001\n",
  291 + " Instruments ...............: CTA\n",
  292 + " Instrument scale factors ..: unity\n",
  293 + " Observation identifiers ...: 000001\n",
  294 + " Model type ................: \"PowerLaw\" * \"Constant\"\n",
  295 + " Number of parameters ......: 4\n",
  296 + " Number of spectral par's ..: 3\n",
  297 + " Prefactor ................: 0.505907031991183 +/- 0.00781154537579767 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient)\n",
  298 + " Index ....................: 0.19573511102578 +/- 0.00990457582529741 [-5,5] (free,scale=1,gradient)\n",
  299 + " PivotEnergy ..............: 1000000 [10000,1000000000] MeV (fixed,scale=1000000,gradient)\n",
  300 + " Number of temporal par's ..: 1\n",
  301 + " Normalization ............: 1 (relative value) (fixed,scale=1,gradient)\n",
  302 + "=== GCTAModelIrfBackground ===\n",
  303 + " Name ......................: Background_000002\n",
  304 + " Instruments ...............: CTA\n",
  305 + " Instrument scale factors ..: unity\n",
  306 + " Observation identifiers ...: 000002\n",
  307 + " Model type ................: \"PowerLaw\" * \"Constant\"\n",
  308 + " Number of parameters ......: 4\n",
  309 + " Number of spectral par's ..: 3\n",
  310 + " Prefactor ................: 2.0120585192912 +/- 0.0174910114190175 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient)\n",
  311 + " Index ....................: -0.199891285321279 +/- 0.00515953660690254 [-5,5] (free,scale=1,gradient)\n",
  312 + " PivotEnergy ..............: 1000000 [10000,1000000000] MeV (fixed,scale=1000000,gradient)\n",
  313 + " Number of temporal par's ..: 1\n",
  314 + " Normalization ............: 1 (relative value) (fixed,scale=1,gradient)\n"
  315 + ]
  316 + }
  317 + ],
  318 + "source": [
  319 + "print(like.obs().models())"
  320 + ]
  321 + },
  322 + {
  323 + "cell_type": "markdown",
  324 + "metadata": {},
  325 + "source": [
  326 + "Obviously the two background models have different best fitting spectral parameters which correspond to the simulated values (see above)."
  327 + ]
  328 + }
  329 + ],
  330 + "metadata": {
  331 + "kernelspec": {
  332 + "display_name": "Python 2",
  333 + "language": "python",
  334 + "name": "python2"
  335 + },
  336 + "language_info": {
  337 + "codemirror_mode": {
  338 + "name": "ipython",
  339 + "version": 2
  340 + },
  341 + "file_extension": ".py",
  342 + "mimetype": "text/x-python",
  343 + "name": "python",
  344 + "nbconvert_exporter": "python",
  345 + "pygments_lexer": "ipython2",
  346 + "version": "2.7.11"
  347 + }
  348 + },
  349 + "nbformat": 4,
  350 + "nbformat_minor": 2
  351 +}
doc/source/users/tutorials/howto/howto_connect_models.png deleted

261 KB

doc/source/users/tutorials/howto/howto_connect_models.rst deleted
1 -.. _howto_connect_models:  
2 -  
3 -How to connecting observations to specific models?  
4 ---------------------------------------------------  
5 -  
6 - .. admonition:: What you will learn  
7 -  
8 - You will learn how to **connect individual observations to specific  
9 - model components**.  
10 -  
11 -In the previous examples there was always a single background model  
12 -component to describe the residual particle background in the  
13 -various dataset.  
14 -This implies that the spatial and spectral shape of the background  
15 -distribution is assumed to be identical for all observations.  
16 -This is fine in a simulation, but for a real life situation this  
17 -assumption will probably not hold.  
18 -  
19 -Let's go back to the case of a joint analysis of two observations,  
20 -specified by the following observation definition XML file:  
21 -  
22 -.. code-block:: xml  
23 -  
24 - <?xml version="1.0" standalone="no"?>  
25 - <observation_list title="observation library">  
26 - <observation name="Crab" id="00001" instrument="CTA">  
27 - <parameter name="EventList" file="events1.fits"/>  
28 - </observation>  
29 - <observation name="Crab" id="00002" instrument="CTA">  
30 - <parameter name="EventList" file="events2.fits"/>  
31 - </observation>  
32 - </observation_list>  
33 -  
34 -Each observation has a **unique identifier string** and you can use this  
35 -unique string to connect an observation to a specific model component.  
36 -This is illustrated in the model XML file below that now has two background  
37 -components.  
38 -Both components have an ``id`` attribute that ties the model to a specific  
39 -observation.  
40 -Using ``id="00001"``, the first background model is tied to the  
41 -``events1.fits`` file, using ``id="00002"``, the second background model is  
42 -tied to the ``events2.fits`` file.  
43 -  
44 -.. code-block:: xml  
45 -  
46 - <?xml version="1.0" standalone="no"?>  
47 - <source_library title="source library">  
48 - <source name="Crab" type="PointSource">  
49 - <spectrum type="PowerLaw">  
50 - <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>  
51 - <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>  
52 - <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>  
53 - </spectrum>  
54 - <spatialModel type="PointSource">  
55 - <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="0"/>  
56 - <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="0"/>  
57 - </spatialModel>  
58 - </source>  
59 - <source name="Background_00001" type="CTAIrfBackground" instrument="CTA" id="00001">  
60 - <spectrum type="PowerLaw">  
61 - <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e+3" free="1"/>  
62 - <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/>  
63 - <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>  
64 - </spectrum>  
65 - </source>  
66 - <source name="Background_00002" type="CTAIrfBackground" instrument="CTA" id="00002">  
67 - <spectrum type="PowerLaw">  
68 - <parameter name="Prefactor" scale="1.0" value="10.0" min="1e-3" max="1e+3" free="1"/>  
69 - <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/>  
70 - <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>  
71 - </spectrum>  
72 - </source>  
73 - </source_library>  
74 -  
75 -.. note::  
76 - **Model components in a XML file need to have a unique name.**  
77 - For this reason the components are named here ``Background_00001``  
78 - and ``Background_00002``.  
79 -  
80 -Note that both background model components distinguish in their event rate.  
81 -``Background_00002`` has a ten times larger background rate than  
82 -``Background_00001``.  
83 -To illustrate this difference, two observations offset by +/- 2 degrees from  
84 -the Crab nebulae have been simulated using :ref:`ctobssim`.  
85 -A joint fit of the observations is then performed using :ref:`ctlike` and  
86 -a residual map is created using :ref:`csresmap`.  
87 -  
88 -The result is shown below.  
89 -Obviously, the upper observation has larger residuals owing to the ten  
90 -times larger background rate that was used in the simulation of the  
91 -associated data.  
92 -  
93 -.. figure:: howto_connect_models.png  
94 - :height: 400px  
95 - :align: center  
96 -  
97 - *Residual map of two jointly analysed observations offset by +/- 2 degrees*  
98 -  
99 -The scheme is even more versatile in that it allows to connect a given  
100 -model component to several specific observations.  
101 -This is illustrated in the model definition file below where component  
102 -``Background_00001`` is now applicable for observations ``00001``,  
103 -``00003`` and ``00004``.  
104 -  
105 -.. code-block:: xml  
106 -  
107 - <?xml version="1.0" standalone="no"?>  
108 - <source_library title="source library">  
109 - <source name="Crab" type="PointSource">  
110 - <spectrum type="PowerLaw">  
111 - <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>  
112 - <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>  
113 - <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>  
114 - </spectrum>  
115 - <spatialModel type="PointSource">  
116 - <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="0"/>  
117 - <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="0"/>  
118 - </spatialModel>  
119 - </source>  
120 - <source name="Background_00001" type="CTAIrfBackground" instrument="CTA" id="00001,00003,00004">  
121 - <spectrum type="PowerLaw">  
122 - <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e+3" free="1"/>  
123 - <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/>  
124 - <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>  
125 - </spectrum>  
126 - </source>  
127 - <source name="Background_00002" type="CTAIrfBackground" instrument="CTA" id="00002">  
128 - <spectrum type="PowerLaw">  
129 - <parameter name="Prefactor" scale="1.0" value="10.0" min="1e-3" max="1e+3" free="1"/>  
130 - <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/>  
131 - <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>  
132 - </spectrum>  
133 - </source>  
134 - </source_library>  
doc/source/users/tutorials/howto/howto_stacked_analysis.ipynb
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 "cell_type": "raw", 11 "cell_type": "raw",
12 "metadata": {}, 12 "metadata": {},
13 "source": [ 13 "source": [
14 - "<div align=\"right\"><a href=\"../../../_downloads/stacked-analysis.ipynb\" download=\"stacked-analysis.ipynb\"><img src=\"../../../_static/download-notebook.jpg\" alt=\"Download Notebook\" height=\"40\"></a></div>" 14 + "<div align=\"right\"><a href=\"../../../_downloads/howto_stacked_analysis.ipynb\" download=\"howto_stacked_analysis.ipynb\"><img src=\"../../../_static/download-notebook.jpg\" alt=\"Download Notebook\" height=\"40\"></a></div>"
15 ] 15 ]
16 }, 16 },
17 { 17 {
doc/source/users/tutorials/notebooks.rst
@@ -15,6 +15,7 @@ it on your computer. All notebooks are also available for download from @@ -15,6 +15,7 @@ it on your computer. All notebooks are also available for download from
15 this page. 15 this page.
16 16
17 * :download:`Using ctools from Python <quickstart/ctools-from-python.ipynb>` 17 * :download:`Using ctools from Python <quickstart/ctools-from-python.ipynb>`
18 -* :download:`Combining observations <howto/howto_combine_observations.ipynb>`  
19 -* :download:`Performing a stacked analysis <howto/howto_stacked_analysis.ipynb>`  
20 -* :download:`Advanced model manipulation and fitting in Python <howto/howto_advanced_python_fitting.ipynb>` 18 +* :download:`How to combine observations? <howto/howto_combine_observations.ipynb>`
  19 +* :download:`How to connect observations to specific models? <howto/howto_connect_models.ipynb>`
  20 +* :download:`How to perform a stacked analysis? <howto/howto_stacked_analysis.ipynb>`
  21 +* :download:`How to do advanced model manipulation and fitting in Python? <howto/howto_advanced_python_fitting.ipynb>`
models/Makefile.am
1 ############################################################################# 1 #############################################################################
2 # Makefile for models # 2 # Makefile for models #
3 # ------------------------------------------------------------------------- # 3 # ------------------------------------------------------------------------- #
4 -# Copyright (C) 2016 Juergen Knoedlseder # 4 +# Copyright (C) 2016-2018 Juergen Knoedlseder #
5 # ------------------------------------------------------------------------- # 5 # ------------------------------------------------------------------------- #
6 # # 6 # #
7 # This program is free software: you can redistribute it and/or modify # 7 # This program is free software: you can redistribute it and/or modify #
@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 # Models to install 22 # Models to install
23 models = crab.xml \ 23 models = crab.xml \
24 crab_beyond.xml \ 24 crab_beyond.xml \
  25 + crab_2bkg.xml \
25 crab_poly.xml \ 26 crab_poly.xml \
26 crab_profile.xml \ 27 crab_profile.xml \
27 disk.xml \ 28 disk.xml \
models/crab_2bkg.xml 0 → 100644
  1 +<?xml version="1.0" standalone="no"?>
  2 +<source_library title="source library">
  3 + <source name="Crab" type="PointSource">
  4 + <spectrum type="PowerLaw">
  5 + <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
  6 + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>
  7 + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>
  8 + </spectrum>
  9 + <spatialModel type="PointSource">
  10 + <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="0"/>
  11 + <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="0"/>
  12 + </spatialModel>
  13 + </source>
  14 + <source name="Background_000001" type="CTAIrfBackground" instrument="CTA" id="000001">
  15 + <spectrum type="PowerLaw">
  16 + <parameter name="Prefactor" scale="1.0" value="0.5" min="1e-3" max="1e+3" free="1"/>
  17 + <parameter name="Index" scale="1.0" value="0.2" min="-5.0" max="+5.0" free="1"/>
  18 + <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
  19 + </spectrum>
  20 + </source>
  21 + <source name="Background_000002" type="CTAIrfBackground" instrument="CTA" id="000002">
  22 + <spectrum type="PowerLaw">
  23 + <parameter name="Prefactor" scale="1.0" value="2.0" min="1e-3" max="1e+3" free="1"/>
  24 + <parameter name="Index" scale="1.0" value="-0.2" min="-5.0" max="+5.0" free="1"/>
  25 + <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
  26 + </spectrum>
  27 + </source>
  28 +</source_library>