Commit df8dd6d936cca8ebe00aeb35a46b4cc32cc8de86
1 parent
89895869
Added documentation and script to plot butterfly
Showing
5 changed files
with
506 additions
and
0 deletions
doc/source/fhelp/ctbutterfly.html
0 → 100644
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
| 2 | +<html lang="en"><head> | |
| 3 | +<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>ctbutterfly</title> | |
| 4 | + | |
| 5 | +<link rel="stylesheet" type="text/css" media="screen,print" href="ctools.css"> | |
| 6 | +<meta content="Michael Mayer" name="author"> | |
| 7 | +<meta content="Spectral butterfly (confidence band) computation tools" name="description"> | |
| 8 | +</head> | |
| 9 | +<body> | |
| 10 | +<p class="Header">ctbutterfly</p> | |
| 11 | +<p class="Body">Butterfly calculation tool.</p> | |
| 12 | +<br> | |
| 13 | +<p class="Title">Synopsis</p> | |
| 14 | +<p style="padding-top: 0pt; text-align: left;" class="Body">Calculates | |
| 15 | +the confidence band of a spectral model, taking into account the | |
| 16 | +covariance matrix of a likelihood fit. | |
| 17 | +</p> | |
| 18 | +<br> | |
| 19 | +<p class="Title">Links</p> | |
| 20 | +<ul class="Body"> | |
| 21 | +<li><a href="ftools_usage.html">Basic FTOOL | |
| 22 | +Parameter Usage</a></li> | |
| 23 | +</ul> | |
| 24 | +<p style="padding-top: 0pt; text-align: left;" class="Body"></p> | |
| 25 | +<br> | |
| 26 | +<p class="Title">General parameters</p> | |
| 27 | +<table id="table1" class="Body" border="0" cellpadding="0" cellspacing="0" width="600"> | |
| 28 | +<tbody> | |
| 29 | +<tr> | |
| 30 | +<td width="50"> </td> | |
| 31 | +<td colspan="2"><span class="irafpar"><strong>infile | |
| 32 | +[file]</strong></span></td> | |
| 33 | +</tr> | |
| 34 | +<tr> | |
| 35 | +<td width="50"> </td> | |
| 36 | +<td width="25"> </td> | |
| 37 | +<td width="525">XML or fits file that defines the observation</td> | |
| 38 | +</tr> | |
| 39 | +<tr> | |
| 40 | +<td width="50"> </td> | |
| 41 | +<td> </td> | |
| 42 | +<td width="525"> </td> | |
| 43 | +</tr> | |
| 44 | +<tr> | |
| 45 | +<td width="50"> </td> | |
| 46 | +<td colspan="2"><span class="irafpar"><strong>srcmdl | |
| 47 | +[file]</strong></span></td> | |
| 48 | +</tr> | |
| 49 | +<tr> | |
| 50 | +<td width="50"> </td> | |
| 51 | +<td width="25"> </td> | |
| 52 | +<td width="525">Model XML file containing the source and background definitions</td> | |
| 53 | +</tr> | |
| 54 | +<tr> | |
| 55 | +<td width="50"> </td> | |
| 56 | +<td> </td> | |
| 57 | +<td width="525"> </td> | |
| 58 | +</tr> | |
| 59 | +<td width="50"> </td> | |
| 60 | +<td colspan="2"><span class="irafpar"><strong>srcname | |
| 61 | + [file]</strong></span></td> | |
| 62 | +</tr> | |
| 63 | +<tr> | |
| 64 | + <td width="50"> </td> | |
| 65 | + <td width="25"> </td> | |
| 66 | + <td width="525">Name of model for which butterfly should be computed</td> | |
| 67 | +</tr> | |
| 68 | +<tr> | |
| 69 | + <td width="50"> </td> | |
| 70 | + <td> </td> | |
| 71 | + <td width="525"> </td> | |
| 72 | +</tr> | |
| 73 | +<tr> | |
| 74 | + <td width="50"> </td> | |
| 75 | + <td colspan="2"><span class="irafpar"><strong>caldb | |
| 76 | + [string]</strong></span></td> | |
| 77 | +</tr> | |
| 78 | +<tr> | |
| 79 | + <td width="50"> </td> | |
| 80 | + <td width="25"> </td> | |
| 81 | + <td width="525">Calibration database repository.</td> | |
| 82 | +</tr> | |
| 83 | +<tr> | |
| 84 | + <td width="50"> </td> | |
| 85 | + <td> </td> | |
| 86 | + <td width="525"> </td> | |
| 87 | +</tr> | |
| 88 | +<tr> | |
| 89 | + <td width="50"> </td> | |
| 90 | + <td colspan="2"><span class="irafpar"><strong>irf | |
| 91 | + [string]</strong></span></td> | |
| 92 | +</tr> | |
| 93 | +<tr> | |
| 94 | + <td width="50"> </td> | |
| 95 | + <td width="25"> </td> | |
| 96 | + <td width="525">Instrumental response function that | |
| 97 | + should be used for event generation.</td> | |
| 98 | +</tr> | |
| 99 | +<tr> | |
| 100 | + <td width="50"> </td> | |
| 101 | + <td> </td> | |
| 102 | + <td width="525"> </td> | |
| 103 | +</tr> | |
| 104 | +<tr> | |
| 105 | + <td width="50"> </td> | |
| 106 | + <td colspan="2"><span class="irafpar"><strong>outfile | |
| 107 | + [file]</strong></span></td> | |
| 108 | +</tr> | |
| 109 | +<tr> | |
| 110 | + <td width="50"> </td> | |
| 111 | + <td width="25"> </td> | |
| 112 | + <td width="525">Output butterfly file name</td> | |
| 113 | +</tr> | |
| 114 | +<tr> | |
| 115 | + <td width="50"> </td> | |
| 116 | + <td> </td> | |
| 117 | + <td width="525"> </td> | |
| 118 | +</tr> | |
| 119 | +<tr> | |
| 120 | + <td width="50"> </td> | |
| 121 | + <td colspan="2"><span class="irafpar"><strong>(matrix = "NONE") | |
| 122 | + [file]</strong></span></td> | |
| 123 | +</tr> | |
| 124 | +<tr> | |
| 125 | + <td width="50"> </td> | |
| 126 | + <td width="25"> </td> | |
| 127 | + <td width="525">Input covariance matrix file (not used)</td> | |
| 128 | +</tr> | |
| 129 | +<tr> | |
| 130 | + <td width="50"> </td> | |
| 131 | + <td> </td> | |
| 132 | + <td width="525"> </td> | |
| 133 | +</tr> | |
| 134 | +<td width="50"> </td> | |
| 135 | +<td colspan="2"><span class="irafpar"><strong>emin | |
| 136 | + [double]</strong></span></td> | |
| 137 | +</tr> | |
| 138 | +<tr> | |
| 139 | + <td width="50"> </td> | |
| 140 | + <td width="25"> </td> | |
| 141 | + <td width="525">Minimum energy of butterfly (in | |
| 142 | + TeV).</td> | |
| 143 | +</tr> | |
| 144 | +<tr> | |
| 145 | + <td width="50"> </td> | |
| 146 | + <td> </td> | |
| 147 | + <td width="525"> </td> | |
| 148 | +</tr> | |
| 149 | +<tr> | |
| 150 | + <td width="50"> </td> | |
| 151 | + <td colspan="2"><span class="irafpar"><strong>emax | |
| 152 | + [double]</strong></span></td> | |
| 153 | +</tr> | |
| 154 | +<tr> | |
| 155 | + <td width="50"> </td> | |
| 156 | + <td width="25"> </td> | |
| 157 | + <td width="525">Maximum energy of butterfly (in | |
| 158 | + TeV).</td> | |
| 159 | +</tr> | |
| 160 | +<tr> | |
| 161 | + <td width="50"> </td> | |
| 162 | + <td> </td> | |
| 163 | + <td width="525"> </td> | |
| 164 | +</tr> | |
| 165 | +<tr> | |
| 166 | + <td width="50"> </td> | |
| 167 | + <td colspan="2"><span class="irafpar"><strong>(ebinalg | |
| 168 | + = "LOG") <FILE|LIN|LOG> | |
| 169 | + [string]</strong></span></td> | |
| 170 | +</tr> | |
| 171 | +<tr> | |
| 172 | + <td width="50"> </td> | |
| 173 | + <td width="25"> </td> | |
| 174 | + <td width="525">Butterfly binning algorithm</td> | |
| 175 | +</tr> | |
| 176 | +<tr> | |
| 177 | + <td width="50"> </td> | |
| 178 | + <td> </td> | |
| 179 | + <td width="525"> </td> | |
| 180 | +</tr> | |
| 181 | +<tr> | |
| 182 | + <td width="50"> </td> | |
| 183 | + <td colspan="2"><span class="irafpar"><strong>(enumbins | |
| 184 | + = 100) | |
| 185 | + [string]</strong></span></td> | |
| 186 | +</tr> | |
| 187 | +<tr> | |
| 188 | + <td width="50"> </td> | |
| 189 | + <td width="25"> </td> | |
| 190 | + <td width="525">Number of energy bins of butterfly</td> | |
| 191 | +</tr> | |
| 192 | +<tr> | |
| 193 | + <td width="50"> </td> | |
| 194 | + <td> </td> | |
| 195 | + <td width="525"> </td> | |
| 196 | +</tr> | |
| 197 | +<tr> | |
| 198 | + <td width="50"> </td> | |
| 199 | + <td colspan="2"><span class="irafpar"><strong>(ebinfile | |
| 200 | + = "NONE") | |
| 201 | + [string]</strong></span></td> | |
| 202 | +</tr> | |
| 203 | +<tr> | |
| 204 | + <td width="50"> </td> | |
| 205 | + <td width="25"> </td> | |
| 206 | + <td width="525">File for energy binning algorithm</td> | |
| 207 | +</tr> | |
| 208 | +<tr> | |
| 209 | + <td width="50"> </td> | |
| 210 | + <td> </td> | |
| 211 | + <td width="525"> </td> | |
| 212 | +</tr> | |
| 213 | +</tbody> | |
| 214 | +</table> | |
| 215 | +<p class="Title">Standard parameters</p> | |
| 216 | +<table id="table1" class="Body" border="0" cellpadding="0" cellspacing="0" width="600"> | |
| 217 | +<tbody> | |
| 218 | +<tr> | |
| 219 | +<td width="50"> </td> | |
| 220 | +<td colspan="2"><span class="irafpar"><strong>(chatter | |
| 221 | += 2) [integer]</strong></span></td> | |
| 222 | +</tr> | |
| 223 | +<tr> | |
| 224 | +<td width="50"> </td> | |
| 225 | +<td width="25"> </td> | |
| 226 | +<td width="525">Verbosity of the executable:<br> | |
| 227 | +<code>chatter = 0</code>: no information will be | |
| 228 | +logged<br> | |
| 229 | +<code>chatter = 1</code>: only errors will be logged<br> | |
| 230 | +<code>chatter = 2</code>: errors and actions will be | |
| 231 | +logged<br> | |
| 232 | +<code>chatter = 3</code>: report about the task | |
| 233 | +execution<br> | |
| 234 | +<code>chatter = 4</code>: detailed report about the | |
| 235 | +task execution</td> | |
| 236 | +</tr> | |
| 237 | +<tr> | |
| 238 | +<td width="50"> </td> | |
| 239 | +<td> </td> | |
| 240 | +<td width="525"> </td> | |
| 241 | +</tr> | |
| 242 | +<tr> | |
| 243 | +<td width="50"> </td> | |
| 244 | +<td colspan="2"><span class="irafpar"><strong>(clobber | |
| 245 | += yes) [boolean]</strong></span></td> | |
| 246 | +</tr> | |
| 247 | +<tr> | |
| 248 | +<td width="50"> </td> | |
| 249 | +<td width="25"> </td> | |
| 250 | +<td width="525">Specifies whether an existing output | |
| 251 | +event list should be overwritten.</td> | |
| 252 | +</tr> | |
| 253 | +<tr> | |
| 254 | +<td width="50"> </td> | |
| 255 | +<td> </td> | |
| 256 | +<td width="525"> </td> | |
| 257 | +</tr> | |
| 258 | +<tr> | |
| 259 | +<td width="50"> </td> | |
| 260 | +<td colspan="2"><span class="irafpar"><strong>(debug | |
| 261 | += no) [boolean]</strong></span></td> | |
| 262 | +</tr> | |
| 263 | +<tr> | |
| 264 | +<td width="50"> </td> | |
| 265 | +<td width="25"> </td> | |
| 266 | +<td width="525">Enables debug mode. In debug mode | |
| 267 | +the executable will dump any log file output in the console.</td> | |
| 268 | +</tr> | |
| 269 | +<tr> | |
| 270 | +<td width="50"> </td> | |
| 271 | +<td> </td> | |
| 272 | +<td width="525"> </td> | |
| 273 | +</tr> | |
| 274 | +<tr> | |
| 275 | +<td width="50"> </td> | |
| 276 | +<td colspan="2"><span class="irafpar"><strong>(mode | |
| 277 | += ql) [string]</strong></span></td> | |
| 278 | +</tr> | |
| 279 | +<tr> | |
| 280 | +<td width="50"> </td> | |
| 281 | +<td width="25"> </td> | |
| 282 | +<td width="525">Mode of automatic parameters.</td> | |
| 283 | +</tr> | |
| 284 | +<tr> | |
| 285 | +<td width="50"> </td> | |
| 286 | +<td> </td> | |
| 287 | +<td width="525"> </td> | |
| 288 | +</tr> | |
| 289 | +</tbody> | |
| 290 | +</table> | |
| 291 | +<br> | |
| 292 | +<p class="Title">Related FTOOLS</p> | |
| 293 | +<br> | |
| 294 | +<hr size="1"> | |
| 295 | +<p class="Body">Last updated by: Michael | |
| 296 | +Mayer 30 October | |
| 297 | +2014 | |
| 298 | +</p> | |
| 299 | +<br> | |
| 300 | +</body></html> | |
| 0 | 301 | \ No newline at end of file | ... | ... |
doc/source/tools_reference.rst
| ... | ... | @@ -14,6 +14,7 @@ ctools |
| 14 | 14 | * `ctobssim <fhelp/ctobssim.html>`__ --- Observation simulator. |
| 15 | 15 | * `ctselect <fhelp/ctselect.html>`__ --- Performs sub-selections of event data which are needed for unbinned maximum likelihood analysis. |
| 16 | 16 | * `ctskymap <fhelp/ctskymap.html>`__ --- Computes sky map from CTA data. |
| 17 | +* `ctbutterfly <fhelp/ctbutterfly.html>`__ --- Computes a butterfly from a spectral model. | |
| 17 | 18 | |
| 18 | 19 | cscripts |
| 19 | 20 | -------- | ... | ... |
doc/source/user_manual/getting_started/butterfly.jpg
0 → 100644
58.9 KB
doc/source/user_manual/getting_started/quickstart.rst
| ... | ... | @@ -19,6 +19,8 @@ The example consists of the following analysis steps: |
| 19 | 19 | |
| 20 | 20 | - :ref:`sec_unbinned_cta` |
| 21 | 21 | |
| 22 | +- :ref:`sec_butterfly_cta` | |
| 23 | + | |
| 22 | 24 | |
| 23 | 25 | .. _sec_simulating_cta: |
| 24 | 26 | |
| ... | ... | @@ -638,3 +640,130 @@ the same events for both analyses. |
| 638 | 640 | 2014-01-09T21:47:54: +==============+ |
| 639 | 641 | 2014-01-09T21:47:54: |
| 640 | 642 | 2014-01-09T21:47:54: Application "ctlike" terminated after 6 wall clock seconds, consuming 0.163384 seconds of CPU time. |
| 643 | + | |
| 644 | + .. _sec_butterfly_cta: | |
| 645 | + | |
| 646 | +Calculate and visualise butterfly | |
| 647 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 648 | + | |
| 649 | +To visualise the analysis results retrieved above, one can calculate the | |
| 650 | +confidence band of the spectral fit. The tool ctbutterfly takes the optimised | |
| 651 | +source model as input. It takes the covariance matrix from the fit to conduct a | |
| 652 | +Gaussian error propagation for each energy value. | |
| 653 | +The following example shows how to compute such a butterfly from the command line | |
| 654 | +and subsequently shows how to visualise the spectral fit using matplotlib. | |
| 655 | + | |
| 656 | +.. code-block:: bash | |
| 657 | + | |
| 658 | + $ ctbutterfly | |
| 659 | + Input event list, cube or observation definition file [$CTOOLS/test/data/crab_events.fits.gz] | |
| 660 | + Calibration database [share/caldb/data/cta/dummy//cta_dummy_irf] share/caldb/data/cta/dummy/bcf/ | |
| 661 | + Instrument response function [cta_dummy_irf] | |
| 662 | + Source model [$CTOOLS/test/data/crab.xml] | |
| 663 | + Source of interest [CrabNebula] Crab | |
| 664 | + Start value for first energy bin in TeV [0.1] | |
| 665 | + Stop value for last energy bin in TeV [100.] | |
| 666 | + Output ascii file [butterfly.txt] | |
| 667 | + | |
| 668 | +Below some lines of the ``ctbutterfly.log``: | |
| 669 | + | |
| 670 | +.. code-block:: xml | |
| 671 | + | |
| 672 | + 2014-10-30T17:51:24: ******************************************************************************** | |
| 673 | + 2014-10-30T17:51:24: * ctbutterfly * | |
| 674 | + 2014-10-30T17:51:24: * ---------------------------------------------------------------------------- * | |
| 675 | + 2014-10-30T17:51:24: * Version: 00-01-00 * | |
| 676 | + 2014-10-30T17:51:24: ******************************************************************************** | |
| 677 | + 2014-10-30T17:51:39: +============+ | |
| 678 | + 2014-10-30T17:51:39: | Parameters | | |
| 679 | + 2014-10-30T17:51:39: +============+ | |
| 680 | + 2014-10-30T17:51:39: infile ....................: $CTOOLS/test/data/crab_events.fits.gz | |
| 681 | + 2014-10-30T17:51:39: srcmdl ....................: $CTOOLS/test/data/crab.xml | |
| 682 | + 2014-10-30T17:51:39: srcname ...................: Crab | |
| 683 | + 2014-10-30T17:51:39: caldb .....................: share/caldb/data/cta/dummy/bcf/ | |
| 684 | + 2014-10-30T17:51:39: irf .......................: cta_dummy_irf | |
| 685 | + 2014-10-30T17:51:39: outfile ...................: butterfly.txt | |
| 686 | + 2014-10-30T17:51:39: matrix ....................: NONE | |
| 687 | + 2014-10-30T17:51:39: ebinalg ...................: LOG | |
| 688 | + 2014-10-30T17:51:39: emin ......................: 0.1 | |
| 689 | + 2014-10-30T17:51:39: emax ......................: 100. | |
| 690 | + 2014-10-30T17:51:39: enumbins ..................: 100 | |
| 691 | + 2014-10-30T17:51:39: ebinfile ..................: NONE | |
| 692 | + 2014-10-30T17:51:39: chatter ...................: 2 | |
| 693 | + 2014-10-30T17:51:39: clobber ...................: yes | |
| 694 | + 2014-10-30T17:51:39: debug .....................: no | |
| 695 | + 2014-10-30T17:51:39: mode ......................: ql | |
| 696 | + 2014-10-30T17:51:39: logfile ...................: ctbutterfly.log | |
| 697 | + 2014-10-30T17:51:39: | |
| 698 | + 2014-10-30T17:51:39: +=============+ | |
| 699 | + 2014-10-30T17:51:39: | Observation | | |
| 700 | + 2014-10-30T17:51:39: +=============+ | |
| 701 | + 2014-10-30T17:51:39: === GObservations === | |
| 702 | + 2014-10-30T17:51:39: Number of observations ....: 1 | |
| 703 | + 2014-10-30T17:51:39: Number of predicted events : 0 | |
| 704 | + 2014-10-30T17:51:39: === GCTAObservation === | |
| 705 | + 2014-10-30T17:51:39: Name ......................: | |
| 706 | + 2014-10-30T17:51:39: Identifier ................: | |
| 707 | + 2014-10-30T17:51:39: Instrument ................: CTA | |
| 708 | + 2014-10-30T17:51:39: Event file ................: test/data/crab_events.fits.gz | |
| 709 | + 2014-10-30T17:51:39: Event type ................: EventList | |
| 710 | + 2014-10-30T17:51:39: Statistics ................: Poisson | |
| 711 | + 2014-10-30T17:51:39: Ontime ....................: 1800 s | |
| 712 | + 2014-10-30T17:51:39: Livetime ..................: 1710 s | |
| 713 | + 2014-10-30T17:51:39: Deadtime correction .......: 0.95 | |
| 714 | + 2014-10-30T17:51:39: === GCTAPointing === | |
| 715 | + 2014-10-30T17:51:39: Pointing direction ........: (RA,Dec)=(83.63,22.01) | |
| 716 | + 2014-10-30T17:51:39: === GCTAResponseIrf === | |
| 717 | + 2014-10-30T17:51:39: Response name .............: cta_dummy_irf | |
| 718 | + 2014-10-30T17:51:39: Energy dispersion .........: Not used | |
| 719 | + 2014-10-30T17:51:39: === GCaldb === | |
| 720 | + 2014-10-30T17:51:39: Database root .............: share/caldb/data/cta/dummy/bcf/ | |
| 721 | + 2014-10-30T17:51:39: === GCTAAeffPerfTable === | |
| 722 | + 2014-10-30T17:51:39: Filename ..................: share/caldb/data/cta/dummy/bcf//cta_dummy_irf.dat | |
| 723 | + 2014-10-30T17:51:39: Number of energy bins .....: 20 | |
| 724 | + 2014-10-30T17:51:39: Log10(Energy) range .......: 0.0199526 - 125.893 TeV | |
| 725 | + 2014-10-30T17:51:39: Offset angle dependence ...: Fixed sigma=3 | |
| 726 | + 2014-10-30T17:51:39: === GCTAPsfPerfTable === | |
| 727 | + 2014-10-30T17:51:39: Filename ..................: share/caldb/data/cta/dummy/bcf//cta_dummy_irf.dat | |
| 728 | + 2014-10-30T17:51:39: Number of energy bins .....: 20 | |
| 729 | + 2014-10-30T17:51:39: Log10(Energy) range .......: 0.0199526 - 125.893 TeV | |
| 730 | + 2014-10-30T17:51:39: === GCTAEdispPerfTable === | |
| 731 | + 2014-10-30T17:51:39: Filename ..................: share/caldb/data/cta/dummy/bcf//cta_dummy_irf.dat | |
| 732 | + 2014-10-30T17:51:39: Number of energy bins .....: 20 | |
| 733 | + 2014-10-30T17:51:39: Log10(Energy) range .......: 0.0199526 - 125.893 TeV | |
| 734 | + 2014-10-30T17:51:39: === GCTABackgroundPerfTable === | |
| 735 | + 2014-10-30T17:51:39: Filename ..................: share/caldb/data/cta/dummy/bcf//cta_dummy_irf.dat | |
| 736 | + 2014-10-30T17:51:39: Number of energy bins .....: 20 | |
| 737 | + 2014-10-30T17:51:39: Log10(Energy) range .......: 0.0199526 - 125.893 TeV | |
| 738 | + 2014-10-30T17:51:39: Offset angle dependence ...: Fixed sigma=3 | |
| 739 | + 2014-10-30T17:51:39: === GCTAEventList === | |
| 740 | + 2014-10-30T17:51:39: Number of events ..........: 6141 | |
| 741 | + 2014-10-30T17:51:39: Time interval .............: 51544.5 - 51544.5 days | |
| 742 | + 2014-10-30T17:51:39: | |
| 743 | + 2014-10-30T17:51:39: +===========================+ | |
| 744 | + 2014-10-30T17:51:39: | Compute covariance matrix | | |
| 745 | + 2014-10-30T17:51:39: +===========================+ | |
| 746 | + 2014-10-30T17:51:39: | |
| 747 | + 2014-10-30T17:51:39: +====================+ | |
| 748 | + 2014-10-30T17:51:39: | Generate butterfly | | |
| 749 | + 2014-10-30T17:51:39: +====================+ | |
| 750 | + 2014-10-30T17:51:39: | |
| 751 | + 2014-10-30T17:51:39: +========================+ | |
| 752 | + 2014-10-30T17:51:39: | Save Butterfly to file | | |
| 753 | + 2014-10-30T17:51:39: +========================+ | |
| 754 | + 2014-10-30T17:51:39: | |
| 755 | + 2014-10-30T17:51:39: Application "ctbutterfly" terminated after 15 wall clock seconds, consuming 0.051253 seconds of CPU time. | |
| 756 | + | |
| 757 | +Now that you have computed the confidence band of the spectral fit, you can visualise | |
| 758 | +file with an example script. The script is located in the "examples" folder. Make sure you | |
| 759 | +have installed matplotlib on your system. Then run the following script: | |
| 760 | + | |
| 761 | +.. code-block:: bash | |
| 762 | + python $CTOOLS/examples/show_butterfly.py butterfly.txt | |
| 763 | + | |
| 764 | +This will result in a canvas which should look like the following: | |
| 765 | +.. figure:: butterfly.jpg | |
| 766 | + :width: 60% | |
| 767 | + | |
| 768 | + *Confidence band of the fit* | |
| 769 | + | |
| 641 | 770 | \ No newline at end of file | ... | ... |
examples/show_butterfly.py
0 → 100644
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This script shows how to plot a butterfly created with ctbutterfly | |
| 4 | +# | |
| 5 | +# Copyright (C) 2014 Michael Mayer | |
| 6 | +# | |
| 7 | +# This program is free software: you can redistribute it and/or modify | |
| 8 | +# it under the terms of the GNU General Public License as published by | |
| 9 | +# the Free Software Foundation, either version 3 of the License, or | |
| 10 | +# (at your option) any later version. | |
| 11 | +# | |
| 12 | +# This program is distributed in the hope that it will be useful, | |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | +# GNU General Public License for more details. | |
| 16 | +# | |
| 17 | +# You should have received a copy of the GNU General Public License | |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | +# | |
| 20 | +# ========================================================================== | |
| 21 | + | |
| 22 | +import gammalib | |
| 23 | +import sys | |
| 24 | +try: | |
| 25 | + import matplotlib.pyplot as plt | |
| 26 | +except: | |
| 27 | + sys.exit("This script needs matplotlib") | |
| 28 | + | |
| 29 | +# =============== # | |
| 30 | +# Script entry # | |
| 31 | +# =============== # | |
| 32 | +if __name__ == "__main__": | |
| 33 | + | |
| 34 | + # check for given butterfly file | |
| 35 | + if not len(sys.argv) == 2: | |
| 36 | + sys.exit("Usage: show_butterfly.py butterfly.txt") | |
| 37 | + | |
| 38 | + # Read given butterfly file | |
| 39 | + filename = sys.argv[1] | |
| 40 | + csv = gammalib.GCsv(filename) | |
| 41 | + | |
| 42 | + # initialise arrays to be filled | |
| 43 | + butterfly_x = [] | |
| 44 | + butterfly_y = [] | |
| 45 | + | |
| 46 | + line_x = [] | |
| 47 | + line_y = [] | |
| 48 | + | |
| 49 | + # loop over rows of the file | |
| 50 | + nrows = csv.nrows() | |
| 51 | + for row in range(nrows): | |
| 52 | + # Compute upper edge of confidence band | |
| 53 | + butterfly_x.append(csv.real(row,0)) | |
| 54 | + butterfly_y.append(csv.real(row,1)+csv.real(row,2)) | |
| 55 | + | |
| 56 | + # Set line values | |
| 57 | + line_x.append(csv.real(row,0)) | |
| 58 | + line_y.append(csv.real(row,1)) | |
| 59 | + | |
| 60 | + # Loop over the rows backwards to compute the lower edge | |
| 61 | + # of the confidence band | |
| 62 | + for row in range(nrows): | |
| 63 | + index = nrows - 1 - row | |
| 64 | + | |
| 65 | + butterfly_x.append(csv.real(index,0)) | |
| 66 | + butterfly_y.append(csv.real(index,1)-csv.real(index,2)) | |
| 67 | + | |
| 68 | + # plot the butterfly and spectral line | |
| 69 | + plt.figure() | |
| 70 | + plt.loglog() | |
| 71 | + plt.grid() | |
| 72 | + plt.plot(line_x,line_y,color='black',ls='-') | |
| 73 | + plt.fill(butterfly_x,butterfly_y,color='green',alpha=0.5) | |
| 74 | + plt.xlabel("Energy [MeV]") | |
| 75 | + plt.ylabel(r"dN/dE [MeV$^{-1}$ s$^{-1}$ cm$^{-2}$]") | |
| 76 | + plt.show() | |
| 0 | 77 | \ No newline at end of file | ... | ... |