Commit 14f9d87c77c882bb27b52d9dc3e85fc929ea25c3
Merge branch 'release'
Showing
149 changed files
with
6447 additions
and
2907 deletions
Too many changes.
To preserve performance only 100 of 149 files are displayed.
.gitignore
| ... | ... | @@ -46,8 +46,10 @@ doc/man |
| 46 | 46 | src/ctools-setup |
| 47 | 47 | pyext/build/ |
| 48 | 48 | pyext/setup.py |
| 49 | +pyext/ctools/__init__.py | |
| 49 | 50 | pyext/ctools/tools.py |
| 50 | 51 | pyext/ctools/tools_wrap.cpp |
| 52 | +cscripts/__init__.py | |
| 51 | 53 | src/ctbin/ctbin |
| 52 | 54 | src/ctlike/ctlike |
| 53 | 55 | src/cttsmap/cttsmap |
| ... | ... | @@ -63,6 +65,7 @@ src/ctbutterfly/ctbutterfly |
| 63 | 65 | src/ctulimit/ctulimit |
| 64 | 66 | src/cterror/cterror |
| 65 | 67 | test/pfiles/ |
| 68 | +test/caldb/ | |
| 66 | 69 | test/*.fits |
| 67 | 70 | test/*.dat |
| 68 | 71 | test/*.xml |
| ... | ... | @@ -70,6 +73,8 @@ test/*.trs |
| 70 | 73 | test/test_cscripts.sh |
| 71 | 74 | test/reports/*.xml |
| 72 | 75 | test/butterfly.txt |
| 76 | +test/model.reg | |
| 77 | +test/obs.reg | |
| 73 | 78 | examples/*.fits |
| 74 | 79 | examples/*.xml |
| 75 | 80 | examples/*.dat | ... | ... |
AUTHORS
ChangeLog
| 1 | +2015-12-18 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 2 | + | |
| 3 | + * Version 1.0.0 released | |
| 4 | + ======================== | |
| 5 | + | |
| 6 | + Update end-user documentation | |
| 7 | + Rename cshessobs to csiactobs and add csiactdata (#1608) | |
| 8 | + Ignore errors in El Capitan post processing (#1605) | |
| 9 | + Change GException to RuntimeError in cscripts (#1604) | |
| 10 | + Adapt to GammaLib interface changs (#1603) | |
| 11 | + Add csobs2caldb script (#1579) | |
| 12 | + Add csobsinfo, csmodelinfo, csmodelmerge, cstsmapmerge (#1578) | |
| 13 | + Implement handling of stacked data in csspec (#1566) | |
| 14 | + Resolve Python test problem on El Capitan (#1563) | |
| 15 | + | |
| 16 | + | |
| 1 | 17 | 2015-10-31 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> |
| 2 | 18 | |
| 3 | 19 | * Version 0.10.0 released | ... | ... |
NEWS
| 1 | -New Features and Important Changes in ctools 0.10.0 | |
| 1 | +New Features and Important Changes in ctools 1.0.0 | |
| 2 | 2 | |
| 3 | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | |
| 5 | -31 October 2015 | |
| 5 | +18 December 2015 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | 1. Introduction |
| 9 | 9 | --------------- |
| 10 | 10 | This document briefly summarizes executable by executable the most important |
| 11 | -changes made since the last release of ctools. The code complies to GammaLib | |
| 12 | -version 0.11.0 or above. | |
| 11 | +changes made since the last release of ctools. The code complies to ctools | |
| 12 | +version 1.0.0 or above. | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | 2. Configuration |
| 16 | 16 | ----------------- |
| 17 | -None | |
| 17 | +A special post processing of the Python module libraries has been added for | |
| 18 | +Mac OS X 10.11 and higher (El Capitan). This post processing is a replacement for | |
| 19 | +setting DYLD_LIBRARY_PATH during unit testing since the environment variable is | |
| 20 | +ignored in certain circumstances by El Capitan. Any errors that occur in the | |
| 21 | +post-processing will be ignored. | |
| 18 | 22 | |
| 19 | 23 | |
| 20 | 24 | 3. Python interface |
| 21 | 25 | ------------------- |
| 22 | -A specific cscripts Python module has been created for cscripts. This module | |
| 23 | -can be imported using | |
| 24 | - | |
| 25 | - >>> import cscripts | |
| 26 | - | |
| 27 | -The obsutils utility functions have also been moved into the scripts folder. | |
| 28 | - | |
| 29 | -The obsutils.spectrum() function has been removed as it is now replaced by the | |
| 30 | -csspec script. | |
| 31 | - | |
| 32 | -Some tests for the installed ctools package have been added. They can be | |
| 33 | -executed by typing the following under Python: | |
| 34 | - | |
| 35 | - >>> cscripts.test() | |
| 26 | +None | |
| 36 | 27 | |
| 37 | 28 | |
| 38 | 29 | 4. Support model |
| 39 | 30 | ---------------- |
| 40 | -The ctool base class now handles the specification of the --help option on | |
| 41 | -the command line. For each tools or script, a help text that is generated from | |
| 42 | -the .rst documentation files is displayed on the console when --help is given. | |
| 31 | +Adapt the ctool::create_ebounds() method to the change in the GEbounds | |
| 32 | +interface (the extname argument has been removed from the GEbounds::load() | |
| 33 | +method and replaced by using the GFilename class to handle extension names | |
| 34 | +as part of the file name). | |
| 43 | 35 | |
| 44 | 36 | |
| 45 | 37 | 5. ctobssim - CTA observation simulation |
| ... | ... | @@ -54,14 +46,12 @@ None |
| 54 | 46 | |
| 55 | 47 | 7. ctbin - CTA event binning |
| 56 | 48 | ---------------------------- |
| 57 | -ctbin now verifies if an ROI has been set properly, and throws an exception in | |
| 58 | -case that no ROI information could be found. | |
| 49 | +None | |
| 59 | 50 | |
| 60 | 51 | |
| 61 | 52 | 8. ctlike - Maximum likelihood fitting |
| 62 | 53 | -------------------------------------- |
| 63 | -The optimizer is now allocated upon construction so that ctlike always returns a | |
| 64 | -meaningful object using the opt() method. | |
| 54 | +None | |
| 65 | 55 | |
| 66 | 56 | |
| 67 | 57 | 9. cttsmap - Generation of Test Statistics map |
| ... | ... | @@ -91,8 +81,7 @@ None |
| 91 | 81 | |
| 92 | 82 | 14. ctbkgcube - CTA background cube generation |
| 93 | 83 | ---------------------------------------------- |
| 94 | -Limit the power law prefactor to a range of [0.01,100] and the index to [-5,5]. This | |
| 95 | -solves some stability problems in csspec (#1547). | |
| 84 | +None | |
| 96 | 85 | |
| 97 | 86 | |
| 98 | 87 | 15. ctcubemask - CTA cube filtering |
| ... | ... | @@ -112,24 +101,28 @@ None |
| 112 | 101 | |
| 113 | 102 | 18. cterror - Likelihood profile error computation |
| 114 | 103 | -------------------------------------------------- |
| 115 | -Added initial version of the likelihood profile error computation tool. This | |
| 116 | -tool will scan the likelihood function to find the confidence interval for | |
| 117 | -all source parameters. | |
| 104 | +None | |
| 118 | 105 | |
| 119 | 106 | |
| 120 | -19. Examples | |
| 107 | +19. cscripts | |
| 121 | 108 | ------------ |
| 122 | -None | |
| 109 | +The following scripts have been added: | |
| 110 | +- csobsinfo: dump information in observation container | |
| 111 | +- csmodelinfo: dump information in model container | |
| 112 | +- csmodelmerge: merge model containers into single container | |
| 113 | +- cstsmapmerge: merge sliced TS map into single map | |
| 114 | +- csobs2caldb: creates calibration database from observation | |
| 115 | +- csiactdata: inspects IACT data | |
| 123 | 116 | |
| 117 | +The cshessobs script has been renamed to csiactobs. | |
| 124 | 118 | |
| 125 | -20. Scripts | |
| 126 | ------------ | |
| 127 | -Added csinfo script to provide some information about the GammaLib and ctools | |
| 128 | -installation. To be run in case of problems to help diagnostics. | |
| 119 | +All GExceptions are replaced by Python RuntimeErrors as the GException | |
| 120 | +classes are not exposed to Python. | |
| 129 | 121 | |
| 130 | -The cspull script was extended to now also handle stacked analysis in case | |
| 131 | -that an observation definition XML file is specified with multiple observations | |
| 132 | -by the inobs parameter. | |
| 122 | + | |
| 123 | +20. Examples | |
| 124 | +------------ | |
| 125 | +None | |
| 133 | 126 | |
| 134 | 127 | |
| 135 | 128 | 21. caldb | ... | ... |
README
| 1 | 1 | ctools information |
| 2 | 2 | ================== |
| 3 | -Version: 0.10.0 (31 October 2015) | |
| 3 | +Version: 1.0.0 (18 December 2015) | |
| 4 | 4 | Author: Juergen Knodlseder (jurgen.knodlseder@irap.omp.eu) |
| 5 | -GammaLib dependency: 0.11.0 | |
| 5 | +GammaLib dependency: 1.0.0 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | License information |
| ... | ... | @@ -38,6 +38,7 @@ The following tools are available: |
| 38 | 38 | ctbkgcube - generate a background cube |
| 39 | 39 | ctbutterfly - create a butterfly |
| 40 | 40 | ctcubemask - mask bins in binned analysis |
| 41 | + cterror - likelihood profile error estimation | |
| 41 | 42 | ctexpcube - generate an exposure cube |
| 42 | 43 | ctlike - maximum likelihood model fitting |
| 43 | 44 | ctmodel - generation of model counts map |
| ... | ... | @@ -51,10 +52,8 @@ The following tools are available: |
| 51 | 52 | |
| 52 | 53 | Web sites |
| 53 | 54 | ========= |
| 54 | -http://cta.irap.omp.eu/ctools - ctools documentation | |
| 55 | +http://cta.irap.omp.eu/ctools - for ctools users | |
| 55 | 56 | https://cta-redmine.irap.omp.eu/projects/ctools - for ctools development |
| 56 | -https://cta-redmine.irap.omp.eu/projects/gammalib - for GammaLib documentation | |
| 57 | -https://sourceforge.net/projects/gammalib/ - for GammaLib downloads | |
| 58 | 57 | |
| 59 | 58 | |
| 60 | 59 | Prerequisites | ... | ... |
configure.ac
| ... | ... | @@ -29,7 +29,7 @@ |
| 29 | 29 | ############################################################################# |
| 30 | 30 | # Initialisation # |
| 31 | 31 | ############################################################################# |
| 32 | -AC_INIT([ctools], [0.10.0], [jurgen.knodlseder@irap.omp.eu], [ctools]) | |
| 32 | +AC_INIT([ctools], [1.0.0], [jurgen.knodlseder@irap.omp.eu], [ctools]) | |
| 33 | 33 | AC_CONFIG_SRCDIR([src/ctselect/ctselect.cpp]) |
| 34 | 34 | AC_CONFIG_MACRO_DIR([m4]) |
| 35 | 35 | #AM_INIT_AUTOMAKE([gnu no-dependencies]) |
| ... | ... | @@ -39,6 +39,27 @@ AC_CONFIG_HEADER([config.h]) |
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | ############################################################################# |
| 42 | +# Library versioning (current:revision:age) # | |
| 43 | +# ------------------------------------------------------------------------- # | |
| 44 | +# Here are a set of rules to update your library version information: # | |
| 45 | +# 1. Update the version information only immediately before a public # | |
| 46 | +# release of your software. More frequent updates are unnecessary, # | |
| 47 | +# and only guarantee that the current interface number gets larger # | |
| 48 | +# faster. # | |
| 49 | +# 2. If the library source code has changed at all since the last update, # | |
| 50 | +# then increment revision. # | |
| 51 | +# 3. If any interfaces have been added, removed, or changed since the last # | |
| 52 | +# update, increment current, and set revision to 0. # | |
| 53 | +# 4. If any interfaces have been added since the last public release, then # | |
| 54 | +# increment age. # | |
| 55 | +# 5. If any interfaces have been removed or changed since the last public # | |
| 56 | +# release, then set age to 0. # | |
| 57 | +############################################################################# | |
| 58 | +CTOOLS_LT_VERSION="1:0:0" | |
| 59 | +AC_SUBST(CTOOLS_LT_VERSION) | |
| 60 | + | |
| 61 | + | |
| 62 | +############################################################################# | |
| 42 | 63 | # Set prefix # |
| 43 | 64 | # ------------------------------------------------------------------------- # |
| 44 | 65 | # By default, ctools get installed into "/usr/local/gamma". The default # |
| ... | ... | @@ -71,19 +92,42 @@ AC_CANONICAL_HOST |
| 71 | 92 | # # |
| 72 | 93 | # A special kluge was added for Mac OS X >=10.7. As Apple switched to clang # |
| 73 | 94 | # we search from this version on for the clang compiler. # |
| 95 | +# # | |
| 96 | +# We also signal whether Mac OS X >=10.11 (El Capitan). # | |
| 74 | 97 | ############################################################################# |
| 98 | +# Set default Mac OS X version flags | |
| 99 | +osx_lion=no | |
| 100 | +osx_el_capitan=no | |
| 75 | 101 | |
| 76 | 102 | # Set default compiler lists |
| 77 | 103 | cxx_list="g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++" |
| 78 | 104 | cc_list="gcc cc cl.exe clang" |
| 79 | 105 | |
| 80 | -# Check if we have Mac OS X >= 10.7 | |
| 106 | +# Check if we have Mac OS X >= 10.7 and >= 10.11 | |
| 81 | 107 | if test `uname -s` = "Darwin"; then |
| 82 | - if test `sw_vers -productVersion | sed 's/\(10\.[[0-9]]*\).*/\1/'` '>' 10.6; then | |
| 108 | + version=`sw_vers -productVersion | sed 's/\(10\.[[0-9]]*\).*/\1/' | sed -e 's/\.//g'` | |
| 109 | + if [ test $version -ge 107 ]; then | |
| 83 | 110 | cxx_list="clang++ g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC" |
| 84 | 111 | cc_list="clang gcc cc cl.exe" |
| 112 | + osx_lion=yes | |
| 113 | + fi | |
| 114 | + if [ test $version -ge 1011 ]; then | |
| 115 | + osx_el_capitan=yes | |
| 85 | 116 | fi |
| 86 | 117 | fi |
| 118 | +AC_MSG_CHECKING([for Mac OS X >= 10.7]) | |
| 119 | +if [test "x$osx_lion" = "xyes"]; then | |
| 120 | + AC_MSG_RESULT(yes) | |
| 121 | +else | |
| 122 | + AC_MSG_RESULT(no) | |
| 123 | +fi | |
| 124 | +AC_MSG_CHECKING([for Mac OS X >= 10.11]) | |
| 125 | +if [test "x$osx_el_capitan" = "xyes"]; then | |
| 126 | + AC_MSG_RESULT(yes) | |
| 127 | +else | |
| 128 | + AC_MSG_RESULT(no) | |
| 129 | +fi | |
| 130 | +AM_CONDITIONAL(IS_ELCAPITAN, test "x$osx_el_capitan" = "xyes") | |
| 87 | 131 | |
| 88 | 132 | # Our language is C++ |
| 89 | 133 | AC_LANG(C++) |
| ... | ... | @@ -897,10 +941,12 @@ AC_CONFIG_FILES([Makefile |
| 897 | 941 | test/test_cscripts.sh |
| 898 | 942 | pyext/Makefile |
| 899 | 943 | pyext/setup.py |
| 944 | + pyext/ctools/__init__.py | |
| 945 | + cscripts/__init__.py | |
| 946 | + cscripts/Makefile | |
| 900 | 947 | caldb/Makefile |
| 901 | 948 | models/Makefile |
| 902 | 949 | examples/Makefile |
| 903 | - cscripts/Makefile | |
| 904 | 950 | ctools.pc |
| 905 | 951 | testconf.sh], |
| 906 | 952 | [if test -f test/test_cscripts.sh; then chmod +x test/test_cscripts.sh; fi; | ... | ... |
cscripts/Makefile.am
| 1 | 1 | ## Process this file with automake to produce Makefile.in |
| 2 | 2 | |
| 3 | -# Scripts to be distributed in bindir | |
| 4 | -binscripts = tsmerge.py | |
| 5 | - | |
| 6 | 3 | # Scripts to be distributed in $(pyexecdir)/cscripts |
| 7 | 4 | pythonscripts = __init__.py \ |
| 8 | 5 | cspull.py cssens.py cstsdist.py cscaldb.py csresmap.py \ |
| 9 | - cshessobs.py csobsdef.py csspec.py cslightcrv.py \ | |
| 10 | - csinfo.py \ | |
| 6 | + csiactobs.py csiactdata.py csobsdef.py csspec.py cslightcrv.py csobsinfo.py \ | |
| 7 | + csinfo.py csmodelinfo.py csmodelmerge.py cstsmapmerge.py \ | |
| 8 | + csobs2caldb.py \ | |
| 11 | 9 | obsutils.py |
| 12 | 10 | |
| 13 | 11 | # Scripts for which symbolic links will be created in bindir |
| 14 | 12 | linkscripts = cspull cssens cstsdist cscaldb csresmap \ |
| 15 | - cshessobs csobsdef csspec cslightcrv \ | |
| 16 | - csinfo | |
| 13 | + csiactobs csiactdata csobsdef csspec cslightcrv csobsinfo \ | |
| 14 | + csinfo csmodelinfo csmodelmerge cstsmapmerge \ | |
| 15 | + csobs2caldb | |
| 17 | 16 | |
| 18 | 17 | # Distribute scripts |
| 19 | 18 | EXTRA_DIST = $(binscripts) $(pythonscripts) | ... | ... |
cscripts/__init__.py renamed to cscripts/__init__.py.in
| ... | ... | @@ -21,30 +21,42 @@ |
| 21 | 21 | # List all scripts in this module |
| 22 | 22 | __all__ = [ |
| 23 | 23 | "cscaldb", |
| 24 | - "cshessobs", | |
| 24 | + "csiactdata", | |
| 25 | + "csiactobs", | |
| 25 | 26 | "csinfo", |
| 26 | 27 | "cslightcrv", |
| 28 | + "csmodelinfo", | |
| 29 | + "csmodelmerge", | |
| 30 | + "csobs2caldb", | |
| 27 | 31 | "csobsdef", |
| 32 | + "csobsinfo", | |
| 28 | 33 | "cspull", |
| 29 | 34 | "csresmap", |
| 30 | 35 | "cssens", |
| 31 | 36 | "csspec", |
| 32 | 37 | "cstsdist", |
| 38 | + "cstsmapmerge", | |
| 33 | 39 | "obsutils", |
| 34 | 40 | "test", |
| 35 | 41 | ] |
| 36 | 42 | |
| 37 | 43 | # Import |
| 38 | -from .cscaldb import cscaldb | |
| 39 | -from .cshessobs import cshessobs | |
| 40 | -from .csinfo import csinfo | |
| 41 | -from .cslightcrv import cslightcrv | |
| 42 | -from .csobsdef import csobsdef | |
| 43 | -from .cspull import cspull | |
| 44 | -from .csresmap import csresmap | |
| 45 | -from .cssens import cssens | |
| 46 | -from .csspec import csspec | |
| 47 | -from .cstsdist import cstsdist | |
| 44 | +from .cscaldb import cscaldb | |
| 45 | +from .csiactdata import csiactdata | |
| 46 | +from .csiactobs import csiactobs | |
| 47 | +from .csinfo import csinfo | |
| 48 | +from .cslightcrv import cslightcrv | |
| 49 | +from .csmodelinfo import csmodelinfo | |
| 50 | +from .csmodelmerge import csmodelmerge | |
| 51 | +from .csobs2caldb import csobs2caldb | |
| 52 | +from .csobsdef import csobsdef | |
| 53 | +from .csobsinfo import csobsinfo | |
| 54 | +from .cspull import cspull | |
| 55 | +from .csresmap import csresmap | |
| 56 | +from .cssens import cssens | |
| 57 | +from .csspec import csspec | |
| 58 | +from .cstsdist import cstsdist | |
| 59 | +from .cstsmapmerge import cstsmapmerge | |
| 48 | 60 | from . import obsutils |
| 49 | 61 | |
| 50 | 62 | # Add test function |
| ... | ... | @@ -53,3 +65,6 @@ def test(): |
| 53 | 65 | Run cscripts tests. |
| 54 | 66 | """ |
| 55 | 67 | print("No cscripts unit tests have been implemented so far.") |
| 68 | + | |
| 69 | +# Add version | |
| 70 | +__version__ = '@PACKAGE_VERSION@' | |
| 56 | 71 | \ No newline at end of file | ... | ... |
cscripts/cshessobs.py deleted
| 1 | -#!/usr/bin/env python | |
| 2 | -# ========================================================================== | |
| 3 | -# Generation of an H.E.S.S. observation definition file. | |
| 4 | -# | |
| 5 | -# Copyright (C) 2015 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 | -import gammalib | |
| 22 | -import ctools | |
| 23 | -import sys | |
| 24 | -import os | |
| 25 | -import glob | |
| 26 | -import math | |
| 27 | - | |
| 28 | - | |
| 29 | -# =============== # | |
| 30 | -# cshessobs class # | |
| 31 | -# =============== # | |
| 32 | -class cshessobs(ctools.cscript): | |
| 33 | - """ | |
| 34 | - This class implements the creation of a observation xml file for HESS | |
| 35 | - data analysis. This class is dedicated for use inside the HESS Collaboration, | |
| 36 | - i.e. it can only be used if you have access to HESS data in FITS format. | |
| 37 | - The HESSFITS environment has to be set correctly to use this script | |
| 38 | - Please see the internal documentation for this purpose: | |
| 39 | - https://hess-confluence.desy.de/confluence/display/HESS/HESS+Open+Source+Tools+-+HESS+data+and+IRFs+in+FITS+format | |
| 40 | - """ | |
| 41 | - def __init__(self, *argv): | |
| 42 | - """ | |
| 43 | - Constructor. | |
| 44 | - """ | |
| 45 | - # Set name | |
| 46 | - self.name = "cshessobs" | |
| 47 | - self.version = "0.2.0" | |
| 48 | - self.datapath = "" | |
| 49 | - self.m_erange = gammalib.GEbounds() | |
| 50 | - | |
| 51 | - # Check on existence of HESSFITS environment variable | |
| 52 | - try: | |
| 53 | - self.datapath = os.environ["HESSFITS"] | |
| 54 | - except KeyError: | |
| 55 | - raise RuntimeError("Environment variable \"HESSFITS\" not set. " \ | |
| 56 | - "Please set the environment variable \"HESSFITS\" to use this script") | |
| 57 | - | |
| 58 | - # Initialise some members | |
| 59 | - self.inmodels = None | |
| 60 | - self.outobs = "obs.xml" | |
| 61 | - | |
| 62 | - # Make sure that parfile exists | |
| 63 | - file = self.parfile() | |
| 64 | - | |
| 65 | - # Initialise application | |
| 66 | - if len(argv) == 0: | |
| 67 | - ctools.cscript.__init__(self, self.name, self.version) | |
| 68 | - elif len(argv) ==1: | |
| 69 | - ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 70 | - else: | |
| 71 | - raise TypeError("Invalid number of arguments given.") | |
| 72 | - | |
| 73 | - # Set logger properties | |
| 74 | - self.log_header() | |
| 75 | - self.log.date(True) | |
| 76 | - | |
| 77 | - # Return | |
| 78 | - return | |
| 79 | - | |
| 80 | - def __del__(self): | |
| 81 | - """ | |
| 82 | - Destructor. | |
| 83 | - """ | |
| 84 | - # Return | |
| 85 | - return | |
| 86 | - | |
| 87 | - def parfile(self): | |
| 88 | - """ | |
| 89 | - Check if parfile exists. If parfile does not exist then create a | |
| 90 | - default parfile. This kluge avoids shipping the cscript with a parfile. | |
| 91 | - """ | |
| 92 | - | |
| 93 | - # Set parfile name | |
| 94 | - parfile = self.name+".par" | |
| 95 | - | |
| 96 | - try: | |
| 97 | - pars = gammalib.GApplicationPars(parfile) | |
| 98 | - except: | |
| 99 | - # Signal that parfile was not found | |
| 100 | - print("Parfile \""+parfile+"\" not found. Create default parfile.") | |
| 101 | - | |
| 102 | - # Check for folders and possible/available configurations | |
| 103 | - chains = os.listdir(self.datapath) | |
| 104 | - | |
| 105 | - # Initialise folder dictionary | |
| 106 | - folders = {} | |
| 107 | - | |
| 108 | - # Loop over possible analysis chains | |
| 109 | - for chain in chains: | |
| 110 | - | |
| 111 | - # Omit hidden files/folders | |
| 112 | - if chain[0]=="." or not os.path.isdir(self.datapath+"/"+chain): | |
| 113 | - continue | |
| 114 | - | |
| 115 | - # Initialise dictionary per chain | |
| 116 | - folders[chain] = {} | |
| 117 | - | |
| 118 | - # Read available DST versions | |
| 119 | - dstversions = os.listdir(self.datapath+"/"+chain) | |
| 120 | - | |
| 121 | - # Loop over DST versions | |
| 122 | - for dstver in dstversions: | |
| 123 | - | |
| 124 | - # Omit hidden files/folders | |
| 125 | - if dstver[0] == "." or not os.path.isdir(self.datapath+"/"+chain+"/"+dstver): | |
| 126 | - continue | |
| 127 | - | |
| 128 | - # Initialise available cut configurations | |
| 129 | - folders[chain][dstver] = [] | |
| 130 | - configs = os.listdir(self.datapath+"/"+chain+"/"+dstver) | |
| 131 | - | |
| 132 | - # Loop over configurations | |
| 133 | - for config in configs: | |
| 134 | - | |
| 135 | - # Omit hidden files/folders | |
| 136 | - if config[0] == "." or not os.path.isdir(self.datapath+"/"+chain+"/"+dstver+"/"+config): | |
| 137 | - continue | |
| 138 | - | |
| 139 | - # Append configuration to corresponding dictionary | |
| 140 | - folders[chain][dstver].append(config) | |
| 141 | - | |
| 142 | - # Check for appropriate folder structure | |
| 143 | - checked_folders = self.check_structure(folders) | |
| 144 | - if not len(checked_folders): | |
| 145 | - raise KeyError("Appropriate folder structure not found in $HESSFITS. The correct structure can be found on HESS internal documentation") | |
| 146 | - | |
| 147 | - # Create default parfile | |
| 148 | - pars = gammalib.GApplicationPars() | |
| 149 | - | |
| 150 | - # Create parameters for each available config | |
| 151 | - avchains = "" | |
| 152 | - for chain in checked_folders: | |
| 153 | - avchains += chain +"|" | |
| 154 | - avdsts = "" | |
| 155 | - for dstver in checked_folders[chain]: | |
| 156 | - avdsts+=dstver+"|" | |
| 157 | - avconfigs = "" | |
| 158 | - for config in checked_folders[chain][dstver]: | |
| 159 | - avconfigs += config+"|" | |
| 160 | - pars.append(gammalib.GApplicationPar(chain+"_"+dstver+"_config","s","a",checked_folders[chain][dstver][0],avconfigs[:-1],"","Analysis configuration")) | |
| 161 | - pars.append(gammalib.GApplicationPar(chain+"_dstver","s","a",checked_folders[chain].keys()[0],avdsts[:-1],"","DST version")) | |
| 162 | - pars.append(gammalib.GApplicationPar("chain","s","a",checked_folders.keys()[0],avchains[:-1],"","Analysis chain")) | |
| 163 | - pars.append(gammalib.GApplicationPar("runlistfile","f","a","runlist.lis","","","Runlist file")) | |
| 164 | - pars.append(gammalib.GApplicationPar("inmodel","f","h","NONE","","","Input model XML file (optional)")) | |
| 165 | - pars.append(gammalib.GApplicationPar("outobs","f","a","obs.xml","","","Observation XML outfile")) | |
| 166 | - pars.append(gammalib.GApplicationPar("outmodel","f","a","bgmodels.xml","","","Output model XML file")) | |
| 167 | - pars.append(gammalib.GApplicationPar("datapath","s","h",self.datapath,"","","Data directoy")) | |
| 168 | - pars.append(gammalib.GApplicationPar("bkgpars","i","a","1","","","Number of free parameters per background model")) | |
| 169 | - pars.append(gammalib.GApplicationPar("usetrig","b","h","yes","yes|no","","Pre-estimate background normalisation? Recommended for binned analysis")) | |
| 170 | - pars.append(gammalib.GApplicationPar("bkgtype","s","a","irf","gauss|irf|aeff","","What background model should be used")) | |
| 171 | - pars.append_standard() | |
| 172 | - pars.save(parfile) | |
| 173 | - | |
| 174 | - # Return | |
| 175 | - return | |
| 176 | - | |
| 177 | - def get_parameters(self): | |
| 178 | - """ | |
| 179 | - Get parameters from parfile and setup the observation. | |
| 180 | - """ | |
| 181 | - # Get parameters | |
| 182 | - self.runlistfile = self["runlistfile"].filename() | |
| 183 | - | |
| 184 | - # Read models if user input | |
| 185 | - self.inmodel = self["inmodel"].filename() | |
| 186 | - if not (self.inmodel == "NONE" or self.inmodel == ""): | |
| 187 | - self.inmodels = gammalib.GModels(self.inmodel) | |
| 188 | - | |
| 189 | - # Observation outfile | |
| 190 | - self.outobs = self["outobs"].filename() | |
| 191 | - | |
| 192 | - # Output model file | |
| 193 | - self.outmodel = self["outmodel"].filename() | |
| 194 | - | |
| 195 | - # Read hidden parameters | |
| 196 | - self.bkgpars = self["bkgpars"].integer() | |
| 197 | - self.bkgtype = self["bkgtype"].string() | |
| 198 | - self.usetrig = self["usetrig"].boolean() | |
| 199 | - self.datapath = self["datapath"].string() | |
| 200 | - | |
| 201 | - # Read run configuration parameters | |
| 202 | - self.chain = self["chain"].string() | |
| 203 | - self.dstver = self[self.chain+"_dstver"].string() | |
| 204 | - self.config = self[self.chain+"_"+self.dstver+"_config"].string() | |
| 205 | - | |
| 206 | - # Build directory name prefix | |
| 207 | - self.directory = self.datapath+"/" | |
| 208 | - self.directory += self.chain +"/" | |
| 209 | - self.directory += self.dstver +"/" | |
| 210 | - self.directory += self.config +"/" | |
| 211 | - | |
| 212 | - if not os.path.isdir(self.directory): | |
| 213 | - raise gammalib.Exception.runtime_error("Folder structure not found. Please check your HESSFITS environment variable") | |
| 214 | - | |
| 215 | - self.m_log = False # Logging in client tools | |
| 216 | - self.m_debug = False # Debugging in client tools | |
| 217 | - self.m_clobber = self["clobber"].boolean() | |
| 218 | - | |
| 219 | - # Return | |
| 220 | - return | |
| 221 | - | |
| 222 | - def check_structure(self,folders): | |
| 223 | - | |
| 224 | - # Initialise valid folders | |
| 225 | - newfolders = {} | |
| 226 | - | |
| 227 | - # Check if we have found possible chains | |
| 228 | - if len(folders): | |
| 229 | - | |
| 230 | - # Loop over chains | |
| 231 | - for chain in folders: | |
| 232 | - | |
| 233 | - # Loop over dst versions | |
| 234 | - for dst in folders[chain]: | |
| 235 | - | |
| 236 | - # Loop over configs: | |
| 237 | - for config in folders[chain][dst]: | |
| 238 | - | |
| 239 | - # check if config is valid | |
| 240 | - path = self.datapath+"/"+chain+"/"+dst+"/"+config | |
| 241 | - if os.path.isdir(path) and len(glob.glob(path+"/run*")): | |
| 242 | - if not chain in newfolders: | |
| 243 | - newfolders[chain] = {} | |
| 244 | - if not dst in newfolders[chain]: | |
| 245 | - newfolders[chain][dst] = [] | |
| 246 | - newfolders[chain][dst].append(config) | |
| 247 | - | |
| 248 | - # Return valid configs | |
| 249 | - return newfolders | |
| 250 | - | |
| 251 | - def background_spectrum(self, run, prefactor, index, aefffile = ""): | |
| 252 | - | |
| 253 | - scale = pow(10,math.floor(math.log10(abs(prefactor)))) | |
| 254 | - | |
| 255 | - if index == 0.0 and self.bkgpars <= 1: | |
| 256 | - spec = gammalib.GModelSpectralConst() | |
| 257 | - spec["Value"].min(0.1*scale) | |
| 258 | - spec["Value"].max(10*scale) | |
| 259 | - spec["Value"].value(prefactor) | |
| 260 | - spec["Value"].scale(scale) | |
| 261 | - if self.bkgpars == 0: | |
| 262 | - spec["Value"].fix() | |
| 263 | - else: | |
| 264 | - spec["Value"].free() | |
| 265 | - | |
| 266 | - else: | |
| 267 | - | |
| 268 | - # Create power law if number of free parameters are less 2 or less | |
| 269 | - if self.bkgpars <= 2: | |
| 270 | - e = gammalib.GEnergy(1.0,"TeV") | |
| 271 | - spec = gammalib.GModelSpectralPlaw(prefactor, index, e) | |
| 272 | - | |
| 273 | - # Set parameter ranges | |
| 274 | - spec[0].scale(scale) | |
| 275 | - spec[0].min(0.01 * scale) | |
| 276 | - spec[0].max(100.0 * scale) | |
| 277 | - spec[1].scale(1) | |
| 278 | - spec[1].min(-5.0) | |
| 279 | - spec[1].max(5.0) | |
| 280 | - | |
| 281 | - # Set number of free parameters | |
| 282 | - if self.bkgpars == 0: | |
| 283 | - spec[0].fix() | |
| 284 | - spec[1].fix() | |
| 285 | - elif self.bkgpars == 1: | |
| 286 | - spec[0].free() | |
| 287 | - spec[1].fix() | |
| 288 | - else: | |
| 289 | - spec[0].free() | |
| 290 | - spec[1].free() | |
| 291 | - | |
| 292 | - else: | |
| 293 | - | |
| 294 | - # Use several energy-dependent scaling factors | |
| 295 | - fits = gammalib.GFits(aefffile) | |
| 296 | - emin = fits["EFFECTIVE AREA"].real("LO_THRES") | |
| 297 | - emax = fits["EFFECTIVE AREA"].real("HI_THRES") | |
| 298 | - fits.close() | |
| 299 | - | |
| 300 | - # Create reference powerlaw | |
| 301 | - plaw = gammalib.GModelSpectralPlaw(prefactor, index, gammalib.GEnergy(1.0,"TeV")) | |
| 302 | - | |
| 303 | - # Create spectral model and energy values | |
| 304 | - spec = gammalib.GModelSpectralNodes() | |
| 305 | - bounds = gammalib.GEbounds(self.bkgpars,gammalib.GEnergy(emin,"TeV"),gammalib.GEnergy(emax,"TeV"),True) | |
| 306 | - for i in range(bounds.size()): | |
| 307 | - energy = bounds.elogmean(i) | |
| 308 | - spec.append(energy, plaw.eval(energy, gammalib.GTime())) | |
| 309 | - for par in spec: | |
| 310 | - | |
| 311 | - if "Energy" in par.name(): | |
| 312 | - par.fix() | |
| 313 | - elif "Intensity" in par.name(): | |
| 314 | - parscale = pow(10,math.floor(math.log10(abs(par.value())))) | |
| 315 | - par.scale(parscale) | |
| 316 | - par.min(0.01*parscale) | |
| 317 | - par.max(100.0*parscale) | |
| 318 | - | |
| 319 | - | |
| 320 | - return spec | |
| 321 | - | |
| 322 | - def hess_background(self, run, aefffile, trgrate, zenith): | |
| 323 | - | |
| 324 | - # Set IrfBackground | |
| 325 | - if self.bkgtype == "irf": | |
| 326 | - prefactor = 1.0 | |
| 327 | - index = 0.0 | |
| 328 | - if self.usetrig and trgrate > 0.0: | |
| 329 | - # Use value from lookup | |
| 330 | - prefactor = 0.00427233352611 * trgrate + 0.181244590076 | |
| 331 | - spec = self.background_spectrum(run, prefactor, index, aefffile) | |
| 332 | - # Create background model instance | |
| 333 | - bck = gammalib.GCTAModelIrfBackground(spec) | |
| 334 | - | |
| 335 | - # Set AeffBackground | |
| 336 | - elif self.bkgtype == "aeff": | |
| 337 | - prefactor = 5e-14 | |
| 338 | - index = -2.5 | |
| 339 | - # Use values from lookup if possible | |
| 340 | - if self.usetrig and trgrate > 0.0: | |
| 341 | - prefactor = 1.52976410372e-16 * trgrate + 2.71805547108e-14 | |
| 342 | - if zenith > 0.0: | |
| 343 | - index = 0.000271928721732 * zenith * zenith -0.0029602286453 * zenith -2.76404600416 | |
| 344 | - | |
| 345 | - spec = self.background_spectrum(run, prefactor, index, aefffile) | |
| 346 | - | |
| 347 | - # Create background model instance | |
| 348 | - bck = gammalib.GCTAModelAeffBackground(spec) | |
| 349 | - | |
| 350 | - # Set Gaussian Background | |
| 351 | - elif self.bkgtype == "gauss": | |
| 352 | - spec = self.background_spectrum(run, 1e-4, -1.8, aefffile) | |
| 353 | - radial = gammalib.GCTAModelRadialGauss(2.5) | |
| 354 | - bck = gammalib.GCTAModelRadialAcceptance(radial, spec) | |
| 355 | - | |
| 356 | - else: | |
| 357 | - sys.exit("Background type \""+self.bkgtype+"\" unsupported") | |
| 358 | - | |
| 359 | - # Copy model | |
| 360 | - model = bck.clone() | |
| 361 | - | |
| 362 | - # Assign specific run id | |
| 363 | - model.ids(str(int(run))) | |
| 364 | - | |
| 365 | - # Assign instrument | |
| 366 | - model.instruments("HESS") | |
| 367 | - | |
| 368 | - # Set name (arbitrary) | |
| 369 | - model.name("bkg_"+run) | |
| 370 | - | |
| 371 | - # Turn off TS calculation for background model | |
| 372 | - model.tscalc(False) | |
| 373 | - | |
| 374 | - # Return model | |
| 375 | - return model | |
| 376 | - | |
| 377 | - | |
| 378 | - def erange(self): | |
| 379 | - """ | |
| 380 | - Returns runlist energy range | |
| 381 | - """ | |
| 382 | - return self.m_erange | |
| 383 | - | |
| 384 | - def execute(self): | |
| 385 | - """ | |
| 386 | - Execute the script. | |
| 387 | - """ | |
| 388 | - # Run the script | |
| 389 | - self.run() | |
| 390 | - | |
| 391 | - # Save residual map | |
| 392 | - self.save(self.outobs, self.m_clobber) | |
| 393 | - | |
| 394 | - # Return | |
| 395 | - return | |
| 396 | - | |
| 397 | - # Get runfolder from runnumber (subject to defined folder structure) | |
| 398 | - def get_runfolder(self,runnr): | |
| 399 | - | |
| 400 | - start = runnr[:-2]+"00" | |
| 401 | - if not int(runnr[-3]) % 2 == 0: | |
| 402 | - start = str(int(start)-100) | |
| 403 | - if len(start) == 5: | |
| 404 | - start = "0"+start | |
| 405 | - int_end = int(start)+199 | |
| 406 | - end = str(int_end) | |
| 407 | - if len(end) == 5: | |
| 408 | - end = "0"+ end | |
| 409 | - | |
| 410 | - runfold = runnr | |
| 411 | - if len(runfold) == 5: | |
| 412 | - runfold = "0"+runfold | |
| 413 | - | |
| 414 | - return self.directory+"/run"+start+"-"+end+"/run"+runfold+"/" | |
| 415 | - | |
| 416 | - def run(self): | |
| 417 | - """ | |
| 418 | - Run the script. | |
| 419 | - """ | |
| 420 | - # Switch screen logging on in debug mode | |
| 421 | - if self.logDebug(): | |
| 422 | - self.log.cout(True) | |
| 423 | - | |
| 424 | - # Get parameters | |
| 425 | - self.get_parameters() | |
| 426 | - | |
| 427 | - # Write input parameters into logger | |
| 428 | - if self.logTerse(): | |
| 429 | - self.log_parameters() | |
| 430 | - self.log("\n") | |
| 431 | - | |
| 432 | - # Initialise empty models | |
| 433 | - self.models = gammalib.GModels() | |
| 434 | - | |
| 435 | - # Initialise empty xml file and append an observation list | |
| 436 | - self.xml = gammalib.GXml() | |
| 437 | - self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) | |
| 438 | - lib = self.xml.element("observation_list", 0) | |
| 439 | - | |
| 440 | - # Read runlist from file | |
| 441 | - runlist = [] | |
| 442 | - runfile = open(self.runlistfile) | |
| 443 | - for line in runfile.readlines(): | |
| 444 | - if len(line) == 0: | |
| 445 | - continue | |
| 446 | - if line[0] == '#': | |
| 447 | - continue | |
| 448 | - if len(line.split()) > 0: | |
| 449 | - runlist.append(line.split()[0]) | |
| 450 | - else: | |
| 451 | - runlist.append('') | |
| 452 | - runfile.close() | |
| 453 | - | |
| 454 | - # Loop over runs | |
| 455 | - # Log output | |
| 456 | - if self.logTerse(): | |
| 457 | - self.log("\n") | |
| 458 | - self.log.header1("Looping over runs") | |
| 459 | - | |
| 460 | - # Initialise energy range values for logging | |
| 461 | - runlist_emin = 100.0 | |
| 462 | - runlist_emax = 0.0 | |
| 463 | - | |
| 464 | - for runnr in runlist: | |
| 465 | - | |
| 466 | - # Unify run number string length | |
| 467 | - run = runnr | |
| 468 | - if len(run) == 5: | |
| 469 | - run = "0"+run | |
| 470 | - | |
| 471 | - # Get folder in which run files should be located | |
| 472 | - runfolder = self.get_runfolder(run) | |
| 473 | - | |
| 474 | - # construct filenames | |
| 475 | - eventfile = runfolder + "hess_events_"+run+".fits.gz" | |
| 476 | - aefffile = runfolder + "hess_aeff_2d_"+run+".fits.gz" | |
| 477 | - psffile = runfolder + "hess_psf_king_"+run+".fits.gz" | |
| 478 | - edispfile = runfolder + "hess_edisp_2d_"+run+".fits.gz" | |
| 479 | - bgfile = runfolder + "hess_bkg_offruns_"+run+".fits.gz" | |
| 480 | - | |
| 481 | - # Check for existence of files | |
| 482 | - msg = "" | |
| 483 | - skip = False | |
| 484 | - if not os.path.isdir(runfolder): | |
| 485 | - msg = "Run "+str(int(run))+" does not exist in FITS format" | |
| 486 | - skip = True | |
| 487 | - elif not os.path.isfile(eventfile): | |
| 488 | - msg = "Run "+str(int(run))+" has no eventfile - Run is skipped" | |
| 489 | - skip = True | |
| 490 | - elif not os.path.isfile(aefffile): | |
| 491 | - msg = "Run "+str(int(run))+" has no effective area - Run is skipped" | |
| 492 | - skip = True | |
| 493 | - elif not os.path.isfile(psffile): | |
| 494 | - msg = "Run "+str(int(run))+" has no PSF - Run is skipped" | |
| 495 | - skip = True | |
| 496 | - elif not os.path.isfile(edispfile): | |
| 497 | - msg = "Warning: Run "+str(int(run))+" has no energy dispersion - usage of energy dispersion not possible" | |
| 498 | - skip = False | |
| 499 | - edispfile = "" | |
| 500 | - elif not os.path.isfile(bgfile): | |
| 501 | - msg = "Warning: Run "+str(int(run))+" has no background file - use of IRF background not possible" | |
| 502 | - skip = False | |
| 503 | - bgfile = "" | |
| 504 | - else: | |
| 505 | - msg = "Adding run "+str(int(run)) | |
| 506 | - | |
| 507 | - # Log ouput and skip run if not available | |
| 508 | - if self.logTerse(): | |
| 509 | - self.log(msg+"\n") | |
| 510 | - if skip: | |
| 511 | - continue | |
| 512 | - if self.logExplicit(): | |
| 513 | - self.log(" Event file: "+eventfile+"\n") | |
| 514 | - self.log(" Effective area: "+aefffile+"\n") | |
| 515 | - self.log(" Point spread function: "+psffile+"\n") | |
| 516 | - self.log(" Energy dispersion: "+edispfile+"\n") | |
| 517 | - self.log(" Background file: "+bgfile+"\n") | |
| 518 | - | |
| 519 | - # Open fits file to determine the observation name | |
| 520 | - fits = gammalib.GFits(eventfile) | |
| 521 | - object_name = fits["EVENTS"].string("OBJECT") | |
| 522 | - | |
| 523 | - # Retrieve trigger rate and zenith if available | |
| 524 | - trgrate = 0.0 | |
| 525 | - zenith = 0.0 | |
| 526 | - if fits["EVENTS"].has_card("ZTRGRATE"): | |
| 527 | - trgrate = fits["EVENTS"].real("ZTRGRATE") | |
| 528 | - if fits["EVENTS"].has_card("ALT_PNT"): | |
| 529 | - zenith = 90.-fits["EVENTS"].real("ALT_PNT") | |
| 530 | - | |
| 531 | - # Close FITS file | |
| 532 | - fits.close() | |
| 533 | - | |
| 534 | - # Open effective area file to look for threshold | |
| 535 | - aeff_fits = gammalib.GFits(aefffile) | |
| 536 | - run_emin = aeff_fits["EFFECTIVE AREA"].real("LO_THRES") | |
| 537 | - run_emax = aeff_fits["EFFECTIVE AREA"].real("HI_THRES") | |
| 538 | - if run_emin < runlist_emin: | |
| 539 | - runlist_emin = run_emin | |
| 540 | - if run_emax > runlist_emax: | |
| 541 | - runlist_emax = run_emax | |
| 542 | - aeff_fits.close() | |
| 543 | - | |
| 544 | - # Append observation to XML and set attributes | |
| 545 | - obs = lib.append("observation"); | |
| 546 | - obs.attribute("name", object_name); | |
| 547 | - obs.attribute("id", str(int(run))); | |
| 548 | - obs.attribute("instrument", "HESS"); | |
| 549 | - | |
| 550 | - # Append event file | |
| 551 | - par = gammalib.GXmlElement("parameter name=\"EventList\"") | |
| 552 | - par.attribute("file", eventfile); | |
| 553 | - obs.append(par) | |
| 554 | - | |
| 555 | - # Append effective area | |
| 556 | - aeff = gammalib.GXmlElement("parameter name=\"EffectiveArea\"") | |
| 557 | - aeff.attribute("file",aefffile) | |
| 558 | - | |
| 559 | - # Append PSF | |
| 560 | - psf = gammalib.GXmlElement("parameter name=\"PointSpreadFunction\"") | |
| 561 | - psf.attribute("file",psffile) | |
| 562 | - | |
| 563 | - # Append energy dispersion | |
| 564 | - edisp = gammalib.GXmlElement("parameter name=\"EnergyDispersion\"") | |
| 565 | - edisp.attribute("file",edispfile) | |
| 566 | - | |
| 567 | - # Append background | |
| 568 | - bck = gammalib.GXmlElement("parameter name=\"Background\"") | |
| 569 | - bck.attribute("file",bgfile) | |
| 570 | - | |
| 571 | - # assign events and IRFs to observation | |
| 572 | - obs.append(aeff) | |
| 573 | - obs.append(psf) | |
| 574 | - obs.append(edisp) | |
| 575 | - obs.append(bck) | |
| 576 | - | |
| 577 | - # Append instrumental background model | |
| 578 | - self.models.append(self.hess_background(run, aefffile, trgrate, zenith)) | |
| 579 | - | |
| 580 | - # Continue only if there are observations available | |
| 581 | - if lib.size(): | |
| 582 | - | |
| 583 | - # Store energy range as member | |
| 584 | - self.m_erange = gammalib.GEbounds(gammalib.GEnergy(runlist_emin,"TeV"),gammalib.GEnergy(runlist_emax,"TeV")) | |
| 585 | - | |
| 586 | - # Write energy range into log file | |
| 587 | - if self.logTerse(): | |
| 588 | - self.log("\n") | |
| 589 | - self.log("Eenrgy range of obervation list: ") | |
| 590 | - self.log(("% 3.2f" % runlist_emin)+" - "+("% 3.2f" % runlist_emax)+" TeV") | |
| 591 | - | |
| 592 | - else: | |
| 593 | - self.log.header2("WARNING: No observation from given runlist available") | |
| 594 | - | |
| 595 | - # Append models provided by 'inmodels' if necessary | |
| 596 | - if not self.inmodels == None: | |
| 597 | - if self.logTerse(): | |
| 598 | - self.log("\n") | |
| 599 | - self.log.header1("Appending models") | |
| 600 | - | |
| 601 | - # Loop over input models | |
| 602 | - for model in self.inmodels: | |
| 603 | - if self.logTerse(): | |
| 604 | - self.log.header3("Adding model \""+model.name()+"\"") | |
| 605 | - self.models.append(model) | |
| 606 | - | |
| 607 | - # Return | |
| 608 | - return | |
| 609 | - | |
| 610 | - def save(self,outfile,clobber): | |
| 611 | - | |
| 612 | - # Save observation XML file | |
| 613 | - self.xml.save(outfile) | |
| 614 | - | |
| 615 | - # Save model XML file | |
| 616 | - self.models.save(self.outmodel) | |
| 617 | - | |
| 618 | - | |
| 619 | -# ======================== # | |
| 620 | -# Main routine entry point # | |
| 621 | -# ======================== # | |
| 622 | -if __name__ == '__main__': | |
| 623 | - """ | |
| 624 | - Generates observation file. | |
| 625 | - """ | |
| 626 | - # Create instance of application | |
| 627 | - app = cshessobs(sys.argv) | |
| 628 | - | |
| 629 | - # Open logfile | |
| 630 | - app.logFileOpen() | |
| 631 | - | |
| 632 | - # Execute application | |
| 633 | - app.execute() |
cscripts/csiactdata.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Inspection of IACT data storage | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 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 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | +import os | |
| 25 | +import json | |
| 26 | + | |
| 27 | + | |
| 28 | +# ================ # | |
| 29 | +# csiactdata class # | |
| 30 | +# ================ # | |
| 31 | +class csiactdata(ctools.cscript): | |
| 32 | + """ | |
| 33 | + This script inspects the available FITS data storage on the user machine | |
| 34 | + and writes information about the available FITS configurations into a log | |
| 35 | + file or prints it on the screen. These information can be used as input | |
| 36 | + for 'csiactobs'. | |
| 37 | + """ | |
| 38 | + def __init__(self, *argv): | |
| 39 | + """ | |
| 40 | + Constructor. | |
| 41 | + """ | |
| 42 | + # Set name | |
| 43 | + self.name = "csiactdata" | |
| 44 | + self.version = "1.0.0" | |
| 45 | + self.datapath = os.getenv("VHEFITS","") | |
| 46 | + | |
| 47 | + # Make sure that parfile exists | |
| 48 | + file = self.parfile() | |
| 49 | + | |
| 50 | + # Initialise application | |
| 51 | + if len(argv) == 0: | |
| 52 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 53 | + elif len(argv) == 1: | |
| 54 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 55 | + else: | |
| 56 | + raise TypeError("Invalid number of arguments given.") | |
| 57 | + | |
| 58 | + # Set logger properties | |
| 59 | + self.log_header() | |
| 60 | + self.log.date(True) | |
| 61 | + | |
| 62 | + # Return | |
| 63 | + return | |
| 64 | + | |
| 65 | + def __del__(self): | |
| 66 | + """ | |
| 67 | + Destructor. | |
| 68 | + """ | |
| 69 | + # Return | |
| 70 | + return | |
| 71 | + | |
| 72 | + def parfile(self): | |
| 73 | + """ | |
| 74 | + Check if parfile exists. If parfile does not exist then create a | |
| 75 | + default parfile. This kluge avoids shipping the cscript with a | |
| 76 | + parfile. | |
| 77 | + """ | |
| 78 | + # Set parfile name | |
| 79 | + parfile = self.name+".par" | |
| 80 | + | |
| 81 | + try: | |
| 82 | + pars = gammalib.GApplicationPars(parfile) | |
| 83 | + except: | |
| 84 | + # Signal if parfile was not found | |
| 85 | + sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") | |
| 86 | + | |
| 87 | + # Create default parfile | |
| 88 | + pars = gammalib.GApplicationPars() | |
| 89 | + pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data is located")) | |
| 90 | + pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) | |
| 91 | + pars.append_standard() | |
| 92 | + pars.append(gammalib.GApplicationPar("logfile","f","h","csiactdata.log","","","Log filename")) | |
| 93 | + pars.save(parfile) | |
| 94 | + | |
| 95 | + # Return | |
| 96 | + return | |
| 97 | + | |
| 98 | + def get_parameters(self): | |
| 99 | + """ | |
| 100 | + Get parameters from parfile and setup the observation. | |
| 101 | + """ | |
| 102 | + | |
| 103 | + # Get datapath if not already set | |
| 104 | + if self.datapath == "": | |
| 105 | + self.datapath = self["datapath"].string() | |
| 106 | + | |
| 107 | + # Expand environment | |
| 108 | + self.datapath = gammalib.expand_env(self.datapath) | |
| 109 | + | |
| 110 | + # Get filename of master index file | |
| 111 | + self.m_master_indx = self["master_indx"].string() | |
| 112 | + self.m_master_file = os.path.join(self.datapath, self.m_master_indx) | |
| 113 | + | |
| 114 | + # Return | |
| 115 | + return | |
| 116 | + | |
| 117 | + def execute(self): | |
| 118 | + """ | |
| 119 | + Execute the script. | |
| 120 | + """ | |
| 121 | + # Run the script | |
| 122 | + self.run() | |
| 123 | + | |
| 124 | + # Return | |
| 125 | + return | |
| 126 | + | |
| 127 | + def run(self): | |
| 128 | + """ | |
| 129 | + Run the script. | |
| 130 | + """ | |
| 131 | + # Switch screen logging on | |
| 132 | + self.log.cout(True) | |
| 133 | + | |
| 134 | + # Get parameters | |
| 135 | + self.get_parameters() | |
| 136 | + | |
| 137 | + # Write input parameters into logger | |
| 138 | + if self.logTerse(): | |
| 139 | + self.log_parameters() | |
| 140 | + self.log("\n") | |
| 141 | + | |
| 142 | + self.log("\n") | |
| 143 | + self.log.header1("Data storage entries") | |
| 144 | + self.log("\n") | |
| 145 | + self.log.parformat("Master index file") | |
| 146 | + self.log(self.m_master_file) | |
| 147 | + self.log("\n") | |
| 148 | + self.log("\n") | |
| 149 | + | |
| 150 | + # Open and load JSON file | |
| 151 | + json_data = open(self.m_master_file).read() | |
| 152 | + data = json.loads(json_data) | |
| 153 | + configs = data["datasets"] | |
| 154 | + | |
| 155 | + # Loop over configs and display unavailable storage first | |
| 156 | + for config in configs: | |
| 157 | + | |
| 158 | + # Create hdu and obs index files | |
| 159 | + hdu = os.path.join(self.datapath, config["hduindx"]) | |
| 160 | + obs = os.path.join(self.datapath, config["obsindx"]) | |
| 161 | + | |
| 162 | + # Check if index files are available | |
| 163 | + if not (gammalib.is_fits(str(hdu)) and gammalib.is_fits(str(obs))): | |
| 164 | + self.log.parformat(str(config["name"])) | |
| 165 | + self.log("Not available") | |
| 166 | + self.log("\n") | |
| 167 | + | |
| 168 | + # Loop over configs and log available configs | |
| 169 | + for config in configs: | |
| 170 | + | |
| 171 | + # Create hdu and obs index files | |
| 172 | + hdu = os.path.join(self.datapath, config["hduindx"]) | |
| 173 | + obs = os.path.join(self.datapath, config["obsindx"]) | |
| 174 | + | |
| 175 | + # Check if index files are available | |
| 176 | + if gammalib.is_fits(str(hdu)) and gammalib.is_fits(str(obs)): | |
| 177 | + | |
| 178 | + # Log data information | |
| 179 | + self.log("\n") | |
| 180 | + self.log.header3(str(config["name"])) | |
| 181 | + for key in config: | |
| 182 | + self.log.parformat(str(key)) | |
| 183 | + self.log(str(config[key])) | |
| 184 | + self.log("\n") | |
| 185 | + | |
| 186 | + # Return | |
| 187 | + return | |
| 188 | + | |
| 189 | +# ======================== # | |
| 190 | +# Main routine entry point # | |
| 191 | +# ======================== # | |
| 192 | +if __name__ == '__main__': | |
| 193 | + """ | |
| 194 | + Shows data storage information | |
| 195 | + """ | |
| 196 | + # Create instance of application | |
| 197 | + app = csiactdata(sys.argv) | |
| 198 | + | |
| 199 | + # Open logfile | |
| 200 | + app.logFileOpen() | |
| 201 | + | |
| 202 | + # Execute application | |
| 203 | + app.execute() | ... | ... |
cscripts/csiactobs.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Generation of an IACT observation definition file. | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 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 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | +import os | |
| 25 | +import json | |
| 26 | + | |
| 27 | + | |
| 28 | +# =============== # | |
| 29 | +# csiactobs class # | |
| 30 | +# =============== # | |
| 31 | +class csiactobs(ctools.cscript): | |
| 32 | + """ | |
| 33 | + This class implements the creation of a observation xml file for IACT | |
| 34 | + data analysis. This class is dedicated for use inside a IACT | |
| 35 | + Collaboration, i.e. it can only be used if you have access to IACT data | |
| 36 | + in FITS format. The FITS data has to be structured and in the format | |
| 37 | + described here: | |
| 38 | + http://gamma-astro-data-formats.readthedocs.org/en/latest/ | |
| 39 | + """ | |
| 40 | + def __init__(self, *argv): | |
| 41 | + """ | |
| 42 | + Constructor. | |
| 43 | + """ | |
| 44 | + # Set name and version | |
| 45 | + self.name = "csiactobs" | |
| 46 | + self.version = "1.0.0" | |
| 47 | + | |
| 48 | + # Initialise some members | |
| 49 | + self.m_erange = gammalib.GEbounds() | |
| 50 | + self.datapath = os.getenv("VHEFITS","") | |
| 51 | + self.inmodels = None | |
| 52 | + self.outobs = "obs.xml" | |
| 53 | + | |
| 54 | + # Make sure that parfile exists | |
| 55 | + file = self.parfile() | |
| 56 | + | |
| 57 | + # Initialise application | |
| 58 | + if len(argv) == 0: | |
| 59 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 60 | + elif len(argv) == 1: | |
| 61 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 62 | + else: | |
| 63 | + raise TypeError("Invalid number of arguments given.") | |
| 64 | + | |
| 65 | + # Set logger properties | |
| 66 | + self.log_header() | |
| 67 | + self.log.date(True) | |
| 68 | + | |
| 69 | + # Return | |
| 70 | + return | |
| 71 | + | |
| 72 | + def __del__(self): | |
| 73 | + """ | |
| 74 | + Destructor. | |
| 75 | + """ | |
| 76 | + # Return | |
| 77 | + return | |
| 78 | + | |
| 79 | + def parfile(self): | |
| 80 | + """ | |
| 81 | + Check if parfile exists. If parfile does not exist then create a | |
| 82 | + default parfile. This kluge avoids shipping the cscript with a parfile. | |
| 83 | + """ | |
| 84 | + # Set parfile name | |
| 85 | + parfile = self.name+".par" | |
| 86 | + | |
| 87 | + try: | |
| 88 | + pars = gammalib.GApplicationPars(parfile) | |
| 89 | + except: | |
| 90 | + # Signal if parfile was not found | |
| 91 | + sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") | |
| 92 | + | |
| 93 | + # Create default parfile | |
| 94 | + pars = gammalib.GApplicationPars() | |
| 95 | + pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data is located")) | |
| 96 | + pars.append(gammalib.GApplicationPar("prodname","s","a","","","","Data storage name (Run csdsinfo to view your options)")) | |
| 97 | + pars.append(gammalib.GApplicationPar("runlistfile","f","a","runlist.lis","","","Runlist file")) | |
| 98 | + pars.append(gammalib.GApplicationPar("bkgpars","i","a","1","","","Number of free parameters per background model")) | |
| 99 | + pars.append(gammalib.GApplicationPar("outobs","f","a","obs.xml","","","Observation XML outfile")) | |
| 100 | + pars.append(gammalib.GApplicationPar("outmodel","f","a","bgmodels.xml","","","Output model XML file")) | |
| 101 | + pars.append(gammalib.GApplicationPar("inmodel","f","h","NONE","","","Input model XML file (optional)")) | |
| 102 | + pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) | |
| 103 | + pars.append(gammalib.GApplicationPar("ev_hiera","s","h","events","","","Hierarchy of event formats")) | |
| 104 | + pars.append(gammalib.GApplicationPar("aeff_hiera","s","h","aeff_2d","","","Hierarchy of effective area formats")) | |
| 105 | + pars.append(gammalib.GApplicationPar("psf_hiera","s","h","psf_king|psf_3gauss","","","Hierarchy of psf formats")) | |
| 106 | + pars.append(gammalib.GApplicationPar("edisp_hiera","s","h","edisp_2d","","","Hierarchy of energy dispersion formats")) | |
| 107 | + pars.append(gammalib.GApplicationPar("bkg_hiera","s","h","bkg_3d","","","Hierarchy of background formats")) | |
| 108 | + pars.append(gammalib.GApplicationPar("bkg_mod_hiera","s","h","irf","irf|aeff|gauss","","Hierarchy of background models")) | |
| 109 | + pars.append(gammalib.GApplicationPar("bkg_gauss_norm","r","h","1e-8","","","Input normalisation for Gaussian background")) | |
| 110 | + pars.append(gammalib.GApplicationPar("bkg_gauss_index","r","h","-2.0","","","Input spectral index for Gaussian background")) | |
| 111 | + pars.append(gammalib.GApplicationPar("bkg_gauss_sigma","r","h","2.5","","","Input sigma for Gaussian background")) | |
| 112 | + pars.append(gammalib.GApplicationPar("bkg_aeff_norm","r","h","1e-14","","","Input normalisation for effective area background")) | |
| 113 | + pars.append(gammalib.GApplicationPar("bkg_aeff_index","r","h","-2.0","","","Input spectral index for effective area background")) | |
| 114 | + pars.append(gammalib.GApplicationPar("bkg_range_factor","r","h","100.0","","","Factor to determine range of background normalisation")) | |
| 115 | + pars.append_standard() | |
| 116 | + pars.append(gammalib.GApplicationPar("logfile","f","h","csiactobs.log","","","Log filename")) | |
| 117 | + pars.save(parfile) | |
| 118 | + | |
| 119 | + # Return | |
| 120 | + return | |
| 121 | + | |
| 122 | + def get_parameters(self): | |
| 123 | + """ | |
| 124 | + Get parameters from parfile and setup the observation. | |
| 125 | + """ | |
| 126 | + | |
| 127 | + if self.datapath == "": | |
| 128 | + self.datapath = self["datapath"].string() | |
| 129 | + | |
| 130 | + # Expand environment | |
| 131 | + self.datapath = gammalib.expand_env(self.datapath) | |
| 132 | + | |
| 133 | + # Read user parameters | |
| 134 | + self.m_prodname = self["prodname"].string() | |
| 135 | + self.m_runlistfile = gammalib.expand_env(self["runlistfile"].filename()) | |
| 136 | + self.m_bkgpars = self["bkgpars"].integer() | |
| 137 | + | |
| 138 | + # Output model file | |
| 139 | + self.outmodel = self["outmodel"].filename() | |
| 140 | + | |
| 141 | + # Observation outfile | |
| 142 | + self.outobs = self["outobs"].filename() | |
| 143 | + | |
| 144 | + # Master index file name | |
| 145 | + self.m_master_indx = self["master_indx"].string() | |
| 146 | + | |
| 147 | + # Read hierarchy of file loading | |
| 148 | + self.m_ev_hiera = self["ev_hiera"].string().split("|") | |
| 149 | + self.m_aeff_hiera = self["aeff_hiera"].string().split("|") | |
| 150 | + self.m_psf_hiera = self["psf_hiera"].string().split("|") | |
| 151 | + self.m_bkg_hiera = self["bkg_hiera"].string().split("|") | |
| 152 | + self.m_edisp_hiera = self["edisp_hiera"].string().split("|") | |
| 153 | + self.m_bkg_mod_hiera = self["bkg_mod_hiera"].string().split("|") | |
| 154 | + | |
| 155 | + # Read hidden background parameters | |
| 156 | + self.m_bkg_gauss_norm = self["bkg_gauss_norm"].real() | |
| 157 | + self.m_bkg_gauss_index = self["bkg_gauss_index"].real() | |
| 158 | + self.m_bkg_gauss_sigma = self["bkg_gauss_sigma"].real() | |
| 159 | + self.m_bkg_aeff_index = self["bkg_aeff_index"].real() | |
| 160 | + self.m_bkg_aeff_norm = self["bkg_aeff_norm"].real() | |
| 161 | + self.m_bkg_range_factor = self["bkg_range_factor"].real() | |
| 162 | + | |
| 163 | + # Open master index file and look for prodname | |
| 164 | + master_file = os.path.join(self.datapath, self.m_master_indx) | |
| 165 | + if not os.path.isfile(master_file): | |
| 166 | + raise RuntimeError("FITS data store not available. No master index file found. Make sure the file is copied from the server and your datapath is set correctly.") | |
| 167 | + | |
| 168 | + # Open and load JSON file | |
| 169 | + json_data = open(master_file).read() | |
| 170 | + data = json.loads(json_data) | |
| 171 | + if not "datasets" in data: | |
| 172 | + raise RuntimeError("Key \"datasets\" not available in master index file.") | |
| 173 | + | |
| 174 | + # Get configurations | |
| 175 | + configs = data["datasets"] | |
| 176 | + | |
| 177 | + # Initialise HDUs | |
| 178 | + self.m_hdu_index = self.m_obs_index = "" | |
| 179 | + | |
| 180 | + # Get HDUs | |
| 181 | + for config in configs: | |
| 182 | + if self.m_prodname == config["name"]: | |
| 183 | + self.m_hdu_index = str(os.path.join(self.datapath, config["hduindx"])) | |
| 184 | + self.m_obs_index = str(os.path.join(self.datapath, config["obsindx"])) | |
| 185 | + break | |
| 186 | + | |
| 187 | + # Check HDUs | |
| 188 | + if self.m_hdu_index == "" or self.m_obs_index == "": | |
| 189 | + raise RuntimeError("FITS data store \""+self.m_prodname+"\" not available. Run csdsinfo to get a list of available storage names") | |
| 190 | + if not gammalib.is_fits(self.m_hdu_index+"[HDU_INDEX]"): | |
| 191 | + raise RuntimeError("HDU index file \""+self.m_hdu_index+"[HDU_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csdsinfo to get a list of available storage names.") | |
| 192 | + | |
| 193 | + # Load index | |
| 194 | + if gammalib.is_fits(self.m_obs_index+"[OBS_INDEX]"): | |
| 195 | + fits = gammalib.GFits(self.m_obs_index) | |
| 196 | + self.has_bkg_scale = fits["OBS_INDEX"].contains("BKG_SCALE") | |
| 197 | + fits.close() | |
| 198 | + else: | |
| 199 | + self.has_bkg_scale = False | |
| 200 | + | |
| 201 | + # Create base data directory from hdu index file location | |
| 202 | + self.subdir = os.path.dirname(self.m_hdu_index) | |
| 203 | + self.m_log = False # Logging in client tools | |
| 204 | + self.m_debug = False # Debugging in client tools | |
| 205 | + self.m_clobber = self["clobber"].boolean() | |
| 206 | + | |
| 207 | + # Return | |
| 208 | + return | |
| 209 | + | |
| 210 | + def background_spectrum(self, run, prefactor, index, emin, emax): | |
| 211 | + | |
| 212 | + # Handle constant spectral model | |
| 213 | + if index == 0.0 and self.m_bkgpars <= 1: | |
| 214 | + spec = gammalib.GModelSpectralConst() | |
| 215 | + spec["Value"].min(prefactor / self.m_bkg_range_factor) | |
| 216 | + spec["Value"].max(prefactor * self.m_bkg_range_factor) | |
| 217 | + spec["Value"].value(prefactor) | |
| 218 | + if self.m_bkgpars == 0: | |
| 219 | + spec["Value"].fix() | |
| 220 | + else: | |
| 221 | + spec["Value"].free() | |
| 222 | + | |
| 223 | + else: | |
| 224 | + | |
| 225 | + # Create power law model | |
| 226 | + if self.m_bkgpars <= 2: | |
| 227 | + e = gammalib.GEnergy(1.0,"TeV") | |
| 228 | + spec = gammalib.GModelSpectralPlaw(prefactor, index, e) | |
| 229 | + | |
| 230 | + # Set parameter ranges | |
| 231 | + spec[0].min(0.01 * prefactor) | |
| 232 | + spec[0].max(100.0 * prefactor) | |
| 233 | + spec[1].scale(1) | |
| 234 | + spec[1].min(-5.0) | |
| 235 | + spec[1].max(5.0) | |
| 236 | + | |
| 237 | + # Set number of free parameters | |
| 238 | + if self.m_bkgpars == 0: | |
| 239 | + spec[0].fix() | |
| 240 | + spec[1].fix() | |
| 241 | + elif self.m_bkgpars == 1: | |
| 242 | + spec[0].free() | |
| 243 | + spec[1].fix() | |
| 244 | + else: | |
| 245 | + spec[0].free() | |
| 246 | + spec[1].free() | |
| 247 | + | |
| 248 | + else: | |
| 249 | + | |
| 250 | + # Create reference powerlaw | |
| 251 | + plaw = gammalib.GModelSpectralPlaw(prefactor, index, gammalib.GEnergy(1.0,"TeV")) | |
| 252 | + | |
| 253 | + # Create spectral model and energy values | |
| 254 | + spec = gammalib.GModelSpectralNodes() | |
| 255 | + bounds = gammalib.GEbounds(self.bkgpars,gammalib.GEnergy(emin,"TeV"),gammalib.GEnergy(emax,"TeV"),True) | |
| 256 | + for i in range(bounds.size()): | |
| 257 | + energy = bounds.elogmean(i) | |
| 258 | + value = plaw.eval(energy, gammalib.GTime()) | |
| 259 | + spec.append(energy, value) | |
| 260 | + for par in spec: | |
| 261 | + | |
| 262 | + if "Energy" in par.name(): | |
| 263 | + par.fix() | |
| 264 | + elif "Intensity" in par.name(): | |
| 265 | + par.min(value / self.m_bkg_range_factor) | |
| 266 | + par.max(value * self.m_bkg_range_factor) | |
| 267 | + | |
| 268 | + # Return spectrum | |
| 269 | + return spec | |
| 270 | + | |
| 271 | + def iact_background(self, telescope, obs_id, bkg_scale, bkgtype, emin=0.1, emax=100): | |
| 272 | + | |
| 273 | + # handle IrfBackground | |
| 274 | + if bkgtype == "irf": | |
| 275 | + prefactor = 1.0 | |
| 276 | + index = 0.0 | |
| 277 | + prefactor *= bkg_scale | |
| 278 | + spec = self.background_spectrum(obs_id, prefactor, index, emin, emax) | |
| 279 | + | |
| 280 | + # Create background model instance | |
| 281 | + bck = gammalib.GCTAModelIrfBackground(spec) | |
| 282 | + | |
| 283 | + # Set AeffBackground | |
| 284 | + elif self.bkgtype == "aeff": | |
| 285 | + | |
| 286 | + prefactor = bkg_scale * self.m_bkg_aeff_norm | |
| 287 | + spec = self.background_spectrum(obs_id, prefactor, self.m_bkg_aeff_index, emin, emax) | |
| 288 | + | |
| 289 | + # Create background model instance | |
| 290 | + bck = gammalib.GCTAModelAeffBackground(spec) | |
| 291 | + | |
| 292 | + # Set Gaussian Background | |
| 293 | + elif self.bkgtype == "gauss": | |
| 294 | + prefactor = bkg_scale * self.m_bkg_gauss_norm | |
| 295 | + spec = self.background_spectrum(obs_id, prefactor, self.m_bkg_gauss_index, emin, emax) | |
| 296 | + radial = gammalib.GCTAModelRadialGauss(self.m_bkg_gauss_sigma) | |
| 297 | + bck = gammalib.GCTAModelRadialAcceptance(radial, spec) | |
| 298 | + | |
| 299 | + else: | |
| 300 | + sys.exit("Background type \""+self.bkgtype+"\" unsupported") | |
| 301 | + | |
| 302 | + # Copy model | |
| 303 | + model = bck.clone() | |
| 304 | + | |
| 305 | + # Assign specific run id | |
| 306 | + model.ids(str(obs_id)) | |
| 307 | + | |
| 308 | + # Assign instrument | |
| 309 | + model.instruments(telescope) | |
| 310 | + | |
| 311 | + # Set name (arbitrary) | |
| 312 | + model.name("bkg_"+str(obs_id)) | |
| 313 | + | |
| 314 | + # Turn off TS calculation for background model | |
| 315 | + model.tscalc(False) | |
| 316 | + | |
| 317 | + # Return model | |
| 318 | + return model | |
| 319 | + | |
| 320 | + def erange(self): | |
| 321 | + """ | |
| 322 | + Returns runlist energy range | |
| 323 | + """ | |
| 324 | + return self.m_erange | |
| 325 | + | |
| 326 | + def execute(self): | |
| 327 | + """ | |
| 328 | + Execute the script. | |
| 329 | + """ | |
| 330 | + # Run the script | |
| 331 | + self.run() | |
| 332 | + | |
| 333 | + # Save residual map | |
| 334 | + self.save(self.outobs, self.m_clobber) | |
| 335 | + | |
| 336 | + # Return | |
| 337 | + return | |
| 338 | + | |
| 339 | + def run(self): | |
| 340 | + """ | |
| 341 | + Run the script. | |
| 342 | + """ | |
| 343 | + # Switch screen logging on in debug mode | |
| 344 | + if self.logDebug(): | |
| 345 | + self.log.cout(True) | |
| 346 | + | |
| 347 | + # Get parameters | |
| 348 | + self.get_parameters() | |
| 349 | + | |
| 350 | + # Write input parameters into logger | |
| 351 | + if self.logTerse(): | |
| 352 | + self.log_parameters() | |
| 353 | + self.log("\n") | |
| 354 | + | |
| 355 | + # Initialise empty models | |
| 356 | + self.models = gammalib.GModels() | |
| 357 | + | |
| 358 | + # Initialise empty xml file and append an observation list | |
| 359 | + self.xml = gammalib.GXml() | |
| 360 | + self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) | |
| 361 | + lib = self.xml.element("observation_list", 0) | |
| 362 | + | |
| 363 | + # Read runlist from file | |
| 364 | + runlist = [] | |
| 365 | + runfile = open(self.m_runlistfile) | |
| 366 | + for line in runfile.readlines(): | |
| 367 | + if len(line) == 0: | |
| 368 | + continue | |
| 369 | + if line[0] == '#': | |
| 370 | + continue | |
| 371 | + if len(line.split()) > 0: | |
| 372 | + runlist.append(line.split()[0]) | |
| 373 | + else: | |
| 374 | + runlist.append('') | |
| 375 | + runfile.close() | |
| 376 | + | |
| 377 | + # Loop over runs | |
| 378 | + # Log output | |
| 379 | + if self.logTerse(): | |
| 380 | + self.log("\n") | |
| 381 | + self.log.header1("Looping over runs") | |
| 382 | + | |
| 383 | + # Initialise energy range values for logging | |
| 384 | + runlist_emin = 100.0 | |
| 385 | + runlist_emax = 0.0 | |
| 386 | + | |
| 387 | + for obs_id in runlist: | |
| 388 | + | |
| 389 | + obs_selection = "[OBS_ID=="+str(obs_id)+"]" | |
| 390 | + | |
| 391 | + hduindx = gammalib.GFits(self.m_hdu_index+"[HDU_INDEX]"+obs_selection) | |
| 392 | + hduindx_hdu = hduindx["HDU_INDEX"] | |
| 393 | + | |
| 394 | + eventfile = aefffile = psffile = edispfile = bkgfile = "" | |
| 395 | + eventhdu = aeffhdu = "" | |
| 396 | + | |
| 397 | + types = [] | |
| 398 | + formats = [] | |
| 399 | + for i in range(hduindx_hdu.nrows()): | |
| 400 | + types.append(hduindx_hdu["HDU_TYPE"][i]) | |
| 401 | + formats.append(hduindx_hdu["HDU_CLASS"][i]) | |
| 402 | + | |
| 403 | + # Handle events | |
| 404 | + index = -1 | |
| 405 | + for version in self.m_ev_hiera: | |
| 406 | + n = formats.count(version) | |
| 407 | + if n > 0: | |
| 408 | + index = formats.index(version) | |
| 409 | + break | |
| 410 | + if index >= 0: | |
| 411 | + eventfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 412 | + eventhdu = hduindx_hdu["HDU_NAME"][index] | |
| 413 | + eventfile += "["+eventhdu+"]" | |
| 414 | + if not gammalib.is_fits(eventfile): | |
| 415 | + if self.logTerse(): | |
| 416 | + self.log("Skipping observation "+str(obs_id)+": eventfile \""+eventfile+"\" not found\n") | |
| 417 | + continue | |
| 418 | + | |
| 419 | + # Handle Aeff | |
| 420 | + index = -1 | |
| 421 | + for version in self.m_aeff_hiera: | |
| 422 | + n = formats.count(version) | |
| 423 | + if n > 0: | |
| 424 | + index = formats.index(version) | |
| 425 | + break | |
| 426 | + if index >= 0: | |
| 427 | + aefffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 428 | + aeffhdu = hduindx_hdu["HDU_NAME"][index] | |
| 429 | + aefffile += "["+aeffhdu+"]" | |
| 430 | + if not gammalib.is_fits(aefffile): | |
| 431 | + if self.logTerse(): | |
| 432 | + self.log("Skipping observation "+str(obs_id)+": effective area \""+aefffile+"\" not found\n") | |
| 433 | + continue | |
| 434 | + | |
| 435 | + # Handle psf | |
| 436 | + index = -1 | |
| 437 | + for version in self.m_psf_hiera: | |
| 438 | + n = formats.count(version) | |
| 439 | + if n > 0: | |
| 440 | + index = formats.index(version) | |
| 441 | + break | |
| 442 | + if index >= 0: | |
| 443 | + psffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 444 | + psffile += "["+hduindx_hdu["HDU_NAME"][index]+"]" | |
| 445 | + if not gammalib.is_fits(psffile): | |
| 446 | + if self.logTerse(): | |
| 447 | + self.log("Skipping observation "+str(obs_id)+": point spread function \""+psffile+"\" not found\n") | |
| 448 | + continue | |
| 449 | + | |
| 450 | + # Handle edisp | |
| 451 | + index = -1 | |
| 452 | + for version in self.m_edisp_hiera: | |
| 453 | + n = formats.count(version) | |
| 454 | + if n > 0: | |
| 455 | + index = formats.index(version) | |
| 456 | + break | |
| 457 | + if index >= 0: | |
| 458 | + edispfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 459 | + edispfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" | |
| 460 | + if not gammalib.is_fits(edispfile): | |
| 461 | + if self.logTerse(): | |
| 462 | + self.log("Warning: observation "+str(obs_id)+" has no energy dispersion \""+edispfile+"\" information\n") | |
| 463 | + edispfile = "" | |
| 464 | + | |
| 465 | + # Handle background | |
| 466 | + index = -1 | |
| 467 | + bkg_mod_hierarchy = self.m_bkg_mod_hiera | |
| 468 | + for version in self.m_bkg_hiera: | |
| 469 | + n = formats.count(version) | |
| 470 | + if n > 0: | |
| 471 | + index = formats.index(version) | |
| 472 | + break | |
| 473 | + if index >= 0: | |
| 474 | + bkgfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) | |
| 475 | + bkgfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" | |
| 476 | + if not gammalib.is_fits(bkgfile): | |
| 477 | + if self.logTerse(): | |
| 478 | + self.log("Warning: observation "+str(obs_id)+" has no background information in \""+bkgfile+"\". IRF background cannot be used\n") | |
| 479 | + bkgfile = "" | |
| 480 | + bkg_mod_hierarchy.remove("irf") | |
| 481 | + | |
| 482 | + # Handle background scale information if available | |
| 483 | + bkg_scale = 1.0 | |
| 484 | + if self.has_bkg_scale: | |
| 485 | + obsindx = gammalib.GFits(self.m_obs_index+"[OBS_INDEX]"+obs_selection) | |
| 486 | + bkg_scale = obsindx["OBS_INDEX"]["BKG_SCALE"][0] | |
| 487 | + obsindx.close() | |
| 488 | + | |
| 489 | + # Open fits file to determine the observation name | |
| 490 | + fits = gammalib.GFits(eventfile) | |
| 491 | + events = fits[eventhdu] | |
| 492 | + object_name = events.string("OBJECT") | |
| 493 | + telescope = events.string("TELESCOP") | |
| 494 | + | |
| 495 | + # Close FITS file | |
| 496 | + fits.close() | |
| 497 | + | |
| 498 | + # Open effective area file to look for threshold | |
| 499 | + aeff_fits = gammalib.GFits(aefffile) | |
| 500 | + aeff_table = aeff_fits[aeffhdu] | |
| 501 | + | |
| 502 | + # Initialise energy range in case no threshold is available | |
| 503 | + run_emin = 0.1 | |
| 504 | + run_emax = 100.0 | |
| 505 | + | |
| 506 | + # Set energy range from heady keywords | |
| 507 | + if aeff_table.has_card("LO_THRES") and aeff_table.has_card["HI_THRES"]: | |
| 508 | + run_emin = aeff_table.real("LO_THRES") | |
| 509 | + run_emax = aeff_table.real("HI_THRES") | |
| 510 | + | |
| 511 | + # Close Aeff fits file | |
| 512 | + aeff_fits.close() | |
| 513 | + | |
| 514 | + # Adapt runlist energy range if necessary | |
| 515 | + if run_emin < runlist_emin: | |
| 516 | + runlist_emin = run_emin | |
| 517 | + if run_emax > runlist_emax: | |
| 518 | + runlist_emax = run_emax | |
| 519 | + | |
| 520 | + # Logging | |
| 521 | + if self.logTerse(): | |
| 522 | + self.log("Adding observation "+str(obs_id)+" (\""+object_name+"\")\n") | |
| 523 | + | |
| 524 | + if self.logExplicit(): | |
| 525 | + self.log(" Event file: "+eventfile+"\n") | |
| 526 | + self.log(" Effective area: "+aefffile+"\n") | |
| 527 | + self.log(" Point spread function: "+psffile+"\n") | |
| 528 | + self.log(" Energy dispersion: "+edispfile+"\n") | |
| 529 | + self.log(" Background file: "+bkgfile+"\n") | |
| 530 | + if self.has_bkg_scale: | |
| 531 | + self.log(" Background scale: "+str(bkg_scale)+"\n") | |
| 532 | + self.log("\n") | |
| 533 | + | |
| 534 | + # Append observation to XML and set attributes | |
| 535 | + obs = lib.append("observation"); | |
| 536 | + obs.attribute("name", object_name); | |
| 537 | + obs.attribute("id", str(obs_id)); | |
| 538 | + obs.attribute("instrument", telescope); | |
| 539 | + | |
| 540 | + # Append event file | |
| 541 | + ev = gammalib.GXmlElement("parameter name=\"EventList\"") | |
| 542 | + ev.attribute("file", eventfile); | |
| 543 | + | |
| 544 | + # Append effective area | |
| 545 | + aeff = gammalib.GXmlElement("parameter name=\"EffectiveArea\"") | |
| 546 | + aeff.attribute("file",aefffile) | |
| 547 | + | |
| 548 | + # Append PSF | |
| 549 | + psf = gammalib.GXmlElement("parameter name=\"PointSpreadFunction\"") | |
| 550 | + psf.attribute("file",psffile) | |
| 551 | + | |
| 552 | + # Append energy dispersion | |
| 553 | + edisp = gammalib.GXmlElement("parameter name=\"EnergyDispersion\"") | |
| 554 | + edisp.attribute("file",edispfile) | |
| 555 | + | |
| 556 | + # Append background | |
| 557 | + bck = gammalib.GXmlElement("parameter name=\"Background\"") | |
| 558 | + bck.attribute("file",bkgfile) | |
| 559 | + | |
| 560 | + # assign events and IRFs to observation | |
| 561 | + obs.append(ev) | |
| 562 | + obs.append(aeff) | |
| 563 | + obs.append(psf) | |
| 564 | + obs.append(edisp) | |
| 565 | + obs.append(bck) | |
| 566 | + | |
| 567 | + # Append instrumental background model | |
| 568 | + self.models.append(self.iact_background(telescope, obs_id, bkg_scale, bkg_mod_hierarchy[0], run_emin, run_emax)) | |
| 569 | + | |
| 570 | + # Continue only if there are observations available | |
| 571 | + if lib.size(): | |
| 572 | + | |
| 573 | + # Store energy range as member | |
| 574 | + self.m_erange = gammalib.GEbounds(gammalib.GEnergy(runlist_emin,"TeV"),gammalib.GEnergy(runlist_emax,"TeV")) | |
| 575 | + | |
| 576 | + # Write energy range into log file | |
| 577 | + if self.logTerse(): | |
| 578 | + self.log("\n") | |
| 579 | + self.log("Eenrgy range of obervation list: ") | |
| 580 | + self.log(("% 3.2f" % runlist_emin)+" - "+("% 3.2f" % runlist_emax)+" TeV") | |
| 581 | + self.log("\n") | |
| 582 | + | |
| 583 | + else: | |
| 584 | + self.log.header2("WARNING: No observation from given runlist available") | |
| 585 | + | |
| 586 | + # Append models provided by 'inmodels' if necessary | |
| 587 | + if not self.inmodels == None: | |
| 588 | + if self.logTerse(): | |
| 589 | + self.log("\n") | |
| 590 | + self.log.header1("Appending models") | |
| 591 | + | |
| 592 | + # Loop over input models | |
| 593 | + for model in self.inmodels: | |
| 594 | + if self.logTerse(): | |
| 595 | + self.log.header3("Adding model \""+model.name()+"\"") | |
| 596 | + self.models.append(model) | |
| 597 | + | |
| 598 | + # Return | |
| 599 | + return | |
| 600 | + | |
| 601 | + def save(self,outfile,clobber): | |
| 602 | + | |
| 603 | + # Save observation XML file | |
| 604 | + self.xml.save(outfile) | |
| 605 | + | |
| 606 | + # Save model XML file | |
| 607 | + self.models.save(self.outmodel) | |
| 608 | + | |
| 609 | + # Return | |
| 610 | + return | |
| 611 | + | |
| 612 | +# ======================== # | |
| 613 | +# Main routine entry point # | |
| 614 | +# ======================== # | |
| 615 | +if __name__ == '__main__': | |
| 616 | + """ | |
| 617 | + Generates observation file. | |
| 618 | + """ | |
| 619 | + # Create instance of application | |
| 620 | + app = csiactobs(sys.argv) | |
| 621 | + | |
| 622 | + # Open logfile | |
| 623 | + app.logFileOpen() | |
| 624 | + | |
| 625 | + # Execute application | |
| 626 | + app.execute() | ... | ... |
cscripts/cslightcrv.py
| ... | ... | @@ -98,15 +98,15 @@ class cslightcrv(ctools.cscript): |
| 98 | 98 | |
| 99 | 99 | # Create default parfile |
| 100 | 100 | pars = gammalib.GApplicationPars() |
| 101 | - pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Event list, counts cube, or observation definition file")) | |
| 102 | - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) | |
| 101 | + pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Input event list, counts cube, or observation definition XML file")) | |
| 102 | + pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) | |
| 103 | 103 | pars.append(gammalib.GApplicationPar("srcname","s","a","Crab","","","Source name")) |
| 104 | - pars.append(gammalib.GApplicationPar("outfile","f","a","lightcurve.fits","","","Output file name")) | |
| 105 | - pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) | |
| 106 | - pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","PSF cube file (only needed for stacked analysis)")) | |
| 107 | - pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Background cube file (only needed for stacked analysis)")) | |
| 104 | + pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Input exposure cube file (only needed for stacked analysis)")) | |
| 105 | + pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","Input PSF cube file (only needed for stacked analysis)")) | |
| 106 | + pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Input background cube file (only needed for stacked analysis)")) | |
| 108 | 107 | pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) |
| 109 | - pars.append(gammalib.GApplicationPar("irf","s","a","South_50h","","","Instrument response function")) | |
| 108 | + pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) | |
| 109 | + pars.append(gammalib.GApplicationPar("outfile","f","a","lightcurve.fits","","","Output light curve file")) | |
| 110 | 110 | pars.append(gammalib.GApplicationPar("tbinalg","s","a","GTI","FILE|LIN|GTI","", "Algorithm for defining time bins")) |
| 111 | 111 | pars.append(gammalib.GApplicationPar("tmin","r","a","51544.5","","days","Lightcurve start time [MJD]")) |
| 112 | 112 | pars.append(gammalib.GApplicationPar("tmax","r","a","51544.6","","days","Lightcurve stop time [MJD]")) | ... | ... |
cscripts/csmodelinfo.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Dump information about models into log file | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 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 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | + | |
| 25 | + | |
| 26 | +# ================= # | |
| 27 | +# csmodelinfo class # | |
| 28 | +# ================= # | |
| 29 | +class csmodelinfo(ctools.cscript): | |
| 30 | + """ | |
| 31 | + This class dumps information about a model container into a logfile or | |
| 32 | + on screen. This might be helpful for quick access to the model container, | |
| 33 | + showing, e.g., number of sources, background models, free and fixed | |
| 34 | + parameters etc. The tool can also dump the models into a region file to | |
| 35 | + display e.g. with ds9. | |
| 36 | + """ | |
| 37 | + def __init__(self, *argv): | |
| 38 | + """ | |
| 39 | + Constructor. | |
| 40 | + """ | |
| 41 | + # Set name | |
| 42 | + self.name = "csmodelinfo" | |
| 43 | + self.version = "1.1.0" | |
| 44 | + | |
| 45 | + # Make sure that parfile exists | |
| 46 | + file = self.parfile() | |
| 47 | + | |
| 48 | + # Initialise application | |
| 49 | + if len(argv) == 0: | |
| 50 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 51 | + elif len(argv) == 1: | |
| 52 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 53 | + else: | |
| 54 | + raise TypeError("Invalid number of arguments given.") | |
| 55 | + | |
| 56 | + # Set logger properties | |
| 57 | + self.log_header() | |
| 58 | + self.log.date(True) | |
| 59 | + | |
| 60 | + # Return | |
| 61 | + return | |
| 62 | + | |
| 63 | + def __del__(self): | |
| 64 | + """ | |
| 65 | + Destructor. | |
| 66 | + """ | |
| 67 | + # Return | |
| 68 | + return | |
| 69 | + | |
| 70 | + def parfile(self): | |
| 71 | + """ | |
| 72 | + Check if parfile exists. If parfile does not exist then create a | |
| 73 | + default parfile. This kluge avoids shipping the cscript with a | |
| 74 | + parfile. | |
| 75 | + """ | |
| 76 | + | |
| 77 | + # Set parfile name | |
| 78 | + parfile = self.name+".par" | |
| 79 | + | |
| 80 | + try: | |
| 81 | + pars = gammalib.GApplicationPars(parfile) | |
| 82 | + except: | |
| 83 | + # Signal that parfile was not found | |
| 84 | + print("Parfile \""+parfile+"\" not found. Create default parfile.") | |
| 85 | + | |
| 86 | + # Create default parfile | |
| 87 | + pars = gammalib.GApplicationPars() | |
| 88 | + pars.append(gammalib.GApplicationPar("inmodel","f","a","model.xml","","","Input model XML file")) | |
| 89 | + pars.append(gammalib.GApplicationPar("ds9file","f","h","NONE","","","DS9 region file containing models")) | |
| 90 | + pars.append(gammalib.GApplicationPar("pnt_type","s","h","cross","circle|box|diamond|cross|x|arrow|boxcircle","","Marker type for point sources")) | |
| 91 | + pars.append(gammalib.GApplicationPar("pnt_mark_size","i","h","12","","","Marker size for point sources")) | |
| 92 | + pars.append(gammalib.GApplicationPar("show_labels","b","h","yes","yes|no","","Add source labels?")) | |
| 93 | + pars.append(gammalib.GApplicationPar("width","i","h","2","","","Line width for regions")) | |
| 94 | + pars.append(gammalib.GApplicationPar("font","s","h","helvetica","helvetica|times|courier","","Font for source labels")) | |
| 95 | + pars.append(gammalib.GApplicationPar("fontsize","i","h","12","","","Font size for source labels")) | |
| 96 | + pars.append(gammalib.GApplicationPar("fonttype","s","h","normal","normal|bold","","Use normal or bold font?")) | |
| 97 | + pars.append(gammalib.GApplicationPar("fonttype2","s","h","roman","roman|italic","","Use roman or italic font?")) | |
| 98 | + pars.append(gammalib.GApplicationPar("show_ext_type","b","h","yes","yes|no","","Show type of extended model in source name")) | |
| 99 | + pars.append(gammalib.GApplicationPar("free_color","s","h","green","","","Color for sources with free parameters (any ds9 color or hex code)")) | |
| 100 | + pars.append(gammalib.GApplicationPar("fixed_color","s","h","magenta","","","Color for source without free parameters (any ds9 color or hex code)")) | |
| 101 | + pars.append_standard() | |
| 102 | + pars.append(gammalib.GApplicationPar("logfile","f","h","csmodelinfo.log","","","Log filename")) | |
| 103 | + pars.save(parfile) | |
| 104 | + | |
| 105 | + # Return | |
| 106 | + return | |
| 107 | + | |
| 108 | + def get_parameters(self): | |
| 109 | + """ | |
| 110 | + Get parameters from parfile and setup the observation. | |
| 111 | + """ | |
| 112 | + # Get models | |
| 113 | + self.models = gammalib.GModels(self["inmodel"].filename()) | |
| 114 | + | |
| 115 | + # Get ds9 filename | |
| 116 | + self.ds9file = self["ds9file"].filename() | |
| 117 | + | |
| 118 | + # Get hidden parameters for region file | |
| 119 | + self.pnt_type = self["pnt_type"].string() | |
| 120 | + self.pnt_mark_size = self["pnt_mark_size"].integer() | |
| 121 | + self.show_labels = self["show_labels"].boolean() | |
| 122 | + self.width = self["width"].integer() | |
| 123 | + self.font = self["font"].string() | |
| 124 | + self.fontsize = self["fontsize"].integer() | |
| 125 | + self.fonttype = self["fonttype"].string() | |
| 126 | + self.fonttype2 = self["fonttype2"].string() | |
| 127 | + self.show_ext_type = self["show_ext_type"].boolean() | |
| 128 | + self.free_color = self["free_color"].string() | |
| 129 | + self.fixed_color = self["fixed_color"].string() | |
| 130 | + | |
| 131 | + # Return | |
| 132 | + return | |
| 133 | + | |
| 134 | + def run(self): | |
| 135 | + """ | |
| 136 | + Run the script. | |
| 137 | + """ | |
| 138 | + # Switch screen logging on in debug mode | |
| 139 | + if self.logDebug(): | |
| 140 | + self.log.cout(True) | |
| 141 | + | |
| 142 | + # Get parameters | |
| 143 | + self.get_parameters() | |
| 144 | + | |
| 145 | + # Write input parameters into logger | |
| 146 | + if self.logTerse(): | |
| 147 | + self.log_parameters() | |
| 148 | + self.log("\n") | |
| 149 | + | |
| 150 | + if self.logVerbose(): | |
| 151 | + self.log("\n") | |
| 152 | + self.log.header1("Models in detail") | |
| 153 | + self.log("\n") | |
| 154 | + self.log(str(self.models)) | |
| 155 | + self.log("\n") | |
| 156 | + | |
| 157 | + # Initialise output values | |
| 158 | + types = {} | |
| 159 | + instruments = {} | |
| 160 | + ts = {} | |
| 161 | + pars_at_limit = {} | |
| 162 | + free_src_pars = {} | |
| 163 | + n_par_total = 0 | |
| 164 | + n_par_free = 0 | |
| 165 | + n_par_fixed = 0 | |
| 166 | + n_par_at_limit = 0 | |
| 167 | + n_par_free_bkg = 0 | |
| 168 | + n_par_free_src = 0 | |
| 169 | + n_par_free_spec = 0 | |
| 170 | + n_par_free_spat = 0 | |
| 171 | + n_par_free_temp = 0 | |
| 172 | + | |
| 173 | + # Loop over models and initialise dictionaries with model names | |
| 174 | + for model in self.models: | |
| 175 | + types[model.type()] = 0 | |
| 176 | + instruments[model.instruments()] = 0 | |
| 177 | + pars_at_limit[model.name()] = [] | |
| 178 | + | |
| 179 | + # Loop over models again and fill values to be dumped | |
| 180 | + for model in self.models: | |
| 181 | + | |
| 182 | + # Model types | |
| 183 | + types[model.type()] += 1 | |
| 184 | + | |
| 185 | + # Model instruments | |
| 186 | + instruments[model.instruments()] += 1 | |
| 187 | + | |
| 188 | + # TS | |
| 189 | + if model.has_ts(): | |
| 190 | + ts[model.name()] = model.ts() | |
| 191 | + | |
| 192 | + # Skymodel? | |
| 193 | + skymodel = (model.classname() == "GModelSky") | |
| 194 | + if skymodel: | |
| 195 | + free_src_pars[model.name()] = [] | |
| 196 | + | |
| 197 | + # Loop over model parameters | |
| 198 | + for par in model: | |
| 199 | + | |
| 200 | + # Increment total parameters | |
| 201 | + n_par_total += 1 | |
| 202 | + | |
| 203 | + # Check if parameter is at limit | |
| 204 | + if par.has_range(): | |
| 205 | + if par.value() == par.min() or par.value() == par.max(): | |
| 206 | + pars_at_limit[model.name()].append(par.name()) | |
| 207 | + n_par_at_limit += 1 | |
| 208 | + | |
| 209 | + # Check if model parameter is free/fixed and | |
| 210 | + # increment respective variable | |
| 211 | + if par.is_free(): | |
| 212 | + n_par_free += 1 | |
| 213 | + if skymodel: | |
| 214 | + free_src_pars[model.name()].append(par) | |
| 215 | + n_par_free_src += 1 | |
| 216 | + else: | |
| 217 | + n_par_free_bkg += 1 | |
| 218 | + else: | |
| 219 | + n_par_fixed += 1 | |
| 220 | + | |
| 221 | + # If sky model, divide free parameters into spatial, spectral and temporal | |
| 222 | + if skymodel: | |
| 223 | + for par in model.spectral(): | |
| 224 | + if par.is_free(): | |
| 225 | + n_par_free_spec += 1 | |
| 226 | + for par in model.spatial(): | |
| 227 | + if par.is_free(): | |
| 228 | + n_par_free_spat += 1 | |
| 229 | + for par in model.temporal(): | |
| 230 | + if par.is_free(): | |
| 231 | + n_par_free_temp += 1 | |
| 232 | + | |
| 233 | + # Log summary | |
| 234 | + self.log("\n") | |
| 235 | + self.log.header1("Summary") | |
| 236 | + | |
| 237 | + # Log instruments | |
| 238 | + self.log.header3("Instrument specific models") | |
| 239 | + for inst, n_inst in instruments.items(): | |
| 240 | + if inst == "": | |
| 241 | + inst = "All" | |
| 242 | + self.log.parformat(inst) | |
| 243 | + self.log(str(n_inst)) | |
| 244 | + self.log("\n") | |
| 245 | + | |
| 246 | + # Log model types | |
| 247 | + self.log.header3("Model types") | |
| 248 | + for modeltype, n_types in types.items(): | |
| 249 | + self.log.parformat(modeltype) | |
| 250 | + self.log(str(n_types)) | |
| 251 | + self.log("\n") | |
| 252 | + | |
| 253 | + # Log parameter information | |
| 254 | + self.log("\n") | |
| 255 | + self.log.header1("Parameter information") | |
| 256 | + self.log.parformat("All parameters") | |
| 257 | + self.log(str(n_par_total)) | |
| 258 | + self.log("\n") | |
| 259 | + self.log.parformat("Fixed parameters") | |
| 260 | + self.log(str(n_par_fixed)) | |
| 261 | + self.log("\n") | |
| 262 | + self.log.parformat("Free parameters (total)") | |
| 263 | + self.log(str(n_par_free)) | |
| 264 | + self.log("\n") | |
| 265 | + self.log.parformat("Free background parameters") | |
| 266 | + self.log(str(n_par_free_bkg)) | |
| 267 | + self.log("\n") | |
| 268 | + self.log.parformat("Free source parameters") | |
| 269 | + self.log(str(n_par_free_src)) | |
| 270 | + self.log("\n") | |
| 271 | + if n_par_free_spec > 0: | |
| 272 | + self.log.parformat("Free spectral parameters") | |
| 273 | + self.log(str(n_par_free_spec)) | |
| 274 | + self.log("\n") | |
| 275 | + if n_par_free_spat > 0: | |
| 276 | + self.log.parformat("Free spatial parameters") | |
| 277 | + self.log(str(n_par_free_spat)) | |
| 278 | + self.log("\n") | |
| 279 | + if n_par_free_temp > 0: | |
| 280 | + self.log.parformat("Free temporal parameters") | |
| 281 | + self.log(str(n_par_free_temp)) | |
| 282 | + self.log("\n") | |
| 283 | + self.log.parformat("Parameters at limit") | |
| 284 | + self.log(str(n_par_at_limit)) | |
| 285 | + self.log("\n") | |
| 286 | + | |
| 287 | + # Log parameters at limit (if any) | |
| 288 | + if n_par_at_limit > 0: | |
| 289 | + self.log.header3("Parameters at limit") | |
| 290 | + for source, parameter in pars_at_limit.items(): | |
| 291 | + if len(parameter): | |
| 292 | + for par in parameter: | |
| 293 | + self.log.parformat(source) | |
| 294 | + self.log(par) | |
| 295 | + self.log("\n") | |
| 296 | + | |
| 297 | + # Log free parameters if requested | |
| 298 | + if self.logExplicit() and len(free_src_pars): | |
| 299 | + self.log("\n") | |
| 300 | + self.log.header2("Free source parameters") | |
| 301 | + for source, parameter in free_src_pars.items(): | |
| 302 | + if len(parameter): | |
| 303 | + self.log.header3(source) | |
| 304 | + for par in parameter: | |
| 305 | + self.log(str(par)) | |
| 306 | + self.log("\n") | |
| 307 | + self.log("\n") | |
| 308 | + | |
| 309 | + # Log TS values if available | |
| 310 | + if len(ts): | |
| 311 | + self.log.header3("Test statistics") | |
| 312 | + for source,tsvalue in ts.items(): | |
| 313 | + self.log.parformat(source) | |
| 314 | + self.log("%.2f"%tsvalue) | |
| 315 | + self.log("\n") | |
| 316 | + | |
| 317 | + # Return | |
| 318 | + return | |
| 319 | + | |
| 320 | + def save(self): | |
| 321 | + """ | |
| 322 | + Save models to ds9 region file if required | |
| 323 | + """ | |
| 324 | + | |
| 325 | + # Check if ds9 file is valid | |
| 326 | + if not self.ds9file == "NONE": | |
| 327 | + | |
| 328 | + self.log("\n") | |
| 329 | + self.log.header1("Save region file") | |
| 330 | + | |
| 331 | + # Open file | |
| 332 | + f = open(self.ds9file,"w") | |
| 333 | + | |
| 334 | + # Write coordinate system | |
| 335 | + f.write("fk5\n") | |
| 336 | + | |
| 337 | + # Loop over models | |
| 338 | + for model in self.models: | |
| 339 | + | |
| 340 | + # Continue only if point source or extended source model | |
| 341 | + if model.type() == "PointSource" or model.type() == "ExtendedSource": | |
| 342 | + | |
| 343 | + line = self.model2ds9string(model) | |
| 344 | + if len(line): | |
| 345 | + f.write(line+"\n") | |
| 346 | + | |
| 347 | + # Logging for diffuse components | |
| 348 | + elif model.type() == "DiffuseSource": | |
| 349 | + self.log("Skipping diffuse model "+model.name()+"\n") | |
| 350 | + | |
| 351 | + # Logging for background components | |
| 352 | + else: | |
| 353 | + if self.logExplicit(): | |
| 354 | + self.log("Skipping background model "+model.name()+"\n") | |
| 355 | + | |
| 356 | + # Close file | |
| 357 | + f.close() | |
| 358 | + | |
| 359 | + # Return | |
| 360 | + return | |
| 361 | + | |
| 362 | + def model2ds9string(self, model): | |
| 363 | + """ | |
| 364 | + Converts model instance to ds9 region string | |
| 365 | + """ | |
| 366 | + | |
| 367 | + # Initialise return string | |
| 368 | + ds9string = "" | |
| 369 | + | |
| 370 | + # Determine color | |
| 371 | + color = self.fixed_color | |
| 372 | + for par in model: | |
| 373 | + if par.is_free(): | |
| 374 | + color = self.free_color | |
| 375 | + break | |
| 376 | + | |
| 377 | + # Initialise flag ot continue | |
| 378 | + is_valid = True | |
| 379 | + | |
| 380 | + # Retrieve model position | |
| 381 | + try: | |
| 382 | + modelpos = model.spatial().dir() | |
| 383 | + except AttributeError: | |
| 384 | + self.log("Skipping source "+model.name()+": Could not determine sky position\n") | |
| 385 | + is_valid = False | |
| 386 | + | |
| 387 | + # Continue only if position was found | |
| 388 | + if is_valid: | |
| 389 | + | |
| 390 | + # Retrieve model type and name | |
| 391 | + modeltype = model.type() | |
| 392 | + modelname = model.name() | |
| 393 | + | |
| 394 | + # Handle point source | |
| 395 | + if modeltype == "PointSource": | |
| 396 | + | |
| 397 | + ds9string += "point(" | |
| 398 | + ds9string += str(modelpos.ra_deg()) | |
| 399 | + ds9string += "," | |
| 400 | + ds9string += str(modelpos.dec_deg()) | |
| 401 | + ds9string += ") # " | |
| 402 | + ds9string += "point="+self.pnt_type+" " | |
| 403 | + ds9string += str(self.pnt_mark_size)+" " | |
| 404 | + | |
| 405 | + # Hanlde extended sources | |
| 406 | + elif modeltype == "ExtendedSource": | |
| 407 | + | |
| 408 | + # Retrieve spatial model | |
| 409 | + spatial = model.spatial() | |
| 410 | + classname = spatial.classname() | |
| 411 | + | |
| 412 | + # Handle radial sources | |
| 413 | + if "Radial" in classname: | |
| 414 | + | |
| 415 | + # Retrieve short name of model class (e.g. "Gauss" or "Disk) | |
| 416 | + shorttype = classname.split("Radial")[-1] | |
| 417 | + | |
| 418 | + # Handle Disk and Shell model | |
| 419 | + if classname == "GModelSpatialRadialDisk" or classname == "GModelSpatialRadialShell": | |
| 420 | + size = spatial.radius() | |
| 421 | + | |
| 422 | + # Handle Gauss Model | |
| 423 | + elif classname == "GModelSpatialRadialGauss": | |
| 424 | + size = spatial.sigma() | |
| 425 | + | |
| 426 | + # Skip if source is unknown | |
| 427 | + else: | |
| 428 | + self.log("Skipping source "+model.name()+": Spatial model \""+classname+"\" unkown\n") | |
| 429 | + is_valid = False | |
| 430 | + | |
| 431 | + # Append radial ds9 string | |
| 432 | + if is_valid: | |
| 433 | + ds9string += "circle(" | |
| 434 | + ds9string += str(modelpos.ra_deg()) | |
| 435 | + ds9string += "," | |
| 436 | + ds9string += str(modelpos.dec_deg()) | |
| 437 | + ds9string += "," | |
| 438 | + ds9string += str(size*3600.)+"\") #" | |
| 439 | + | |
| 440 | + # Handle elliptical sources | |
| 441 | + elif "Elliptical" in classname: | |
| 442 | + | |
| 443 | + # Retrieve short name and source size | |
| 444 | + shorttype = classname.split("Elliptical")[-1] | |
| 445 | + size1 = spatial.semimajor() | |
| 446 | + size2 = spatial.semiminor() | |
| 447 | + angle = spatial.posangle() | |
| 448 | + | |
| 449 | + # Append elliptical ds9 string | |
| 450 | + ds9string += "ellipse(" | |
| 451 | + ds9string += str(modelpos.ra_deg()) | |
| 452 | + ds9string += "," | |
| 453 | + ds9string += str(modelpos.dec_deg()) | |
| 454 | + ds9string += "," | |
| 455 | + ds9string += str(size1*3600.)+"\"" | |
| 456 | + ds9string += "," | |
| 457 | + ds9string += str(size2*3600.)+"\"" | |
| 458 | + ds9string += "," | |
| 459 | + ds9string += str(angle+90.0)+") # " | |
| 460 | + | |
| 461 | + # Skip if source is neither radial nor elliptical | |
| 462 | + else: | |
| 463 | + self.log("Skipping source "+model.name()+": Spatial model neither \"Radial\" nor \"Elliptical\"\n") | |
| 464 | + | |
| 465 | + # Add short name to modelname | |
| 466 | + if self.show_ext_type: | |
| 467 | + modelname +=" ("+shorttype+")" | |
| 468 | + | |
| 469 | + # Add user defined attributes | |
| 470 | + ds9string += "color="+color+" " | |
| 471 | + ds9string += "width="+str(self.width)+" " | |
| 472 | + ds9string += "font=\""+self.font+" "+str(self.fontsize)+" "+self.fonttype+" "+self.fonttype2+"\" " | |
| 473 | + if self.show_labels: | |
| 474 | + ds9string += "text={"+modelname+"}" | |
| 475 | + | |
| 476 | + # Return string | |
| 477 | + return ds9string | |
| 478 | + | |
| 479 | + def execute(self): | |
| 480 | + """ | |
| 481 | + Execute the script. | |
| 482 | + """ | |
| 483 | + # Run the script | |
| 484 | + self.run() | |
| 485 | + | |
| 486 | + # Save ds9 file if required | |
| 487 | + self.save() | |
| 488 | + | |
| 489 | + # Return | |
| 490 | + return | |
| 491 | + | |
| 492 | + | |
| 493 | +# ======================== # | |
| 494 | +# Main routine entry point # | |
| 495 | +# ======================== # | |
| 496 | +if __name__ == '__main__': | |
| 497 | + """ | |
| 498 | + Generates model information output. | |
| 499 | + """ | |
| 500 | + # Create instance of application | |
| 501 | + app = csmodelinfo(sys.argv) | |
| 502 | + | |
| 503 | + # Open logfile | |
| 504 | + app.logFileOpen() | |
| 505 | + | |
| 506 | + # Execute application | |
| 507 | + app.execute() | ... | ... |
cscripts/csmodelmerge.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Merges model XML files into one file | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 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 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | +import glob | |
| 25 | + | |
| 26 | + | |
| 27 | +# ================== # | |
| 28 | +# csmodelmerge class # | |
| 29 | +# ================== # | |
| 30 | +class csmodelmerge(ctools.cscript): | |
| 31 | + """ | |
| 32 | + This class merges an arbitray number of model container into one output | |
| 33 | + model XML file. | |
| 34 | + """ | |
| 35 | + def __init__(self, *argv): | |
| 36 | + """ | |
| 37 | + Constructor. | |
| 38 | + """ | |
| 39 | + # Set name | |
| 40 | + self.name = "csmodelmerge" | |
| 41 | + self.version = "1.1.0" | |
| 42 | + | |
| 43 | + # Make sure that parfile exists | |
| 44 | + file = self.parfile() | |
| 45 | + | |
| 46 | + # Initialise application | |
| 47 | + if len(argv) == 0: | |
| 48 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 49 | + elif len(argv) == 1: | |
| 50 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 51 | + else: | |
| 52 | + raise TypeError("Invalid number of arguments given.") | |
| 53 | + | |
| 54 | + # Set logger properties | |
| 55 | + self.log_header() | |
| 56 | + self.log.date(True) | |
| 57 | + | |
| 58 | + # Return | |
| 59 | + return | |
| 60 | + | |
| 61 | + def __del__(self): | |
| 62 | + """ | |
| 63 | + Destructor. | |
| 64 | + """ | |
| 65 | + # Return | |
| 66 | + return | |
| 67 | + | |
| 68 | + def parfile(self): | |
| 69 | + """ | |
| 70 | + Check if parfile exists. If parfile does not exist then create a | |
| 71 | + default parfile. This kluge avoids shipping the cscript with a | |
| 72 | + parfile. | |
| 73 | + """ | |
| 74 | + | |
| 75 | + # Set parfile name | |
| 76 | + parfile = self.name+".par" | |
| 77 | + | |
| 78 | + try: | |
| 79 | + pars = gammalib.GApplicationPars(parfile) | |
| 80 | + except: | |
| 81 | + # Signal that parfile was not found | |
| 82 | + print("Parfile \""+parfile+"\" not found. Create default parfile.") | |
| 83 | + | |
| 84 | + # Create default parfile | |
| 85 | + pars = gammalib.GApplicationPars() | |
| 86 | + pars.append(gammalib.GApplicationPar("inmodels","s","a","model.xml","","","Input model XML files")) | |
| 87 | + pars.append(gammalib.GApplicationPar("outmodel","f","a","NONE","","","Output model file")) | |
| 88 | + pars.append_standard() | |
| 89 | + pars.append(gammalib.GApplicationPar("logfile","f","h","csmodelmerge.log","","","Log filename")) | |
| 90 | + pars.save(parfile) | |
| 91 | + | |
| 92 | + # Return | |
| 93 | + return | |
| 94 | + | |
| 95 | + def get_parameters(self): | |
| 96 | + """ | |
| 97 | + Get parameters from parfile and setup the observation. | |
| 98 | + """ | |
| 99 | + # Get input models | |
| 100 | + self.inmodels = self["inmodels"].string() | |
| 101 | + | |
| 102 | + # Interpet inmodels string | |
| 103 | + # Handle ascii files | |
| 104 | + if "@" == self.inmodels[0]: | |
| 105 | + self.files = open(self.inmodels.replace("@","")).read().splitlines() | |
| 106 | + | |
| 107 | + # Handle wild card strings | |
| 108 | + elif "*" in self.inmodels: | |
| 109 | + self.files = glob.glob(self.inmodels) | |
| 110 | + | |
| 111 | + # Handle space-separated list | |
| 112 | + elif " " in self.inmodels: | |
| 113 | + self.files = self.inmodels.split(" ") | |
| 114 | + | |
| 115 | + # Handle comma-separated list | |
| 116 | + elif "," in self.inmodels: | |
| 117 | + self.files = self.inmodels.split(",") | |
| 118 | + | |
| 119 | + # Throw exception if input models cannot be decoded | |
| 120 | + else: | |
| 121 | + msg = "Parameter \"inmodels\" must contain either an @ASCII"+\ | |
| 122 | + " file, a comma-separated or whitespace-separated list"+\ | |
| 123 | + " of files or a wildcard string" | |
| 124 | + raise RuntimeError(msg) | |
| 125 | + | |
| 126 | + # Get output file | |
| 127 | + self.outmodel = self["outmodel"].filename() | |
| 128 | + | |
| 129 | + # Return | |
| 130 | + return | |
| 131 | + | |
| 132 | + def run(self): | |
| 133 | + """ | |
| 134 | + Run the script. | |
| 135 | + """ | |
| 136 | + # Switch screen logging on in debug mode | |
| 137 | + if self.logDebug(): | |
| 138 | + self.log.cout(True) | |
| 139 | + | |
| 140 | + # Get parameters | |
| 141 | + self.get_parameters() | |
| 142 | + | |
| 143 | + # Write input parameters into logger | |
| 144 | + if self.logTerse(): | |
| 145 | + self.log_parameters() | |
| 146 | + self.log("\n") | |
| 147 | + | |
| 148 | + # Dump header | |
| 149 | + if self.logTerse(): | |
| 150 | + self.log("\n") | |
| 151 | + self.log.header1("Merging Models") | |
| 152 | + self.log("\n") | |
| 153 | + | |
| 154 | + # Initialise output model container | |
| 155 | + self.models = gammalib.GModels() | |
| 156 | + | |
| 157 | + # Loop over model files | |
| 158 | + for modelfile in self.files: | |
| 159 | + | |
| 160 | + # Logging | |
| 161 | + self.log("Adding "+modelfile) | |
| 162 | + self.log("\n") | |
| 163 | + | |
| 164 | + # Open models | |
| 165 | + model_add = gammalib.GModels(modelfile) | |
| 166 | + | |
| 167 | + # Append models to container | |
| 168 | + for model in model_add: | |
| 169 | + self.models.append(model) | |
| 170 | + | |
| 171 | + # Return | |
| 172 | + return | |
| 173 | + | |
| 174 | + def save(self): | |
| 175 | + """ | |
| 176 | + Save pointings to ds9 region file if required | |
| 177 | + """ | |
| 178 | + # Logging | |
| 179 | + if self.logExplicit(): | |
| 180 | + self.log("\n") | |
| 181 | + self.log.header1("Saving model file") | |
| 182 | + self.log("\n") | |
| 183 | + | |
| 184 | + # Save models | |
| 185 | + self.models.save(self.outmodel) | |
| 186 | + | |
| 187 | + # Return | |
| 188 | + return | |
| 189 | + | |
| 190 | + def execute(self): | |
| 191 | + """ | |
| 192 | + Execute the script. | |
| 193 | + """ | |
| 194 | + # Run the script | |
| 195 | + self.run() | |
| 196 | + | |
| 197 | + # Save ds9 file if required | |
| 198 | + self.save() | |
| 199 | + | |
| 200 | + # Return | |
| 201 | + return | |
| 202 | + | |
| 203 | + | |
| 204 | +# ======================== # | |
| 205 | +# Main routine entry point # | |
| 206 | +# ======================== # | |
| 207 | +if __name__ == '__main__': | |
| 208 | + """ | |
| 209 | + Merges model XML files | |
| 210 | + """ | |
| 211 | + # Create instance of application | |
| 212 | + app = csmodelmerge(sys.argv) | |
| 213 | + | |
| 214 | + # Open logfile | |
| 215 | + app.logFileOpen() | |
| 216 | + | |
| 217 | + # Execute application | |
| 218 | + app.execute() | ... | ... |
cscripts/csobs2caldb.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Generation of an caldb entry from general IACT observation. | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 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 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | +import os | |
| 25 | +import datetime | |
| 26 | + | |
| 27 | + | |
| 28 | +# ================= # | |
| 29 | +# csobs2caldb class # | |
| 30 | +# ================= # | |
| 31 | +class csobs2caldb(ctools.cscript): | |
| 32 | + """ | |
| 33 | + This class implements the creation of a caldb entry for a particular | |
| 34 | + observation, which might be helpful for running simulations for current | |
| 35 | + IACTs. It takes an observation definition file as input and uses the | |
| 36 | + first observation to create a caldb entry which can be used for | |
| 37 | + simulations and sensitivity studies later on. | |
| 38 | + """ | |
| 39 | + def __init__(self, *argv): | |
| 40 | + """ | |
| 41 | + Constructor. | |
| 42 | + """ | |
| 43 | + # Set name | |
| 44 | + self.name = "csobs2caldb" | |
| 45 | + self.version = "1.1.0" | |
| 46 | + | |
| 47 | + # Make sure that parfile exists | |
| 48 | + file = self.parfile() | |
| 49 | + | |
| 50 | + # Initialise application | |
| 51 | + if len(argv) == 0: | |
| 52 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 53 | + elif len(argv) == 1: | |
| 54 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 55 | + else: | |
| 56 | + raise TypeError("Invalid number of arguments given.") | |
| 57 | + | |
| 58 | + # Set logger properties | |
| 59 | + self.log_header() | |
| 60 | + self.log.date(True) | |
| 61 | + | |
| 62 | + # Return | |
| 63 | + return | |
| 64 | + | |
| 65 | + def __del__(self): | |
| 66 | + """ | |
| 67 | + Destructor. | |
| 68 | + """ | |
| 69 | + # Return | |
| 70 | + return | |
| 71 | + | |
| 72 | + def parfile(self): | |
| 73 | + """ | |
| 74 | + Check if parfile exists. If parfile does not exist then create a | |
| 75 | + default parfile. This kluge avoids shipping the cscript with a | |
| 76 | + parfile. | |
| 77 | + """ | |
| 78 | + | |
| 79 | + # Set parfile name | |
| 80 | + parfile = self.name+".par" | |
| 81 | + | |
| 82 | + try: | |
| 83 | + pars = gammalib.GApplicationPars(parfile) | |
| 84 | + except: | |
| 85 | + # Signal that parfile was not found | |
| 86 | + print("Parfile \""+parfile+"\" not found. Create default parfile.") | |
| 87 | + | |
| 88 | + # Create default parfile | |
| 89 | + pars = gammalib.GApplicationPars() | |
| 90 | + pars.append(gammalib.GApplicationPar("inobs","f","a","obs.xml","","","Input observation definition file")) | |
| 91 | + pars.append(gammalib.GApplicationPar("rspname","s","a","NONE","","","Response output name (e.g. Zenith50)")) | |
| 92 | + pars.append(gammalib.GApplicationPar("outirfs","f","h","irf_file.fits","","","Output IRF file name")) | |
| 93 | + pars.append(gammalib.GApplicationPar("index","i","h","0","","","Index of observation to be used from XML file")) | |
| 94 | + pars.append_standard() | |
| 95 | + pars.append(gammalib.GApplicationPar("logfile","f","h","csobs2caldb.log","","","Log filename")) | |
| 96 | + pars.save(parfile) | |
| 97 | + | |
| 98 | + # Return | |
| 99 | + return | |
| 100 | + | |
| 101 | + def get_parameters(self): | |
| 102 | + """ | |
| 103 | + Get parameters from parfile and setup the observation. | |
| 104 | + """ | |
| 105 | + # Get parameters | |
| 106 | + self.inobs = self["inobs"].filename() | |
| 107 | + self.obs = gammalib.GObservations(self.inobs) | |
| 108 | + | |
| 109 | + # Get index of observation to be used (0=default) | |
| 110 | + inx = self["index"].integer() | |
| 111 | + | |
| 112 | + # Get observation | |
| 113 | + self.observation = self.obs[inx] | |
| 114 | + | |
| 115 | + # Set instrument mission to cta | |
| 116 | + # This is to be compliant with standard gammalib caldb | |
| 117 | + self.m_mission = "CTA" | |
| 118 | + | |
| 119 | + # Get instrument name | |
| 120 | + self.m_instrument = self.observation.instrument() | |
| 121 | + | |
| 122 | + # Get config and file name | |
| 123 | + self.m_rspname = self["rspname"].string() | |
| 124 | + self.m_outfile = self["outirfs"].filename() | |
| 125 | + | |
| 126 | + # Make sure we have a cta observation | |
| 127 | + if not self.observation.classname() == "GCTAObservation": | |
| 128 | + raise gammalib.Exception.runtime_error("Input observation not of type \"GCTAObservation\"") | |
| 129 | + | |
| 130 | + # Make sure we have an irf response | |
| 131 | + if not self.observation.response().classname() == "GCTAResponseIrf": | |
| 132 | + raise gammalib.Exception.runtime_error("Response of input observation not of type \"GCTAResponseIrf\"") | |
| 133 | + | |
| 134 | + # Get other parameters | |
| 135 | + self.m_clobber = self["clobber"].boolean() | |
| 136 | + | |
| 137 | + # Return | |
| 138 | + return | |
| 139 | + | |
| 140 | + def make_irf_file(self): | |
| 141 | + | |
| 142 | + # retrieve response component | |
| 143 | + rsp = self.observation.response() | |
| 144 | + | |
| 145 | + # Initialise FITS file | |
| 146 | + fits = gammalib.GFits() | |
| 147 | + | |
| 148 | + # Create GFilename instances | |
| 149 | + fname_aeff = gammalib.GFilename(rsp.aeff().filename()) | |
| 150 | + fname_psf = gammalib.GFilename(rsp.psf().filename()) | |
| 151 | + fname_edisp = gammalib.GFilename(rsp.edisp().filename()) | |
| 152 | + fname_bkg = gammalib.GFilename(rsp.background().filename()) | |
| 153 | + | |
| 154 | + # Open FITS files of response components | |
| 155 | + fits_aeff = gammalib.GFits(fname_aeff.filename()) | |
| 156 | + fits_psf = gammalib.GFits(fname_psf.filename()) | |
| 157 | + fits_edisp = gammalib.GFits(fname_edisp.filename()) | |
| 158 | + fits_bkg = gammalib.GFits(fname_bkg.filename()) | |
| 159 | + | |
| 160 | + # Bundle IRFs into one file | |
| 161 | + fits.append(fits_aeff[fname_aeff.extname("EFFECTIVE AREA")]) | |
| 162 | + fits.append(fits_psf[fname_psf.extname("POINT SPREAD FUNCTION")]) | |
| 163 | + fits.append(fits_edisp[fname_edisp.extname("ENERGY DISPERSION")]) | |
| 164 | + fits.append(fits_bkg[fname_bkg.extname("BACKGROUND")]) | |
| 165 | + | |
| 166 | + # Return fits file | |
| 167 | + return fits | |
| 168 | + | |
| 169 | + def make_caldb_index(self): | |
| 170 | + | |
| 171 | + # Open calibration database index | |
| 172 | + indx_file = self.base_dir+"/caldb.indx" | |
| 173 | + | |
| 174 | + # Check if indx file exists (create if not existent) | |
| 175 | + if os.path.isfile(indx_file): | |
| 176 | + cif = gammalib.GFits(indx_file) | |
| 177 | + else: | |
| 178 | + cif = gammalib.GFits(indx_file, True) | |
| 179 | + | |
| 180 | + # Retrieve "CIF" table | |
| 181 | + if cif.contains("CIF"): | |
| 182 | + table = cif.table("CIF") | |
| 183 | + else: | |
| 184 | + # Create binary table if not available | |
| 185 | + bintable = gammalib.GFitsBinTable() | |
| 186 | + bintable.extname("CIF") | |
| 187 | + bintable.card("CIFVERSN", "1992a", "Version of CIF format") | |
| 188 | + cif.append(bintable) | |
| 189 | + | |
| 190 | + table = cif.table("CIF") | |
| 191 | + | |
| 192 | + # Copied from cta_root2caldb.py | |
| 193 | + # Attach columns. Reference: CAL/GEN/92-008 | |
| 194 | + table.append(gammalib.GFitsTableStringCol("TELESCOP", 0, 10)) | |
| 195 | + table.append(gammalib.GFitsTableStringCol("INSTRUME", 0, 10)) | |
| 196 | + table.append(gammalib.GFitsTableStringCol("DETNAM", 0, 20)) | |
| 197 | + table.append(gammalib.GFitsTableStringCol("FILTER", 0, 10)) | |
| 198 | + table.append(gammalib.GFitsTableStringCol("CAL_DEV", 0, 20)) | |
| 199 | + table.append(gammalib.GFitsTableStringCol("CAL_DIR", 0, 70)) | |
| 200 | + table.append(gammalib.GFitsTableStringCol("CAL_FILE", 0, 40)) | |
| 201 | + table.append(gammalib.GFitsTableStringCol("CAL_CLAS", 0, 3)) | |
| 202 | + table.append(gammalib.GFitsTableStringCol("CAL_DTYP", 0, 4)) | |
| 203 | + table.append(gammalib.GFitsTableStringCol("CAL_CNAM", 0, 20)) | |
| 204 | + table.append(gammalib.GFitsTableStringCol("CAL_CBD", 0, 70, 9)) | |
| 205 | + table.append(gammalib.GFitsTableShortCol("CAL_XNO", 0)) | |
| 206 | + table.append(gammalib.GFitsTableStringCol("CAL_VSD", 0, 10)) | |
| 207 | + table.append(gammalib.GFitsTableStringCol("CAL_VST", 0, 8)) | |
| 208 | + table.append(gammalib.GFitsTableDoubleCol("REF_TIME", 0)) | |
| 209 | + table.append(gammalib.GFitsTableShortCol("CAL_QUAL", 0)) | |
| 210 | + table.append(gammalib.GFitsTableStringCol("CAL_DATE", 0, 8)) | |
| 211 | + table.append(gammalib.GFitsTableStringCol("CAL_DESC", 0, 70)) | |
| 212 | + | |
| 213 | + # Check if output config already exist | |
| 214 | + has_config = False | |
| 215 | + row_index = -1 | |
| 216 | + for caldir in table["CAL_DIR"]: | |
| 217 | + row_index += 1 | |
| 218 | + if caldir == self.cal_dir: | |
| 219 | + has_config = True | |
| 220 | + break | |
| 221 | + | |
| 222 | + # Create columns if not available | |
| 223 | + if not has_config: | |
| 224 | + # Append 4 rows to CIF extension | |
| 225 | + table.append_rows(4) | |
| 226 | + row_index = table.nrows() | |
| 227 | + else: | |
| 228 | + row_index += 4 | |
| 229 | + | |
| 230 | + # Add generic information for these 4 rows | |
| 231 | + for i in range(4): | |
| 232 | + | |
| 233 | + # Set row number | |
| 234 | + row = i + row_index-4 | |
| 235 | + | |
| 236 | + # Set date | |
| 237 | + now = str(datetime.datetime.now()) | |
| 238 | + today, time = now.split() | |
| 239 | + | |
| 240 | + # Set element | |
| 241 | + table["TELESCOP"][row] = self.m_mission | |
| 242 | + table["INSTRUME"][row] = self.m_instrument | |
| 243 | + table["DETNAM"][row] = "NONE" | |
| 244 | + table["FILTER"][row] = "NONE" | |
| 245 | + table["CAL_DEV"][row] = "ONLINE" | |
| 246 | + table["CAL_CLAS"][row] = "BCF" | |
| 247 | + table["CAL_DTYP"][row] = "DATA" | |
| 248 | + table["CAL_VSD"][row] = today | |
| 249 | + table["CAL_VST"][row] = time.split(".")[0] | |
| 250 | + table["REF_TIME"][row] = 51544.0 | |
| 251 | + table["CAL_QUAL"][row] = 0 | |
| 252 | + table["CAL_CBD"][row] = "NAME("+self.m_rspname+")" | |
| 253 | + table["CAL_DATE"][row] = today.replace("-","/")[2:] | |
| 254 | + table["CAL_DIR"][row] = self.cal_dir | |
| 255 | + table["CAL_FILE"][row] = self.m_outfile | |
| 256 | + | |
| 257 | + # Add effective area information | |
| 258 | + row = row_index-4 | |
| 259 | + table["CAL_CNAM"][row] = "EFF_AREA" | |
| 260 | + table["CAL_DESC"][row] = self.m_instrument+" effective area" | |
| 261 | + | |
| 262 | + # Add point spread function information | |
| 263 | + row = row_index-3 | |
| 264 | + table["CAL_CNAM"][row] = "RPSF" | |
| 265 | + table["CAL_DESC"][row] = self.m_instrument+" point spread function" | |
| 266 | + | |
| 267 | + # Add energy dispersion information | |
| 268 | + row = row_index-2 | |
| 269 | + table["CAL_CNAM"][row] = "EDISP" | |
| 270 | + table["CAL_DESC"][row] = self.m_instrument+" energy dispersion" | |
| 271 | + | |
| 272 | + # Add background information | |
| 273 | + row = row_index-1 | |
| 274 | + table["CAL_CNAM"][row] = "BGD" | |
| 275 | + table["CAL_DESC"][row] = self.m_instrument+" background" | |
| 276 | + | |
| 277 | + # Return CIF FITS file | |
| 278 | + return cif | |
| 279 | + | |
| 280 | + def make_dirs(self): | |
| 281 | + | |
| 282 | + # Create gammalib Caldb | |
| 283 | + caldb = gammalib.GCaldb() | |
| 284 | + | |
| 285 | + # Set calibration directory | |
| 286 | + self.cal_dir = "data" | |
| 287 | + self.cal_dir += "/"+self.m_mission.lower() | |
| 288 | + self.cal_dir += "/"+self.m_instrument.lower() | |
| 289 | + self.cal_dir += "/bcf/"+self.m_rspname | |
| 290 | + | |
| 291 | + # Set absolute path | |
| 292 | + self.base_dir = caldb.rootdir() +"/data" | |
| 293 | + self.base_dir += "/"+self.m_mission.lower() | |
| 294 | + self.base_dir += "/"+self.m_instrument.lower() | |
| 295 | + | |
| 296 | + # Set directory for irf file | |
| 297 | + self.rsp_dir = caldb.rootdir() + "/" + self.cal_dir | |
| 298 | + | |
| 299 | + # Create directories and log information | |
| 300 | + if not os.path.isdir(self.rsp_dir): | |
| 301 | + if self.logExplicit(): | |
| 302 | + self.log(gammalib.parformat("Directory")) | |
| 303 | + self.log(self.rsp_dir) | |
| 304 | + self.log("\n") | |
| 305 | + os.makedirs(self.rsp_dir) | |
| 306 | + else: | |
| 307 | + if self.logExplicit(): | |
| 308 | + self.log(gammalib.parformat("Directory (existing)")) | |
| 309 | + self.log(self.rsp_dir) | |
| 310 | + self.log("\n") | |
| 311 | + | |
| 312 | + # Return | |
| 313 | + return | |
| 314 | + | |
| 315 | + def run(self): | |
| 316 | + """ | |
| 317 | + Run the script. | |
| 318 | + """ | |
| 319 | + # Switch screen logging on in debug mode | |
| 320 | + if self.logDebug(): | |
| 321 | + self.log.cout(True) | |
| 322 | + | |
| 323 | + # Get parameters | |
| 324 | + self.get_parameters() | |
| 325 | + | |
| 326 | + # Write input parameters into logger | |
| 327 | + if self.logTerse(): | |
| 328 | + self.log_parameters() | |
| 329 | + self.log("\n\n") | |
| 330 | + self.log.header1("Creating directory structure") | |
| 331 | + | |
| 332 | + # Create directory structure | |
| 333 | + self.make_dirs() | |
| 334 | + | |
| 335 | + # Logging | |
| 336 | + if self.logTerse(): | |
| 337 | + self.log("\n") | |
| 338 | + self.log.header1("Updating calibration database") | |
| 339 | + | |
| 340 | + # Create/update calibration database | |
| 341 | + self.caldb_inx = self.make_caldb_index() | |
| 342 | + | |
| 343 | + # Logging | |
| 344 | + if self.logTerse(): | |
| 345 | + self.log("\n") | |
| 346 | + self.log.header1("Creating response file") | |
| 347 | + | |
| 348 | + # Create IRF file | |
| 349 | + self.irf_fits = self.make_irf_file() | |
| 350 | + | |
| 351 | + # Return | |
| 352 | + return | |
| 353 | + | |
| 354 | + def save(self): | |
| 355 | + | |
| 356 | + # Save caldb index file | |
| 357 | + self.caldb_inx.save(self.m_clobber) | |
| 358 | + | |
| 359 | + # Save response file | |
| 360 | + self.irf_fits.saveto(self.rsp_dir + "/" + self.m_outfile, self.m_clobber) | |
| 361 | + | |
| 362 | + # Return | |
| 363 | + return | |
| 364 | + | |
| 365 | + def execute(self): | |
| 366 | + """ | |
| 367 | + Execute the script. | |
| 368 | + """ | |
| 369 | + # Run the script | |
| 370 | + self.run() | |
| 371 | + | |
| 372 | + # Save to disk | |
| 373 | + self.save() | |
| 374 | + | |
| 375 | + # Return | |
| 376 | + return | |
| 377 | + | |
| 378 | + | |
| 379 | +# ======================== # | |
| 380 | +# Main routine entry point # | |
| 381 | +# ======================== # | |
| 382 | +if __name__ == '__main__': | |
| 383 | + """ | |
| 384 | + Generates caldb entry. | |
| 385 | + """ | |
| 386 | + # Create instance of application | |
| 387 | + app = csobs2caldb(sys.argv) | |
| 388 | + | |
| 389 | + # Open logfile | |
| 390 | + app.logFileOpen() | |
| 391 | + | |
| 392 | + # Execute application | |
| 393 | + app.execute() | ... | ... |
cscripts/csobsdef.py
| ... | ... | @@ -29,7 +29,7 @@ import sys |
| 29 | 29 | class csobsdef(ctools.cscript): |
| 30 | 30 | """ |
| 31 | 31 | The csobsdef class generates an observation definition file from a |
| 32 | - pointing list. The pointing list is a colon separated value ASCII | |
| 32 | + pointing list. The pointing list is a comma-separated value ASCII | |
| 33 | 33 | file with header keywords in the first row followed by a list of |
| 34 | 34 | pointings (one pointing per row). The following header keywords |
| 35 | 35 | are supported (case sensitive, column order irrelevant): |
| ... | ... | @@ -51,7 +51,7 @@ class csobsdef(ctools.cscript): |
| 51 | 51 | Only the pairs (ra,dec) or (lon,lat) are mandatory header keywords. |
| 52 | 52 | All other keywords are optional and can be specified when calling |
| 53 | 53 | csobsdef as user parameters. The only exception is the "duration" |
| 54 | - keyword that will automatically queried. | |
| 54 | + keyword that will automatically be queried. | |
| 55 | 55 | |
| 56 | 56 | Here some usage examples: |
| 57 | 57 | |
| ... | ... | @@ -128,8 +128,8 @@ class csobsdef(ctools.cscript): |
| 128 | 128 | |
| 129 | 129 | # Create default parfile |
| 130 | 130 | pars = gammalib.GApplicationPars() |
| 131 | - pars.append(gammalib.GApplicationPar("inpnt","f","a","NONE","","","Pointing definition file")) | |
| 132 | - pars.append(gammalib.GApplicationPar("outobs","f","a","obs.xml","","","Output observation definition file")) | |
| 131 | + pars.append(gammalib.GApplicationPar("inpnt","f","a","NONE","","","Input pointing definition file")) | |
| 132 | + pars.append(gammalib.GApplicationPar("outobs","f","a","obs.xml","","","Output observation definition XML file")) | |
| 133 | 133 | pars.append(gammalib.GApplicationPar("duration","r","a","1800.0","","","Pointing duration (seconds)")) |
| 134 | 134 | pars.append(gammalib.GApplicationPar("caldb","s","h","","","","Calibration database")) |
| 135 | 135 | pars.append(gammalib.GApplicationPar("irf","s","h","","","","Instrument response function")) |
| ... | ... | @@ -249,8 +249,7 @@ class csobsdef(ctools.cscript): |
| 249 | 249 | pntdir = gammalib.GSkyDir() |
| 250 | 250 | pntdir.lb_deg(lon,lat) |
| 251 | 251 | else: |
| 252 | - raise gammalib.GException.invalid_value(self.name, | |
| 253 | - "No (ra,dec) or (lon,lat) columns found in pointing" | |
| 252 | + raise RuntimeError("No (ra,dec) or (lon,lat) columns found in pointing" | |
| 254 | 253 | " definition file.") |
| 255 | 254 | obs.pointing(gammalib.GCTAPointing(pntdir)) |
| 256 | 255 | ... | ... |
cscripts/csobsinfo.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Dump information about observation into log file | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 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 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | + | |
| 25 | + | |
| 26 | +# =============== # | |
| 27 | +# csobsinfo class # | |
| 28 | +# =============== # | |
| 29 | +class csobsinfo(ctools.cscript): | |
| 30 | + """ | |
| 31 | + This class dumps information about an observation container into a | |
| 32 | + logfile or on screen. This might be helpful for quick access to an | |
| 33 | + observation container showing, e.g., total lifetime, energy range etc. | |
| 34 | + """ | |
| 35 | + def __init__(self, *argv): | |
| 36 | + """ | |
| 37 | + Constructor. | |
| 38 | + """ | |
| 39 | + # Set name | |
| 40 | + self.name = "csobsinfo" | |
| 41 | + self.version = "1.1.0" | |
| 42 | + | |
| 43 | + # Make sure that parfile exists | |
| 44 | + file = self.parfile() | |
| 45 | + | |
| 46 | + # Initialise application | |
| 47 | + if len(argv) == 0: | |
| 48 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 49 | + elif len(argv) == 1: | |
| 50 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 51 | + else: | |
| 52 | + raise TypeError("Invalid number of arguments given.") | |
| 53 | + | |
| 54 | + # Set logger properties | |
| 55 | + self.log_header() | |
| 56 | + self.log.date(True) | |
| 57 | + | |
| 58 | + # Return | |
| 59 | + return | |
| 60 | + | |
| 61 | + def __del__(self): | |
| 62 | + """ | |
| 63 | + Destructor. | |
| 64 | + """ | |
| 65 | + # Return | |
| 66 | + return | |
| 67 | + | |
| 68 | + def parfile(self): | |
| 69 | + """ | |
| 70 | + Check if parfile exists. If parfile does not exist then create a | |
| 71 | + default parfile. This kluge avoids shipping the cscript with a | |
| 72 | + parfile. | |
| 73 | + """ | |
| 74 | + | |
| 75 | + # Set parfile name | |
| 76 | + parfile = self.name+".par" | |
| 77 | + | |
| 78 | + try: | |
| 79 | + pars = gammalib.GApplicationPars(parfile) | |
| 80 | + except: | |
| 81 | + # Signal that parfile was not found | |
| 82 | + print("Parfile \""+parfile+"\" not found. Create default parfile.") | |
| 83 | + | |
| 84 | + # Create default parfile | |
| 85 | + pars = gammalib.GApplicationPars() | |
| 86 | + pars.append(gammalib.GApplicationPar("inobs","f","a","obs.xml","","","Event list, counts cube, or observation definition file")) | |
| 87 | + pars.append(gammalib.GApplicationPar("offset","b","h","no","","","Compute offset from target to pointing positions")) | |
| 88 | + pars.append(gammalib.GApplicationPar("ra","r","a","0.0","","","Target Right Ascension")) | |
| 89 | + pars.append(gammalib.GApplicationPar("dec","r","a","0.0","","","Target Declination")) | |
| 90 | + pars.append(gammalib.GApplicationPar("ds9file","f","h","NONE","","","DS9 region file containing pointings")) | |
| 91 | + pars.append_standard() | |
| 92 | + pars.append(gammalib.GApplicationPar("logfile","f","h","csobsinfo.log","","","Log filename")) | |
| 93 | + pars.save(parfile) | |
| 94 | + | |
| 95 | + # Return | |
| 96 | + return | |
| 97 | + | |
| 98 | + def get_parameters(self): | |
| 99 | + """ | |
| 100 | + Get parameters from parfile and setup the observation. | |
| 101 | + """ | |
| 102 | + # Get parameters | |
| 103 | + self.require_inobs("csobsinfo::get_parameters") | |
| 104 | + self.obs = self.get_observations(False) | |
| 105 | + | |
| 106 | + # Initialise object position | |
| 107 | + self.obj_dir = gammalib.GSkyDir() | |
| 108 | + | |
| 109 | + # Get (optional) offset parameters | |
| 110 | + self.m_offset = self["offset"].boolean() | |
| 111 | + if self.m_offset: | |
| 112 | + ra = self["ra"].real() | |
| 113 | + dec = self["dec"].real() | |
| 114 | + self.obj_dir.radec_deg(ra,dec) | |
| 115 | + | |
| 116 | + # Get (optional) DS9 filename | |
| 117 | + self.ds9file = self["ds9file"].filename() | |
| 118 | + | |
| 119 | + # Return | |
| 120 | + return | |
| 121 | + | |
| 122 | + def run(self): | |
| 123 | + """ | |
| 124 | + Run the script. | |
| 125 | + """ | |
| 126 | + # Switch screen logging on in debug mode | |
| 127 | + if self.logDebug(): | |
| 128 | + self.log.cout(True) | |
| 129 | + | |
| 130 | + # Get parameters | |
| 131 | + self.get_parameters() | |
| 132 | + | |
| 133 | + # Write input parameters into logger | |
| 134 | + if self.logTerse(): | |
| 135 | + self.log_parameters() | |
| 136 | + self.log("\n") | |
| 137 | + | |
| 138 | + # Initialise arrays to store certain values for reuse | |
| 139 | + # Todo, think about using a python dictionary | |
| 140 | + self.offsets = [] | |
| 141 | + self.zeniths = [] | |
| 142 | + self.azimuths = [] | |
| 143 | + self.pnt_ra = [] | |
| 144 | + self.pnt_dec = [] | |
| 145 | + obs_names = [] | |
| 146 | + | |
| 147 | + # Initialise output to be filled | |
| 148 | + self.ebounds = gammalib.GEbounds() | |
| 149 | + self.gti = gammalib.GGti() | |
| 150 | + ontime = 0.0 | |
| 151 | + livetime = 0.0 | |
| 152 | + n_events = 0 | |
| 153 | + n_eventbins = 0 | |
| 154 | + n_obs_binned = 0 | |
| 155 | + n_obs_unbinned = 0 | |
| 156 | + | |
| 157 | + # Logging | |
| 158 | + self.log.header1("Looping over observations") | |
| 159 | + | |
| 160 | + # Loop over observations | |
| 161 | + for obs in self.obs: | |
| 162 | + | |
| 163 | + | |
| 164 | + # Skip non-CTA observations | |
| 165 | + if not obs.classname() == "GCTAObservation": | |
| 166 | + self.log("Skipping "+obs.instrument()+" observation\n") | |
| 167 | + continue | |
| 168 | + | |
| 169 | + # Use observed object as observation name | |
| 170 | + # if name is not given | |
| 171 | + obs_name = obs.name() | |
| 172 | + if obs_name == "": | |
| 173 | + obs_name = obs.object() | |
| 174 | + | |
| 175 | + # Logging | |
| 176 | + if self.logTerse(): | |
| 177 | + self.log.header2(obs_name) | |
| 178 | + | |
| 179 | + # Retrieve observation name | |
| 180 | + obs_names.append(obs_name) | |
| 181 | + | |
| 182 | + # Retrieve energy boundaries | |
| 183 | + obs_bounds = obs.events().ebounds() | |
| 184 | + | |
| 185 | + # Retrieve time interval | |
| 186 | + obs_gti = obs.events().gti() | |
| 187 | + | |
| 188 | + # Compute mean time and dead time fraction in percent | |
| 189 | + tmean = (obs_gti.tstart() + obs_gti.tstop()) | |
| 190 | + tmean *= 0.5 | |
| 191 | + deadfrac = (1.0-obs.deadc(tmean))*100.0 | |
| 192 | + | |
| 193 | + # Retrieve pointing and store Ra,Dec | |
| 194 | + pnt_dir = obs.pointing().dir() | |
| 195 | + self.pnt_ra.append(pnt_dir.ra_deg()) | |
| 196 | + self.pnt_dec.append(pnt_dir.dec_deg()) | |
| 197 | + | |
| 198 | + # If avaliable append energy boundaries | |
| 199 | + if obs_bounds.size() > 0 : | |
| 200 | + self.ebounds.merge(obs_bounds.emin(),obs_bounds.emax()) | |
| 201 | + | |
| 202 | + # Append time interval | |
| 203 | + self.gti.merge(obs_gti.tstart(), obs_gti.tstop()) | |
| 204 | + | |
| 205 | + # increment global livetime and ontime | |
| 206 | + ontime += obs.ontime() | |
| 207 | + livetime += obs.livetime() | |
| 208 | + | |
| 209 | + # Log the event type (binned or unbinned) | |
| 210 | + if self.logTerse(): | |
| 211 | + self.log.parformat("binned") | |
| 212 | + | |
| 213 | + if obs.eventtype() == "CountsCube": | |
| 214 | + n_eventbins += obs.events().size() | |
| 215 | + n_obs_binned += 1 | |
| 216 | + if self.logTerse(): | |
| 217 | + self.log("yes") | |
| 218 | + self.log("\n") | |
| 219 | + self.log.parformat("Number of bins") | |
| 220 | + self.log(str(obs.events().size())) | |
| 221 | + self.log("\n") | |
| 222 | + else: | |
| 223 | + n_events += obs.events().size() | |
| 224 | + n_obs_unbinned += 1 | |
| 225 | + if self.logTerse(): | |
| 226 | + self.log("no") | |
| 227 | + self.log("\n") | |
| 228 | + self.log.parformat("Number of events") | |
| 229 | + self.log(str(obs.events().size())) | |
| 230 | + self.log("\n") | |
| 231 | + | |
| 232 | + # Log option | |
| 233 | + if self.logTerse(): | |
| 234 | + | |
| 235 | + # Log the observation energy range (if available) | |
| 236 | + self.log.parformat("Energy range") | |
| 237 | + if obs_bounds.size() == 0: | |
| 238 | + self.log("undefined") | |
| 239 | + else: | |
| 240 | + self.log(str(obs_bounds.emin())+" - "+str(obs_bounds.emax())) | |
| 241 | + self.log("\n") | |
| 242 | + | |
| 243 | + # Log observation time interval | |
| 244 | + self.log.parformat("Time range (MJD)") | |
| 245 | + if obs_gti.size() == 0: | |
| 246 | + self.log("undefined") | |
| 247 | + else: | |
| 248 | + self.log(str(obs_gti.tstart().mjd())+" - "+str(obs_gti.tstop().mjd())) | |
| 249 | + self.log("\n") | |
| 250 | + | |
| 251 | + # Log ontime | |
| 252 | + self.log.parformat("Ontime [s]") | |
| 253 | + self.log(str(obs.ontime())) | |
| 254 | + self.log("\n") | |
| 255 | + | |
| 256 | + # Log livetime | |
| 257 | + self.log.parformat("Livetime [s]") | |
| 258 | + self.log(str(obs.livetime())) | |
| 259 | + self.log("\n") | |
| 260 | + | |
| 261 | + # Log dead time fraction | |
| 262 | + self.log.parformat("Dead-time fraction (%)") | |
| 263 | + self.log("%.3f" % (deadfrac)) | |
| 264 | + self.log("\n") | |
| 265 | + | |
| 266 | + # Log pointing direction | |
| 267 | + self.log.parformat("Pointing") | |
| 268 | + self.log(str(pnt_dir)) | |
| 269 | + self.log("\n") | |
| 270 | + | |
| 271 | + # Log offset if possible | |
| 272 | + if self.m_offset: | |
| 273 | + offset = pnt_dir.dist_deg(self.obj_dir) | |
| 274 | + self.offsets.append(offset) | |
| 275 | + self.log.parformat("Offset") | |
| 276 | + self.log("%.2f" % (offset)) | |
| 277 | + self.log("\n") | |
| 278 | + else: | |
| 279 | + self.offsets.append(-1.0) | |
| 280 | + | |
| 281 | + # Retrieve zenith and azimuth and store for later use | |
| 282 | + zenith = obs.pointing().zenith() | |
| 283 | + azimuth = obs.pointing().azimuth() | |
| 284 | + self.zeniths.append(zenith) | |
| 285 | + self.azimuths.append(azimuth) | |
| 286 | + | |
| 287 | + # Log Zenith and Azimuth if required | |
| 288 | + if self.logExplicit(): | |
| 289 | + self.log.parformat("Zenith angle") | |
| 290 | + self.log("%.2f" % (zenith)) | |
| 291 | + self.log("\n") | |
| 292 | + self.log.parformat("Azimuth angle") | |
| 293 | + self.log("%.2f" % (azimuth)) | |
| 294 | + self.log("\n\n") | |
| 295 | + | |
| 296 | + # Log summary | |
| 297 | + self.log("\n") | |
| 298 | + self.log.header1("Summary") | |
| 299 | + | |
| 300 | + # Log general summary | |
| 301 | + self.log.parformat("Unbinned observations") | |
| 302 | + self.log(str(n_obs_unbinned)) | |
| 303 | + self.log("\n") | |
| 304 | + self.log.parformat("Number of events") | |
| 305 | + self.log(str(n_events)) | |
| 306 | + self.log("\n") | |
| 307 | + self.log.parformat("Binned observations") | |
| 308 | + self.log(str(n_obs_binned)) | |
| 309 | + self.log("\n") | |
| 310 | + self.log.parformat("Number of bins") | |
| 311 | + self.log(str(n_eventbins)) | |
| 312 | + self.log("\n\n") | |
| 313 | + | |
| 314 | + # Log pointing summary | |
| 315 | + self.log.header3("Pointings") | |
| 316 | + | |
| 317 | + # Log mean offset if possible | |
| 318 | + if self.m_offset: | |
| 319 | + self.log.parformat("Mean offset angle") | |
| 320 | + self.log("%.2f" % (sum(self.offsets)/len(self.offsets))) | |
| 321 | + self.log("\n") | |
| 322 | + | |
| 323 | + # Log mean azimuth and zenith angle | |
| 324 | + self.log.parformat("Mean zenith angle") | |
| 325 | + self.log("%.2f" % (sum(self.zeniths)/len(self.zeniths))) | |
| 326 | + self.log("\n") | |
| 327 | + self.log.parformat("Mean azimuth angle") | |
| 328 | + self.log("%.2f" % (sum(self.azimuths)/len(self.azimuths))) | |
| 329 | + self.log("\n") | |
| 330 | + | |
| 331 | + # Log name of observations if requested | |
| 332 | + if self.logExplicit(): | |
| 333 | + obs_set = set(obs_names) | |
| 334 | + for name in obs_set: | |
| 335 | + self.log.parformat("\""+name+"\"") | |
| 336 | + self.log(str(obs_names.count(name))) | |
| 337 | + self.log("\n") | |
| 338 | + self.log("\n") | |
| 339 | + | |
| 340 | + # Log energy range | |
| 341 | + self.log.header3("Energy range") | |
| 342 | + self.log.parformat("Emin") | |
| 343 | + if self.ebounds.size() == 0: | |
| 344 | + self.log("undefined") | |
| 345 | + else: | |
| 346 | + self.log(str(self.ebounds.emin())) | |
| 347 | + self.log("\n") | |
| 348 | + self.log.parformat("Emax") | |
| 349 | + if self.ebounds.size() == 0: | |
| 350 | + self.log("undefined") | |
| 351 | + else: | |
| 352 | + self.log(str(self.ebounds.emax())) | |
| 353 | + self.log("\n\n") | |
| 354 | + | |
| 355 | + # Log time range | |
| 356 | + self.log.header3("Time range") | |
| 357 | + self.log.parformat("Start [MJD]") | |
| 358 | + self.log(str(self.gti.tstart().mjd())) | |
| 359 | + self.log("\n") | |
| 360 | + self.log.parformat("Stop [MJD]") | |
| 361 | + self.log(str(self.gti.tstop().mjd())) | |
| 362 | + self.log("\n") | |
| 363 | + | |
| 364 | + # Log ontime and livetime in different units | |
| 365 | + self.log.parformat("Total ontime") | |
| 366 | + self.log("%.2f s = %.2f min = %.2f h" % (ontime, ontime/60., ontime/3600.)) | |
| 367 | + self.log("\n") | |
| 368 | + self.log.parformat("Total livetime") | |
| 369 | + self.log("%.2f s = %.2f min = %.2f h" % (livetime, livetime/60.0, livetime/3600.)) | |
| 370 | + self.log("\n") | |
| 371 | + | |
| 372 | + # Return | |
| 373 | + return | |
| 374 | + | |
| 375 | + def save(self): | |
| 376 | + """ | |
| 377 | + Save pointings to ds9 region file if required | |
| 378 | + """ | |
| 379 | + | |
| 380 | + # Check if ds9 file is valid | |
| 381 | + if not self.ds9file == "NONE": | |
| 382 | + | |
| 383 | + # Open file | |
| 384 | + f = open(self.ds9file,"w") | |
| 385 | + | |
| 386 | + # Write coordinate system | |
| 387 | + f.write("fk5\n") | |
| 388 | + | |
| 389 | + # Loop over pointings | |
| 390 | + for i in range(len(self.pnt_ra)): | |
| 391 | + | |
| 392 | + # Create string | |
| 393 | + line = "point(" | |
| 394 | + line+=str(self.pnt_ra[i])+","+str(self.pnt_dec[i])+")" | |
| 395 | + line+=" # point=cross 20 width=3 \n" | |
| 396 | + | |
| 397 | + # Write to file | |
| 398 | + f.write(line) | |
| 399 | + | |
| 400 | + # Close file | |
| 401 | + f.close() | |
| 402 | + | |
| 403 | + # Return | |
| 404 | + return | |
| 405 | + | |
| 406 | + | |
| 407 | + def zeniths(self): | |
| 408 | + """ | |
| 409 | + Return zenith angles | |
| 410 | + """ | |
| 411 | + return self.zeniths | |
| 412 | + | |
| 413 | + def azimuths(self): | |
| 414 | + """ | |
| 415 | + Return azimuth angles | |
| 416 | + """ | |
| 417 | + return self.azimuths | |
| 418 | + | |
| 419 | + def offsets(self): | |
| 420 | + """ | |
| 421 | + Return offset angles | |
| 422 | + """ | |
| 423 | + return self.offsets | |
| 424 | + | |
| 425 | + def ebounds(self): | |
| 426 | + """ | |
| 427 | + Return energy boundaries | |
| 428 | + """ | |
| 429 | + return self.ebounds | |
| 430 | + | |
| 431 | + def gti(self): | |
| 432 | + """ | |
| 433 | + Return good time intervals | |
| 434 | + """ | |
| 435 | + return self.gti | |
| 436 | + | |
| 437 | + def execute(self): | |
| 438 | + """ | |
| 439 | + Execute the script. | |
| 440 | + """ | |
| 441 | + # Run the script | |
| 442 | + self.run() | |
| 443 | + | |
| 444 | + # Save ds9 file if required | |
| 445 | + self.save() | |
| 446 | + | |
| 447 | + # Return | |
| 448 | + return | |
| 449 | + | |
| 450 | + | |
| 451 | +# ======================== # | |
| 452 | +# Main routine entry point # | |
| 453 | +# ======================== # | |
| 454 | +if __name__ == '__main__': | |
| 455 | + """ | |
| 456 | + Generates information about an observation container. | |
| 457 | + """ | |
| 458 | + # Create instance of application | |
| 459 | + app = csobsinfo(sys.argv) | |
| 460 | + | |
| 461 | + # Open logfile | |
| 462 | + app.logFileOpen() | |
| 463 | + | |
| 464 | + # Execute application | |
| 465 | + app.execute() | ... | ... |
cscripts/cspull.py
| ... | ... | @@ -101,13 +101,13 @@ class cspull(ctools.cscript): |
| 101 | 101 | |
| 102 | 102 | # Create default parfile |
| 103 | 103 | pars = gammalib.GApplicationPars() |
| 104 | - pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Event list, counts cube, or observation definition file")) | |
| 105 | - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) | |
| 106 | - pars.append(gammalib.GApplicationPar("outfile","f","a","pull.dat","","","Output file name")) | |
| 104 | + pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Input event list, counts cube, or observation definition XML file")) | |
| 105 | + pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) | |
| 107 | 106 | pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) |
| 108 | - pars.append(gammalib.GApplicationPar("irf","s","a","South_50h","","","Instrument response function")) | |
| 109 | - pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","0","1","Deadtime correction factor")) | |
| 107 | + pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) | |
| 110 | 108 | pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) |
| 109 | + pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","0","1","Deadtime correction factor")) | |
| 110 | + pars.append(gammalib.GApplicationPar("outfile","f","a","pull.dat","","","Output pull distribution file")) | |
| 111 | 111 | pars.append(gammalib.GApplicationPar("profile","b","h","no","","","Use likelihood profile method for errors?")) |
| 112 | 112 | pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials")) |
| 113 | 113 | pars.append(gammalib.GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)")) | ... | ... |
cscripts/csresmap.py
| ... | ... | @@ -103,16 +103,16 @@ class csresmap(ctools.cscript): |
| 103 | 103 | |
| 104 | 104 | # Create default parfile |
| 105 | 105 | pars = gammalib.GApplicationPars() |
| 106 | - pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Event list, counts cube, or observation definition file")) | |
| 107 | - pars.append(gammalib.GApplicationPar("modcube","f","a","NONE","","","Model cube file (generated with ctmodel)")) | |
| 108 | - pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) | |
| 109 | - pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","PSF cube file (only needed for stacked analysis)")) | |
| 110 | - pars.append(gammalib.GApplicationPar("bkgcube","f","a","NONE","","","Background cube file (only needed for stacked analysis)")) | |
| 111 | - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) | |
| 112 | - pars.append(gammalib.GApplicationPar("outmap","f","a","resmap.fits","","","Output residual map")) | |
| 113 | - pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) | |
| 106 | + pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Input event list, counts cube, or observation definition XML file")) | |
| 107 | + pars.append(gammalib.GApplicationPar("modcube","f","a","NONE","","","Input model cube file (generated with ctmodel)")) | |
| 108 | + pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Input exposure cube file (only needed for stacked analysis)")) | |
| 109 | + pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","Input PSF cube file (only needed for stacked analysis)")) | |
| 110 | + pars.append(gammalib.GApplicationPar("bkgcube","f","a","NONE","","","Input background cube file (only needed for stacked analysis)")) | |
| 111 | + pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) | |
| 114 | 112 | pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) |
| 115 | - pars.append(gammalib.GApplicationPar("irf","s","a","South_50h","","","Instrument response function")) | |
| 113 | + pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) | |
| 114 | + pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) | |
| 115 | + pars.append(gammalib.GApplicationPar("outmap","f","a","resmap.fits","","","Output residual map file")) | |
| 116 | 116 | pars.append(gammalib.GApplicationPar("ebinalg","s","h","LOG","LIN|LOG|FILE","","Binning algorithm")) |
| 117 | 117 | pars.append(gammalib.GApplicationPar("emin","r","h","0.1","","","Lower energy limit (TeV)")) |
| 118 | 118 | pars.append(gammalib.GApplicationPar("emax","r","h","100.0","","","Upper energy limit (TeV)")) | ... | ... |
cscripts/cssens.py
| ... | ... | @@ -97,14 +97,14 @@ class cssens(ctools.cscript): |
| 97 | 97 | |
| 98 | 98 | # Create default parfile |
| 99 | 99 | pars = gammalib.GApplicationPars() |
| 100 | - pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Event list, counts cube, or observation definition file")) | |
| 101 | - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) | |
| 100 | + pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Input event list, counts cube, or observation definition XML file")) | |
| 101 | + pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) | |
| 102 | 102 | pars.append(gammalib.GApplicationPar("srcname","s","a","Crab","","","Source name")) |
| 103 | - pars.append(gammalib.GApplicationPar("offset","r","h","0.0","","","Source offset angle (deg)")) | |
| 104 | 103 | pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) |
| 105 | - pars.append(gammalib.GApplicationPar("irf","s","a","South_50h","","","Instrument response function")) | |
| 104 | + pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) | |
| 106 | 105 | pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","0","1","Deadtime correction factor")) |
| 107 | - pars.append(gammalib.GApplicationPar("outfile","f","h","sensitivity.dat","","","Output file name")) | |
| 106 | + pars.append(gammalib.GApplicationPar("outfile","f","h","sensitivity.dat","","","Output sensitivity ASCII file")) | |
| 107 | + pars.append(gammalib.GApplicationPar("offset","r","h","0.0","","","Source offset angle (deg)")) | |
| 108 | 108 | pars.append(gammalib.GApplicationPar("duration","r","a","180000.0","","","Effective exposure time (s)")) |
| 109 | 109 | pars.append(gammalib.GApplicationPar("rad","r","a","5.0","","","Radius of ROI (deg)")) |
| 110 | 110 | pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) |
| ... | ... | @@ -241,7 +241,7 @@ class cssens(ctools.cscript): |
| 241 | 241 | else: |
| 242 | 242 | msg = "Invalid sensitivity type \""+self.m_type+"\" encountered."+ \ |
| 243 | 243 | " Either use \"Differential\" or \"Integral\"." |
| 244 | - raise gammalib.GException.invalid_value("cssens", msg) | |
| 244 | + raise RuntimeError(msg) | |
| 245 | 245 | |
| 246 | 246 | # Determine sensitivity |
| 247 | 247 | result = self.get_sensitivity(self.obs, emin, emax, |
| ... | ... | @@ -347,7 +347,7 @@ class cssens(ctools.cscript): |
| 347 | 347 | if not model.has_par("Prefactor"): |
| 348 | 348 | msg = "Model \""+self.m_srcname+"\" has no parameter \"Prefactor\"."+ \ |
| 349 | 349 | " Only spectral models with a \"Prefactor\" parameter are supported." |
| 350 | - raise gammalib.GException.invalid_value("cssens", msg) | |
| 350 | + raise RuntimeError(msg) | |
| 351 | 351 | |
| 352 | 352 | # Set source position |
| 353 | 353 | if self.m_ra != None and self.m_dec != None: | ... | ... |
cscripts/csspec.py
| ... | ... | @@ -43,7 +43,7 @@ class csspec(ctools.cscript): |
| 43 | 43 | self.version = "1.0.0" |
| 44 | 44 | |
| 45 | 45 | # Initialise some members |
| 46 | - self.obs = None | |
| 46 | + self.obs = gammalib.GObservations() | |
| 47 | 47 | self.fits = None |
| 48 | 48 | |
| 49 | 49 | # Initialise some members |
| ... | ... | @@ -100,30 +100,21 @@ class csspec(ctools.cscript): |
| 100 | 100 | |
| 101 | 101 | # Create default parfile |
| 102 | 102 | pars = gammalib.GApplicationPars() |
| 103 | - pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Event list, counts cube, or observation definition file")) | |
| 104 | - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) | |
| 103 | + pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Input event list, counts cube, or observation definition XML file")) | |
| 104 | + pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) | |
| 105 | 105 | pars.append(gammalib.GApplicationPar("srcname","s","a","Crab","","","Source name")) |
| 106 | - pars.append(gammalib.GApplicationPar("outfile","f","a","spectrum.fits","","","Output file name")) | |
| 107 | - pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) | |
| 108 | - pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","PSF cube file (only needed for stacked analysis)")) | |
| 109 | - pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Background cube file (only needed for stacked analysis)")) | |
| 106 | + pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Input exposure cube file (only needed for stacked analysis)")) | |
| 107 | + pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","Input PSF cube file (only needed for stacked analysis)")) | |
| 108 | + pars.append(gammalib.GApplicationPar("bkgcube","f","a","NONE","","","Input background cube file (only needed for stacked analysis)")) | |
| 110 | 109 | pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) |
| 111 | - pars.append(gammalib.GApplicationPar("irf","s","a","South_50h","","","Instrument response function")) | |
| 110 | + pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) | |
| 112 | 111 | pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) |
| 113 | - pars.append(gammalib.GApplicationPar("emin","r","h","0.1","","","Lower energy limit for spectral points(TeV)")) | |
| 114 | - pars.append(gammalib.GApplicationPar("emax","r","h","100.0","","","Upper energy limit for spectral points(TeV)")) | |
| 115 | - pars.append(gammalib.GApplicationPar("enumbins","i","a","20","","","Number of spectral points")) | |
| 116 | - pars.append(gammalib.GApplicationPar("ebinalg","s", "h","LOG","FILE|LIN|LOG","", "Algorithm for defining energy bins")) | |
| 117 | - pars.append(gammalib.GApplicationPar("binned","b","a","no","yes|no","","Use binned analysis in each energy bin")) | |
| 118 | - pars.append(gammalib.GApplicationPar("nebins","i","h","5","","","Number of energy bins per spectral point")) | |
| 119 | - pars.append(gammalib.GApplicationPar("coordsys","s","a","CEL","CEL|GAL","","Coordinate System")) | |
| 120 | - pars.append(gammalib.GApplicationPar("proj","s","a","CAR","AIT|AZP|CAR|MER|MOL|STG|TAN","","Projection method")) | |
| 121 | - pars.append(gammalib.GApplicationPar("xref","r","a","83.63","0","360","First coordinate of image center in degrees (RA or galactic l)")) | |
| 122 | - pars.append(gammalib.GApplicationPar("yref","r","a","22.01","-90","90","Second coordinate of image center in degrees (DEC or galactic b)")) | |
| 123 | - pars.append(gammalib.GApplicationPar("nxpix","i","a","200","","","Size of the X axis in pixels")) | |
| 124 | - pars.append(gammalib.GApplicationPar("nypix","i","a","200","","","Size of the Y axis in pixels")) | |
| 125 | - pars.append(gammalib.GApplicationPar("binsz","r","a","0.02","","","Pixel size (deg/pixel)")) | |
| 126 | - pars.append(gammalib.GApplicationPar("anumbins","i","h","200","","","Angular separation bins for PSF cube in binned mode")) | |
| 112 | + pars.append(gammalib.GApplicationPar("outfile","f","a","spectrum.fits","","","Output spectrum file")) | |
| 113 | + pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit for spectral points (TeV)")) | |
| 114 | + pars.append(gammalib.GApplicationPar("emax","r","a","100.0","","","Upper energy limit for spectral points (TeV)")) | |
| 115 | + pars.append(gammalib.GApplicationPar("enumbins","i","a","20","1","10000","Number of spectral points")) | |
| 116 | + pars.append(gammalib.GApplicationPar("ebinalg","s","a","LOG","FILE|LIN|LOG","", "Algorithm for defining energy bins")) | |
| 117 | + pars.append(gammalib.GApplicationPar("ebinfile","f","a","NONE","","", "Name of the file containing the energy bin definition")) | |
| 127 | 118 | pars.append(gammalib.GApplicationPar("calc_ts","b","h","yes","yes|no","","Compute TS value in each bin")) |
| 128 | 119 | pars.append(gammalib.GApplicationPar("calc_ulim","b","h","yes","yes|no","","Compute upper limit in each bin")) |
| 129 | 120 | pars.append(gammalib.GApplicationPar("fix_srcs","b","h","yes","yes|no","","Fix other skymodel parameters")) |
| ... | ... | @@ -143,6 +134,13 @@ class csspec(ctools.cscript): |
| 143 | 134 | if self.obs == None or self.obs.size() == 0: |
| 144 | 135 | self.require_inobs("csspec::get_parameters()") |
| 145 | 136 | self.obs = self.get_observations() |
| 137 | + | |
| 138 | + # Check if we have one binned cta observation, i.e. if we are in binned mode | |
| 139 | + self.m_binned_mode = False | |
| 140 | + if self.obs.size() == 1: | |
| 141 | + if self.obs[0].classname() == "GCTAObservation": | |
| 142 | + if self.obs[0].eventtype() == "CountsCube": | |
| 143 | + self.m_binned_mode = True | |
| 146 | 144 | |
| 147 | 145 | # Set models if we have none |
| 148 | 146 | if self.obs.models().size() == 0: |
| ... | ... | @@ -151,25 +149,11 @@ class csspec(ctools.cscript): |
| 151 | 149 | # Get source name |
| 152 | 150 | self.m_srcname = self["srcname"].string() |
| 153 | 151 | |
| 154 | - # Get ebounds | |
| 155 | - self.m_ebounds = self.create_ebounds() | |
| 156 | - | |
| 157 | - # Get binning flag | |
| 158 | - self.m_binned = self["binned"].boolean() | |
| 159 | - | |
| 152 | + # Set ebounds | |
| 153 | + self.set_ebounds() | |
| 154 | + | |
| 160 | 155 | # Get edisp flag |
| 161 | 156 | self.m_edisp = self["edisp"].boolean() |
| 162 | - | |
| 163 | - if self.m_binned: | |
| 164 | - self.m_xref = self["xref"].real() | |
| 165 | - self.m_yref = self["yref"].real() | |
| 166 | - self.m_nxpix = self["nxpix"].integer() | |
| 167 | - self.m_nypix = self["nypix"].integer() | |
| 168 | - self.m_binsz = self["binsz"].real() | |
| 169 | - self.m_coordsys = self["coordsys"].string() | |
| 170 | - self.m_proj = self["proj"].string() | |
| 171 | - self.m_ebins = self["nebins"].integer() | |
| 172 | - self.m_anumbins = self["anumbins"].integer() | |
| 173 | 157 | |
| 174 | 158 | # Read other parameters |
| 175 | 159 | self.m_outfile = self["outfile"].filename() |
| ... | ... | @@ -189,6 +173,66 @@ class csspec(ctools.cscript): |
| 189 | 173 | # Return |
| 190 | 174 | return |
| 191 | 175 | |
| 176 | + def set_ebounds(self): | |
| 177 | + """ | |
| 178 | + Set energy boundaries. | |
| 179 | + """ | |
| 180 | + # Get ebounds | |
| 181 | + if self.m_binned_mode: | |
| 182 | + | |
| 183 | + # Extract cube ebounds | |
| 184 | + cube_ebounds = self.obs[0].events().ebounds() | |
| 185 | + | |
| 186 | + # Read user parameters | |
| 187 | + self.m_enumbins = self["enumbins"].integer() | |
| 188 | + self.m_emin = self["emin"].real() - 1e-6 # Rounding tolerance | |
| 189 | + self.m_emax = self["emax"].real() + 1e-6 # Rounding tolerance | |
| 190 | + | |
| 191 | + # Set energy range | |
| 192 | + emin = gammalib.GEnergy(self.m_emin, "TeV") | |
| 193 | + emax = gammalib.GEnergy(self.m_emax, "TeV") | |
| 194 | + | |
| 195 | + # Determine all cube layers that overlap with the [emin,emax] | |
| 196 | + # energy range. | |
| 197 | + use_layers = [] | |
| 198 | + for i in range(cube_ebounds.size()): | |
| 199 | + if cube_ebounds.emin(i) < emax and cube_ebounds.emax(i) > emin: | |
| 200 | + use_layers.append(i) | |
| 201 | + | |
| 202 | + # If no layers overlap then throw an exception | |
| 203 | + if (len(use_layers) == 0): | |
| 204 | + msg = "Energy range ["+str(cube_ebounds.emin(i))+ \ | |
| 205 | + ", "+str(cube_ebounds.emax(i))+"] of counts "+ \ | |
| 206 | + "cube does not overlap with specified energy range ["+ \ | |
| 207 | + str(emin)+", "+str(emax)+"]. Specify "+ \ | |
| 208 | + "overlapping energy range." | |
| 209 | + raise RuntimeError(msg) | |
| 210 | + | |
| 211 | + # Determine number of layers to use for each spectral bin | |
| 212 | + n_layers = int(len(use_layers) / self.m_enumbins) | |
| 213 | + | |
| 214 | + # Don't allow zero layers | |
| 215 | + if n_layers == 0: | |
| 216 | + n_layers = 1 | |
| 217 | + | |
| 218 | + # Create energy boundaries | |
| 219 | + self.m_ebounds = gammalib.GEbounds() | |
| 220 | + for i in range(len(use_layers))[::n_layers]: | |
| 221 | + i_start = i | |
| 222 | + i_stop = i + n_layers - 1 | |
| 223 | + if i_stop >= len(use_layers): | |
| 224 | + i_stop = len(use_layers) - 1 | |
| 225 | + ebinmin = cube_ebounds.emin(use_layers[i_start]) | |
| 226 | + ebinmax = cube_ebounds.emax(use_layers[i_stop]) | |
| 227 | + self.m_ebounds.append(ebinmin, ebinmax) | |
| 228 | + | |
| 229 | + # Unbinned mode | |
| 230 | + else: | |
| 231 | + self.m_ebounds = self.create_ebounds() | |
| 232 | + | |
| 233 | + # Return | |
| 234 | + return | |
| 235 | + | |
| 192 | 236 | def models(self, models): |
| 193 | 237 | """ |
| 194 | 238 | Set model. |
| ... | ... | @@ -235,6 +279,24 @@ class csspec(ctools.cscript): |
| 235 | 279 | self.log_parameters() |
| 236 | 280 | self.log("\n") |
| 237 | 281 | |
| 282 | + # Write spectral binning into header | |
| 283 | + if self.logTerse(): | |
| 284 | + self.log("\n") | |
| 285 | + self.log.header1("Spectral binning") | |
| 286 | + if self.m_binned_mode: | |
| 287 | + cube_ebounds = self.obs[0].events().ebounds() | |
| 288 | + self.log.parformat("Counts cube energy range") | |
| 289 | + self.log(str(cube_ebounds.emin())) | |
| 290 | + self.log(" - ") | |
| 291 | + self.log(str(cube_ebounds.emax())) | |
| 292 | + self.log("\n") | |
| 293 | + for i in range(self.m_ebounds.size()): | |
| 294 | + self.log.parformat("Bin "+str(i+1)) | |
| 295 | + self.log(str(self.m_ebounds.emin(i))) | |
| 296 | + self.log(" - ") | |
| 297 | + self.log(str(self.m_ebounds.emax(i))) | |
| 298 | + self.log("\n") | |
| 299 | + | |
| 238 | 300 | # Write observation into logger |
| 239 | 301 | if self.logTerse(): |
| 240 | 302 | self.log("\n") |
| ... | ... | @@ -286,7 +348,8 @@ class csspec(ctools.cscript): |
| 286 | 348 | # Write header |
| 287 | 349 | if self.logTerse(): |
| 288 | 350 | self.log("\n") |
| 289 | - self.log.header1("Generate spectrum") | |
| 351 | + self.log.header1("Generate spectrum") | |
| 352 | + self.log(str(self.m_ebounds)) | |
| 290 | 353 | |
| 291 | 354 | # Initialise FITS Table with extension "SPECTRUM" |
| 292 | 355 | table = gammalib.GFitsBinTable(self.m_ebounds.size()) |
| ... | ... | @@ -298,26 +361,25 @@ class csspec(ctools.cscript): |
| 298 | 361 | |
| 299 | 362 | # Create FITS table columns |
| 300 | 363 | energy = gammalib.GFitsTableDoubleCol("Energy", self.m_ebounds.size()) |
| 301 | - energy.unit("TeV") | |
| 302 | 364 | energy_low = gammalib.GFitsTableDoubleCol("ed_Energy", self.m_ebounds.size()) |
| 303 | - energy_low.unit("TeV") | |
| 304 | 365 | energy_high = gammalib.GFitsTableDoubleCol("eu_Energy", self.m_ebounds.size()) |
| 305 | - energy_high.unit("TeV") | |
| 306 | 366 | flux = gammalib.GFitsTableDoubleCol("Flux", self.m_ebounds.size()) |
| 307 | - flux.unit("erg/cm2/s") | |
| 308 | 367 | flux_err = gammalib.GFitsTableDoubleCol("e_Flux", self.m_ebounds.size()) |
| 309 | - flux_err.unit("erg/cm2/s") | |
| 310 | 368 | TSvalues = gammalib.GFitsTableDoubleCol("TS", self.m_ebounds.size()) |
| 311 | 369 | ulim_values = gammalib.GFitsTableDoubleCol("UpperLimit", self.m_ebounds.size()) |
| 312 | - ulim_values.unit("erg/cm2/s") | |
| 313 | 370 | Npred_values = gammalib.GFitsTableDoubleCol("Npred", self.m_ebounds.size()) |
| 314 | - | |
| 371 | + energy.unit("TeV") | |
| 372 | + energy_low.unit("TeV") | |
| 373 | + energy_high.unit("TeV") | |
| 374 | + flux.unit("erg/cm2/s") | |
| 375 | + flux_err.unit("erg/cm2/s") | |
| 376 | + ulim_values.unit("erg/cm2/s") | |
| 315 | 377 | |
| 316 | 378 | # Loop over energy bins |
| 317 | 379 | for i in range(self.m_ebounds.size()): |
| 318 | 380 | |
| 319 | 381 | # Log information |
| 320 | - if self.logTerse(): | |
| 382 | + if self.logExplicit(): | |
| 321 | 383 | self.log("\n") |
| 322 | 384 | self.log.header2("Energy bin "+str(i+1)) |
| 323 | 385 | |
| ... | ... | @@ -334,8 +396,8 @@ class csspec(ctools.cscript): |
| 334 | 396 | energy_low[i] = (elogmean - emin).TeV() |
| 335 | 397 | energy_high[i] = (emax - elogmean).TeV() |
| 336 | 398 | |
| 337 | - # unbinned analysis | |
| 338 | - if not self.m_binned: | |
| 399 | + # use ctselect for unbinned analysis | |
| 400 | + if not self.m_binned_mode: | |
| 339 | 401 | |
| 340 | 402 | # Log information |
| 341 | 403 | if self.logExplicit(): |
| ... | ... | @@ -355,129 +417,43 @@ class csspec(ctools.cscript): |
| 355 | 417 | # Retrieve observation |
| 356 | 418 | obs = select.obs() |
| 357 | 419 | |
| 358 | - # Binned analysis | |
| 420 | + # use ctcubemask for binned analysis | |
| 359 | 421 | else: |
| 360 | 422 | |
| 361 | 423 | # Header |
| 362 | - if self.logTerse(): | |
| 363 | - self.log.header3("Binning events") | |
| 364 | - | |
| 365 | - # Bin events | |
| 366 | - bin = ctools.ctbin(self.obs) | |
| 367 | - bin["usepnt"] = False | |
| 368 | - bin["ebinalg"] = "LOG" | |
| 369 | - bin["xref"] = self.m_xref | |
| 370 | - bin["yref"] = self.m_yref | |
| 371 | - bin["binsz"] = self.m_binsz | |
| 372 | - bin["nxpix"] = self.m_nxpix | |
| 373 | - bin["nypix"] = self.m_nypix | |
| 374 | - bin["enumbins"] = self.m_ebins | |
| 375 | - bin["emin"] = emin.TeV() | |
| 376 | - bin["emax"] = emax.TeV() | |
| 377 | - bin["coordsys"] = self.m_coordsys | |
| 378 | - bin["proj"] = self.m_proj | |
| 379 | - bin.run() | |
| 380 | - | |
| 381 | - # Header | |
| 382 | - if self.logTerse(): | |
| 383 | - self.log.header3("Creating exposure cube") | |
| 384 | - | |
| 385 | - # Create exposure cube | |
| 386 | - expcube = ctools.ctexpcube(self.obs) | |
| 387 | - expcube["incube"] = "NONE" | |
| 388 | - expcube["usepnt"] = False | |
| 389 | - expcube["ebinalg"] = "LOG" | |
| 390 | - expcube["edisp"] = self.m_edisp | |
| 391 | - expcube["xref"] = self.m_xref | |
| 392 | - expcube["yref"] = self.m_yref | |
| 393 | - expcube["binsz"] = self.m_binsz | |
| 394 | - expcube["nxpix"] = self.m_nxpix | |
| 395 | - expcube["nypix"] = self.m_nypix | |
| 396 | - expcube["enumbins"] = self.m_ebins | |
| 397 | - expcube["emin"] = emin.TeV() | |
| 398 | - expcube["emax"] = emax.TeV() | |
| 399 | - expcube["coordsys"] = self.m_coordsys | |
| 400 | - expcube["proj"] = self.m_proj | |
| 401 | - expcube.run() | |
| 402 | - | |
| 403 | - # Header | |
| 404 | - if self.logTerse(): | |
| 405 | - self.log.header3("Creating PSF cube") | |
| 406 | - | |
| 407 | - # Create psf cube | |
| 408 | - psfcube = ctools.ctpsfcube(self.obs) | |
| 409 | - psfcube["incube"] = "NONE" | |
| 410 | - psfcube["usepnt"] = False | |
| 411 | - psfcube["ebinalg"] = "LOG" | |
| 412 | - psfcube["edisp"] = self.m_edisp | |
| 413 | - psfcube["xref"] = self.m_xref | |
| 414 | - psfcube["yref"] = self.m_yref | |
| 415 | - psfcube["binsz"] = self.m_binsz*20.0 # Slow Psf variation | |
| 416 | - psfcube["nxpix"] = self.m_nxpix/20+1 | |
| 417 | - psfcube["nypix"] = self.m_nypix/20+1 | |
| 418 | - psfcube["enumbins"] = self.m_ebins | |
| 419 | - psfcube["anumbins"] = self.m_anumbins | |
| 420 | - psfcube["emin"] = emin.TeV() | |
| 421 | - psfcube["emax"] = emax.TeV() | |
| 422 | - psfcube["coordsys"] = self.m_coordsys | |
| 423 | - psfcube["proj"] = self.m_proj | |
| 424 | - psfcube.run() | |
| 425 | - | |
| 426 | - # Header | |
| 427 | - if self.logTerse(): | |
| 428 | - self.log.header3("Creating background cube") | |
| 429 | - | |
| 430 | - # Create background cube | |
| 431 | - bkgcube = ctools.ctbkgcube(self.obs) | |
| 432 | - bkgcube["incube"] = "NONE" | |
| 433 | - bkgcube["usepnt"] = False | |
| 434 | - bkgcube["ebinalg"] = "LOG" | |
| 435 | - bkgcube["xref"] = self.m_xref | |
| 436 | - bkgcube["yref"] = self.m_yref | |
| 437 | - bkgcube["binsz"] = self.m_binsz | |
| 438 | - bkgcube["nxpix"] = self.m_nxpix | |
| 439 | - bkgcube["nypix"] = self.m_nypix | |
| 440 | - bkgcube["enumbins"] = self.m_ebins | |
| 441 | - bkgcube["emin"] = emin.TeV() | |
| 442 | - bkgcube["emax"] = emax.TeV() | |
| 443 | - bkgcube["coordsys"] = self.m_coordsys | |
| 444 | - bkgcube["proj"] = self.m_proj | |
| 445 | - bkgcube.run() | |
| 446 | - | |
| 424 | + if self.logExplicit(): | |
| 425 | + self.log.header3("Filtering cube") | |
| 426 | + | |
| 427 | + # Select layers | |
| 428 | + cubemask = ctools.ctcubemask(self.obs) | |
| 429 | + cubemask["regfile"] = "NONE" | |
| 430 | + cubemask["ra"] = "UNDEFINED" | |
| 431 | + cubemask["dec"] = "UNDEFINED" | |
| 432 | + cubemask["rad"] = "UNDEFINED" | |
| 433 | + cubemask["emin"] = emin.TeV() | |
| 434 | + cubemask["emax"] = emax.TeV() | |
| 435 | + cubemask.run() | |
| 436 | + | |
| 447 | 437 | # Set new binned observation |
| 448 | - obs = bin.obs() | |
| 449 | - | |
| 450 | - # Set precomputed binned response | |
| 451 | - obs[0].response(expcube.expcube(), psfcube.psfcube(), bkgcube.bkgcube()) | |
| 452 | - | |
| 453 | - # Get new models | |
| 454 | - models = bkgcube.models() | |
| 455 | - | |
| 456 | - # Fix background models if required | |
| 457 | - if self.m_fix_bkg: | |
| 458 | - for model in models: | |
| 459 | - if not model.classname() == "GModelSky": | |
| 460 | - for par in model: | |
| 461 | - par.fix() | |
| 462 | - | |
| 463 | - # Set new models to binned observation | |
| 464 | - obs.models(models) | |
| 438 | + obs = cubemask.obs() | |
| 465 | 439 | |
| 466 | 440 | # Header |
| 467 | - if self.logTerse(): | |
| 441 | + if self.logExplicit(): | |
| 468 | 442 | self.log.header3("Performing fit") |
| 469 | 443 | |
| 470 | 444 | # Likelihood |
| 471 | - like = ctools.ctlike(obs) | |
| 472 | - like["edisp"].boolean(self.m_edisp) | |
| 445 | + like = ctools.ctlike(obs) | |
| 446 | + like["edisp"] = self.m_edisp | |
| 473 | 447 | like.run() |
| 474 | 448 | |
| 475 | 449 | # Skip bin if no event was present |
| 476 | 450 | if like.obs().logL() == 0.0: |
| 477 | 451 | |
| 478 | 452 | # Log information |
| 479 | - if self.logTerse(): | |
| 480 | - self.log("No event in this bin. Likelihood is zero. Bin is skipped\n") | |
| 453 | + if self.logExplicit(): | |
| 454 | + self.log("No event in this bin. ") | |
| 455 | + self.log("Likelihood is zero. ") | |
| 456 | + self.log("Bin is skipped.") | |
| 481 | 457 | |
| 482 | 458 | # Set all values to 0 |
| 483 | 459 | flux[i] = 0.0 |
| ... | ... | @@ -496,21 +472,21 @@ class csspec(ctools.cscript): |
| 496 | 472 | if self.m_calc_ulimit: |
| 497 | 473 | |
| 498 | 474 | # Logging information |
| 499 | - if self.logTerse(): | |
| 475 | + if self.logExplicit(): | |
| 500 | 476 | self.log.header3("Computing upper limit") |
| 501 | 477 | |
| 502 | 478 | # Create upper limit object |
| 503 | 479 | ulimit = ctools.ctulimit(like.obs()) |
| 504 | 480 | ulimit["srcname"] = self.m_srcname |
| 505 | - ulimit["eref"] = elogmean.TeV() | |
| 481 | + ulimit["eref"] = elogmean.TeV() | |
| 506 | 482 | |
| 507 | 483 | # Try to run upper limit and catch exceptions |
| 508 | 484 | try: |
| 509 | 485 | ulimit.run() |
| 510 | 486 | ulimit_value = ulimit.diff_ulimit() |
| 511 | 487 | except: |
| 512 | - if self.logTerse(): | |
| 513 | - self.log("Upper limit calculation failed\n") | |
| 488 | + if self.logExplicit(): | |
| 489 | + self.log("Upper limit calculation failed.") | |
| 514 | 490 | ulimit_value = -1.0 |
| 515 | 491 | |
| 516 | 492 | # Get TS value |
| ... | ... | @@ -518,9 +494,9 @@ class csspec(ctools.cscript): |
| 518 | 494 | if self.m_calc_ts: |
| 519 | 495 | TS = source.ts() |
| 520 | 496 | |
| 521 | - # Compute Npred value | |
| 497 | + # Compute Npred value (only works for unbinned analysis) | |
| 522 | 498 | Npred = 0.0 |
| 523 | - if not self.m_binned: | |
| 499 | + if not self.m_binned_mode: | |
| 524 | 500 | for observation in like.obs(): |
| 525 | 501 | Npred += observation.npred(source) |
| 526 | 502 | |
| ... | ... | @@ -529,8 +505,8 @@ class csspec(ctools.cscript): |
| 529 | 505 | |
| 530 | 506 | # Compute flux error |
| 531 | 507 | parvalue = source.spectral()[0].value() |
| 532 | - rel_error = source.spectral()[0].error()/parvalue | |
| 533 | - e_flux = fitted_flux*rel_error | |
| 508 | + rel_error = source.spectral()[0].error() / parvalue | |
| 509 | + e_flux = fitted_flux * rel_error | |
| 534 | 510 | |
| 535 | 511 | # Set values for storage |
| 536 | 512 | TSvalues[i] = TS |
| ... | ... | @@ -545,15 +521,17 @@ class csspec(ctools.cscript): |
| 545 | 521 | ulim_values[i] = ulimit_value * elogmean2 * gammalib.MeV2erg |
| 546 | 522 | |
| 547 | 523 | # Log information |
| 548 | - if self.logExplicit(): | |
| 549 | - self.log("Bin "+str(i)+" ["+str(emin.TeV())+"-"+str(emax.TeV())+"] TeV: ") | |
| 550 | - self.log("Flux = "+str(flux[i])) | |
| 551 | - self.log(" +- "+str(flux_err[i])+" [erg/cm2/s]") | |
| 552 | - if self.m_calc_ts and TSvalues[i] > 0.0: | |
| 553 | - self.log(", TS = "+str(TS)) | |
| 554 | - if self.m_calc_ulimit and ulim_values[i] > 0.0: | |
| 555 | - self.log(", UL = "+str(ulim_values[i])+" [erg/cm2/s]") | |
| 524 | + if self.logTerse(): | |
| 556 | 525 | self.log("\n") |
| 526 | + self.log.parformat("Bin "+str(i+1)) | |
| 527 | + self.log(str(flux[i])) | |
| 528 | + self.log(" +/- ") | |
| 529 | + self.log(str(flux_err[i])) | |
| 530 | + if self.m_calc_ulimit and ulim_values[i] > 0.0: | |
| 531 | + self.log(" [< "+str(ulim_values[i])+"]") | |
| 532 | + self.log(" erg/cm2/s") | |
| 533 | + if self.m_calc_ts and TSvalues[i] > 0.0: | |
| 534 | + self.log(" (TS = "+str(TS)+")") | |
| 557 | 535 | |
| 558 | 536 | # Append filled columns to fits table |
| 559 | 537 | table.append(energy) | ... | ... |
cscripts/cstsdist.py
| ... | ... | @@ -94,17 +94,17 @@ class cstsdist(ctools.cscript): |
| 94 | 94 | |
| 95 | 95 | # Create default parfile |
| 96 | 96 | pars = gammalib.GApplicationPars() |
| 97 | - pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Event list, counts cube, or observation definition file")) | |
| 98 | - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Source model")) | |
| 97 | + pars.append(gammalib.GApplicationPar("inobs","f","h","NONE","","","Input event list, counts cube, or observation definition XML file")) | |
| 98 | + pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) | |
| 99 | 99 | pars.append(gammalib.GApplicationPar("srcname","s","a","Crab","","","Source name")) |
| 100 | - pars.append(gammalib.GApplicationPar("outfile","f","a","ts.dat","","","Output file name")) | |
| 101 | - pars.append(gammalib.GApplicationPar("expcube","s","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) | |
| 102 | - pars.append(gammalib.GApplicationPar("psfcube","s","a","NONE","","","PSF cube file (only needed for stacked analysis)")) | |
| 103 | - pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Background cube file (only needed for stacked analysis)")) | |
| 100 | + pars.append(gammalib.GApplicationPar("expcube","s","a","NONE","","","Input exposure cube file (only needed for stacked analysis)")) | |
| 101 | + pars.append(gammalib.GApplicationPar("psfcube","s","a","NONE","","","Input PSF cube file (only needed for stacked analysis)")) | |
| 102 | + pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Input background cube file (only needed for stacked analysis)")) | |
| 104 | 103 | pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) |
| 105 | - pars.append(gammalib.GApplicationPar("irf","s","a","South_50h","","","Instrument response function")) | |
| 104 | + pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) | |
| 106 | 105 | pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","","","Deadtime correction factor")) |
| 107 | 106 | pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) |
| 107 | + pars.append(gammalib.GApplicationPar("outfile","f","a","ts.dat","","","Output Test Statistics distribution file")) | |
| 108 | 108 | pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials")) |
| 109 | 109 | pars.append(gammalib.GApplicationPar("ra","r","a","83.63","0","360","RA of pointing (deg)")) |
| 110 | 110 | pars.append(gammalib.GApplicationPar("dec","r","a","22.01","-90","90","Dec of pointing (deg)")) |
| ... | ... | @@ -275,7 +275,7 @@ class cstsdist(ctools.cscript): |
| 275 | 275 | if not model.has_par("Prefactor"): |
| 276 | 276 | msg = "Model \""+self.m_srcname+"\" has no parameter \"Prefactor\"."+ \ |
| 277 | 277 | " Only spectral models with a \"Prefactor\" parameter are supported." |
| 278 | - raise gammalib.GException.invalid_value("cssens", msg) | |
| 278 | + raise RuntimeError(msg) | |
| 279 | 279 | |
| 280 | 280 | # Fit or fix spatial parameters |
| 281 | 281 | if fitpos: | ... | ... |
cscripts/cstsmapmerge.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Merges sliced TS map files into one map | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 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 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | +import glob | |
| 25 | +import os | |
| 26 | + | |
| 27 | + | |
| 28 | +# ================== # | |
| 29 | +# cstsmapmerge class # | |
| 30 | +# ================== # | |
| 31 | +class cstsmapmerge(ctools.cscript): | |
| 32 | + """ | |
| 33 | + This class merges TS map files into one TS map | |
| 34 | + """ | |
| 35 | + def __init__(self, *argv): | |
| 36 | + """ | |
| 37 | + Constructor. | |
| 38 | + """ | |
| 39 | + # Set name | |
| 40 | + self.name = "cstsmapmerge" | |
| 41 | + self.version = "1.1.0" | |
| 42 | + | |
| 43 | + # Make sure that parfile exists | |
| 44 | + file = self.parfile() | |
| 45 | + | |
| 46 | + # Initialise application | |
| 47 | + if len(argv) == 0: | |
| 48 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 49 | + elif len(argv) == 1: | |
| 50 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 51 | + else: | |
| 52 | + raise TypeError("Invalid number of arguments given.") | |
| 53 | + | |
| 54 | + # Set logger properties | |
| 55 | + self.log_header() | |
| 56 | + self.log.date(True) | |
| 57 | + | |
| 58 | + # Return | |
| 59 | + return | |
| 60 | + | |
| 61 | + def __del__(self): | |
| 62 | + """ | |
| 63 | + Destructor. | |
| 64 | + """ | |
| 65 | + # Return | |
| 66 | + return | |
| 67 | + | |
| 68 | + def parfile(self): | |
| 69 | + """ | |
| 70 | + Check if parfile exists. If parfile does not exist then create a | |
| 71 | + default parfile. This kluge avoids shipping the cscript with a | |
| 72 | + parfile. | |
| 73 | + """ | |
| 74 | + | |
| 75 | + # Set parfile name | |
| 76 | + parfile = self.name+".par" | |
| 77 | + | |
| 78 | + try: | |
| 79 | + pars = gammalib.GApplicationPars(parfile) | |
| 80 | + except: | |
| 81 | + # Signal that parfile was not found | |
| 82 | + print("Parfile \""+parfile+"\" not found. Create default parfile.") | |
| 83 | + | |
| 84 | + # Create default parfile | |
| 85 | + pars = gammalib.GApplicationPars() | |
| 86 | + pars.append(gammalib.GApplicationPar("inmaps","s","a","tsmap.fits","","","Input TS map FITS files")) | |
| 87 | + pars.append(gammalib.GApplicationPar("outmap","f","a","NONE","","","Output TS map FITS file")) | |
| 88 | + pars.append(gammalib.GApplicationPar("overwrite","b","h","yes","","","Overwrite previously filled bins?")) | |
| 89 | + pars.append(gammalib.GApplicationPar("delete","b","h","no","","","Delete merged files?")) | |
| 90 | + pars.append_standard() | |
| 91 | + pars.append(gammalib.GApplicationPar("logfile","f","h","cstsmapmerge.log","","","Log filename")) | |
| 92 | + pars.save(parfile) | |
| 93 | + | |
| 94 | + # Return | |
| 95 | + return | |
| 96 | + | |
| 97 | + def get_parameters(self): | |
| 98 | + """ | |
| 99 | + Get parameters from parfile and setup the observation. | |
| 100 | + """ | |
| 101 | + # Get input models | |
| 102 | + self.inmodels = self["inmaps"].string() | |
| 103 | + | |
| 104 | + # Interpet inmodels string | |
| 105 | + # Handle ascii files | |
| 106 | + if "@" == self.inmodels[0]: | |
| 107 | + self.files = open(self.inmodels.replace("@","")).read().splitlines() | |
| 108 | + | |
| 109 | + # Handle wild card strings | |
| 110 | + elif "*" in self.inmodels: | |
| 111 | + self.files = glob.glob(self.inmodels) | |
| 112 | + | |
| 113 | + # Handle space-separated list | |
| 114 | + elif " " in self.inmodels: | |
| 115 | + self.files = self.inmodels.split(" ") | |
| 116 | + | |
| 117 | + # Handle comma-separated list | |
| 118 | + elif "," in self.inmodels: | |
| 119 | + self.files = self.inmodels.split(",") | |
| 120 | + | |
| 121 | + # Throw exception if input models cannot be decoded | |
| 122 | + else: | |
| 123 | + msg = "Parameter \"inmmaps\" must contain either an @ASCII file,"+\ | |
| 124 | + " a comma-separated or whitespace-separated list of files"+\ | |
| 125 | + " or a wildcard string" | |
| 126 | + raise RuntimeError(msg) | |
| 127 | + | |
| 128 | + # Check number of files. We need at least two files. | |
| 129 | + if len(self.files) <= 1: | |
| 130 | + msg = "Need at least two files to start merging, "+\ | |
| 131 | + str(len(self.files))+" files given." | |
| 132 | + raise RuntimeError(msg) | |
| 133 | + | |
| 134 | + # Get output file | |
| 135 | + self.outmap = self["outmap"].filename() | |
| 136 | + | |
| 137 | + # Get other parameters | |
| 138 | + self.overwrite = self["overwrite"].boolean() | |
| 139 | + self.delete = self["delete"].boolean() | |
| 140 | + | |
| 141 | + # Return | |
| 142 | + return | |
| 143 | + | |
| 144 | + def init_map(self, fitsfile): | |
| 145 | + """ | |
| 146 | + """ | |
| 147 | + # Set filename | |
| 148 | + self.in_filename = fitsfile | |
| 149 | + | |
| 150 | + # Open FITS file | |
| 151 | + fits = gammalib.GFits(fitsfile) | |
| 152 | + self.tsmap = gammalib.GSkyMap() | |
| 153 | + self.tsmap.read(fits[0]) | |
| 154 | + self.statusmap = gammalib.GSkyMap() | |
| 155 | + self.statusmap.read(fits["STATUS MAP"]) | |
| 156 | + | |
| 157 | + # Get other maps | |
| 158 | + self.maps = [] | |
| 159 | + self.mapnames = [] | |
| 160 | + | |
| 161 | + # Loop over extensions | |
| 162 | + for hdu in fits: | |
| 163 | + | |
| 164 | + # Leave out primary and status extension | |
| 165 | + if hdu.extname() != "IMAGE" and hdu.extname() != "STATUS MAP": | |
| 166 | + | |
| 167 | + # Add present maps | |
| 168 | + skymap = gammalib.GSkyMap() | |
| 169 | + skymap.read(hdu) | |
| 170 | + self.maps.append(skymap) | |
| 171 | + self.mapnames.append(hdu.extname()) | |
| 172 | + | |
| 173 | + # Close FITS file | |
| 174 | + fits.close() | |
| 175 | + | |
| 176 | + # Return | |
| 177 | + return | |
| 178 | + | |
| 179 | + # Add map instances to each other. In this way the TS maps get merged | |
| 180 | + def add(self, fitsfile): | |
| 181 | + | |
| 182 | + # open FITS file | |
| 183 | + fits = gammalib.GFits(fitsfile) | |
| 184 | + add_tsmap = gammalib.GSkyMap() | |
| 185 | + add_tsmap.read(fits[0]) | |
| 186 | + add_statusmap = gammalib.GSkyMap() | |
| 187 | + add_statusmap.read(fits["STATUS MAP"]) | |
| 188 | + | |
| 189 | + # Get other maps | |
| 190 | + add_maps = [] | |
| 191 | + | |
| 192 | + # Loop over extensions | |
| 193 | + for hdu in fits: | |
| 194 | + | |
| 195 | + # Leave out primary and status extension | |
| 196 | + if hdu.extname() != "IMAGE" and hdu.extname() != "STATUS MAP": | |
| 197 | + | |
| 198 | + # Add present maps | |
| 199 | + skymap = gammalib.GSkyMap() | |
| 200 | + skymap.read(hdu) | |
| 201 | + add_maps.append(skymap) | |
| 202 | + | |
| 203 | + # Close FITS file | |
| 204 | + fits.close() | |
| 205 | + | |
| 206 | + # Compare size of other maps | |
| 207 | + if not len(add_maps) == len(self.maps): | |
| 208 | + self.error("Maps cannot be added: Maps from \""+self.in_filename+"\" do not match from \""+fitsfile+"\"") | |
| 209 | + | |
| 210 | + # Loop over bins | |
| 211 | + for i in range(self.tsmap.npix()): | |
| 212 | + if add_statusmap[i] > 0.5: | |
| 213 | + | |
| 214 | + # Throw exception if this bin has already been computed | |
| 215 | + if self.statusmap[i] > 0.5 and not self.overwrite: | |
| 216 | + msg = "Attempt to merge bin which apparently has already"+\ | |
| 217 | + " been merged. File \""+fitsfile+"\" contains"+\ | |
| 218 | + " already merged bins. Set hidden parameter"+\ | |
| 219 | + " overwrite=yes to avoid this error." | |
| 220 | + raise RuntimeError(msg) | |
| 221 | + | |
| 222 | + # Copy TS values | |
| 223 | + self.tsmap[i] = add_tsmap[i] | |
| 224 | + | |
| 225 | + # Copy status | |
| 226 | + self.statusmap[i] = add_statusmap[i] | |
| 227 | + | |
| 228 | + # Loop over maps and copy entries | |
| 229 | + for j in range(len(self.maps)): | |
| 230 | + self.maps[j][i] = add_maps[j][i] | |
| 231 | + | |
| 232 | + # Return | |
| 233 | + return | |
| 234 | + | |
| 235 | + def run(self): | |
| 236 | + """ | |
| 237 | + Run the script. | |
| 238 | + """ | |
| 239 | + # Switch screen logging on in debug mode | |
| 240 | + if self.logDebug(): | |
| 241 | + self.log.cout(True) | |
| 242 | + | |
| 243 | + # Get parameters | |
| 244 | + self.get_parameters() | |
| 245 | + | |
| 246 | + # Write input parameters into logger | |
| 247 | + if self.logTerse(): | |
| 248 | + self.log_parameters() | |
| 249 | + self.log("\n") | |
| 250 | + | |
| 251 | + if self.logTerse(): | |
| 252 | + self.log("\n") | |
| 253 | + self.log.header1("Merging sliced TS map files") | |
| 254 | + self.log("\n") | |
| 255 | + | |
| 256 | + # Initialise file to start with | |
| 257 | + file0 = "" | |
| 258 | + | |
| 259 | + self.added_files = [] | |
| 260 | + | |
| 261 | + # Test files for the entry status map | |
| 262 | + # use the first one to appear useful | |
| 263 | + for fitsfile in self.files: | |
| 264 | + if not gammalib.is_fits(fitsfile): | |
| 265 | + self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") | |
| 266 | + fits = gammalib.GFits(fitsfile) | |
| 267 | + | |
| 268 | + if fits.contains("STATUS MAP"): | |
| 269 | + self.log("Using file \""+fitsfile+"\" as initialising map\n") | |
| 270 | + file0 = fitsfile | |
| 271 | + break | |
| 272 | + else: | |
| 273 | + if self.logExplicit(): | |
| 274 | + self.log("File \""+fitsfile+"\" has not \"STATUS MAP\" extension\n") | |
| 275 | + | |
| 276 | + # Print an error message if no suitable file was provided | |
| 277 | + if file0 == "": | |
| 278 | + if self.logTerse(): | |
| 279 | + self.log("None of the provided file seems to be a sliced ts map file (no \"STATUS MAP\" extension)\n") | |
| 280 | + | |
| 281 | + # Otherwise merge files | |
| 282 | + else: | |
| 283 | + | |
| 284 | + # copy file list | |
| 285 | + workfiles = self.files | |
| 286 | + | |
| 287 | + # Remove entry which will be used to initalise the map | |
| 288 | + workfiles.remove(file0) | |
| 289 | + | |
| 290 | + # Initialise map from first file | |
| 291 | + self.init_map(file0) | |
| 292 | + | |
| 293 | + # Append to added files | |
| 294 | + self.added_files.append(file0) | |
| 295 | + | |
| 296 | + # Loop over files | |
| 297 | + for fitsfile in workfiles: | |
| 298 | + | |
| 299 | + # Skip if file is not FITS | |
| 300 | + if not gammalib.is_fits(fitsfile): | |
| 301 | + if self.logTerse(): | |
| 302 | + self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") | |
| 303 | + continue | |
| 304 | + | |
| 305 | + # Skip if file does not contain status map | |
| 306 | + fits = gammalib.GFits(fitsfile) | |
| 307 | + if not fits.contains("STATUS MAP"): | |
| 308 | + if self.logTerse(): | |
| 309 | + self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") | |
| 310 | + continue | |
| 311 | + | |
| 312 | + # Logging | |
| 313 | + if self.logTerse(): | |
| 314 | + self.log("Adding TS map slice \""+fitsfile+"\"\n") | |
| 315 | + | |
| 316 | + # Add file | |
| 317 | + self.add(fitsfile) | |
| 318 | + | |
| 319 | + # Append to added files | |
| 320 | + self.added_files.append(fitsfile) | |
| 321 | + | |
| 322 | + # Return | |
| 323 | + return | |
| 324 | + | |
| 325 | + def save(self): | |
| 326 | + """ | |
| 327 | + Save merged tsmap file and remove slices if requested | |
| 328 | + """ | |
| 329 | + | |
| 330 | + # Logging | |
| 331 | + if self.logExplicit(): | |
| 332 | + self.log("\n") | |
| 333 | + self.log.header1("Saving merged TS map") | |
| 334 | + self.log("\n") | |
| 335 | + | |
| 336 | + # Create FITS file | |
| 337 | + fits = gammalib.GFits() | |
| 338 | + | |
| 339 | + # Write TS map into primary | |
| 340 | + self.tsmap.write(fits) | |
| 341 | + | |
| 342 | + # Loop over maps and write them to fits | |
| 343 | + for i in range(len(self.maps)): | |
| 344 | + self.maps[i].write(fits) | |
| 345 | + | |
| 346 | + # Set map names as extensions | |
| 347 | + for i in range(len(self.mapnames)): | |
| 348 | + fits[i+1].extname(self.mapnames[i]) | |
| 349 | + | |
| 350 | + # Check if map is fully done | |
| 351 | + done = True | |
| 352 | + for pix in self.statusmap: | |
| 353 | + if pix < 0.5: | |
| 354 | + done = False | |
| 355 | + break | |
| 356 | + | |
| 357 | + # Write Status map if we are not done yet | |
| 358 | + if not done: | |
| 359 | + self.statusmap.write(fits) | |
| 360 | + fits[fits.size()-1].extname("STATUS MAP") | |
| 361 | + | |
| 362 | + # Save FITS file | |
| 363 | + fits.saveto(self.outmap, self.clobber()) | |
| 364 | + if self.logExplicit(): | |
| 365 | + self.log("Saved output map to \""+self.outmap+"\"\n") | |
| 366 | + if self.delete: | |
| 367 | + if self.logTerse(): | |
| 368 | + self.log("\n") | |
| 369 | + self.log.header1("Deleting slices") | |
| 370 | + self.log("\n") | |
| 371 | + for filename in self.added_files: | |
| 372 | + if self.logExplicit(): | |
| 373 | + self.log("Deleting file \""+filename+"\"\n") | |
| 374 | + os.remove(filename) | |
| 375 | + | |
| 376 | + # Return | |
| 377 | + return | |
| 378 | + | |
| 379 | + def execute(self): | |
| 380 | + """ | |
| 381 | + Execute the script. | |
| 382 | + """ | |
| 383 | + # Run the script | |
| 384 | + self.run() | |
| 385 | + | |
| 386 | + # Save ds9 file if required | |
| 387 | + self.save() | |
| 388 | + | |
| 389 | + # Return | |
| 390 | + return | |
| 391 | + | |
| 392 | + | |
| 393 | +# ======================== # | |
| 394 | +# Main routine entry point # | |
| 395 | +# ======================== # | |
| 396 | +if __name__ == '__main__': | |
| 397 | + """ | |
| 398 | + Merges ts map slices. | |
| 399 | + """ | |
| 400 | + # Create instance of application | |
| 401 | + app = cstsmapmerge(sys.argv) | |
| 402 | + | |
| 403 | + # Open logfile | |
| 404 | + app.logFileOpen() | |
| 405 | + | |
| 406 | + # Execute application | |
| 407 | + app.execute() | ... | ... |
cscripts/tsmerge.py deleted
| 1 | -#!/usr/bin/env python | |
| 2 | - | |
| 3 | -import gammalib | |
| 4 | -import sys | |
| 5 | -import os | |
| 6 | -import glob | |
| 7 | -import json | |
| 8 | - | |
| 9 | -def print_help(): | |
| 10 | - print("") | |
| 11 | - print("tsmerge.py expects two keyword argumens: use via command line as follows") | |
| 12 | - print("tsmerge.py files=<list of files> outfile=<desired outfile name>") | |
| 13 | - print("-------------------------------------------------------------------------") | |
| 14 | - print("*** \"outfile\" should be a path to a fits file") | |
| 15 | - print("*** \"files\" should be either be:") | |
| 16 | - print(" - an ascii-file listing the files your want to merge") | |
| 17 | - print(" OR - a wildcard string describing the files for merging") | |
| 18 | - print("-------------------------------------------------------------------------") | |
| 19 | - print("") | |
| 20 | - print("Example: python tsmerge,py files=tsmap*.fits outfile=tsmap.fits") | |
| 21 | - print("") | |
| 22 | - sys.exit(-1) | |
| 23 | - | |
| 24 | - | |
| 25 | -# Maps class holding the different sky maps | |
| 26 | -# created by cttsmap | |
| 27 | -class maps: | |
| 28 | - | |
| 29 | - # Constructor | |
| 30 | - def __init__(self,fitsfile): | |
| 31 | - | |
| 32 | - self.filename = fitsfile | |
| 33 | - if not os.path.isfile(fitsfile): | |
| 34 | - self.error("Maps instance cannot be constructed: File \""+self.filename+"\" does not exist") | |
| 35 | - | |
| 36 | - # open FITS file | |
| 37 | - fits = gammalib.GFits(fitsfile) | |
| 38 | - | |
| 39 | - # get TS map | |
| 40 | - self.tsmap = gammalib.GSkyMap() | |
| 41 | - self.tsmap.read(fits[0]) | |
| 42 | - | |
| 43 | - # Get status map | |
| 44 | - if not fits.contains("STATUS MAP"): | |
| 45 | - self.error("No extension \"STATUS MAP\" found in \""+self.filename+"\"") | |
| 46 | - self.statusmap = gammalib.GSkyMap() | |
| 47 | - self.statusmap.read(fits["STATUS MAP"]) | |
| 48 | - | |
| 49 | - # Get other maps | |
| 50 | - self.maps = [] | |
| 51 | - self.mapnames = [] | |
| 52 | - for hdu in fits: | |
| 53 | - if hdu.extname() != "IMAGE" and hdu.extname() != "STATUS MAP": | |
| 54 | - skymap = gammalib.GSkyMap() | |
| 55 | - skymap.read(hdu) | |
| 56 | - self.maps.append(skymap) | |
| 57 | - self.mapnames.append(hdu.extname()) | |
| 58 | - | |
| 59 | - # len operator | |
| 60 | - def __len__(self): | |
| 61 | - return len(self.maps) | |
| 62 | - | |
| 63 | - # operator [] | |
| 64 | - def __getitem__(self,index): | |
| 65 | - return self.maps[index] | |
| 66 | - | |
| 67 | - # Check the status map for completeness | |
| 68 | - def check_status(self): | |
| 69 | - check = True | |
| 70 | - for pix in self.statusmap: | |
| 71 | - if pix < 0.5: | |
| 72 | - check = False | |
| 73 | - break | |
| 74 | - return check | |
| 75 | - | |
| 76 | - # Save maps to outfile | |
| 77 | - def save(self,outfile): | |
| 78 | - | |
| 79 | - fits = gammalib.GFits() | |
| 80 | - self.tsmap.write(fits) | |
| 81 | - | |
| 82 | - for i in range(len(self.maps)): | |
| 83 | - self.maps[i].write(fits) | |
| 84 | - | |
| 85 | - for i in range(len(self.mapnames)): | |
| 86 | - fits[i+1].extname(self.mapnames[i]) | |
| 87 | - | |
| 88 | - if not self.check_status(): | |
| 89 | - self.statusmap.write(fits) | |
| 90 | - fits[fits.size()-1].extname("STATUS MAP") | |
| 91 | - fits.saveto(outfile,True) | |
| 92 | - | |
| 93 | - # Add map instances to each other | |
| 94 | - # in this way the TS maps get merged | |
| 95 | - def add(self,addmaps): | |
| 96 | - if not len(addmaps) == len(self.maps): | |
| 97 | - self.error("Maps cannot be added: Maps from \""+self.filename+"\" do not match from \""+addmaps.filename+"\"") | |
| 98 | - | |
| 99 | - # Loop over bins | |
| 100 | - for i in range(self.tsmap.npix()): | |
| 101 | - if addmaps.statusmap[i] > 0.5: | |
| 102 | - self.tsmap[i] = addmaps.tsmap[i] | |
| 103 | - self.statusmap[i] = addmaps.statusmap[i] | |
| 104 | - for j in range(len(self.maps)): | |
| 105 | - self.maps[j][i] = addmaps[j][i] | |
| 106 | - # Unify error messages | |
| 107 | - def error(self,message): | |
| 108 | - print("*** ERROR ***: "+message) | |
| 109 | - sys.exit(-1) | |
| 110 | - | |
| 111 | - | |
| 112 | -def pars_from_argv(argv): | |
| 113 | - | |
| 114 | - if argv is None: | |
| 115 | - argv = sys.argv | |
| 116 | - | |
| 117 | - args = [] | |
| 118 | - kwargs = {} | |
| 119 | - for s in argv[1:]: | |
| 120 | - if s.count('=') == 1: | |
| 121 | - key, value = s.split('=', 1) | |
| 122 | - else: | |
| 123 | - key, value = None, s | |
| 124 | - try: | |
| 125 | - value = json.loads(value) | |
| 126 | - except ValueError: | |
| 127 | - pass | |
| 128 | - if key: | |
| 129 | - kwargs[key] = value | |
| 130 | - else: | |
| 131 | - args.append(value) | |
| 132 | - return args, kwargs | |
| 133 | - | |
| 134 | - | |
| 135 | -def get_kwargs(argv): | |
| 136 | - kwargs = {} | |
| 137 | - | |
| 138 | - for s in argv: | |
| 139 | - if s.count('=') == 1: | |
| 140 | - key, value = s.split('=', 1) | |
| 141 | - kwargs[key] = value | |
| 142 | - | |
| 143 | - else: | |
| 144 | - print_help() | |
| 145 | - | |
| 146 | - return kwargs | |
| 147 | - | |
| 148 | -if __name__ == "__main__": | |
| 149 | - # Initialise list of files | |
| 150 | - | |
| 151 | - kwargs = get_kwargs(sys.argv[1:]) | |
| 152 | - if "outfile" not in kwargs or "files" not in kwargs: | |
| 153 | - print_help() | |
| 154 | - outfile = kwargs["outfile"] | |
| 155 | - files = kwargs["files"] | |
| 156 | - allfiles = [] | |
| 157 | - if os.path.isfile(files): | |
| 158 | - allfiles = open(files).read().splitlines() | |
| 159 | - else: | |
| 160 | - allfiles = glob.glob(files) | |
| 161 | - | |
| 162 | - # Initialise files to be merged | |
| 163 | - mergefiles = [] | |
| 164 | - | |
| 165 | - # Test files for the entry status map | |
| 166 | - # and add them to the file list | |
| 167 | - for fitsfile in allfiles: | |
| 168 | - fits = gammalib.GFits(fitsfile) | |
| 169 | - if fits.contains("STATUS MAP"): | |
| 170 | - mergefiles.append(fitsfile) | |
| 171 | - fits.close() | |
| 172 | - | |
| 173 | - # create a maps instance from the first file | |
| 174 | - finalmaps = maps(mergefiles[0]) | |
| 175 | - | |
| 176 | - # add other files to the maps instance | |
| 177 | - for fitsfile in mergefiles[1:]: | |
| 178 | - finalmaps.add(maps(fitsfile)) | |
| 179 | - | |
| 180 | - # save the filled maps to file | |
| 181 | - finalmaps.save(outfile=outfile) |
ctools.pc.in
| ... | ... | @@ -6,9 +6,9 @@ includedir=${prefix}/include |
| 6 | 6 | Name: ctools |
| 7 | 7 | Description: CTA science analysis tools |
| 8 | 8 | URL: http://cta.irap.omp.eu/ctools |
| 9 | -Version: 0.10.0 | |
| 9 | +Version: 1.0.0 | |
| 10 | 10 | Requires: |
| 11 | -Requires.private: gammalib >= 0.11.0 | |
| 11 | +Requires.private: gammalib >= 1.0.0 | |
| 12 | 12 | Conflicts: |
| 13 | 13 | Cflags: -I${includedir}/ctools @OPENMP_CXXFLAGS@ |
| 14 | 14 | Libs: -L${libdir} -lctools | ... | ... |
doc/Doxyfile
| ... | ... | @@ -32,7 +32,7 @@ PROJECT_NAME = ctools |
| 32 | 32 | # This could be handy for archiving the generated documentation or |
| 33 | 33 | # if some version control system is used. |
| 34 | 34 | |
| 35 | -PROJECT_NUMBER = 0.10.0 | |
| 35 | +PROJECT_NUMBER = 1.0.0 | |
| 36 | 36 | |
| 37 | 37 | # Using the PROJECT_BRIEF tag one can provide an optional one line description |
| 38 | 38 | # for a project that appears at the top of each page and should give viewer | ... | ... |
doc/source/conf.py
| ... | ... | @@ -66,10 +66,10 @@ copyright = u'2014-2015, ctools developers' |
| 66 | 66 | # built documents. |
| 67 | 67 | # |
| 68 | 68 | # The short X.Y version. |
| 69 | -version = '0.10' | |
| 69 | +version = '1.0' | |
| 70 | 70 | |
| 71 | 71 | # The full version, including alpha/beta/rc tags. |
| 72 | -release = '0.10.0' | |
| 72 | +release = '1.0.0' | |
| 73 | 73 | |
| 74 | 74 | # The language for content autogenerated by Sphinx. Refer to documentation |
| 75 | 75 | # for a list of supported languages. | ... | ... |
doc/source/develop.rst
| ... | ... | @@ -8,12 +8,12 @@ to the development. |
| 8 | 8 | Contributions can come in any areas: writing C++ code, contributing Python |
| 9 | 9 | scripts, writing documentation, testing code, etc. |
| 10 | 10 | |
| 11 | -The ctools development is managed by a development platform that is | |
| 12 | -accessible at `<https://cta-redmine.irap.omp.eu/projects/ctools/>`_. | |
| 11 | +The ctools software development is managed by a | |
| 12 | +`Redmine <https://cta-redmine.irap.omp.eu/projects/ctools/>`_ platform. | |
| 13 | 13 | Please check out the |
| 14 | 14 | `Wiki <https://cta-redmine.irap.omp.eu/projects/ctools/wiki/Contributing_to_ctools>`_ |
| 15 | -on that platform that contains information on how to contribute to the | |
| 16 | -ctools development. | |
| 15 | +on that platform to learn how you can contribute to the ctools software | |
| 16 | +development. | |
| 17 | 17 | |
| 18 | 18 | You may also want to get in the ctools information flow by subscribing to |
| 19 | 19 | the ctools@irap.omp.eu mailing list. |
| ... | ... | @@ -24,5 +24,5 @@ to allow newcomers to get familiar with the code base and the coding |
| 24 | 24 | practices. |
| 25 | 25 | You are highly invited to join one of the next coding sprints. |
| 26 | 26 | |
| 27 | -You can also follow `@gammalib <https://twitter.com/gammalib>`_ on | |
| 28 | -twitter to get informed about new release of GammaLib and ctools. | |
| 29 | 27 | \ No newline at end of file |
| 28 | +You can also follow `@ctools_software <https://twitter.com/ctools_software>`_ on | |
| 29 | +twitter to get informed about new ctools releases. | |
| 30 | 30 | \ No newline at end of file | ... | ... |
doc/source/download.rst
| ... | ... | @@ -13,7 +13,7 @@ bugs. |
| 13 | 13 | Releases |
| 14 | 14 | -------- |
| 15 | 15 | |
| 16 | -The latest ctools release is ``ctools-0.10.0`` (1 November 2015). | |
| 16 | +The latest ctools release is ``ctools-1.0.0`` (18 December 2015). | |
| 17 | 17 | |
| 18 | 18 | Below a table of ctools releases. Please note that at this stage of the |
| 19 | 19 | project there is a strict link between the ctools and gammalib versions. |
| ... | ... | @@ -28,6 +28,9 @@ gammalib. |
| 28 | 28 | * - `ctools <http://cta.irap.omp.eu/ctools/releases/ctools/ChangeLog>`_ |
| 29 | 29 | - `gammalib <http://cta.irap.omp.eu/ctools/releases/gammalib/ChangeLog>`_ |
| 30 | 30 | - Mac OS X package |
| 31 | + * - `1.0.0 <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-1.0.0.tar.gz>`_ | |
| 32 | + - `1.0.0 <http://cta.irap.omp.eu/ctools/releases/gammalib/gammalib-1.0.0.tar.gz>`_ | |
| 33 | + - `ctools-1.0.0-macosx10.3.dmg <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-1.0.0-macosx10.3.dmg>`_ | |
| 31 | 34 | * - `0.10.0 <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-0.10.0.tar.gz>`_ |
| 32 | 35 | - `0.11.0 <http://cta.irap.omp.eu/ctools/releases/gammalib/gammalib-0.11.0.tar.gz>`_ |
| 33 | 36 | - `ctools-0.10.0-macosx10.3.dmg <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-0.10.0-macosx10.3.dmg>`_ | ... | ... |
doc/source/help.rst
| ... | ... | @@ -3,8 +3,44 @@ |
| 3 | 3 | Getting Help |
| 4 | 4 | ============ |
| 5 | 5 | |
| 6 | -Any questions, bug reports, or suggested enhancements related to | |
| 7 | -ctools should be submitted via the | |
| 8 | -`issue tracker <https://cta-redmine.irap.omp.eu/projects/ctools/issues/new>`_ | |
| 9 | -or the | |
| 10 | -`mailing list <mailto:ctools@irap.omp.eu>`_. | |
| 11 | 6 | \ No newline at end of file |
| 7 | +If you need help you should first check the | |
| 8 | +:ref:`Frequently Asked Questions <faq>` and the list of | |
| 9 | +:ref:`Known Issues <issues>`. | |
| 10 | +In case that you do not find an answer to your question you may post your | |
| 11 | +question on the ctools@irap.omp.eu mailing list. | |
| 12 | +To subscribe to this list you simply need to send an e-mail to | |
| 13 | +ctools-subscribe@irap.omp.eu (content is irrelevant). | |
| 14 | + | |
| 15 | +You can also use the `Redmine <https://cta-redmine.irap.omp.eu/projects/ctools>`_ | |
| 16 | +system that we use for the ctools software development management to ask for | |
| 17 | +support, report a bug, or request a new feature. To use the system you | |
| 18 | +will first need to | |
| 19 | +`register <https://cta-redmine.irap.omp.eu/account/register>`_. | |
| 20 | + | |
| 21 | +Once registered, you can sign-in and ask for support by creating a | |
| 22 | +`support issue <https://cta-redmine.irap.omp.eu/projects/ctools/issues/new>`_. | |
| 23 | +Specify ``Support`` as Tracker, choose a short and meaningful subject, | |
| 24 | +and add an exhaustive description of your request. | |
| 25 | + | |
| 26 | +If you find a bug you should first check the | |
| 27 | +`list of bugs <https://cta-redmine.irap.omp.eu/projects/ctools/issues?utf8=?&set_filter=1&f%5B%5D=status_id&op%5Bstatus_id%5D=*&f%5B%5D=tracker_id&op%5Btracker_id%5D=%3D&v%5Btracker_id%5D%5B%5D=1&f%5B%5D=&c%5B%5D=tracker&c%5B%5D=status&c%5B%5D=priority&c%5B%5D=subject&c%5B%5D=assigned_to&c%5B%5D=updated_on&c%5B%5D=fixed_version&c%5B%5D=done_ratio&group_by=>`_ | |
| 28 | +to see whether your bug is already known. If the bug is known, you may edit | |
| 29 | +the issue and add some information (e.g. a log file, screen shot, etc.). | |
| 30 | +If the bug is not yet known, please create a | |
| 31 | +`bug issue <https://cta-redmine.irap.omp.eu/projects/ctools/issues/new>`_. | |
| 32 | +Specify ``Bug`` as Tracker, provide a short and meaningful subject, and add | |
| 33 | +an exhaustive description of the bug. Include the ctools software version, | |
| 34 | +your operating system, and the conditions under which the bug occurred. Ideally | |
| 35 | +you should provide all files and the command sequence (or a script) that | |
| 36 | +will allow us to reproduce the bug. | |
| 37 | + | |
| 38 | +If you would like to suggest some enhancements to ctools you should create | |
| 39 | +a | |
| 40 | +`feature issue <https://cta-redmine.irap.omp.eu/projects/ctools/issues/new>`_. | |
| 41 | +Specify ``Feature`` as Tracker, choose a short and meaningful subject, | |
| 42 | +and add an exhaustive description of your feature request. | |
| 43 | +Also explain the motivation for your request and provide some hint on how | |
| 44 | +urgently you need the new feature. | |
| 45 | + | |
| 46 | +You may click on ``Watch`` in the top-right corner of the issue page to make sure | |
| 47 | +that you will receive an e-mail notification when the issue is updated. | |
| 12 | 48 | \ No newline at end of file | ... | ... |
doc/source/issues.rst
| ... | ... | @@ -11,7 +11,6 @@ list of |
| 11 | 11 | |
| 12 | 12 | - :ref:`Certificate problem when cloning from Git <issue_ssl>` |
| 13 | 13 | - :ref:`Python module does not work <issue_python>` |
| 14 | -- :ref:`Python unit test fails on El Capitan <issue_elcapitan>` | |
| 15 | 14 | - :ref:`Installing on Solaris <issue_solaris>` |
| 16 | 15 | - :ref:`Installing on OpenSolaris <issue_opensolaris>` |
| 17 | 16 | |
| ... | ... | @@ -68,16 +67,6 @@ Installation issues |
| 68 | 67 | If the ``Python.h`` header file does not exist then install the Python |
| 69 | 68 | development package. |
| 70 | 69 | |
| 71 | -.. _issue_elcapitan: | |
| 72 | - | |
| 73 | -.. topic:: Python unit test fails on El Capitan | |
| 74 | - | |
| 75 | - On Mac OS X 10.11 (El Capitan) the Python unit tests fail when ctools | |
| 76 | - are not installed due to the way the ``DYLD_LIBRARY_PATH`` environment | |
| 77 | - variable is handled by the operating system. A (not very elegant) | |
| 78 | - workaround is to install the ctools before running the unit test using | |
| 79 | - ``make check``. | |
| 80 | - | |
| 81 | 70 | .. _issue_solaris: |
| 82 | 71 | |
| 83 | 72 | .. topic:: Installing on Solaris | ... | ... |
doc/source/reference_manual/cscaldb.rst
| 1 | -.. _cscaldb: cscaldb ======= Dumps all available instrument response functions into log fil. Synopsis -------- This scripts dumps all instrument response functions that are available in the calibration database into the log file. If you want the information on the screen, add the ``debug=yes`` parameter. General parameters ------------------ None Standard parameters ------------------- ``(chatter = 2) [integer]`` Verbosity of the executable: chatter = 0: no information will be logged chatter = 1: only errors will be logged chatter = 2: errors and actions will be logged chatter = 3: report about the task execution chatter = 4: detailed report about the task execution ``(clobber = yes) [boolean]`` Specifies whether an existing output counts cube should be overwritten. ``(debug = no) [boolean]`` Enables debug mode. In debug mode the executable will dump any log file output to the console. ``(mode = ql) [string]`` Mode of automatic parameters (default is "ql", i.e. "query and learn"). Related tools ------------- None | |
| 2 | 1 | \ No newline at end of file |
| 2 | +.. _cscaldb: | |
| 3 | + | |
| 4 | +cscaldb | |
| 5 | +======= | |
| 6 | + | |
| 7 | +Dumps all available instrument response functions into log file. | |
| 8 | + | |
| 9 | + | |
| 10 | +Synopsis | |
| 11 | +-------- | |
| 12 | + | |
| 13 | +This scripts dumps all instrument response functions that are available | |
| 14 | +in the calibration database into the log file. If you want the information | |
| 15 | +on the screen, add the ``debug=yes`` parameter. | |
| 16 | + | |
| 17 | + | |
| 18 | +General parameters | |
| 19 | +------------------ | |
| 20 | + | |
| 21 | +None | |
| 22 | + | |
| 23 | + | |
| 24 | +Standard parameters | |
| 25 | +------------------- | |
| 26 | + | |
| 27 | +``(chatter = 2) [integer]`` | |
| 28 | + Verbosity of the executable: | |
| 29 | + chatter = 0: no information will be logged | |
| 30 | + | |
| 31 | + chatter = 1: only errors will be logged | |
| 32 | + | |
| 33 | + chatter = 2: errors and actions will be logged | |
| 34 | + | |
| 35 | + chatter = 3: report about the task execution | |
| 36 | + | |
| 37 | + chatter = 4: detailed report about the task execution | |
| 38 | + | |
| 39 | +``(clobber = yes) [boolean]`` | |
| 40 | + Specifies whether an existing output counts cube should be overwritten. | |
| 41 | + | |
| 42 | +``(debug = no) [boolean]`` | |
| 43 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 44 | + | |
| 45 | +``(mode = ql) [string]`` | |
| 46 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 47 | + | |
| 48 | + | |
| 49 | +Related tools of scripts | |
| 50 | +------------------------ | |
| 51 | + | |
| 52 | +None | ... | ... |
doc/source/reference_manual/cslightcrv.rst
| ... | ... | @@ -9,12 +9,14 @@ Computes a lightcurve for a given source. |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Computes a lightcurve by performing a maximum likekihood fit in a series of | |
| 13 | -time bins. The time bins can be either specified in an ASCII file, as an | |
| 14 | -interval divided into equally sized time bins, or can be taken from the Good | |
| 15 | -Time Intervals of the observation(s). The format of the ASCII file is one | |
| 16 | -row per time bin, each specifying the start of stop value of the bin, separated | |
| 17 | -by a whitespace. The times are given in Modified Julian Days (MJD). | |
| 12 | +This script computes a lightcurve by performing a maximum likelihood fit | |
| 13 | +using :doc:`ctlike` in a series of time bins. The time bins can be either | |
| 14 | +specified in an ASCII file, as an interval divided into equally sized time | |
| 15 | +bins, or can be taken from the Good Time Intervals of the observation(s). | |
| 16 | +The format of the ASCII file is one row per time bin, each specifying the | |
| 17 | +start of stop value of the bin, separated by a whitespace. The times are | |
| 18 | +given in Modified Julian Days (MJD). | |
| 19 | + | |
| 18 | 20 | cslightcrv writes the fitted model parameters and their statistical errors |
| 19 | 21 | in a FITS file. In addition, it computes for each time bin the statistical |
| 20 | 22 | significance of the detection, expressed by the Test Statistics, and the |
| ... | ... | @@ -28,7 +30,7 @@ General parameters |
| 28 | 30 | Input event list, counts cube or observation definition XML file. |
| 29 | 31 | |
| 30 | 32 | ``inmodel [file]`` |
| 31 | - Input source model XML file. | |
| 33 | + Input model XML file. | |
| 32 | 34 | |
| 33 | 35 | ``srcname [string]`` |
| 34 | 36 | Name of the source in the source model XML file which should be used |
| ... | ... | @@ -141,7 +143,7 @@ Standard parameters |
| 141 | 143 | Log filename. |
| 142 | 144 | |
| 143 | 145 | |
| 144 | -Related tools | |
| 145 | -------------- | |
| 146 | +Related tools or scripts | |
| 147 | +------------------------ | |
| 146 | 148 | |
| 147 | -None | |
| 149 | +:doc:`ctlike` | ... | ... |
doc/source/reference_manual/csmodelinfo.rst
0 → 100644
| 1 | +.. _csmodelinfo: | |
| 2 | + | |
| 3 | +csmodelinfo | |
| 4 | +=========== | |
| 5 | + | |
| 6 | +Dumps information about a model container into log file or on screen. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | + | |
| 12 | +This script provides detailled information about a given model container. | |
| 13 | +It presents the number of parameters, the number of free parameters (sub- | |
| 14 | +divided by spectral, spatial and temporal type). The tool further creates | |
| 15 | +information about any parameter that is stuck at the parameter boundaries. | |
| 16 | +This might be quite useful for debugging a fit. Finally the tool also list | |
| 17 | +the TS values of each source that was fitted, in order have a quick overview | |
| 18 | +on these quantities on the screen. | |
| 19 | + | |
| 20 | +In addition the tool is also capable of exporting the input model XML container | |
| 21 | +to a region file which is compatible to be read with ds9 or other displying | |
| 22 | +tools. To create a region file, the hidden parameter "ds9file" needs to be | |
| 23 | +specified. There are quite a few further hidden parameters to steer e.g. | |
| 24 | +color, font, etc of the region file output. | |
| 25 | + | |
| 26 | + | |
| 27 | +General parameters | |
| 28 | +------------------ | |
| 29 | + | |
| 30 | +``inmodel [file]`` | |
| 31 | + Event list, counts cube, or observation definition file | |
| 32 | + | |
| 33 | +``(ds9file = NONE) [file]`` | |
| 34 | + Output DS9 region file containing models | |
| 35 | + | |
| 36 | +``(pnt_type=cross) <circle|box|diamond|cross|x|arrow|boxcircle> [string]`` | |
| 37 | + Marker type for point sources | |
| 38 | + | |
| 39 | +``pnt_mark_size [integer]`` | |
| 40 | + Marker size for point sources | |
| 41 | + | |
| 42 | +``(show_labels=yes) [boolean]`` | |
| 43 | + Add source labels? | |
| 44 | + | |
| 45 | +``(width=2) [integer]`` | |
| 46 | + Line width for regions | |
| 47 | + | |
| 48 | + ``(font=helvetica) <helvetica|times|courier> [string]`` | |
| 49 | + Font for source labels | |
| 50 | + | |
| 51 | +``(fontsize=12) [integer]`` | |
| 52 | + Font size for source labels | |
| 53 | + | |
| 54 | +``(fonttype=normal) <normal|bold> [string]`` | |
| 55 | + Use normal or bold font? | |
| 56 | + | |
| 57 | +``(fonttype2=roman) <roman|italic> [string]`` | |
| 58 | + Use roman or italic font? | |
| 59 | + | |
| 60 | +``(show_ext_type=yes) [boolean]`` | |
| 61 | + Show type of extended model in source name? | |
| 62 | + | |
| 63 | +``(free_color=green) [string]`` | |
| 64 | + Color for sources with free parameters (any ds9 color or hex code) | |
| 65 | + | |
| 66 | +``(fixed_color=magenta) [string]`` | |
| 67 | + Color for sources without free parameters (any ds9 color or hex code) | |
| 68 | + | |
| 69 | + | |
| 70 | +Standard parameters | |
| 71 | +------------------- | |
| 72 | + | |
| 73 | +``(chatter = 2) [integer]`` | |
| 74 | + Verbosity of the executable: | |
| 75 | + chatter = 0: no information will be logged | |
| 76 | + | |
| 77 | + chatter = 1: only errors will be logged | |
| 78 | + | |
| 79 | + chatter = 2: errors and actions will be logged | |
| 80 | + | |
| 81 | + chatter = 3: report about the task execution | |
| 82 | + | |
| 83 | + chatter = 4: detailed report about the task execution | |
| 84 | + | |
| 85 | +``(clobber = yes) [boolean]`` | |
| 86 | + Specifies whether an existing output counts cube should be overwritten. | |
| 87 | + | |
| 88 | +``(debug = no) [boolean]`` | |
| 89 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 90 | + | |
| 91 | +``(mode = ql) [string]`` | |
| 92 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 93 | + | |
| 94 | +``(logfile = csmodelinfo.log) [filename]`` | |
| 95 | + Log filename. | |
| 96 | + | |
| 97 | + | |
| 98 | +Related tools or scripts | |
| 99 | +------------------------ | |
| 100 | + | |
| 101 | +None | |
| 0 | 102 | \ No newline at end of file | ... | ... |
doc/source/reference_manual/csmodelmerge.rst
0 → 100644
| 1 | +.. _csmodelmerge: | |
| 2 | + | |
| 3 | +csmodelmerge | |
| 4 | +============ | |
| 5 | + | |
| 6 | +Merges an arbitrary number of model XML files into a single file. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | + | |
| 12 | +This script merges several model XML file into a single model XML file. The | |
| 13 | +files are passed via the ``inmodels`` parameter. There are 4 options to specify | |
| 14 | +a list of files that should be merged: | |
| 15 | +- a space-separated list of file names (e.g. model1.xml model2.xml) | |
| 16 | +- a comma-separated list of file names (e.g. model1.xml,model2.xml) | |
| 17 | +- a wildcard string (e.g. mymodel*.xml) | |
| 18 | +- an ASCII file containing the file names, one file per line (e.g. @mymodels.txt) | |
| 19 | + | |
| 20 | +Note that the "@" needs to be specified in case of an ASCII file name. It is | |
| 21 | +also important to note that models with the same name cannot be appended. The | |
| 22 | +tool will throw and exception if the provided file contain models with the same | |
| 23 | +name. | |
| 24 | + | |
| 25 | + | |
| 26 | +General parameters | |
| 27 | +------------------ | |
| 28 | + | |
| 29 | +``inmodels [string]`` | |
| 30 | + Input model XML files | |
| 31 | + | |
| 32 | +``outmodel [file]`` | |
| 33 | + Output model file | |
| 34 | + | |
| 35 | + | |
| 36 | +Standard parameters | |
| 37 | +------------------- | |
| 38 | + | |
| 39 | +``(chatter = 2) [integer]`` | |
| 40 | + Verbosity of the executable: | |
| 41 | + chatter = 0: no information will be logged | |
| 42 | + | |
| 43 | + chatter = 1: only errors will be logged | |
| 44 | + | |
| 45 | + chatter = 2: errors and actions will be logged | |
| 46 | + | |
| 47 | + chatter = 3: report about the task execution | |
| 48 | + | |
| 49 | + chatter = 4: detailed report about the task execution | |
| 50 | + | |
| 51 | +``(clobber = yes) [boolean]`` | |
| 52 | + Specifies whether an existing output counts cube should be overwritten. | |
| 53 | + | |
| 54 | +``(debug = no) [boolean]`` | |
| 55 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 56 | + | |
| 57 | +``(mode = ql) [string]`` | |
| 58 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 59 | + | |
| 60 | +``(logfile = csmodelmerge.log) [filename]`` | |
| 61 | + Log filename. | |
| 62 | + | |
| 63 | + | |
| 64 | +Related tools or scripts | |
| 65 | +------------------------ | |
| 66 | + | |
| 67 | +None | |
| 0 | 68 | \ No newline at end of file | ... | ... |
doc/source/reference_manual/csobs2caldb.rst
0 → 100644
| 1 | +.. _csobs2caldb: | |
| 2 | + | |
| 3 | +csobs2caldb | |
| 4 | +=========== | |
| 5 | + | |
| 6 | +Creates a caldb entry from an input observation. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | + | |
| 12 | +This script creates an entry in the local calibration database from an | |
| 13 | +input observation container. The caldb entry can be used for simulations | |
| 14 | +with :doc:`ctobssim` later on. On default csobs2caldb uses the first observation | |
| 15 | +in the given container. This can be modified using the hidden parameter "index" | |
| 16 | +(e.g. index=3 instructs the tool to use the third observation in the container). | |
| 17 | +Note that for the moment, the script only works for unbinned observations which | |
| 18 | +use the latest CTA IRF format (i.e. 2D/3D FITS binary tables). | |
| 19 | + | |
| 20 | +In particular this script might be useful for simulations of current IACT data. | |
| 21 | +Provided a specific observation with IRFs e.g. at certain zenith/azimuth angle, | |
| 22 | +the user can create a caldb entry using this tool and subsequently simulate e.g. | |
| 23 | +50 hours using this configuration. | |
| 24 | + | |
| 25 | +General parameters | |
| 26 | +------------------ | |
| 27 | + | |
| 28 | +``inobs [file]`` | |
| 29 | + Input event list, counts cube or observation definition XML file. | |
| 30 | + | |
| 31 | +``rspname [string]`` | |
| 32 | + Response output name (e.g. Zenith50). | |
| 33 | + | |
| 34 | +``(outirfs = irf_file.fits) [file]`` | |
| 35 | + Output IRF file name. | |
| 36 | + | |
| 37 | +``(index = 0) [integer]`` | |
| 38 | + Index of observation to be used from XML file. | |
| 39 | + | |
| 40 | + | |
| 41 | +Standard parameters | |
| 42 | +------------------- | |
| 43 | + | |
| 44 | +``(chatter = 2) [integer]`` | |
| 45 | + Verbosity of the executable: | |
| 46 | + chatter = 0: no information will be logged | |
| 47 | + | |
| 48 | + chatter = 1: only errors will be logged | |
| 49 | + | |
| 50 | + chatter = 2: errors and actions will be logged | |
| 51 | + | |
| 52 | + chatter = 3: report about the task execution | |
| 53 | + | |
| 54 | + chatter = 4: detailed report about the task execution | |
| 55 | + | |
| 56 | +``(clobber = yes) [boolean]`` | |
| 57 | + Specifies whether an existing output counts cube should be overwritten. | |
| 58 | + | |
| 59 | +``(debug = no) [boolean]`` | |
| 60 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 61 | + | |
| 62 | +``(mode = ql) [string]`` | |
| 63 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 64 | + | |
| 65 | +``(logfile = csobs2caldb.log) [filename]`` | |
| 66 | + Log filename. | |
| 67 | + | |
| 68 | + | |
| 69 | +Related tools or scripts | |
| 70 | +------------------------ | |
| 71 | + | |
| 72 | +:doc:`cscaldb` | ... | ... |
doc/source/reference_manual/csobsdef.rst
| ... | ... | @@ -10,9 +10,9 @@ Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | 12 | The csobsdef script generates an observation definition file from |
| 13 | -a pointing list. The pointing list is a colon separated value ASCII | |
| 14 | -file with header keywords in the first row followed by a list of | |
| 15 | -pointings (one pointing per row). The following header keywords | |
| 13 | +a pointing list. The pointing list is a comma-separated value (CSV) | |
| 14 | +ASCII file with header keywords in the first row followed by a list | |
| 15 | +of pointings (one pointing per row). The following header keywords | |
| 16 | 16 | are supported (case sensitive, column order irrelevant): |
| 17 | 17 | |
| 18 | 18 | * name - Observation name string |
| ... | ... | @@ -32,7 +32,7 @@ are supported (case sensitive, column order irrelevant): |
| 32 | 32 | Only the pairs (ra,dec) or (lon,lat) are mandatory header keywords. |
| 33 | 33 | All other keywords are optional and can be specified when calling |
| 34 | 34 | csobsdef as user parameters. The only exception is the "duration" |
| 35 | -keyword that will automatically queried. | |
| 35 | +keyword that will automatically be queried. | |
| 36 | 36 | |
| 37 | 37 | Here some usage examples: |
| 38 | 38 | |
| ... | ... | @@ -46,15 +46,15 @@ Here some usage examples: |
| 46 | 46 | Creates observation definition file with a ROI radius of 5 deg. |
| 47 | 47 | |
| 48 | 48 | ``csobsdef caldb=prod2 irf=South_50h`` |
| 49 | - Creates observation definition file using the "South_50h" IRF in the | |
| 50 | - "prod2" calibration database. | |
| 49 | + Creates observation definition file using the ``South_50h`` IRF in the | |
| 50 | + ``prod2`` calibration database. | |
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | General parameters |
| 54 | 54 | ------------------ |
| 55 | 55 | |
| 56 | 56 | ``inpnt [file]`` |
| 57 | - Pointing definition ASCII file in colon separated values format. | |
| 57 | + Pointing definition ASCII file in comma-separated value (CSV) format. | |
| 58 | 58 | |
| 59 | 59 | ``outobs [file]`` |
| 60 | 60 | Output Observation Definition XML file. |
| ... | ... | @@ -109,7 +109,7 @@ Standard parameters |
| 109 | 109 | Log filename. |
| 110 | 110 | |
| 111 | 111 | |
| 112 | -Related tools | |
| 113 | -------------- | |
| 112 | +Related tools or scripts | |
| 113 | +------------------------ | |
| 114 | 114 | |
| 115 | 115 | None | ... | ... |
doc/source/reference_manual/csobsinfo.rst
0 → 100644
| 1 | +.. _csobsinfo: | |
| 2 | + | |
| 3 | +csobsinfo | |
| 4 | +========= | |
| 5 | + | |
| 6 | +Dumps information about an observation container into log file or on | |
| 7 | +screen. | |
| 8 | + | |
| 9 | + | |
| 10 | +Synopsis | |
| 11 | +-------- | |
| 12 | + | |
| 13 | +This script provides detailed information about a given observation container. | |
| 14 | +For IACT observations usually several observations with different configurations | |
| 15 | +are combined. The script computes e.g. the overall energy range which could be | |
| 16 | +an important input for :doc:`ctbin` to create a suitable energy range. In | |
| 17 | +addition the script prints the pointing attributes like the average | |
| 18 | +zenith/azimuth angle. If the hidden boolean parameter "offset" is specified to | |
| 19 | +"yes", the script queries for the target position and computes the run-by-run | |
| 20 | +offset as well as its average. In the observation summary, the time range of | |
| 21 | +the observations including total ontime and (dead-time corrected) livetime is | |
| 22 | +shown. | |
| 23 | + | |
| 24 | +The script further contains the hidden parameter "ds9file". If specified with | |
| 25 | +a file name, the tool writes out a ds9 region file including a cross for each | |
| 26 | +pointing position in the sky. | |
| 27 | + | |
| 28 | +When executed from within python, the script provides methods to return arrays | |
| 29 | +containing observation-wise parameters. This might be useful for graphical | |
| 30 | +display within a script. The following methods are implemented: | |
| 31 | +- zeniths (returning all zenith angles) | |
| 32 | +- azimuths (returning all azimuth angles) | |
| 33 | +- offsets (returning all offset angles, provided the hidden parameter offset=yes) | |
| 34 | +- ebounds (returning energy boundaries) | |
| 35 | +- gtis (returning good time intervals) | |
| 36 | + | |
| 37 | + | |
| 38 | +General parameters | |
| 39 | +------------------ | |
| 40 | + | |
| 41 | +``inobs [file]`` | |
| 42 | + Event list, counts cube, or observation definition file | |
| 43 | + | |
| 44 | +``(offset = no) [file]`` | |
| 45 | + Compute offset from target to pointing positions | |
| 46 | + | |
| 47 | +``ra [real]`` | |
| 48 | + Target right ascension for offset computation (only queried if offset=yes) | |
| 49 | + | |
| 50 | +``dec [real]`` | |
| 51 | + Target declination for offset computation (only queried if offset=yes) | |
| 52 | + | |
| 53 | +``(ds9file = NONE) [file]`` | |
| 54 | + DS9 region file containing pointings | |
| 55 | + | |
| 56 | + | |
| 57 | +Standard parameters | |
| 58 | +------------------- | |
| 59 | + | |
| 60 | +``(chatter = 2) [integer]`` | |
| 61 | + Verbosity of the executable: | |
| 62 | + chatter = 0: no information will be logged | |
| 63 | + | |
| 64 | + chatter = 1: only errors will be logged | |
| 65 | + | |
| 66 | + chatter = 2: errors and actions will be logged | |
| 67 | + | |
| 68 | + chatter = 3: report about the task execution | |
| 69 | + | |
| 70 | + chatter = 4: detailed report about the task execution | |
| 71 | + | |
| 72 | +``(clobber = yes) [boolean]`` | |
| 73 | + Specifies whether an existing output counts cube should be overwritten. | |
| 74 | + | |
| 75 | +``(debug = no) [boolean]`` | |
| 76 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 77 | + | |
| 78 | +``(mode = ql) [string]`` | |
| 79 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 80 | + | |
| 81 | +``(logfile = csobsinfo.log) [filename]`` | |
| 82 | + Log filename. | |
| 83 | + | |
| 84 | + | |
| 85 | +Related tools or scripts | |
| 86 | +------------------------ | |
| 87 | + | |
| 88 | +None | |
| 0 | 89 | \ No newline at end of file | ... | ... |
doc/source/reference_manual/cspull.rst
| ... | ... | @@ -3,17 +3,33 @@ |
| 3 | 3 | cspull |
| 4 | 4 | ====== |
| 5 | 5 | |
| 6 | -Generates pull distribution for all model parameters. | |
| 6 | +Generates pull distribution for all free model parameters. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Generates pull distributions for all parameters in a model. The pull is | |
| 13 | -defined by the fitted value minus the simulated true value, devided by | |
| 14 | -the statistical uncertainty. For unbiased parameter estimates, the pull | |
| 15 | -distribution should follow a Gaussian centred on 0 and a sigma parameter | |
| 16 | -of 1. | |
| 12 | +This script generates pull distributions for all free model parameters. | |
| 13 | +The pull is defined as the fitted model parameter value minus the true | |
| 14 | +value, devided by the parameter error. cspull will perform ``ntrials`` | |
| 15 | +statistically independent Monte Carlo simulations followed by maximum | |
| 16 | +likelihood model fitting to derive the pull distribution for each free | |
| 17 | +model parameter. If the model fit is unbiased and the parameters are | |
| 18 | +correct, the pull distribution should follow a Gaussian centred on 0 | |
| 19 | +and with a sigma parameter of 1. | |
| 20 | + | |
| 21 | +cspull will generate an ASCII file in comma-separated value (CSV) format, | |
| 22 | +containing one row per pull. The first row is a header row providing the | |
| 23 | +column names. The following rows give the pull results, one row per pull. | |
| 24 | +This includes for each parameter the parameter value, error and pull. The | |
| 25 | +maximum likelihood value and the observed and the estimated number of counts | |
| 26 | +are also given. | |
| 27 | + | |
| 28 | +From the output file, pull distribution plots can be generated using for | |
| 29 | +example the ``show_pull_histogram.py`` script in the examples folder. The | |
| 30 | +script ``show_pull_evolution.py`` in the same folder shows the evolution | |
| 31 | +of the mean and standard deviation of the pull as function of the number | |
| 32 | +of trials. Both scripts require matplotlib for plotting. | |
| 17 | 33 | |
| 18 | 34 | |
| 19 | 35 | General parameters |
| ... | ... | @@ -23,8 +39,7 @@ General parameters |
| 23 | 39 | Event list, counts cube, or observation definition XML file. |
| 24 | 40 | |
| 25 | 41 | ``inmodel [file]`` |
| 26 | - XML file that describes the astrophysical sources and the instrumental | |
| 27 | - background. | |
| 42 | + Input model XML file. | |
| 28 | 43 | |
| 29 | 44 | ``outfile [file]`` |
| 30 | 45 | ASCII file containing the individual pull values. |
| ... | ... | @@ -118,7 +133,8 @@ Standard parameters |
| 118 | 133 | Log filename. |
| 119 | 134 | |
| 120 | 135 | |
| 121 | -Related tools | |
| 122 | -------------- | |
| 136 | +Related tools or scripts | |
| 137 | +------------------------ | |
| 123 | 138 | |
| 124 | -None | |
| 139 | +:doc:`ctlike` | |
| 140 | +:doc:`cstsdist` | ... | ... |
doc/source/reference_manual/csresmap.rst
| ... | ... | @@ -3,13 +3,26 @@ |
| 3 | 3 | csresmap |
| 4 | 4 | ======== |
| 5 | 5 | |
| 6 | -Generates residual counts map. | |
| 6 | +Generates residual map. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This scripts generates a residual counts map. | |
| 12 | +This scripts generates a residual map for a given model. It works for | |
| 13 | +event lists, counts cubes or observation definition files. For event | |
| 14 | +lists, parameters that define the spatial and spectral binning need to | |
| 15 | +be provided so that the script can bin the data internally. The model | |
| 16 | +is then convolved with the instrumental response function for that | |
| 17 | +binning and used for residual computation. Before residual computation, | |
| 18 | +the counts and model cubes are collapsed into maps by summing over all | |
| 19 | +energies. Three options exist then for residual computation: | |
| 20 | + | |
| 21 | +* the subtraction of the model from the counts (SUB) | |
| 22 | +* the subtraction and division by the model (SUBDIV) | |
| 23 | +* the subtraction and division by the square root of the model (SUBDIVSQRT) | |
| 24 | + | |
| 25 | +The residual map is written into a FITS file. | |
| 13 | 26 | |
| 14 | 27 | |
| 15 | 28 | General parameters |
| ... | ... | @@ -19,7 +32,7 @@ General parameters |
| 19 | 32 | Input event list, counts cube or observation definition XML file. |
| 20 | 33 | |
| 21 | 34 | ``inmodel [file]`` |
| 22 | - Model XML file. | |
| 35 | + Input model XML file. | |
| 23 | 36 | |
| 24 | 37 | ``outmap [file]`` |
| 25 | 38 | Output residual counts map file. |
| ... | ... | @@ -94,8 +107,11 @@ Standard parameters |
| 94 | 107 | ``(mode = ql) [string]`` |
| 95 | 108 | Mode of automatic parameters (default is "ql", i.e. "query and learn"). |
| 96 | 109 | |
| 110 | +``(logfile = csresmap.log) [string]`` | |
| 111 | + Log filename. | |
| 112 | + | |
| 97 | 113 | |
| 98 | -Related tools | |
| 99 | -------------- | |
| 114 | +Related tools or scripts | |
| 115 | +------------------------ | |
| 100 | 116 | |
| 101 | 117 | None | ... | ... |
doc/source/reference_manual/cssens.rst
| ... | ... | @@ -3,18 +3,40 @@ |
| 3 | 3 | cssens |
| 4 | 4 | ====== |
| 5 | 5 | |
| 6 | -Computes the CTA sensitivity for a number of energy bins. | |
| 6 | +Computes differential or integrated CTA sensitivity. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Computes the CTA sensitivity for a number of energy bins using :doc:`ctlike`. | |
| 13 | -Crab spectra are fitted in narrow energy bins to simulated data, and the | |
| 14 | -flux level is determined that leads to a particular significance. The | |
| 15 | -significance is estimated using the Test Statistic value. The simplified | |
| 16 | -assumption is made that the significance (in Gaussian sigma) is the square | |
| 17 | -root of the Test Statistic. | |
| 12 | +This script computes the differential or integrated CTA sensitivity using | |
| 13 | +maximum likelihood fitting of a test source. The differential sensitivity | |
| 14 | +is determined for a number of energy bins, the integral sensitivity is | |
| 15 | +determined for a number of energy thresholds. The test source is fitted to | |
| 16 | +simulated data using :doc:`ctlike` to determine it's detection significance | |
| 17 | +as a function of source flux. The source flux is then varied until the | |
| 18 | +source significance achieves a given level, specified by the (hidden) | |
| 19 | +significance parameter ``sigma``. To damp variations between individual | |
| 20 | +Monte Carlo simulations, a sliding average is applied in the significance | |
| 21 | +computation (controlled by hidden ``num_avg`` parameter). | |
| 22 | + | |
| 23 | +The significance is estimated using the Test Statistic value, defined as | |
| 24 | +twice the log-likelihood difference that is obtained when fitting the | |
| 25 | +simulated data with and without the test source. The simplified assumption | |
| 26 | +is made that the significance (in Gaussian sigma) is the square root of | |
| 27 | +the Test Statistic. | |
| 28 | + | |
| 29 | +cssens will generate an ASCII file in comma-separated value (CSV) format | |
| 30 | +containing the sensitivity as function of energy. The first row is a header | |
| 31 | +row providing the column names. The following rows provide the mean | |
| 32 | +logarithmic energy and the boundaries of the energy bin for which the | |
| 33 | +sensitivity was computed. They also provide the flux within the energy bin | |
| 34 | +in Crab units, in photons (ph/cm2/s) and in energy (ers/cm2/s). Finally, | |
| 35 | +the sensitivity is given as the test source spectrum evaluated at the mean | |
| 36 | +logarithmic energy multiplied by the energy squared (erg/cm2/s). | |
| 37 | + | |
| 38 | +The sensitivity can be displayed using the ``show_sensitivity.py`` script | |
| 39 | +in the example folder. Matplotlib is required to execute the script. | |
| 18 | 40 | |
| 19 | 41 | |
| 20 | 42 | General parameters |
| ... | ... | @@ -24,7 +46,7 @@ General parameters |
| 24 | 46 | Input event list, counts cube or observation definition XML file. |
| 25 | 47 | |
| 26 | 48 | ``inmodel [file]`` |
| 27 | - Input source model XML file. | |
| 49 | + Input model XML file. | |
| 28 | 50 | |
| 29 | 51 | ``srcname [string]`` |
| 30 | 52 | Name of the source in the source model XML file which should be used |
| ... | ... | @@ -110,7 +132,7 @@ Standard parameters |
| 110 | 132 | Log filename. |
| 111 | 133 | |
| 112 | 134 | |
| 113 | -Related tools | |
| 114 | -------------- | |
| 135 | +Related tools or scripts | |
| 136 | +------------------------ | |
| 115 | 137 | |
| 116 | -None | |
| 138 | +:doc:`ctlike` | ... | ... |
doc/source/reference_manual/csspec.rst
| ... | ... | @@ -9,7 +9,40 @@ Computes spectrum for a given source. |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Computes spectral points for a given source. | |
| 12 | +This script computes the source spectrum by fitting a model in a given set | |
| 13 | +of spectral bins. The model fit per spectral bin is performed using :doc:`ctlike` | |
| 14 | +and the script provides the possibility to fix sources other than the | |
| 15 | +source of interest (hidden parameter ``fix_srcs``) or to fix the background | |
| 16 | +model component(s) (hidden parameter ``fix_bkg``). The script computes the | |
| 17 | +source flux and its uncertainty in each spectral bin, as well as the | |
| 18 | +significance of the source detection. Optionally, it also computes an upper | |
| 19 | +flux limit that is particularily useful in case that the source is not | |
| 20 | +significantly detected within a spectral bin (hidden parameter ``calc_ulim``). | |
| 21 | + | |
| 22 | +The script works on binned and unbinned data. | |
| 23 | + | |
| 24 | +For unbinned data, the spectral binning is either defined by a FITS file | |
| 25 | +containing the energy boundaries of each bin (option ``ebinalg=FILE``) or | |
| 26 | +as ``enumbins`` bins spread linearly (option ``ebinalg=LIN``) or | |
| 27 | +logarithmically (option ``ebinalg=LOG``) from a minimum energy given by | |
| 28 | +``emin`` to a maximum energy given by ``emax``. | |
| 29 | + | |
| 30 | +For binned data, all energy bins within the counts cube that overlap with | |
| 31 | +the energy range spanned by ``emin`` and ``emax`` are considered. The number | |
| 32 | +of spectral bins is only approximately determined by the ``enumbins`` parameter. | |
| 33 | +Naturally, the script cannot create more spectral bins than the number of | |
| 34 | +energy bins that are available in the cube. Also, in case that ``enumbins`` | |
| 35 | +is smaller than the number of energy bins in the cube, the script will fit | |
| 36 | +several layers of the counts cube for each spectral bin. The number of | |
| 37 | +layers fit is determined by the total number of energy bins divided by the | |
| 38 | +``enumbins`` parameter. | |
| 39 | + | |
| 40 | +On output, the script will provide a FITS file with the fitted source | |
| 41 | +spectrum in form of a binary table. Each row corresponds to a spectral bin. | |
| 42 | +The columns are the mean as well as the boundaries of the spectral bin, | |
| 43 | +the fitted flux and flux error, the Test Statistics value (option | |
| 44 | +``calc_ts=yes``), the upper flux limit (option ``calc_ulim=yes``) and the | |
| 45 | +predicted number of events (only for unbinned data). | |
| 13 | 46 | |
| 14 | 47 | |
| 15 | 48 | General parameters |
| ... | ... | @@ -19,7 +52,7 @@ General parameters |
| 19 | 52 | Input event list, counts cube or observation definition XML file. |
| 20 | 53 | |
| 21 | 54 | ``inmodel [file]`` |
| 22 | - Input source model XML file. | |
| 55 | + Input model XML file. | |
| 23 | 56 | |
| 24 | 57 | ``srcname [string]`` |
| 25 | 58 | Name of the source in the source model XML file which should be used |
| ... | ... | @@ -43,6 +76,9 @@ General parameters |
| 43 | 76 | ``irf [string]`` |
| 44 | 77 | Instrumental response function. |
| 45 | 78 | |
| 79 | +``(edisp = no) [boolean]`` | |
| 80 | + Apply energy dispersion to response computation? | |
| 81 | + | |
| 46 | 82 | ``emin [real]`` |
| 47 | 83 | Lower energy limit of events (in TeV). |
| 48 | 84 | |
| ... | ... | @@ -50,41 +86,14 @@ General parameters |
| 50 | 86 | Upper energy limit of events (in TeV). |
| 51 | 87 | |
| 52 | 88 | ``enumbins [integer]`` |
| 53 | - Number of energy bins (0=unbinned). | |
| 89 | + Number of energy bins. | |
| 54 | 90 | |
| 55 | -``(ebinalg = LOG) <FILE|LIN|LOG> [string]`` | |
| 91 | +``ebinalg <FILE|LIN|LOG> [string]`` | |
| 56 | 92 | Algorithm for defining energy bins. |
| 57 | 93 | |
| 58 | -``binned [boolean]`` | |
| 59 | - Specifies whether a binned computation should be used. | |
| 60 | - | |
| 61 | -``(nebins = 5) [integer]`` | |
| 62 | - Number of bins per spectral point for binned analysis. | |
| 63 | - | |
| 64 | -``coordsys <CEL|GAL> [string]`` | |
| 65 | - Coordinate system (CEL - celestial, GAL - galactic). | |
| 66 | - | |
| 67 | -``proj <AIT|AZP|CAR|MER|MOL|STG|TAN> [string]`` | |
| 68 | - Projection method. | |
| 69 | - | |
| 70 | -``xref [real]`` | |
| 71 | - Right Ascension / Galactic longitude of image centre (J2000, in degrees). | |
| 72 | - | |
| 73 | -``yref [real]`` | |
| 74 | - Declination / Galactic latitude of image centre (J2000, in degrees). | |
| 94 | +``ebinfile [file]`` | |
| 95 | + Name of the file containing the energy bin definition. | |
| 75 | 96 | |
| 76 | -``nxpix [integer]`` | |
| 77 | - Size of the Right Ascension / Galactic longitude axis (in pixels). | |
| 78 | - | |
| 79 | -``nypix [integer]`` | |
| 80 | - Size of the Declination / Galactic latitude axis (in pixels). | |
| 81 | - | |
| 82 | -``binsz [real]`` | |
| 83 | - Pixel size (in degrees/pixel). | |
| 84 | - | |
| 85 | -``(anumbins = 200) [integer]`` | |
| 86 | - Number of angular separation bins. | |
| 87 | - | |
| 88 | 97 | ``(calc_ts = yes) [boolean]`` |
| 89 | 98 | Compute TS for each spectral point? |
| 90 | 99 | |
| ... | ... | @@ -126,7 +135,7 @@ Standard parameters |
| 126 | 135 | Log filename. |
| 127 | 136 | |
| 128 | 137 | |
| 129 | -Related tools | |
| 130 | -------------- | |
| 138 | +Related tools or scripts | |
| 139 | +------------------------ | |
| 131 | 140 | |
| 132 | -None | |
| 141 | +:doc:`ctlike` | ... | ... |
doc/source/reference_manual/cstsdist.rst
| ... | ... | @@ -3,14 +3,30 @@ |
| 3 | 3 | cstsdist |
| 4 | 4 | ======== |
| 5 | 5 | |
| 6 | -Generates the TS distribution for a particular model. | |
| 6 | +Generates the TS distribution for a given source. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Generates the Test Statistics (TS) distribution for a particular model | |
| 13 | -based on Monte-Carlo simulations. | |
| 12 | +This script generates the Test Statistics (TS) distribution for a given | |
| 13 | +source by repeatedly computing the TS value for ``ntrials`` simulated data | |
| 14 | +sets. The Test Statistics is defined as twice the log-likelihood difference | |
| 15 | +that is obtained when fitting simulated data with and without a given | |
| 16 | +source model component. | |
| 17 | + | |
| 18 | +This script either performs an unbinned or a binned simulation, stacked | |
| 19 | +analysis is not yet supported. | |
| 20 | + | |
| 21 | +cstsdist will create an ASCII file in comma-separated value (CSV) format, | |
| 22 | +containing one row per TS computation. The first row is a header row providing | |
| 23 | +the column names. The following rows give the TS value, the log-likelihood | |
| 24 | +values of the fit with or without the source, the number of observed and | |
| 25 | +fitted events, as well as the values and errors for all fitted parameters. | |
| 26 | + | |
| 27 | +From the output file, TS distribution plots can be generated using for | |
| 28 | +example the ``show_ts_distribution.py`` script in the examples folder. The | |
| 29 | +script require matplotlib for plotting. | |
| 14 | 30 | |
| 15 | 31 | |
| 16 | 32 | General parameters |
| ... | ... | @@ -20,11 +36,11 @@ General parameters |
| 20 | 36 | Input event list, counts cube or observation definition XML file. |
| 21 | 37 | |
| 22 | 38 | ``inmodel [file]`` |
| 23 | - Input source model XML file. | |
| 39 | + Input model XML file. | |
| 24 | 40 | |
| 25 | 41 | ``srcname [string]`` |
| 26 | 42 | Name of the source in the source model XML file which should be used |
| 27 | - for sensitivity computation. | |
| 43 | + for Test Statistics computation. | |
| 28 | 44 | |
| 29 | 45 | ``outfile [file]`` |
| 30 | 46 | ASCII file containing the TS distribution values. |
| ... | ... | @@ -118,7 +134,9 @@ Standard parameters |
| 118 | 134 | Log filename. |
| 119 | 135 | |
| 120 | 136 | |
| 121 | -Related tools | |
| 122 | -------------- | |
| 137 | +Related tools or scripts | |
| 138 | +------------------------ | |
| 139 | + | |
| 140 | +:doc:`ctlike` | |
| 141 | +:doc:`cspull` | |
| 123 | 142 | |
| 124 | -None | ... | ... |
doc/source/reference_manual/cstsmapmerge.rst
0 → 100644
| 1 | +.. _cstsmapmerge: | |
| 2 | + | |
| 3 | +cstsmapmerge | |
| 4 | +============ | |
| 5 | + | |
| 6 | +Merges slices of splitted tsmap computations. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | + | |
| 12 | +In case a TS map has been computed using the option to split the calculations | |
| 13 | +into several jobs, this tool is required to merge the output into one final | |
| 14 | +map again. Running :doc:`cttsmap` with the hidden parameters ``binmin`` and | |
| 15 | +``binmax`` specified will result in several sliced TS maps. This script merges | |
| 16 | +them into one FITS file. The input slices can be passed via the ``inmaps`` | |
| 17 | +parameter. There are 4 options to specify a list of files that should be merged: | |
| 18 | +- a space-separated list of file names (e.g. tsmap1.fits tsmap2.fits) | |
| 19 | +- a comma-separated list of file names (e.g. tsmap1.fits,tsmap2.fits) | |
| 20 | +- a wildcard string (e.g. tsmap*.xml) | |
| 21 | +- an ASCII file containing the file names, one file per line (e.g. @mymaps.txt) | |
| 22 | + | |
| 23 | +Note that the "@" needs to be specified in case of an ASCII file name. | |
| 24 | + | |
| 25 | +General parameters | |
| 26 | +------------------ | |
| 27 | + | |
| 28 | +``inmaps [string]`` | |
| 29 | + Input TS map FITS files | |
| 30 | + | |
| 31 | +``outmap [file]`` | |
| 32 | + Output TS map FITS file | |
| 33 | + | |
| 34 | +``(overwrite=yes) [boolean]`` | |
| 35 | + Overwrite previously filled bins? | |
| 36 | + | |
| 37 | +``(delete=no) [boolean]`` | |
| 38 | + Delete merged files? | |
| 39 | + | |
| 40 | + | |
| 41 | +Standard parameters | |
| 42 | +------------------- | |
| 43 | + | |
| 44 | +``(chatter = 2) [integer]`` | |
| 45 | + Verbosity of the executable: | |
| 46 | + chatter = 0: no information will be logged | |
| 47 | + | |
| 48 | + chatter = 1: only errors will be logged | |
| 49 | + | |
| 50 | + chatter = 2: errors and actions will be logged | |
| 51 | + | |
| 52 | + chatter = 3: report about the task execution | |
| 53 | + | |
| 54 | + chatter = 4: detailed report about the task execution | |
| 55 | + | |
| 56 | +``(clobber = yes) [boolean]`` | |
| 57 | + Specifies whether an existing output counts cube should be overwritten. | |
| 58 | + | |
| 59 | +``(debug = no) [boolean]`` | |
| 60 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 61 | + | |
| 62 | +``(mode = ql) [string]`` | |
| 63 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 64 | + | |
| 65 | +``(logfile = cstsmapmerge.log) [filename]`` | |
| 66 | + Log filename. | |
| 67 | + | |
| 68 | + | |
| 69 | +Related tools or scripts | |
| 70 | +------------------------ | |
| 71 | + | |
| 72 | +:ref:`cstsmap` | ... | ... |
doc/source/reference_manual/ctbin.rst
| ... | ... | @@ -3,18 +3,27 @@ |
| 3 | 3 | ctbin |
| 4 | 4 | ===== |
| 5 | 5 | |
| 6 | -Generate a counts cube for binned maximum likelihood analysis. | |
| 6 | +Generate counts cube from event list(s). | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This tool computes the counts cube for use in a binned maximum likelihood | |
| 13 | -analysis. The counts cubes are 3-dimensional data cubes spanned by Right | |
| 14 | -Ascension or Galactic longitude, Declination or Galactic latitude, and energy. | |
| 15 | -The energy binning may be either linear, logarithmic, or custom defined. | |
| 16 | -If an observation definition XML file containing several observations is | |
| 17 | -provided on input, the tool will stack all data into a single counts cube. | |
| 12 | +This tool creates a counts cube and fills it with events. A counts cube is | |
| 13 | +a 3-dimensional data cube spanned by Right Ascension or Galactic longitude, | |
| 14 | +Declination or Galactic latitude, and energy. The energy binning may be either | |
| 15 | +linear, logarithmic, or custom defined using an input file. The events are | |
| 16 | +either taken from a single event list file or from the event lists that are | |
| 17 | +specified in an observation definition file. In case that multiple event | |
| 18 | +lists are given in an observation definition file, the tool will loop over | |
| 19 | +all event lists and fill all events into a single counts cube. | |
| 20 | + | |
| 21 | +ctbin generates a counts cube FITS file comprising three extensions. The | |
| 22 | +primary extension contains a 3-dimensional image that contains the counts | |
| 23 | +cube values. The next extension named ``EBOUNDS`` contains a binary table | |
| 24 | +that defines the energy boundaries of the counts cube. The last extension | |
| 25 | +named ``GTI`` contains a binary table that defines the Good Time Intervals | |
| 26 | +of all event lists that have been filled into the counts cube. | |
| 18 | 27 | |
| 19 | 28 | |
| 20 | 29 | General parameters |
| ... | ... | @@ -94,7 +103,9 @@ Standard parameters |
| 94 | 103 | Name of log file. |
| 95 | 104 | |
| 96 | 105 | |
| 97 | -Related tools | |
| 98 | -------------- | |
| 106 | +Related tools or scripts | |
| 107 | +------------------------ | |
| 99 | 108 | |
| 100 | -None | |
| 109 | +:doc:`ctexpcube` | |
| 110 | +:doc:`ctpsfcube` | |
| 111 | +:doc:`ctbkgcube` | ... | ... |
doc/source/reference_manual/ctbkgcube.rst
| ... | ... | @@ -3,36 +3,70 @@ |
| 3 | 3 | ctbkgcube |
| 4 | 4 | ========= |
| 5 | 5 | |
| 6 | -Generate a background cube for binned maximum likelihood analysis. | |
| 6 | +Generate background cube for a counts cube. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This tool generates a background cube for use in a binned maximum | |
| 13 | -likelihood analysis. | |
| 12 | +This tool generates a background cube for a counts cube based on an input | |
| 13 | +model. A background cube is a 3-dimensional cube spanned by Right Ascension | |
| 14 | +or Galactic longitude, Declination or Galactic latitude, and energy. The | |
| 15 | +energy binning may be either linear, logarithmic, or custom defined using an | |
| 16 | +input file. The input model is used to predict the expected number of | |
| 17 | +background counts in each background cube bin. | |
| 18 | + | |
| 19 | +ctbkgcube requires on input the event list or observation definition file | |
| 20 | +that has been used in the generation of the counts cube using :doc:`ctbin`. | |
| 21 | + | |
| 22 | +To assure consistency between an existing counts cube and the | |
| 23 | +corresponding background cube, it is recommended to specify the counts | |
| 24 | +cube as ``incube`` parameter. This will instruct ctbkgcube to extract the | |
| 25 | +background cube definition (such as sky coordinates and projection, number | |
| 26 | +of pixels, pixel scale, energy binning) from the counts cube. | |
| 27 | + | |
| 28 | +ctbkgcube generates a background cube FITS file comprising two extensions. | |
| 29 | +The primary extension contains a 3-dimensional image that contains the | |
| 30 | +background cube values. The next extension named ``EBOUNDS`` contains a | |
| 31 | +binary table that defines the energy boundaries of the background cube. | |
| 32 | + | |
| 33 | +ctbkgcube generates also an output model XML file that can serve as input | |
| 34 | +for a maximum likelihood analysis. The output model XML file is a copy of | |
| 35 | +the input model XML file where the input background model has been replaced | |
| 36 | +by a background model of type ``CTACubeBackground``. The ``CTACubeBackground`` | |
| 37 | +background model instructs any tool analysing binned data to extract | |
| 38 | +background information from a background cube. The ``CTACubeBackground`` | |
| 39 | +model has a spectral component that can be adjusted in a maximum | |
| 40 | +likelihood fit to accomodate for uncertainties in the prediction of the | |
| 41 | +energy dependence of the background rate. ctbkgcube will use a power law | |
| 42 | +as spectral component, but you can replace this by any component of your | |
| 43 | +choice. | |
| 44 | + | |
| 14 | 45 | |
| 15 | 46 | |
| 16 | 47 | General parameters |
| 17 | 48 | ------------------ |
| 18 | 49 | |
| 19 | 50 | ``inobs [file]`` |
| 20 | - Input event list, cube or observation definition XML file. | |
| 51 | + Input event list or observation definition XML file. | |
| 21 | 52 | |
| 22 | 53 | ``inmodel [file]`` |
| 23 | - Input (background) model XML file. | |
| 54 | + Input model XML file. | |
| 24 | 55 | |
| 25 | 56 | ``incube [file]`` |
| 26 | - Counts cube for background cube definition. | |
| 27 | - | |
| 28 | -``outcube [file]`` | |
| 29 | - Output background cube file. | |
| 57 | + Input counts cube file to extract background cube definition. | |
| 30 | 58 | |
| 31 | 59 | ``caldb [string]`` |
| 32 | 60 | Calibration database. |
| 33 | 61 | |
| 34 | 62 | ``irf [string]`` |
| 35 | - Response function. | |
| 63 | + Instrument response function. | |
| 64 | + | |
| 65 | +``outcube [file]`` | |
| 66 | + Output background cube file. | |
| 67 | + | |
| 68 | +``outmodel [file]`` | |
| 69 | + Output model XML file. | |
| 36 | 70 | |
| 37 | 71 | ``ebinalg <FILE|LIN|LOG> [string]`` |
| 38 | 72 | Algorithm for defining energy bins. |
| ... | ... | @@ -102,7 +136,7 @@ Standard parameters |
| 102 | 136 | Name of log file. |
| 103 | 137 | |
| 104 | 138 | |
| 105 | -Related tools | |
| 106 | -------------- | |
| 139 | +Related tools or scripts | |
| 140 | +------------------------ | |
| 107 | 141 | |
| 108 | -None | |
| 142 | +:doc:`ctbin` | ... | ... |
doc/source/reference_manual/ctbutterfly.rst
| ... | ... | @@ -9,16 +9,31 @@ Computes butterfly diagram for a power law model. |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Calculates the confidence band of a power law model, taking into account the | |
| 13 | -covariance matrix resulting from a maximum likelihood fit. The tool derives | |
| 14 | -the envelope of all power law models whose prefactor and spectral index fall | |
| 15 | -within the error ellipse that is associated with the covariance of the | |
| 16 | -parameters. It outputs an ASCII file in column separated value (CSV) format | |
| 17 | -containing the results. Each row in the result file corresponds to an energy. | |
| 18 | -The columns give the energy in MeV, the fitted intensity in ph/cm2/s/MeV, | |
| 19 | -and the minimum and maximum intensity that envelope the power law model | |
| 20 | -with a given confidence (by default a confidence level of 68% is used, but | |
| 21 | -the level can be adjusted using the ``confidence`` parameter). | |
| 12 | +This tool calculates a butterfly diagram for a specific source with power law | |
| 13 | +spectral model. The butterfly diagram is the envelope of all power law models | |
| 14 | +that are within a given confidence limit compatible with the data. By default | |
| 15 | +a confidence level of 68% is used, but the level can be adjusted using the | |
| 16 | +hidden ``confidence`` parameter. ctbutterfly computes this envelope by | |
| 17 | +evaluating for each energy the minimum and maximum intensity of all power law | |
| 18 | +models that fall within the error ellipse of the prefactor and index parameters. | |
| 19 | +The error ellipse is derived from the covariance matrix of a maximum likelihood | |
| 20 | +fit. | |
| 21 | + | |
| 22 | +ctbutterfly assumes that the input model (parameter ``inmodel``) has been | |
| 23 | +adjusted using :doc:`ctlike` to the data, but if this is not the case you | |
| 24 | +can request a maximum likelihood fit by setting the hidden parameter ``fit=yes``. | |
| 25 | + | |
| 26 | +ctbutterfly writes the butterfly diagram into an ASCII file with 4 columns | |
| 27 | +separated by a whitespace. Each row in the result file corresponds to a specific | |
| 28 | +energy. The meaning of the columns are: | |
| 29 | + | |
| 30 | +* Energy in MeV | |
| 31 | +* Fitted intensity for that energy in ph/cm2/s/MeV | |
| 32 | +* Minimum intensity for that energy in ph/cm2/s/MeV | |
| 33 | +* Maximum intensity for that energy in ph/cm2/s/MeV | |
| 34 | + | |
| 35 | +The butterfly diagram can be displayed using the ``show_butterfly.py`` script | |
| 36 | +in the example folder. | |
| 22 | 37 | |
| 23 | 38 | |
| 24 | 39 | General parameters |
| ... | ... | @@ -28,19 +43,19 @@ General parameters |
| 28 | 43 | Input event list, counts cube or observation definition XML file. |
| 29 | 44 | |
| 30 | 45 | ``inmodel [file]`` |
| 31 | - Model XML file containing the source and background definitions. | |
| 46 | + Input model XML file. | |
| 32 | 47 | |
| 33 | 48 | ``srcname [string]`` |
| 34 | - Name of model component for which butterfly should be computed. | |
| 49 | + Name of source model for which the butterfly diagram should be computed. | |
| 35 | 50 | |
| 36 | 51 | ``expcube [file]`` |
| 37 | - Exposure cube file (only needed for stacked analysis). | |
| 52 | + Input exposure cube file (only needed for stacked analysis). | |
| 38 | 53 | |
| 39 | 54 | ``psfcube [file]`` |
| 40 | - PSF cube file (only needed for stacked analysis). | |
| 55 | + Input PSF cube file (only needed for stacked analysis). | |
| 41 | 56 | |
| 42 | 57 | ``bkgcube [file]`` |
| 43 | - Background cube file (only needed for stacked analysis). | |
| 58 | + Input background cube file (only needed for stacked analysis). | |
| 44 | 59 | |
| 45 | 60 | ``caldb [string]`` |
| 46 | 61 | Calibration database. |
| ... | ... | @@ -54,8 +69,9 @@ General parameters |
| 54 | 69 | ``outfile [file]`` |
| 55 | 70 | Output butterfly ASCII file name. |
| 56 | 71 | |
| 57 | -``(refit = no) [boolean]`` | |
| 58 | - Performs refitting of solution ignoring any provided covariance matrix. | |
| 72 | +``(fit = no) [boolean]`` | |
| 73 | + Performs maximum likelihood fitting of input model ignoring any provided | |
| 74 | + covariance matrix. | |
| 59 | 75 | |
| 60 | 76 | ``(confidence = 0.68) [real]`` |
| 61 | 77 | Confidence level for error computation. |
| ... | ... | @@ -107,8 +123,9 @@ Standard parameters |
| 107 | 123 | Name of log file. |
| 108 | 124 | |
| 109 | 125 | |
| 110 | -Related tools | |
| 111 | -------------- | |
| 126 | +Related tools or scripts | |
| 127 | +------------------------ | |
| 112 | 128 | |
| 129 | +:doc:`ctlike` | |
| 113 | 130 | :ref:`ctulimit` |
| 114 | 131 | :ref:`cterror` | ... | ... |
doc/source/reference_manual/ctcubemask.rst
| ... | ... | @@ -3,14 +3,32 @@ |
| 3 | 3 | ctcubemask |
| 4 | 4 | ========== |
| 5 | 5 | |
| 6 | -Filter a counts cube. | |
| 6 | +Mask out bins of a counts cube. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | 12 | This tool masks out specific regions from a counts cube by setting the |
| 13 | -corresponding pixels to negative values. | |
| 13 | +corresponding bin values to -1. Bins with negative values will be ignored | |
| 14 | +in a maximum likelihood analysis. A mask is applied spatially and spectrally. | |
| 15 | + | |
| 16 | +ctcubemask applies a spatial mask that is comprised of a circular selection | |
| 17 | +region and a list of circular exclusion regions. The circular selection region | |
| 18 | +is specified by the sky direction of the centre and the radius of the circle. | |
| 19 | +The circular exclusion regions are specified by an ASCII file in ds9 format. | |
| 20 | +The ASCII file contains one row per exclusion region, given in the format | |
| 21 | + | |
| 22 | +``circle(83.63, 21.5, 0.4)`` | |
| 23 | + | |
| 24 | +where ``83.63`` and ``21.5`` are the Right Ascension and Declination of | |
| 25 | +the centre and ``0.4`` is the radius (in degrees) of the exclusion circle. | |
| 26 | + | |
| 27 | +ctcubemask also selects only counts cube energy layers that are fully comprised | |
| 28 | +in the energy interval specified by the ``emin`` and ``emax`` parameters. | |
| 29 | + | |
| 30 | +ctcubemask generates a counts cube FITS file that is a copy of the input | |
| 31 | +counts cube and for which all masked bins have been set to -1. | |
| 14 | 32 | |
| 15 | 33 | |
| 16 | 34 | General parameters |
| ... | ... | @@ -19,9 +37,6 @@ General parameters |
| 19 | 37 | ``inobs [file]`` |
| 20 | 38 | Input counts cube or observation definition XML file. |
| 21 | 39 | |
| 22 | -``regfile [file]`` | |
| 23 | - Exclusion region file in ds9 format. | |
| 24 | - | |
| 25 | 40 | ``outcube [file]`` |
| 26 | 41 | Output counts cube or observation definition XML file. |
| 27 | 42 | |
| ... | ... | @@ -41,6 +56,9 @@ General parameters |
| 41 | 56 | ``rad [real]`` |
| 42 | 57 | Radius of circular selection region (in degrees). |
| 43 | 58 | |
| 59 | +``regfile [file]`` | |
| 60 | + Input exclusion region file in ds9 format. | |
| 61 | + | |
| 44 | 62 | ``emin [real]`` |
| 45 | 63 | Lower energy limit (in TeV). |
| 46 | 64 | |
| ... | ... | @@ -72,11 +90,11 @@ Standard parameters |
| 72 | 90 | ``(mode = ql) [string]`` |
| 73 | 91 | Mode of automatic parameters (default is "ql", i.e. "query and learn"). |
| 74 | 92 | |
| 75 | -``(logfile = ctexpcube.log) [string]`` | |
| 93 | +``(logfile = ctcubemask.log) [string]`` | |
| 76 | 94 | Name of log file. |
| 77 | 95 | |
| 78 | 96 | |
| 79 | -Related tools | |
| 80 | -------------- | |
| 97 | +Related tools or scripts | |
| 98 | +------------------------ | |
| 81 | 99 | |
| 82 | -None | |
| 100 | +:doc:`ctbin` | ... | ... |
doc/source/reference_manual/cterror.rst
| ... | ... | @@ -3,15 +3,26 @@ |
| 3 | 3 | cterror |
| 4 | 4 | ======= |
| 5 | 5 | |
| 6 | -Computes parameter errors for a specific sky model component using | |
| 7 | -a likelihood profile method. | |
| 6 | +Computes parameter errors for a source model from the likelihood profiles. | |
| 8 | 7 | |
| 9 | 8 | |
| 10 | 9 | Synopsis |
| 11 | 10 | -------- |
| 12 | 11 | |
| 13 | -This tool computes the parameter errors for a specific sky model using | |
| 14 | -a likelihood profile method. | |
| 12 | +This tool computes the parameter errors for a specific source model using | |
| 13 | +the likelihood profiles. Starting from the maximum likelihood model parameters, | |
| 14 | +the tool finds the minimum and maximum model parameters that lead to a decrease | |
| 15 | +of the likelihood that corresponds to a given confidence level. By default a | |
| 16 | +confidence level of 68% is used, but this level can be adjusted using the hidden | |
| 17 | +``confidence`` parameter. | |
| 18 | + | |
| 19 | +cterror generates an output model XML file that contains the values of the | |
| 20 | +best fitting model parameters. For all free parameters, an ``error`` attribute | |
| 21 | +is added that provides the statistical uncertainty in the parameter estimate | |
| 22 | +as obtained from the likelihood profile. While cterror computes asymmetrical | |
| 23 | +errors, which are written into the log file, the XML file will contain the | |
| 24 | +mean error that is obtained by computing the mean of the negative and the | |
| 25 | +positive parameter errors. | |
| 15 | 26 | |
| 16 | 27 | |
| 17 | 28 | General parameters |
| ... | ... | @@ -21,22 +32,19 @@ General parameters |
| 21 | 32 | Input event list, counts cube or observation definition XML file. |
| 22 | 33 | |
| 23 | 34 | ``inmodel [file]`` |
| 24 | - Model XML file containing the source and background definitions. | |
| 25 | - | |
| 26 | -``outmodel [file]`` | |
| 27 | - Model XML file with updated error information. | |
| 35 | + Input model XML file. | |
| 28 | 36 | |
| 29 | 37 | ``srcname [string]`` |
| 30 | - Name of model component for which upper limit should be computed. | |
| 38 | + Name of source model for which the parameter errors should be computed. | |
| 31 | 39 | |
| 32 | 40 | ``expcube [file]`` |
| 33 | - Exposure cube file (only needed for stacked analysis). | |
| 41 | + Input exposure cube file (only needed for stacked analysis). | |
| 34 | 42 | |
| 35 | 43 | ``psfcube [file]`` |
| 36 | - PSF cube file (only needed for stacked analysis). | |
| 44 | + Input PSF cube file (only needed for stacked analysis). | |
| 37 | 45 | |
| 38 | 46 | ``bkgcube [file]`` |
| 39 | - Background cube file (only needed for stacked analysis). | |
| 47 | + Input background cube file (only needed for stacked analysis). | |
| 40 | 48 | |
| 41 | 49 | ``caldb [string]`` |
| 42 | 50 | Calibration database. |
| ... | ... | @@ -47,6 +55,9 @@ General parameters |
| 47 | 55 | ``(edisp = no) [boolean]`` |
| 48 | 56 | Applies energy dispersion to response computation. |
| 49 | 57 | |
| 58 | +``outmodel [file]`` | |
| 59 | + Output model XML file with updated error information. | |
| 60 | + | |
| 50 | 61 | ``(confidence = 0.68) [real]`` |
| 51 | 62 | Confidence level for error computation. |
| 52 | 63 | |
| ... | ... | @@ -86,8 +97,9 @@ Standard parameters |
| 86 | 97 | Name of log file. |
| 87 | 98 | |
| 88 | 99 | |
| 89 | -Related tools | |
| 90 | -------------- | |
| 100 | +Related tools or scripts | |
| 101 | +------------------------ | |
| 91 | 102 | |
| 103 | +:ref:`ctlike` | |
| 92 | 104 | :ref:`ctulimit` |
| 93 | 105 | :ref:`ctbutterfly` | ... | ... |
doc/source/reference_manual/ctexpcube.rst
| ... | ... | @@ -3,14 +3,39 @@ |
| 3 | 3 | ctexpcube |
| 4 | 4 | ========= |
| 5 | 5 | |
| 6 | -Generate an exposure cube for binned maximum likelihood analysis. | |
| 6 | +Generate exposure cube for a counts cube. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This tool generates an exposure cube for use in a binned maximum likelihood | |
| 13 | -analysis. | |
| 12 | +This tool generates an exposure cube for a counts cube. An exposure cube is | |
| 13 | +a 3-dimensional cube spanned by Right Ascension or Galactic longitude, | |
| 14 | +Declination or Galactic latitude, and energy, that gives the exposure | |
| 15 | +as function of true sky direction and energy. The energy binning of the cube | |
| 16 | +may be either linear, logarithmic, or custom defined using an input file. | |
| 17 | + | |
| 18 | +ctexpcube requires on input the event list or observation definition file | |
| 19 | +that has been used in the generation of the counts cube using :doc:`ctbin`. | |
| 20 | + | |
| 21 | +For the user's convenience, the counts cube can be specified as ``incube`` | |
| 22 | +parameter which will instruct ctexpcube to extract the exposure cube | |
| 23 | +definition (such as sky coordinates and projection, number of pixels, pixel | |
| 24 | +scale, energy binning) from the counts cube. Note, however, that the exposure | |
| 25 | +cube is defined in true sky coordinates and energy while the counts cube is | |
| 26 | +defined in measured sky coordinates and energy. Consequently, the sky area | |
| 27 | +and energy range covered by the exposure cube should be slightly larger than | |
| 28 | +that of the counts cube to accomodate for spill over of events due to the | |
| 29 | +point spread function and energy dispersion. By computing the exposure map | |
| 30 | +on the same grid as the counts cube, the spill over of events from sources at | |
| 31 | +the edge of cube will not be handled correctly. | |
| 32 | + | |
| 33 | +ctexpcube generates an exposure cube FITS file comprising three extensions. | |
| 34 | +The primary extension contains a 3-dimensional image that contains the | |
| 35 | +exposure values. The next extension named ``EBOUNDS`` contains a binary table | |
| 36 | +that defines the energy boundaries of the exposure cube. The last extension | |
| 37 | +named ``GTI`` contains a binary table that defines the Good Time Intervals | |
| 38 | +of the exposure cube. | |
| 14 | 39 | |
| 15 | 40 | |
| 16 | 41 | General parameters |
| ... | ... | @@ -20,20 +45,20 @@ General parameters |
| 20 | 45 | Input event list or observation definition XML file. |
| 21 | 46 | |
| 22 | 47 | ``incube [file]`` |
| 23 | - Counts cube for PSF cube definition. | |
| 24 | - | |
| 25 | -``outcube [file]`` | |
| 26 | - Output exposure cube file. | |
| 48 | + Input counts cube file to extract exposure cube definition. | |
| 27 | 49 | |
| 28 | 50 | ``caldb [string]`` |
| 29 | 51 | Calibration database. |
| 30 | 52 | |
| 31 | 53 | ``irf [string]`` |
| 32 | - Response function. | |
| 54 | + Instrument response function. | |
| 33 | 55 | |
| 34 | 56 | ``(edisp = no) [boolean]`` |
| 35 | 57 | Apply energy dispersion for response computation? |
| 36 | 58 | |
| 59 | +``outcube [file]`` | |
| 60 | + Output exposure cube file. | |
| 61 | + | |
| 37 | 62 | ``ebinalg <FILE|LIN|LOG> [string]`` |
| 38 | 63 | Algorithm for defining energy bins. |
| 39 | 64 | |
| ... | ... | @@ -102,7 +127,7 @@ Standard parameters |
| 102 | 127 | Name of log file. |
| 103 | 128 | |
| 104 | 129 | |
| 105 | -Related tools | |
| 106 | -------------- | |
| 130 | +Related tools or scripts | |
| 131 | +------------------------ | |
| 107 | 132 | |
| 108 | -None | |
| 133 | +:doc:`ctbin` | ... | ... |
doc/source/reference_manual/ctlike.rst
| ... | ... | @@ -3,26 +3,54 @@ |
| 3 | 3 | ctlike |
| 4 | 4 | ====== |
| 5 | 5 | |
| 6 | -Performs binned and unbinned maximum likelihood analysis of CTA data. | |
| 6 | +Perform maximum likelihood model fitting. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Determines the flux, spectral index, position or extent of gamma-ray | |
| 13 | -sources using maximum likelihood model fitting of CTA data. The analysis | |
| 14 | -can be done in a binned or an unbinned formulation of the log-likelihood | |
| 15 | -function. For binned analysis, a counts cube produced by :doc:`ctbin` is | |
| 16 | -required. If several observations have been stacked into a single counts | |
| 17 | -cube, an exposure cube, a PSF cube and a background cube have to be | |
| 18 | -provided. For a single observation it is sufficient to specify the | |
| 19 | -instrument response function. For unbinned analysis, an event list | |
| 20 | -processed by :doc:`ctselect` is required. Based on files specified on | |
| 21 | -input, ctlike automatically selects between binned or unbinned analysis. | |
| 22 | -The tool can also be applied to lists of observations, specified in form | |
| 23 | -of an observation definition file in XML format. Events of each observation | |
| 24 | -are kept separate, and are associated to their appropriate instrument | |
| 25 | -response function. | |
| 12 | +This tool performs a maximum likelihood fitting of a model to unbinned or | |
| 13 | +binned data. All model parameters marked with the attribute ``free="1"`` | |
| 14 | +in the input model XML file will be adjusted to the value that maximises | |
| 15 | +the probability that the observed data have been drawn from the model. | |
| 16 | +The tool can mix the analysis of unbinned and binned data, and is also able | |
| 17 | +to perform a joint maximum likelihood analysis of data collected in | |
| 18 | +separate observations or with different instruments. | |
| 19 | + | |
| 20 | +ctlike will automatically switch between unbinned, binned and joint analysis | |
| 21 | +on basis of the file provided on input (parameter ``inobs``). Providing an | |
| 22 | +event list will lead to an unbinned analysis while providing a counts cube | |
| 23 | +will lead to a binned analysis. If several observations have been stacked | |
| 24 | +into a single counts cube, an exposure cube, a point spread function cube and | |
| 25 | +a background cube need also to be provided. ctlike will automatically prompt | |
| 26 | +for these parameters in case that a counts cube is given. Answering ``NONE`` | |
| 27 | +will ignore the exposure cube, point spread function cube and background cube | |
| 28 | +and handle the data as a single observation using the specified instrument | |
| 29 | +response function (parameters ``caldb`` and ``irf``). | |
| 30 | + | |
| 31 | +Multiple observations, including data collected with different instruments, | |
| 32 | +can be handled by specifying an observation definition file on input. Each of | |
| 33 | +the observations will be kept separatly and associated with its appropriate | |
| 34 | +instrument response functions, as opposed to a stacked analysis where average | |
| 35 | +response functions, computed using :doc:`ctexpcube`, :doc:`ctpsfcube` and :doc:`ctbkgcube`, | |
| 36 | +are used. If an observation definition file is provided, ctlike will use the | |
| 37 | +joint likelihood of all the observations for parameter optimisation. | |
| 38 | + | |
| 39 | +By default, ctlike will use the Poisson statistics for likelihood computation, | |
| 40 | +but for binned analysis also Gaussian statistics can be specified (parameter | |
| 41 | +``stat``). Optionally, a refit can be done after an initial fit (parameter ``refit``), | |
| 42 | +but normally this is not needed. For all model components that have the | |
| 43 | +``tscalc="1"`` attribute set, ctlike will also compute the Test Statistics | |
| 44 | +value that is a measure of the source significance. Optionally, the spatial | |
| 45 | +model parameters can be kept fixed during that computation (parameter | |
| 46 | +``fix_spat_for_ts``). | |
| 47 | + | |
| 48 | +ctlike generates an output model XML file that contains the values of the | |
| 49 | +best fitting model parameters. For all free parameters, an ``error`` attribute | |
| 50 | +is added that provides the statistical uncertainty in the parameter estimate. | |
| 51 | +If computation of the Test Statistics has been requested for a model component, | |
| 52 | +a ``ts`` attribute providing the Test Statistics value is added. The output | |
| 53 | +model can be used as an input model for other ctools. | |
| 26 | 54 | |
| 27 | 55 | |
| 28 | 56 | General parameters |
| ... | ... | @@ -32,16 +60,16 @@ General parameters |
| 32 | 60 | Input event list, counts cube or observation definition XML file. |
| 33 | 61 | |
| 34 | 62 | ``inmodel [string]`` |
| 35 | - Source model input XML file. | |
| 63 | + Input model XML file. | |
| 36 | 64 | |
| 37 | 65 | ``expcube [file]`` |
| 38 | - Exposure cube file (only needed for stacked analysis). | |
| 66 | + Input exposure cube file (only needed for stacked analysis). | |
| 39 | 67 | |
| 40 | 68 | ``psfcube [file]`` |
| 41 | - PSF cube file (only needed for stacked analysis). | |
| 69 | + Input PSF cube file (only needed for stacked analysis). | |
| 42 | 70 | |
| 43 | 71 | ``bkgcube [file]`` |
| 44 | - Background cube file (only needed for stacked analysis). | |
| 72 | + Input background cube file (only needed for stacked analysis). | |
| 45 | 73 | |
| 46 | 74 | ``caldb [string]`` |
| 47 | 75 | Calibration database. |
| ... | ... | @@ -49,18 +77,21 @@ General parameters |
| 49 | 77 | ``irf [string]`` |
| 50 | 78 | Instrument response function. |
| 51 | 79 | |
| 80 | +``(edisp = no) [boolean]`` | |
| 81 | + Applies energy dispersion to response computation. | |
| 82 | + | |
| 52 | 83 | ``outmodel [string]`` |
| 53 | - Source model result XML file with values and uncertainties updated by | |
| 84 | + Output model XML file with values and uncertainties updated by | |
| 54 | 85 | the maximum likelihood fit. |
| 55 | 86 | |
| 56 | 87 | ``(stat = POISSON) [string]`` |
| 57 | 88 | Fitting statistics (POISSON or GAUSSIAN; only affects binned analysis). |
| 58 | 89 | |
| 59 | -``(edisp = no) [boolean]`` | |
| 60 | - Applies energy dispersion to response computation. | |
| 61 | - | |
| 62 | 90 | ``(refit = no) [boolean]`` |
| 63 | - Performs refitting of solution after initial fit. | |
| 91 | + Perform refitting of solution after initial fit. | |
| 92 | + | |
| 93 | +``(fix_spat_for_ts = no) [boolean]`` | |
| 94 | + Fix spatial parameters for TS computation. | |
| 64 | 95 | |
| 65 | 96 | |
| 66 | 97 | |
| ... | ... | @@ -92,7 +123,7 @@ Standard parameters |
| 92 | 123 | Name of log file. |
| 93 | 124 | |
| 94 | 125 | |
| 95 | -Related tools | |
| 96 | -------------- | |
| 126 | +Related tools or scripts | |
| 127 | +------------------------ | |
| 97 | 128 | |
| 98 | 129 | None | ... | ... |
doc/source/reference_manual/ctmodel.rst
| ... | ... | @@ -3,48 +3,67 @@ |
| 3 | 3 | ctmodel |
| 4 | 4 | ======= |
| 5 | 5 | |
| 6 | -Computes model counts cube. | |
| 6 | +Generate model cube. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This tool computes a model counts cube based on an XML model. The counts | |
| 13 | -cube is a 3-dimensional data cube spanned by Right Ascension or Galactic | |
| 14 | -longitude, Declination or Galactic latitude, and energy. | |
| 12 | +This tool generates a model cube based on an input model. A model cube is | |
| 13 | +a 3-dimensional cube providing the number of predicted counts for a model as | |
| 14 | +function of Right Ascension or Galactic longitude, Declination or Galactic | |
| 15 | +latitude, and energy. The energy binning may be either linear, logarithmic, | |
| 16 | +or custom defined using an input file. | |
| 17 | + | |
| 18 | +ctmodel requires on input either a counts cube, an event list or an observation | |
| 19 | +definition file. | |
| 20 | + | |
| 21 | +If a counts cube is provided, ctmodel will use the definition of this cube | |
| 22 | +(such as sky coordinates and projection, number of pixels, pixel scale, | |
| 23 | +energy binning) to compute a model cube. In case that the counts cube combines | |
| 24 | +multiple observations (i.e. for a so-called "stacked cube"), an exposure cube, | |
| 25 | +a point spread function cube and a background cube have to be provided | |
| 26 | +(otherwise you may just enter ``NONE`` when the names of these files are | |
| 27 | +queried). | |
| 28 | + | |
| 29 | +If an event list is provided, ctmodel will query for a counts cube to | |
| 30 | +extract the model cube definition (parameter ``incube``). If no counts cube | |
| 31 | +is provided (``incube=NONE``), ctmodel tools will query for cube definition | |
| 32 | +parameters. | |
| 33 | + | |
| 34 | +If an observation definition file is provided, ctmodel will query for a counts | |
| 35 | +cube to extract the model cube definition, unless the observation definition | |
| 36 | +file contains a single binned observation (in that case, the counts cube of | |
| 37 | +that observation will be used to extract the model cube definition). | |
| 38 | + | |
| 39 | +ctmodel generates a model cube FITS file comprising three extensions. The | |
| 40 | +primary extension contains a 3-dimensional image that contains the model | |
| 41 | +cube values. The next extension named ``EBOUNDS`` contains a binary table | |
| 42 | +that defines the energy boundaries of the background cube. The last extension | |
| 43 | +named ``GTI`` contains a binary table that defines the Good Time Intervals | |
| 44 | +that are covered by the model cube. | |
| 15 | 45 | |
| 16 | 46 | |
| 17 | 47 | General parameters |
| 18 | 48 | ------------------ |
| 19 | 49 | |
| 20 | -``incube [file]`` | |
| 21 | - Input counts cube. If a filename is given the counts cube will be | |
| 22 | - used to define the dimensions of the model cube. The content of | |
| 23 | - the counts cube is not relevant. | |
| 50 | +``inobs [file]`` | |
| 51 | + Input event list, counts cube or observation definition XML file. | |
| 24 | 52 | |
| 25 | 53 | ``inmodel [string]`` |
| 26 | - Source model XML file. | |
| 27 | - | |
| 28 | -``outcube [file]`` | |
| 29 | - Output model counts cube. | |
| 30 | - | |
| 31 | -``(edisp = no) [boolean]`` | |
| 32 | - Apply energy dispersion to response computation. | |
| 54 | + Input model XML file. | |
| 33 | 55 | |
| 34 | -``inobs [file]`` | |
| 35 | - Input event list, counts cube or observation definition XML file. | |
| 36 | - This information is needed to determine the observation information | |
| 37 | - (number of observations, duration, liftime, pointing, eventually | |
| 38 | - observation specific instrument response functions, etc.). | |
| 56 | +``incube [file]`` | |
| 57 | + Input counts cube file to extract model cube definition. | |
| 39 | 58 | |
| 40 | 59 | ``expcube [file]`` |
| 41 | - Exposure cube file (only needed for stacked analysis). | |
| 60 | + Input exposure cube file (only needed for stacked analysis). | |
| 42 | 61 | |
| 43 | 62 | ``psfcube [file]`` |
| 44 | - PSF cube file (only needed for stacked analysis). | |
| 63 | + Input PSF cube file (only needed for stacked analysis). | |
| 45 | 64 | |
| 46 | 65 | ``bkgcube [file]`` |
| 47 | - Background cube file (only needed for stacked analysis). | |
| 66 | + Input background cube file (only needed for stacked analysis). | |
| 48 | 67 | |
| 49 | 68 | ``caldb [string]`` |
| 50 | 69 | Calibration database. |
| ... | ... | @@ -52,6 +71,12 @@ General parameters |
| 52 | 71 | ``irf [string]`` |
| 53 | 72 | Instrument response function. |
| 54 | 73 | |
| 74 | +``(edisp = no) [boolean]`` | |
| 75 | + Apply energy dispersion to response computation. | |
| 76 | + | |
| 77 | +``outcube [file]`` | |
| 78 | + Output model cube file. | |
| 79 | + | |
| 55 | 80 | ``ra [real]`` |
| 56 | 81 | Right Ascension of pointing (J2000, in degrees). |
| 57 | 82 | |
| ... | ... | @@ -138,7 +163,10 @@ Standard parameters |
| 138 | 163 | Name of log file. |
| 139 | 164 | |
| 140 | 165 | |
| 141 | -Related tools | |
| 142 | -------------- | |
| 166 | +Related tools or scripts | |
| 167 | +------------------------ | |
| 143 | 168 | |
| 144 | -None | |
| 169 | +:doc:`ctbin` | |
| 170 | +:doc:`ctexpcube` | |
| 171 | +:doc:`ctpsfcube` | |
| 172 | +:doc:`ctbkgcube` | ... | ... |
doc/source/reference_manual/ctobssim.rst
| ... | ... | @@ -3,14 +3,39 @@ |
| 3 | 3 | ctobssim |
| 4 | 4 | ======== |
| 5 | 5 | |
| 6 | -Simulates CTA events. | |
| 6 | +Simulate event list(s). | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Generate photon events from astrophysical sources and background events | |
| 13 | -from an instrumental background model. | |
| 12 | +This tool simulates event list(s) using the instrument characteristics | |
| 13 | +specified by the instrument response function(s) and an input model. The | |
| 14 | +simulation includes photon events from astrophysical sources and background | |
| 15 | +events from an instrumental background model. | |
| 16 | + | |
| 17 | +By default, ctobssim creates a single event list. ctobssim queries a pointing | |
| 18 | +direction, the radius of the simulation region, a time interval, an energy | |
| 19 | +interval, an instrumental response function, and an input model. ctobssim uses | |
| 20 | +a numerical random number generator for the simulations with a seed value | |
| 21 | +provided by the hidden ``seed`` parameter. Changing this parameter for | |
| 22 | +subsequent runs will lead to different event samples. | |
| 23 | + | |
| 24 | +ctobssim performs a safety check on the maximum photon rate for all model | |
| 25 | +components to avoid that the tool locks up and requests huge memory | |
| 26 | +ressources, which may happen if a mistake was made in setting up the input | |
| 27 | +model (for example if an error in the flux units is made). The maximum allowed | |
| 28 | +photon rate is controlled by the hidden ``maxrate`` parameter, which by default | |
| 29 | +is set to 1e6. | |
| 30 | + | |
| 31 | +ctobssim can also generate multiple event lists if an observation definition | |
| 32 | +file is specified on input using the hidden ``inobs`` parameter. In that | |
| 33 | +case, simulation information will be gathered from the file, and for each | |
| 34 | +observation an event list will be created. | |
| 35 | + | |
| 36 | +For each event file, the simulation parameters will be written as data | |
| 37 | +selection keywords to the FITS header. These keywords are mandatory for any | |
| 38 | +unbinned maximum likelihood analysis of the event data. | |
| 14 | 39 | |
| 15 | 40 | |
| 16 | 41 | General parameters |
| ... | ... | @@ -23,14 +48,7 @@ General parameters |
| 23 | 48 | simulation. |
| 24 | 49 | |
| 25 | 50 | ``inmodel [file]`` |
| 26 | - XML file that describes the astrophysical sources and the instrumental | |
| 27 | - background model. | |
| 28 | - | |
| 29 | -``outevents [file]`` | |
| 30 | - Output event list or observation definition XML file. | |
| 31 | - | |
| 32 | -``(prefix = sim_events_) [string]`` | |
| 33 | - Prefix for event list in observation definition XML file. | |
| 51 | + Input model XML file. | |
| 34 | 52 | |
| 35 | 53 | ``caldb [string]`` |
| 36 | 54 | Calibration database. |
| ... | ... | @@ -38,6 +56,15 @@ General parameters |
| 38 | 56 | ``irf [string]`` |
| 39 | 57 | Instrumental response function. |
| 40 | 58 | |
| 59 | +``(edisp = no) [boolean]`` | |
| 60 | + Apply energy dispersion? | |
| 61 | + | |
| 62 | +``outevents [file]`` | |
| 63 | + Output event list or observation definition XML file. | |
| 64 | + | |
| 65 | +``(prefix = sim_events_) [string]`` | |
| 66 | + Prefix for event list in observation definition XML file. | |
| 67 | + | |
| 41 | 68 | ``(seed = 1) [integer]`` |
| 42 | 69 | Integer seed value to be used for Monte Carlo simulations. Keep this |
| 43 | 70 | parameter at the same value for repeatable simulations, or increment |
| ... | ... | @@ -65,9 +92,6 @@ General parameters |
| 65 | 92 | ``emax [real]`` |
| 66 | 93 | Upper energy limit of simulated events (in TeV). |
| 67 | 94 | |
| 68 | -``(edisp = no) [boolean]`` | |
| 69 | - Apply energy dispersion? | |
| 70 | - | |
| 71 | 95 | ``(deadc = 0.95) [real]`` |
| 72 | 96 | Average deadtime correction factor. |
| 73 | 97 | |
| ... | ... | @@ -107,7 +131,7 @@ Standard parameters |
| 107 | 131 | Name of log file. |
| 108 | 132 | |
| 109 | 133 | |
| 110 | -Related tools | |
| 111 | -------------- | |
| 134 | +Related tools or scripts | |
| 135 | +------------------------ | |
| 112 | 136 | |
| 113 | -None | |
| 137 | +:doc:`csobsdef` | ... | ... |
doc/source/reference_manual/ctpsfcube.rst
| ... | ... | @@ -3,15 +3,39 @@ |
| 3 | 3 | ctpsfcube |
| 4 | 4 | ========= |
| 5 | 5 | |
| 6 | -Generate a point spread function cube for binned maximum likelihood | |
| 7 | -analysis. | |
| 6 | +Generate point spread function cube for a counts cube. | |
| 8 | 7 | |
| 9 | 8 | |
| 10 | 9 | Synopsis |
| 11 | 10 | -------- |
| 12 | 11 | |
| 13 | -This tool generates a point spread function cube for use in a binned | |
| 14 | -maximum likelihood analysis. | |
| 12 | +This tool generates a point spread function cube for a counts cube. A point | |
| 13 | +spread function cube is a 4-dimensional cube spanned by Right Ascension or | |
| 14 | +Galactic longitude, Declination or Galactic latitude, energy, and offset | |
| 15 | +angle between true and measured arrival direction of a photon. The energy | |
| 16 | +binning of the cube may be either linear, logarithmic, or custom defined | |
| 17 | +using an input file. | |
| 18 | + | |
| 19 | +ctpsfcube requires on input the event list or observation definition file | |
| 20 | +that has been used in the generation of the counts cube using :doc:`ctbin`. | |
| 21 | + | |
| 22 | +It is not recommended to use the counts cube for the point spread function | |
| 23 | +cube definition, although this is formally possibly by specifying the counts | |
| 24 | +cube as ``incube`` parameter. This leads however to a large FITS file on | |
| 25 | +output since the number of bins in the counts cube will be multiplied by | |
| 26 | +the number of offset angle bins (typically 200). Since the point spread | |
| 27 | +function varies only little over the field of fiew of the camera it is | |
| 28 | +recommended to use a rather coarse spatial binning to keep the file size | |
| 29 | +manageable (with a typical value of ``binsz=1.0``). | |
| 30 | + | |
| 31 | +ctpsfcube generates a point spread function cube FITS file comprising three | |
| 32 | +extensions. The primary extension contains a 3-dimensional image that contains | |
| 33 | +the point spread function values. The energy and offset angle dimensions | |
| 34 | +of the point spread function cube are folded into the 3rd dimension of the | |
| 35 | +FITS image. The next extension named ``EBOUNDS`` contains a binary table | |
| 36 | +that defines the energy boundaries of the exposure cube. The last extension | |
| 37 | +named ``DELTAS`` contains a binary table that defines the offset angles | |
| 38 | +between true and measured arrival direction of the photon. | |
| 15 | 39 | |
| 16 | 40 | |
| 17 | 41 | General parameters |
| ... | ... | @@ -21,20 +45,20 @@ General parameters |
| 21 | 45 | Input event list or observation definition XML file. |
| 22 | 46 | |
| 23 | 47 | ``incube [file]`` |
| 24 | - Counts cube for PSF cube definition. | |
| 25 | - | |
| 26 | -``outcube [file]`` | |
| 27 | - Output PSF cube file. | |
| 48 | + Input counts cube file to extract point spread function cube definition. | |
| 28 | 49 | |
| 29 | 50 | ``caldb [string]`` |
| 30 | 51 | Calibration database. |
| 31 | 52 | |
| 32 | 53 | ``irf [string]`` |
| 33 | - Response function. | |
| 54 | + Instrument response function. | |
| 34 | 55 | |
| 35 | 56 | ``(edisp = no) [boolean]`` |
| 36 | 57 | Apply energy dispersion for response computation. |
| 37 | 58 | |
| 59 | +``outcube [file]`` | |
| 60 | + Output point spread function cube file. | |
| 61 | + | |
| 38 | 62 | ``ebinalg <FILE|LIN|LOG> [string]`` |
| 39 | 63 | Algorithm for defining energy bins. |
| 40 | 64 | |
| ... | ... | @@ -110,7 +134,7 @@ Standard parameters |
| 110 | 134 | Name of log file. |
| 111 | 135 | |
| 112 | 136 | |
| 113 | -Related tools | |
| 114 | -------------- | |
| 137 | +Related tools or scripts | |
| 138 | +------------------------ | |
| 115 | 139 | |
| 116 | -None | |
| 140 | +:doc:`ctbin` | ... | ... |
doc/source/reference_manual/ctselect.rst
| ... | ... | @@ -3,14 +3,36 @@ |
| 3 | 3 | ctselect |
| 4 | 4 | ======== |
| 5 | 5 | |
| 6 | -Performs sub-selections of event data. | |
| 6 | +Select events from event list(s). | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Creates a new FITS file of selected events from an input event list based | |
| 13 | -on spatial, temporal, and energy cuts. | |
| 12 | +This tool selects events from one or several event lists. Event selection | |
| 13 | +is based on a circular acceptance region, a time interval and an energy | |
| 14 | +interval. In addition, any expression following the cfitsio syntax can be | |
| 15 | +used for event selection. | |
| 16 | + | |
| 17 | +Optionally, ctselect may also apply energy thresholds. If ``usethres=DEFAULT`` | |
| 18 | +is specified, ctselect will extract any save thresholds from the instrument | |
| 19 | +response functions, and if they exist, will apply them to the respective | |
| 20 | +event list. Alternatively, if ``usethres=USER`` is specified, ctselect will | |
| 21 | +extract any user thresholds from the observation definition file (attributes | |
| 22 | +``emin`` and ``emax``), and if either of the attributes exists, will apply | |
| 23 | +them to the respective event list. | |
| 24 | + | |
| 25 | +If an event list is provided on input, ctselect creates a new FITS file on | |
| 26 | +output that contains only the selected events. In case that an observation | |
| 27 | +definition file is specified on input, ctselect creates for each event file | |
| 28 | +referenced in the observation definition file a new FITS file with the value | |
| 29 | +of ``prefix`` prepended to the file name that contains only the selected | |
| 30 | +events. In addition, a new observation definition file will be written | |
| 31 | +that references the new FITS files. | |
| 32 | + | |
| 33 | +For each event file, the event selection parameters will be writted as data | |
| 34 | +selection keywords to the FITS header. These keywords are mandatory for any | |
| 35 | +unbinned maximum likelihood analysis of the event data. | |
| 14 | 36 | |
| 15 | 37 | |
| 16 | 38 | General parameters |
| ... | ... | @@ -98,7 +120,7 @@ Standard parameters |
| 98 | 120 | Name of log file. |
| 99 | 121 | |
| 100 | 122 | |
| 101 | -Related tools | |
| 102 | -------------- | |
| 123 | +Related tools or scripts | |
| 124 | +------------------------ | |
| 103 | 125 | |
| 104 | 126 | None | ... | ... |
doc/source/reference_manual/ctskymap.rst
| ... | ... | @@ -3,13 +3,18 @@ |
| 3 | 3 | ctskymap |
| 4 | 4 | ======== |
| 5 | 5 | |
| 6 | -Computes sky map from CTA data. | |
| 6 | +Generate sky map from event list(s). | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This tool generates a sky map from CTA data. | |
| 12 | +This tool creates a sky map from either a single event list or event lists | |
| 13 | +provided in an observation definition file. The tool will loop over all event | |
| 14 | +lists that are provided and fill all events into a single sky map. Only events | |
| 15 | +within an energy interval spanned by ``emin`` and ``emax`` are considered. | |
| 16 | + | |
| 17 | +ctskymap generates a FITS file comprising a sky map as primary extension. | |
| 13 | 18 | |
| 14 | 19 | |
| 15 | 20 | General parameters |
| ... | ... | @@ -19,7 +24,7 @@ General parameters |
| 19 | 24 | Input event list or observation definition XML file. |
| 20 | 25 | |
| 21 | 26 | ``outmap [file]`` |
| 22 | - Output sky map. | |
| 27 | + Output sky map file. | |
| 23 | 28 | |
| 24 | 29 | ``emin [real]`` |
| 25 | 30 | Minimum energy in map (in TeV). |
| ... | ... | @@ -80,7 +85,7 @@ Standard parameters |
| 80 | 85 | Name of log file. |
| 81 | 86 | |
| 82 | 87 | |
| 83 | -Related tools | |
| 84 | -------------- | |
| 88 | +Related tools or scripts | |
| 89 | +------------------------ | |
| 85 | 90 | |
| 86 | 91 | None | ... | ... |
doc/source/reference_manual/cttsmap.rst
| ... | ... | @@ -3,13 +3,25 @@ |
| 3 | 3 | cttsmap |
| 4 | 4 | ======= |
| 5 | 5 | |
| 6 | -Generate a Test Statistic map. | |
| 6 | +Generate a Test Statistic (TS) map. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This tool generates a Test Statistic map. | |
| 12 | +This tool generates a Test Statistic (TS) map for a specific source model. | |
| 13 | +cttsmap works for point, radial and elliptical source models. The tool | |
| 14 | +displaces the specified source on a grid of sky directions and computes for | |
| 15 | +each direction the TS value for the model. The TS value is defined as twice | |
| 16 | +the difference between the log-likelihood obtained for the full model | |
| 17 | +(including the specified source) and the log-likelihood obtained for a model | |
| 18 | +that excludes the specified source. The square-root of the TS values | |
| 19 | +corresponds roughly to the pre-trial detection signifiance of the source (in | |
| 20 | +Gaussian sigma). | |
| 21 | + | |
| 22 | +cttsmap generates a FITS file comprising a sky map of TS values followed by | |
| 23 | +one extension per free parameter that contains sky maps of the fitted | |
| 24 | +parameter values. | |
| 13 | 25 | |
| 14 | 26 | |
| 15 | 27 | General parameters |
| ... | ... | @@ -19,26 +31,25 @@ General parameters |
| 19 | 31 | Input event list, counts cube or observation definition XML file. |
| 20 | 32 | |
| 21 | 33 | ``inmodel [file]`` |
| 22 | - Input source model XML file. | |
| 34 | + Input model XML file. | |
| 23 | 35 | |
| 24 | 36 | ``srcname [string]`` |
| 25 | - Name of the source in the source model XML file for which the Test | |
| 26 | - Statistic map should be computed. | |
| 37 | + Name of source model for which the TS map should be computed. | |
| 27 | 38 | |
| 28 | 39 | ``expcube [file]`` |
| 29 | - Exposure cube file (only needed for stacked analysis). | |
| 40 | + Input exposure cube file (only needed for stacked analysis). | |
| 30 | 41 | |
| 31 | 42 | ``psfcube [file]`` |
| 32 | - PSF cube file (only needed for stacked analysis). | |
| 43 | + Input PSF cube file (only needed for stacked analysis). | |
| 33 | 44 | |
| 34 | 45 | ``bkgcube [file]`` |
| 35 | - Background cube file (only needed for stacked analysis). | |
| 46 | + Input background cube file (only needed for stacked analysis). | |
| 36 | 47 | |
| 37 | 48 | ``caldb [string]`` |
| 38 | 49 | Calibration database. |
| 39 | 50 | |
| 40 | 51 | ``irf [string]`` |
| 41 | - Response function. | |
| 52 | + Instrumental response function. | |
| 42 | 53 | |
| 43 | 54 | ``(edisp = no) [boolean]`` |
| 44 | 55 | Applies energy dispersion to response computation. |
| ... | ... | @@ -108,7 +119,8 @@ Standard parameters |
| 108 | 119 | Name of log file. |
| 109 | 120 | |
| 110 | 121 | |
| 111 | -Related tools | |
| 112 | -------------- | |
| 122 | +Related tools or scripts | |
| 123 | +------------------------ | |
| 124 | + | |
| 125 | +:ref:`cstsmapmerge` | |
| 113 | 126 | |
| 114 | -None | ... | ... |
doc/source/reference_manual/ctulimit.rst
| 1 | 1 | .. _ctulimit: |
| 2 | 2 | |
| 3 | 3 | ctulimit |
| 4 | -=========== | |
| 4 | +======== | |
| 5 | 5 | |
| 6 | -Computes upper limit for a specific sky model component. | |
| 6 | +Computes upper flux limit for a source model. | |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -Computes the upper limit flux of a given source. | |
| 12 | +This tools computes the upper flux limit for a specific source model. Except | |
| 13 | +of the node function, all spectral models are supported. Starting from the | |
| 14 | +maximum likelihood model parameters, the tool finds the model flux that leads | |
| 15 | +to a decrease of the likelihood that corresponds to a given confidence level. | |
| 16 | +By default a confidence level of 95% is used, but this level can be adjusted | |
| 17 | +using the hidden ``confidence`` parameter. | |
| 18 | + | |
| 19 | +ctulimit writes the differential upper flux limit at a given reference | |
| 20 | +energy (specified by the hidden parameter ``eref``) and the integrated | |
| 21 | +upper flux limit (specified by the hidden parameters ``emin`` and ``emax``) | |
| 22 | +into the log file. | |
| 23 | + | |
| 13 | 24 | |
| 14 | 25 | |
| 15 | 26 | General parameters |
| ... | ... | @@ -19,19 +30,19 @@ General parameters |
| 19 | 30 | Input event list, counts cube or observation definition XML file. |
| 20 | 31 | |
| 21 | 32 | ``inmodel [file]`` |
| 22 | - Model XML file containing the source and background definitions. | |
| 33 | + Input model XML file. | |
| 23 | 34 | |
| 24 | 35 | ``srcname [string]`` |
| 25 | - Name of model component for which upper limit should be computed. | |
| 36 | + Name of source model for which the upper flux limit should be computed. | |
| 26 | 37 | |
| 27 | 38 | ``expcube [file]`` |
| 28 | - Exposure cube file (only needed for stacked analysis). | |
| 39 | + Input exposure cube file (only needed for stacked analysis). | |
| 29 | 40 | |
| 30 | 41 | ``psfcube [file]`` |
| 31 | - PSF cube file (only needed for stacked analysis). | |
| 42 | + Input PSF cube file (only needed for stacked analysis). | |
| 32 | 43 | |
| 33 | 44 | ``bkgcube [file]`` |
| 34 | - Background cube file (only needed for stacked analysis). | |
| 45 | + Input background cube file (only needed for stacked analysis). | |
| 35 | 46 | |
| 36 | 47 | ``caldb [string]`` |
| 37 | 48 | Calibration database. |
| ... | ... | @@ -53,11 +64,14 @@ General parameters |
| 53 | 64 | Maximum boundary to start searching for upper limit value. |
| 54 | 65 | Number of standard deviations above best fit value |
| 55 | 66 | |
| 67 | +``(eref = 1.0) [real])`` | |
| 68 | + Reference energy for differential limit (in TeV). | |
| 69 | + | |
| 56 | 70 | ``(emin = 1.0) [real])`` |
| 57 | - Minimum energy of flux limits (in TeV). | |
| 71 | + Minimum energy for integral flux limit (in TeV). | |
| 58 | 72 | |
| 59 | 73 | ``(emax = 100) [real]`` |
| 60 | - Maximum energy of flux limits (in TeV). | |
| 74 | + Maximum energy for integral flux limit (in TeV). | |
| 61 | 75 | |
| 62 | 76 | ``(tol = 1e-5) [real]`` |
| 63 | 77 | Computation tolerance. |
| ... | ... | @@ -98,4 +112,6 @@ Standard parameters |
| 98 | 112 | Related tools |
| 99 | 113 | ------------- |
| 100 | 114 | |
| 101 | -:ref:`cterror` | |
| 102 | 115 | \ No newline at end of file |
| 116 | +:ref:`ctlike` | |
| 117 | +:ref:`cterror` | |
| 118 | +:ref:`ctbutterfly` | ... | ... |
doc/source/reference_manual/index.rst
| ... | ... | @@ -45,3 +45,8 @@ cscripts |
| 45 | 45 | csspec --- Computes spectral points <csspec> |
| 46 | 46 | csresmap --- Generates residual map <csresmap> |
| 47 | 47 | cstsdist --- Generates TS distribution <cstsdist> |
| 48 | + csobsinfo --- Shows observation container content <csobsinfo> | |
| 49 | + csmodelinfo --- Shows model container content <csmodelinfo> | |
| 50 | + csmodelmerge --- Merges several model containers into one file <csmodelmerge> | |
| 51 | + cstsmapmerge --- Merges slices from ts map computations <cstsmapmerge> | |
| 52 | + csobs2caldb --- Creates a caldb entry from an input observation <csobs2caldb> | ... | ... |
doc/source/user_manual/enhancing.rst deleted
| 1 | -Enhancing ctools | |
| 2 | -================ | |
| 3 | - | |
| 4 | -Most ctools users will run the existing ctools or cscripts, | |
| 5 | -which cover the most common simulation and analysis needs. | |
| 6 | - | |
| 7 | -Advanced users and developers can write their own tools and scripts. | |
| 8 | -The following C++ and Python examples can help get you started: | |
| 9 | - | |
| 10 | -* :doxy:`ctlike` | |
| 11 | -* :doxy:`obsutils` | |
| 12 | -* :doxy:`cstsdist` | |
| 13 | - | |
| 14 | -Building your own cscripts | |
| 15 | --------------------------- | |
| 16 | - | |
| 17 | -To be written ... | |
| 18 | - | |
| 19 | - | |
| 20 | -Building your own ctools | |
| 21 | ------------------------- | |
| 22 | - | |
| 23 | -To be written ... |
doc/source/user_manual/expert.rst deleted
| 1 | -Behind the scenes | |
| 2 | -================= | |
| 3 | - | |
| 4 | -CTA data structure | |
| 5 | ------------------- | |
| 6 | - | |
| 7 | -To be written ... | |
| 8 | - | |
| 9 | - | |
| 10 | -Instrument response functions | |
| 11 | ------------------------------ | |
| 12 | - | |
| 13 | -To be written ... | |
| 14 | - | |
| 15 | - | |
| 16 | -Maximum likelihood fitting | |
| 17 | --------------------------- | |
| 18 | - | |
| 19 | -To be written ... |
doc/source/user_manual/getting.rst
| ... | ... | @@ -29,15 +29,15 @@ No system administrator privileges are needed to install ctools. |
| 29 | 29 | |
| 30 | 30 | .. _sec_installing_gammalib: |
| 31 | 31 | |
| 32 | -Installing gammalib | |
| 32 | +Installing GammaLib | |
| 33 | 33 | ------------------- |
| 34 | 34 | |
| 35 | -ctools is built on top of gammalib, hence gammalib needs to be built, | |
| 35 | +ctools is built on top of GammaLib, hence GammaLib needs to be built, | |
| 36 | 36 | installed and configured before ctools can be installed. In case that |
| 37 | 37 | ctools is already installed on your system you may skip reading this |
| 38 | 38 | section and continue with the :ref:`sec_building_ctools` section. |
| 39 | 39 | |
| 40 | -You will need the following to build the gammalib: | |
| 40 | +You will need the following to build the GammaLib: | |
| 41 | 41 | |
| 42 | 42 | - About 200 MB of free disk space. |
| 43 | 43 | |
| ... | ... | @@ -58,12 +58,12 @@ You will need the following to build the gammalib: |
| 58 | 58 | Furthermore it is recommended to have readline and ncurses installed |
| 59 | 59 | (including the developer packages). |
| 60 | 60 | |
| 61 | -After downloading the gammalib tarball (see :ref:`download`), save it | |
| 61 | +After downloading the GammaLib tarball (see :ref:`download`), save it | |
| 62 | 62 | in an appropriate location (for example ``$HOME/builds``), and type |
| 63 | 63 | |
| 64 | 64 | .. code-block:: bash |
| 65 | 65 | |
| 66 | - $ tar xvfz gammalib-0.11.0.tar.gz | |
| 66 | + $ tar xvfz gammalib-1.0.0.tar.gz | |
| 67 | 67 | |
| 68 | 68 | (the ``$`` symbol indicates the console prompt and is not part of the |
| 69 | 69 | command that you should type in). |
| ... | ... | @@ -73,7 +73,7 @@ typing |
| 73 | 73 | |
| 74 | 74 | .. code-block:: bash |
| 75 | 75 | |
| 76 | - $ cd gammalib-0.11.0 | |
| 76 | + $ cd gammalib-1.0.0 | |
| 77 | 77 | $ ./configure |
| 78 | 78 | $ make |
| 79 | 79 | $ make check |
| ... | ... | @@ -82,6 +82,8 @@ typing |
| 82 | 82 | The last step may require system administator privileges. In this case, |
| 83 | 83 | use |
| 84 | 84 | |
| 85 | +.. code-block:: bash | |
| 86 | + | |
| 85 | 87 | $ sudo make install |
| 86 | 88 | |
| 87 | 89 | If you do not have system administrator privileges, change the install |
| ... | ... | @@ -133,7 +135,7 @@ an appropriate location (for example ``$HOME/builds``), and type |
| 133 | 135 | |
| 134 | 136 | .. code-block:: bash |
| 135 | 137 | |
| 136 | - $ tar xvfz ctools-0.10.0.tar.gz | |
| 138 | + $ tar xvfz ctools-1.0.0.tar.gz | |
| 137 | 139 | |
| 138 | 140 | (the ``$`` symbol indicates the console prompt and is not part of the |
| 139 | 141 | command that you should type in). |
| ... | ... | @@ -142,7 +144,7 @@ Step in the directory and build the ctools by typing |
| 142 | 144 | |
| 143 | 145 | .. code-block:: bash |
| 144 | 146 | |
| 145 | - $ cd ctools-0.10.0 | |
| 147 | + $ cd ctools-1.0.0 | |
| 146 | 148 | $ ./configure |
| 147 | 149 | $ make |
| 148 | 150 | |
| ... | ... | @@ -181,7 +183,7 @@ following output at the end of the unit testing: |
| 181 | 183 | PASS: test_python.py |
| 182 | 184 | make[4]: Nothing to be done for `all'. |
| 183 | 185 | ============================================================================ |
| 184 | - Testsuite summary for ctools 0.10.0 | |
| 186 | + Testsuite summary for ctools 1.0.0 | |
| 185 | 187 | ============================================================================ |
| 186 | 188 | # TOTAL: 3 |
| 187 | 189 | # PASS: 3 |
| ... | ... | @@ -219,6 +221,18 @@ For older automake version, you should see |
| 219 | 221 | * Test cscripts * |
| 220 | 222 | ***************** |
| 221 | 223 | Test csobsdef: .. ok |
| 224 | + Test csobs2caldb: .. ok | |
| 225 | + Test csobsinfo: .. ok | |
| 226 | + Test csiactobs: .. ok | |
| 227 | + Test csmodelinfo: .. ok | |
| 228 | + Test csmodelmerge (space-separated): .. ok | |
| 229 | + Test csmodelmerge (comma-separated): .. ok | |
| 230 | + Test csmodelmerge (wildcard string): .. ok | |
| 231 | + Test csmodelmerge (ascii-file): .. ok | |
| 232 | + Test cstsmapmerge (comma-separated): .. ok | |
| 233 | + Test cstsmapmerge (space-separated): .. ok | |
| 234 | + Test cstsmapmerge (wildcard string): .. ok | |
| 235 | + Test cstsmapmerge (ascii-file): .. ok | |
| 222 | 236 | Test cspull: .. ok |
| 223 | 237 | Test cssens: .. ok |
| 224 | 238 | Test cstsdist: .. ok |
| ... | ... | @@ -345,19 +359,8 @@ As a quick check that your setup is okay you can run ``csinfo check``: |
| 345 | 359 | ===> Your Gammalib / ctools setup is OK. |
| 346 | 360 | |
| 347 | 361 | If the setup is not okay, run the ``csinfo info`` command to print |
| 348 | -detailed information about your setup. | |
| 349 | -There's also a ``csinfo list`` command to quickly list the available tools: | |
| 350 | - | |
| 351 | -.. code-block:: bash | |
| 352 | - | |
| 353 | - $ csinfo | |
| 354 | - | |
| 355 | - Print info about Gammalib and ctools to the console. | |
| 356 | - | |
| 357 | - Available commands: | |
| 358 | - csinfo list List available ctools and cscripts | |
| 359 | - csinfo check Check Gammalib / ctools setup | |
| 360 | - csinfo info Print Gammalib / ctools setup info | |
| 362 | +detailed information about your setup. There's also a ``csinfo list`` | |
| 363 | +command to quickly list the available tools. | |
| 361 | 364 | |
| 362 | 365 | |
| 363 | 366 | .. _sec_known_problems: | ... | ... |
doc/source/user_manual/getting_started/beyond.rst
| ... | ... | @@ -3,12 +3,12 @@ |
| 3 | 3 | Beyond the first steps |
| 4 | 4 | ---------------------- |
| 5 | 5 | |
| 6 | -Assuming that you have read the :ref:`quickstart <quickstart>` tutorial, | |
| 7 | -here now some chapters to read if you intend to do more complex | |
| 8 | -analyses. | |
| 9 | -Once you have gone through these chapters you should have a pretty complete | |
| 6 | +Now that you are familiar with the ctools basics, here are some sections | |
| 7 | +to read if you intend to do more complex analyses. | |
| 8 | +Once you have gone through these sections you should have a pretty complete | |
| 10 | 9 | picture about the capabilities of ctools. |
| 11 | -And you should be ready for doing your own cutting edge analyses. | |
| 10 | +And you should be ready for doing your own cutting edge CTA science data | |
| 11 | +analyses. | |
| 12 | 12 | |
| 13 | 13 | .. toctree:: |
| 14 | 14 | :maxdepth: 2 |
| ... | ... | @@ -19,11 +19,3 @@ And you should be ready for doing your own cutting edge analyses. |
| 19 | 19 | beyond_residual |
| 20 | 20 | beyond_irf |
| 21 | 21 | beyond_model |
| 22 | - | |
| 23 | - | |
| 24 | - | |
| 25 | - | |
| 26 | - | |
| 27 | - | |
| 28 | - | |
| 29 | - | ... | ... |
doc/source/user_manual/getting_started/beyond_combine.rst
| ... | ... | @@ -25,9 +25,9 @@ nebula, each offset by 0.5 deg from the nebula in opposite directions: |
| 25 | 25 | Lower energy limit (TeV) [0.1] |
| 26 | 26 | Upper energy limit (TeV) [100.0] |
| 27 | 27 | Calibration database [prod2] |
| 28 | - Instrument response function [South_50h] | |
| 29 | - Model [$CTOOLS/share/models/crab.xml] | |
| 30 | - Output event data file or observation definition file [events.fits] events1.fits | |
| 28 | + Instrument response function [South_0.5h] | |
| 29 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 30 | + Output event data file or observation definition XML file [events.fits] events1.fits | |
| 31 | 31 | |
| 32 | 32 | .. code-block:: bash |
| 33 | 33 | |
| ... | ... | @@ -40,16 +40,16 @@ nebula, each offset by 0.5 deg from the nebula in opposite directions: |
| 40 | 40 | Lower energy limit (TeV) [0.1] |
| 41 | 41 | Upper energy limit (TeV) [100.0] |
| 42 | 42 | Calibration database [prod2] |
| 43 | - Instrument response function [South_50h] | |
| 44 | - Model [$CTOOLS/share/models/crab.xml] | |
| 45 | - Output event data file or observation definition file [events1.fits] events2.fits | |
| 43 | + Instrument response function [South_0.5h] | |
| 44 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 45 | + Output event data file or observation definition XML file [events1.fits] events2.fits | |
| 46 | 46 | |
| 47 | 47 | This will produce the two event files ``events1.fits`` and ``events2.fits`` |
| 48 | 48 | on disk. |
| 49 | 49 | |
| 50 | -As next step we have to create an **observation definition XML file** that | |
| 50 | +As next step you have to create an **observation definition XML file** that | |
| 51 | 51 | collects both observations in a list. |
| 52 | -Here is how such a file would look like: | |
| 52 | +Here is how that file looks like: | |
| 53 | 53 | |
| 54 | 54 | .. code-block:: xml |
| 55 | 55 | |
| ... | ... | @@ -86,116 +86,140 @@ ctools knows which instrument specific functions need to be called.** |
| 86 | 86 | Imaging Air Cherenkov Telescope in a joint analysis. |
| 87 | 87 | **Please recall that instrument strings are case sensitive.** |
| 88 | 88 | |
| 89 | -Now we are ready to do a joint maximum likelihood analysis using | |
| 90 | -:ref:`ctlike`: | |
| 89 | +Now you are ready to do a joint maximum likelihood analysis using | |
| 90 | +:ref:`ctlike`. Type: | |
| 91 | 91 | |
| 92 | 92 | .. code-block:: bash |
| 93 | 93 | |
| 94 | - $ ctlike | |
| 95 | - Event list, counts cube or observation definition file [selected_events.fits] obs.xml | |
| 94 | + $ ctlike chatter=3 | |
| 95 | + Input event list, counts cube or observation definition XML file [events.fits] obs.xml | |
| 96 | 96 | Calibration database [prod2] |
| 97 | - Instrument response function [South_50h] | |
| 98 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 99 | - Source model output file [crab_results.xml] | |
| 97 | + Instrument response function [South_0.5h] | |
| 98 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 99 | + Output model XML file [crab_results.xml] | |
| 100 | 100 | |
| 101 | -Instead of providing an event list or a counts cube, we now provided the | |
| 101 | +Instead of providing an event list or a counts cube, you now provided the | |
| 102 | 102 | filename of the observation definition XML file (here ``obs.xml``) as input |
| 103 | -parameter. | |
| 104 | -:ref:`ctlike` recognises this format and automatically performs a | |
| 105 | -joint analysis, as indicated in the log file: | |
| 103 | +parameter. :ref:`ctlike` recognises this format and automatically performs a | |
| 104 | +joint analysis. To see the result of this you needed to specify the | |
| 105 | +``chatter=3`` parameter so that the chattiness is increased in the log | |
| 106 | +file: | |
| 106 | 107 | |
| 107 | 108 | .. code-block:: xml |
| 108 | 109 | |
| 109 | - 2015-05-22T20:17:07: +==============+ | |
| 110 | - 2015-05-22T20:17:07: | Observations | | |
| 111 | - 2015-05-22T20:17:07: +==============+ | |
| 112 | - 2015-05-22T20:17:07: === GObservations === | |
| 113 | - 2015-05-22T20:17:07: Number of observations ....: 2 | |
| 114 | - 2015-05-22T20:17:07: Number of predicted events : 0 | |
| 115 | - 2015-05-22T20:17:07: === GCTAObservation === | |
| 116 | - 2015-05-22T20:17:07: Name ......................: | |
| 117 | - 2015-05-22T20:17:07: Identifier ................: 00001 | |
| 118 | - 2015-05-22T20:17:07: Instrument ................: CTA | |
| 119 | - 2015-05-22T20:17:07: Event file ................: events1.fits | |
| 120 | - 2015-05-22T20:17:07: Event type ................: EventList | |
| 121 | - 2015-05-22T20:17:07: Statistics ................: Poisson | |
| 122 | - 2015-05-22T20:17:07: Ontime ....................: 1800 s | |
| 123 | - 2015-05-22T20:17:07: Livetime ..................: 1710 s | |
| 124 | - 2015-05-22T20:17:07: Deadtime correction .......: 0.95 | |
| 125 | - 2015-05-22T20:17:07: User energy range .........: undefined | |
| 126 | - 2015-05-22T20:17:07: === GCTAPointing === | |
| 127 | - 2015-05-22T20:17:07: Pointing direction ........: (RA,Dec)=(83.63,21.51) | |
| 110 | + 2015-12-07T21:23:07: +==============+ | |
| 111 | + 2015-12-07T21:23:07: | Observations | | |
| 112 | + 2015-12-07T21:23:07: +==============+ | |
| 113 | + 2015-12-07T21:23:07: === GObservations === | |
| 114 | + 2015-12-07T21:23:07: Number of observations ....: 2 | |
| 115 | + 2015-12-07T21:23:07: Number of models ..........: 2 | |
| 116 | + 2015-12-07T21:23:07: Number of predicted events : 0 | |
| 117 | + 2015-12-07T21:23:07: === GCTAObservation === | |
| 118 | + 2015-12-07T21:23:07: Name ......................: Crab | |
| 119 | + 2015-12-07T21:23:07: Identifier ................: 00001 | |
| 120 | + 2015-12-07T21:23:07: Instrument ................: CTA | |
| 121 | + 2015-12-07T21:23:07: Event file ................: events1.fits | |
| 122 | + 2015-12-07T21:23:07: Event type ................: EventList | |
| 123 | + 2015-12-07T21:23:07: Statistics ................: Poisson | |
| 124 | + 2015-12-07T21:23:07: Ontime ....................: 1800 s | |
| 125 | + 2015-12-07T21:23:07: Livetime ..................: 1710 s | |
| 126 | + 2015-12-07T21:23:07: Deadtime correction .......: 0.95 | |
| 127 | + 2015-12-07T21:23:07: User energy range .........: undefined | |
| 128 | + 2015-12-07T21:23:07: === GCTAPointing === | |
| 129 | + 2015-12-07T21:23:07: Pointing direction ........: (RA,Dec)=(83.63,21.51) | |
| 130 | + 2015-12-07T21:23:07: === GCTAResponseIrf === | |
| 131 | + 2015-12-07T21:23:07: Caldb mission .............: cta | |
| 132 | + 2015-12-07T21:23:07: Caldb instrument ..........: prod2 | |
| 133 | + 2015-12-07T21:23:07: Response name .............: South_0.5h | |
| 134 | + 2015-12-07T21:23:07: Energy dispersion .........: Not used | |
| 135 | + 2015-12-07T21:23:07: Save energy range .........: undefined | |
| 136 | + 2015-12-07T21:23:07: === GCTAEventList === | |
| 137 | + 2015-12-07T21:23:07: Number of events ..........: 22593 | |
| 138 | + 2015-12-07T21:23:07: Time interval .............: 51544.5 - 51544.5 days | |
| 139 | + 2015-12-07T21:23:07: Energy interval ...........: 0.1 - 100 TeV | |
| 140 | + 2015-12-07T21:23:07: Region of interest ........: RA=83.63, DEC=21.51 [0,0] Radius=5 deg | |
| 141 | + 2015-12-07T21:23:07: === GCTAObservation === | |
| 142 | + 2015-12-07T21:23:07: Name ......................: Crab | |
| 143 | + 2015-12-07T21:23:07: Identifier ................: 00002 | |
| 144 | + 2015-12-07T21:23:07: Instrument ................: CTA | |
| 145 | + 2015-12-07T21:23:07: Event file ................: events2.fits | |
| 146 | + 2015-12-07T21:23:07: Event type ................: EventList | |
| 147 | + 2015-12-07T21:23:07: Statistics ................: Poisson | |
| 148 | + 2015-12-07T21:23:07: Ontime ....................: 1800 s | |
| 149 | + 2015-12-07T21:23:07: Livetime ..................: 1710 s | |
| 150 | + 2015-12-07T21:23:07: Deadtime correction .......: 0.95 | |
| 151 | + 2015-12-07T21:23:07: User energy range .........: undefined | |
| 152 | + 2015-12-07T21:23:07: === GCTAPointing === | |
| 153 | + 2015-12-07T21:23:07: Pointing direction ........: (RA,Dec)=(83.63,22.51) | |
| 154 | + 2015-12-07T21:23:07: === GCTAResponseIrf === | |
| 155 | + 2015-12-07T21:23:07: Caldb mission .............: cta | |
| 156 | + 2015-12-07T21:23:07: Caldb instrument ..........: prod2 | |
| 157 | + 2015-12-07T21:23:07: Response name .............: South_0.5h | |
| 158 | + 2015-12-07T21:23:07: Energy dispersion .........: Not used | |
| 159 | + 2015-12-07T21:23:07: Save energy range .........: undefined | |
| 160 | + 2015-12-07T21:23:07: === GCTAEventList === | |
| 161 | + 2015-12-07T21:23:07: Number of events ..........: 22529 | |
| 162 | + 2015-12-07T21:23:07: Time interval .............: 51544.5 - 51544.5 days | |
| 163 | + 2015-12-07T21:23:07: Energy interval ...........: 0.1 - 100 TeV | |
| 164 | + 2015-12-07T21:23:07: Region of interest ........: RA=83.63, DEC=22.51 [0,0] Radius=5 deg | |
| 128 | 165 | ... |
| 129 | - 2015-05-22T20:17:07: === GCTAObservation === | |
| 130 | - 2015-05-22T20:17:07: Name ......................: | |
| 131 | - 2015-05-22T20:17:07: Identifier ................: 00002 | |
| 132 | - 2015-05-22T20:17:07: Instrument ................: CTA | |
| 133 | - 2015-05-22T20:17:07: Event file ................: events2.fits | |
| 134 | - 2015-05-22T20:17:07: Event type ................: EventList | |
| 135 | - 2015-05-22T20:17:07: Statistics ................: Poisson | |
| 136 | - 2015-05-22T20:17:07: Ontime ....................: 1800 s | |
| 137 | - 2015-05-22T20:17:07: Livetime ..................: 1710 s | |
| 138 | - 2015-05-22T20:17:07: Deadtime correction .......: 0.95 | |
| 139 | - 2015-05-22T20:17:07: User energy range .........: undefined | |
| 140 | - 2015-05-22T20:17:07: === GCTAPointing === | |
| 141 | - 2015-05-22T20:17:07: Pointing direction ........: (RA,Dec)=(83.63,22.51) | |
| 166 | + 2015-12-07T21:23:07: +=================================+ | |
| 167 | + 2015-12-07T21:23:07: | Maximum likelihood optimisation | | |
| 168 | + 2015-12-07T21:23:07: +=================================+ | |
| 169 | + 2015-12-07T21:23:07: >Iteration 0: -logL=304176.886, Lambda=1.0e-03 | |
| 170 | + 2015-12-07T21:23:08: >Iteration 1: -logL=304161.799, Lambda=1.0e-03, delta=15.088, max(|grad|)=12.922804 [Index:3] | |
| 171 | + 2015-12-07T21:23:08: >Iteration 2: -logL=304161.783, Lambda=1.0e-04, delta=0.015, max(|grad|)=0.098155 [Index:3] | |
| 172 | + 2015-12-07T21:23:08: >Iteration 3: -logL=304161.783, Lambda=1.0e-05, delta=0.000, max(|grad|)=0.000598 [Index:3] | |
| 142 | 173 | ... |
| 143 | - 2015-05-22T20:17:07: +=================================+ | |
| 144 | - 2015-05-22T20:17:07: | Maximum likelihood optimisation | | |
| 145 | - 2015-05-22T20:17:07: +=================================+ | |
| 146 | - 2015-05-22T20:17:07: >Iteration 0: -logL=201836.657, Lambda=1.0e-03 | |
| 147 | - 2015-05-22T20:17:07: >Iteration 1: -logL=201829.438, Lambda=1.0e-03, delta=7.220, max(|grad|)=22.756507 [Index:7] | |
| 148 | - 2015-05-22T20:17:07: >Iteration 2: -logL=201829.432, Lambda=1.0e-04, delta=0.005, max(|grad|)=0.086395 [Index:3] | |
| 149 | - 2015-05-22T20:17:07: >Iteration 3: -logL=201829.432, Lambda=1.0e-05, delta=0.000, max(|grad|)=0.001287 [Index:3] | |
| 150 | - 2015-05-22T20:17:07: | |
| 151 | - 2015-05-22T20:17:07: +=========================================+ | |
| 152 | - 2015-05-22T20:17:07: | Maximum likelihood optimization results | | |
| 153 | - 2015-05-22T20:17:07: +=========================================+ | |
| 154 | - 2015-05-22T20:17:07: === GOptimizerLM === | |
| 155 | - 2015-05-22T20:17:07: Optimized function value ..: 201829.432 | |
| 156 | - 2015-05-22T20:17:07: Absolute precision ........: 0.005 | |
| 157 | - 2015-05-22T20:17:07: Acceptable value decrease .: 2 | |
| 158 | - 2015-05-22T20:17:07: Optimization status .......: converged | |
| 159 | - 2015-05-22T20:17:07: Number of parameters ......: 10 | |
| 160 | - 2015-05-22T20:17:07: Number of free parameters .: 4 | |
| 161 | - 2015-05-22T20:17:07: Number of iterations ......: 3 | |
| 162 | - 2015-05-22T20:17:07: Lambda ....................: 1e-06 | |
| 163 | - 2015-05-22T20:17:07: Maximum log likelihood ....: -201829.432 | |
| 164 | - 2015-05-22T20:17:07: Observed events (Nobs) ...: 31799.000 | |
| 165 | - 2015-05-22T20:17:07: Predicted events (Npred) ..: 31799.000 (Nobs - Npred = 2.67544e-06) | |
| 166 | - 2015-05-22T20:17:07: === GModels === | |
| 167 | - 2015-05-22T20:17:07: Number of models ..........: 2 | |
| 168 | - 2015-05-22T20:17:07: Number of parameters ......: 10 | |
| 169 | - 2015-05-22T20:17:07: === GModelSky === | |
| 170 | - 2015-05-22T20:17:07: Name ......................: Crab | |
| 171 | - 2015-05-22T20:17:07: Instruments ...............: all | |
| 172 | - 2015-05-22T20:17:07: Instrument scale factors ..: unity | |
| 173 | - 2015-05-22T20:17:07: Observation identifiers ...: all | |
| 174 | - 2015-05-22T20:17:07: Model type ................: PointSource | |
| 175 | - 2015-05-22T20:17:07: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 176 | - 2015-05-22T20:17:07: Number of parameters ......: 6 | |
| 177 | - 2015-05-22T20:17:07: Number of spatial par's ...: 2 | |
| 178 | - 2015-05-22T20:17:07: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 179 | - 2015-05-22T20:17:07: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 180 | - 2015-05-22T20:17:07: Number of spectral par's ..: 3 | |
| 181 | - 2015-05-22T20:17:07: Prefactor ................: 5.8727e-16 +/- 8.04314e-18 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 182 | - 2015-05-22T20:17:07: Index ....................: -2.49825 +/- 0.0118418 [-0,-5] (free,scale=-1,gradient) | |
| 183 | - 2015-05-22T20:17:07: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 184 | - 2015-05-22T20:17:07: Number of temporal par's ..: 1 | |
| 185 | - 2015-05-22T20:17:07: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 186 | - 2015-05-22T20:17:07: === GCTAModelIrfBackground === | |
| 187 | - 2015-05-22T20:17:07: Name ......................: CTABackgroundModel | |
| 188 | - 2015-05-22T20:17:07: Instruments ...............: CTA | |
| 189 | - 2015-05-22T20:17:07: Instrument scale factors ..: unity | |
| 190 | - 2015-05-22T20:17:07: Observation identifiers ...: all | |
| 191 | - 2015-05-22T20:17:07: Model type ................: "PowerLaw" * "Constant" | |
| 192 | - 2015-05-22T20:17:07: Number of parameters ......: 4 | |
| 193 | - 2015-05-22T20:17:07: Number of spectral par's ..: 3 | |
| 194 | - 2015-05-22T20:17:07: Prefactor ................: 1.01608 +/- 0.0152751 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 195 | - 2015-05-22T20:17:07: Index ....................: 0.0226023 +/- 0.0086794 [-5,5] (free,scale=1,gradient) | |
| 196 | - 2015-05-22T20:17:07: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 197 | - 2015-05-22T20:17:07: Number of temporal par's ..: 1 | |
| 198 | - 2015-05-22T20:17:07: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 174 | + | |
| 175 | + 2015-12-07T21:23:08: +=========================================+ | |
| 176 | + 2015-12-07T21:23:08: | Maximum likelihood optimisation results | | |
| 177 | + 2015-12-07T21:23:08: +=========================================+ | |
| 178 | + 2015-12-07T21:23:08: === GOptimizerLM === | |
| 179 | + 2015-12-07T21:23:08: Optimized function value ..: 304161.783 | |
| 180 | + 2015-12-07T21:23:08: Absolute precision ........: 0.005 | |
| 181 | + 2015-12-07T21:23:08: Acceptable value decrease .: 2 | |
| 182 | + 2015-12-07T21:23:08: Optimization status .......: converged | |
| 183 | + 2015-12-07T21:23:08: Number of parameters ......: 10 | |
| 184 | + 2015-12-07T21:23:08: Number of free parameters .: 4 | |
| 185 | + 2015-12-07T21:23:08: Number of iterations ......: 3 | |
| 186 | + 2015-12-07T21:23:08: Lambda ....................: 1e-06 | |
| 187 | + 2015-12-07T21:23:08: Maximum log likelihood ....: -304161.783 | |
| 188 | + 2015-12-07T21:23:08: Observed events (Nobs) ...: 45122.000 | |
| 189 | + 2015-12-07T21:23:08: Predicted events (Npred) ..: 45122.000 (Nobs - Npred = 1.04131e-06) | |
| 190 | + 2015-12-07T21:23:08: === GModels === | |
| 191 | + 2015-12-07T21:23:08: Number of models ..........: 2 | |
| 192 | + 2015-12-07T21:23:08: Number of parameters ......: 10 | |
| 193 | + 2015-12-07T21:23:08: === GModelSky === | |
| 194 | + 2015-12-07T21:23:08: Name ......................: Crab | |
| 195 | + 2015-12-07T21:23:08: Instruments ...............: all | |
| 196 | + 2015-12-07T21:23:08: Instrument scale factors ..: unity | |
| 197 | + 2015-12-07T21:23:08: Observation identifiers ...: all | |
| 198 | + 2015-12-07T21:23:08: Model type ................: PointSource | |
| 199 | + 2015-12-07T21:23:08: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 200 | + 2015-12-07T21:23:08: Number of parameters ......: 6 | |
| 201 | + 2015-12-07T21:23:08: Number of spatial par's ...: 2 | |
| 202 | + 2015-12-07T21:23:08: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 203 | + 2015-12-07T21:23:08: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 204 | + 2015-12-07T21:23:08: Number of spectral par's ..: 3 | |
| 205 | + 2015-12-07T21:23:08: Prefactor ................: 5.78382e-16 +/- 7.27218e-18 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 206 | + 2015-12-07T21:23:08: Index ....................: -2.5314 +/- 0.0112546 [-0,-5] (free,scale=-1,gradient) | |
| 207 | + 2015-12-07T21:23:08: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 208 | + 2015-12-07T21:23:08: Number of temporal par's ..: 1 | |
| 209 | + 2015-12-07T21:23:08: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 210 | + 2015-12-07T21:23:08: === GCTAModelIrfBackground === | |
| 211 | + 2015-12-07T21:23:08: Name ......................: CTABackgroundModel | |
| 212 | + 2015-12-07T21:23:08: Instruments ...............: CTA | |
| 213 | + 2015-12-07T21:23:08: Instrument scale factors ..: unity | |
| 214 | + 2015-12-07T21:23:08: Observation identifiers ...: all | |
| 215 | + 2015-12-07T21:23:08: Model type ................: "PowerLaw" * "Constant" | |
| 216 | + 2015-12-07T21:23:08: Number of parameters ......: 4 | |
| 217 | + 2015-12-07T21:23:08: Number of spectral par's ..: 3 | |
| 218 | + 2015-12-07T21:23:08: Prefactor ................: 1.0008 +/- 0.00839192 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 219 | + 2015-12-07T21:23:08: Index ....................: 0.0102998 +/- 0.0051965 [-5,5] (free,scale=1,gradient) | |
| 220 | + 2015-12-07T21:23:08: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 221 | + 2015-12-07T21:23:08: Number of temporal par's ..: 1 | |
| 222 | + 2015-12-07T21:23:08: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 199 | 223 | |
| 200 | 224 | The log file indicates that the fit converged quickly, the spectral |
| 201 | 225 | parameters of the Crab nebula have now been constrained using the events | ... | ... |
doc/source/user_manual/getting_started/beyond_irf.rst
| ... | ... | @@ -6,9 +6,9 @@ Connecting observations to dedicated instrument response functions |
| 6 | 6 | So far the same instrument response function has been used for all |
| 7 | 7 | observations in our analysis examples. |
| 8 | 8 | You may have recognised that we always specified the calibration database |
| 9 | -``prod2`` and the instrument response function ``South_50h`` that | |
| 9 | +``prod2`` and the instrument response function ``South_0.5h`` that | |
| 10 | 10 | are shipped with ctools. |
| 11 | -When combining multiple observations in a joint analysis we may however | |
| 11 | +When combining multiple observations in a joint analysis you may however | |
| 12 | 12 | need to specify dedicated instrument response functions for the |
| 13 | 13 | different observations. |
| 14 | 14 | |
| ... | ... | @@ -26,40 +26,40 @@ the northern array and the other with the southern array: |
| 26 | 26 | Lower energy limit (TeV) [0.1] |
| 27 | 27 | Upper energy limit (TeV) [100.0] |
| 28 | 28 | Calibration database [prod2] |
| 29 | - Instrument response function [South_50h] North_50h | |
| 30 | - Model [$CTOOLS/share/models/crab.xml] | |
| 31 | - Output event data file or observation definition file [events.fits] events1.fits | |
| 29 | + Instrument response function [South_0.5h] North_0.5h | |
| 30 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 31 | + Output event data file or observation definition XML file [events.fits] north.fits | |
| 32 | 32 | |
| 33 | 33 | .. code-block:: bash |
| 34 | 34 | |
| 35 | 35 | $ ctobssim |
| 36 | 36 | RA of pointing (degrees) (0-360) [83.63] |
| 37 | - Dec of pointing (degrees) (-90-90) [22.01] 22.51 | |
| 37 | + Dec of pointing (degrees) (-90-90) [21.51] 22.51 | |
| 38 | 38 | Radius of FOV (degrees) (0-180) [5.0] |
| 39 | 39 | Start time (MET in s) [0.0] |
| 40 | 40 | End time (MET in s) [1800.0] |
| 41 | 41 | Lower energy limit (TeV) [0.1] |
| 42 | 42 | Upper energy limit (TeV) [100.0] |
| 43 | 43 | Calibration database [prod2] |
| 44 | - Instrument response function [North_50h] South_50h | |
| 45 | - Model [$CTOOLS/share/models/crab.xml] | |
| 46 | - Output event data file or observation definition file [events1.fits] events2.fits | |
| 44 | + Instrument response function [North_0.5h] South_0.5h | |
| 45 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 46 | + Output event data file or observation definition XML file [north.fits] south.fits | |
| 47 | 47 | |
| 48 | -Now we combine the information about these two observations in an | |
| 48 | +You now need to combine the information about these two observations in an | |
| 49 | 49 | observation definition XML file: |
| 50 | 50 | |
| 51 | 51 | .. code-block:: xml |
| 52 | 52 | |
| 53 | - <?xml version="1.0" standalone="no"?> | |
| 54 | - <observation_list title="observation library"> | |
| 55 | - <observation name="Crab" id="00001" instrument="CTA"> | |
| 56 | - <parameter name="EventList" file="events1.fits"/> | |
| 57 | - <parameter name="Calibration" database="prod2" response="North_50h"/> | |
| 58 | - </observation> | |
| 59 | - <observation name="Crab" id="00002" instrument="CTA"> | |
| 60 | - <parameter name="EventList" file="events2.fits"/> | |
| 61 | - <parameter name="Calibration" database="prod2" response="South_50h"/> | |
| 62 | - </observation> | |
| 53 | + <?xml version="1.0" standalone="no"?> | |
| 54 | + <observation_list title="observation library"> | |
| 55 | + <observation name="Crab" id="00001" instrument="CTA"> | |
| 56 | + <parameter name="EventList" file="north.fits"/> | |
| 57 | + <parameter name="Calibration" database="prod2" response="North_0.5h"/> | |
| 58 | + </observation> | |
| 59 | + <observation name="Crab" id="00002" instrument="CTA"> | |
| 60 | + <parameter name="EventList" file="south.fits"/> | |
| 61 | + <parameter name="Calibration" database="prod2" response="South_0.5h"/> | |
| 62 | + </observation> | |
| 63 | 63 | </observation_list> |
| 64 | 64 | |
| 65 | 65 | Each observation now has a ``Calibration`` parameter with the attributes |
| ... | ... | @@ -97,126 +97,136 @@ Within this database there are six response functions: |
| 97 | 97 | ``North_0.5h``, ``North_5h``, ``North_50h``, |
| 98 | 98 | ``South_0.5h``, ``South_5h``, and ``South_50h``. |
| 99 | 99 | |
| 100 | -We now jointly fit both observations using :ref:`ctlike`: | |
| 100 | +You now jointly fit both observations using :ref:`ctlike`: | |
| 101 | 101 | |
| 102 | 102 | .. code-block:: bash |
| 103 | 103 | |
| 104 | - $ ctlike | |
| 105 | - Event list, counts cube or observation definition file [obs.xml] obs_irf.xml | |
| 106 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 107 | - Source model output file [crab_results.xml] | |
| 104 | + $ ctlike chatter=3 | |
| 105 | + Input event list, counts cube or observation definition XML file [events.fits] obs_irf.xml | |
| 106 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 107 | + Output model XML file [crab_results.xml] | |
| 108 | 108 | |
| 109 | 109 | To see the usage of the individual response functions you may inspect the |
| 110 | -log file. You will notice that each observation now has a specific response | |
| 110 | +log file (you need to set ``chatter=3`` to see the details of the | |
| 111 | +observations in the log file). | |
| 112 | +You will notice that each observation now has a specific response | |
| 111 | 113 | function and that the filename of the response information differs for |
| 112 | 114 | both observations. |
| 113 | 115 | |
| 114 | 116 | .. code-block:: xml |
| 115 | 117 | |
| 116 | - 2015-05-22T22:06:43: +==============+ | |
| 117 | - 2015-05-22T22:06:43: | Observations | | |
| 118 | - 2015-05-22T22:06:43: +==============+ | |
| 119 | - 2015-05-22T22:06:43: === GObservations === | |
| 120 | - 2015-05-22T22:06:43: Number of observations ....: 2 | |
| 121 | - 2015-05-22T22:06:43: Number of predicted events : 0 | |
| 122 | - 2015-05-22T22:06:43: === GCTAObservation === | |
| 123 | - 2015-05-22T22:06:43: Name ......................: | |
| 124 | - 2015-05-22T22:06:43: Identifier ................: 00001 | |
| 125 | - 2015-05-22T22:06:43: Instrument ................: CTA | |
| 126 | - 2015-05-22T22:06:43: Event file ................: events1.fits | |
| 127 | - 2015-05-22T22:06:43: Event type ................: EventList | |
| 128 | - 2015-05-22T22:06:43: Statistics ................: Poisson | |
| 129 | - 2015-05-22T22:06:43: Ontime ....................: 1800 s | |
| 130 | - 2015-05-22T22:06:43: Livetime ..................: 1710 s | |
| 131 | - 2015-05-22T22:06:43: Deadtime correction .......: 0.95 | |
| 132 | - 2015-05-22T22:06:43: User energy range .........: undefined | |
| 133 | - 2015-05-22T22:06:43: === GCTAPointing === | |
| 134 | - 2015-05-22T22:06:43: Pointing direction ........: (RA,Dec)=(83.63,21.51) | |
| 135 | - 2015-05-22T22:06:43: === GCTAResponseIrf === | |
| 136 | - 2015-05-22T22:06:43: Caldb mission .............: cta | |
| 137 | - 2015-05-22T22:06:43: Caldb instrument ..........: prod2 | |
| 138 | - 2015-05-22T22:06:43: Response name .............: North_50h | |
| 139 | - 2015-05-22T22:06:43: Energy dispersion .........: Not used | |
| 140 | - 2015-05-22T22:06:43: Save energy range .........: undefined | |
| 118 | + 2015-12-07T22:22:18: +==============+ | |
| 119 | + 2015-12-07T22:22:18: | Observations | | |
| 120 | + 2015-12-07T22:22:18: +==============+ | |
| 121 | + 2015-12-07T22:22:18: === GObservations === | |
| 122 | + 2015-12-07T22:22:18: Number of observations ....: 2 | |
| 123 | + 2015-12-07T22:22:18: Number of models ..........: 2 | |
| 124 | + 2015-12-07T22:22:18: Number of predicted events : 0 | |
| 125 | + 2015-12-07T22:22:18: === GCTAObservation === | |
| 126 | + 2015-12-07T22:22:18: Name ......................: Crab | |
| 127 | + 2015-12-07T22:22:18: Identifier ................: 00001 | |
| 128 | + 2015-12-07T22:22:18: Instrument ................: CTA | |
| 129 | + 2015-12-07T22:22:18: Event file ................: north.fits | |
| 130 | + 2015-12-07T22:22:18: Event type ................: EventList | |
| 131 | + 2015-12-07T22:22:18: Statistics ................: Poisson | |
| 132 | + 2015-12-07T22:22:18: Ontime ....................: 1800 s | |
| 133 | + 2015-12-07T22:22:18: Livetime ..................: 1710 s | |
| 134 | + 2015-12-07T22:22:18: Deadtime correction .......: 0.95 | |
| 135 | + 2015-12-07T22:22:18: User energy range .........: undefined | |
| 136 | + 2015-12-07T22:22:18: === GCTAPointing === | |
| 137 | + 2015-12-07T22:22:18: Pointing direction ........: (RA,Dec)=(83.63,21.51) | |
| 138 | + 2015-12-07T22:22:18: === GCTAResponseIrf === | |
| 139 | + 2015-12-07T22:22:18: Caldb mission .............: cta | |
| 140 | + 2015-12-07T22:22:18: Caldb instrument ..........: prod2 | |
| 141 | + 2015-12-07T22:22:18: Response name .............: North_0.5h | |
| 142 | + 2015-12-07T22:22:18: Energy dispersion .........: Not used | |
| 143 | + 2015-12-07T22:22:18: Save energy range .........: undefined | |
| 144 | + 2015-12-07T22:22:18: === GCTAEventList === | |
| 145 | + 2015-12-07T22:22:18: Number of events ..........: 8469 | |
| 146 | + 2015-12-07T22:22:18: Time interval .............: 51544.5 - 51544.5 days | |
| 147 | + 2015-12-07T22:22:18: Energy interval ...........: 0.1 - 100 TeV | |
| 148 | + 2015-12-07T22:22:18: Region of interest ........: RA=83.63, DEC=21.51 [0,0] Radius=5 deg | |
| 149 | + 2015-12-07T22:22:18: === GCTAObservation === | |
| 150 | + 2015-12-07T22:22:18: Name ......................: Crab | |
| 151 | + 2015-12-07T22:22:18: Identifier ................: 00002 | |
| 152 | + 2015-12-07T22:22:18: Instrument ................: CTA | |
| 153 | + 2015-12-07T22:22:18: Event file ................: south.fits | |
| 154 | + 2015-12-07T22:22:18: Event type ................: EventList | |
| 155 | + 2015-12-07T22:22:18: Statistics ................: Poisson | |
| 156 | + 2015-12-07T22:22:18: Ontime ....................: 1800 s | |
| 157 | + 2015-12-07T22:22:18: Livetime ..................: 1710 s | |
| 158 | + 2015-12-07T22:22:18: Deadtime correction .......: 0.95 | |
| 159 | + 2015-12-07T22:22:18: User energy range .........: undefined | |
| 160 | + 2015-12-07T22:22:18: === GCTAPointing === | |
| 161 | + 2015-12-07T22:22:18: Pointing direction ........: (RA,Dec)=(83.63,22.51) | |
| 162 | + 2015-12-07T22:22:18: === GCTAResponseIrf === | |
| 163 | + 2015-12-07T22:22:18: Caldb mission .............: cta | |
| 164 | + 2015-12-07T22:22:18: Caldb instrument ..........: prod2 | |
| 165 | + 2015-12-07T22:22:18: Response name .............: South_0.5h | |
| 166 | + 2015-12-07T22:22:18: Energy dispersion .........: Not used | |
| 167 | + 2015-12-07T22:22:18: Save energy range .........: undefined | |
| 168 | + 2015-12-07T22:22:18: === GCTAEventList === | |
| 169 | + 2015-12-07T22:22:18: Number of events ..........: 22529 | |
| 170 | + 2015-12-07T22:22:18: Time interval .............: 51544.5 - 51544.5 days | |
| 171 | + 2015-12-07T22:22:18: Energy interval ...........: 0.1 - 100 TeV | |
| 172 | + 2015-12-07T22:22:18: Region of interest ........: RA=83.63, DEC=22.51 [0,0] Radius=5 deg | |
| 141 | 173 | ... |
| 142 | - 2015-05-22T22:06:43: === GCTAObservation === | |
| 143 | - 2015-05-22T22:06:43: Name ......................: | |
| 144 | - 2015-05-22T22:06:43: Identifier ................: 00002 | |
| 145 | - 2015-05-22T22:06:43: Instrument ................: CTA | |
| 146 | - 2015-05-22T22:06:43: Event file ................: events2.fits | |
| 147 | - 2015-05-22T22:06:43: Event type ................: EventList | |
| 148 | - 2015-05-22T22:06:43: Statistics ................: Poisson | |
| 149 | - 2015-05-22T22:06:43: Ontime ....................: 1800 s | |
| 150 | - 2015-05-22T22:06:43: Livetime ..................: 1710 s | |
| 151 | - 2015-05-22T22:06:43: Deadtime correction .......: 0.95 | |
| 152 | - 2015-05-22T22:06:43: User energy range .........: undefined | |
| 153 | - 2015-05-22T22:06:43: === GCTAPointing === | |
| 154 | - 2015-05-22T22:06:43: Pointing direction ........: (RA,Dec)=(83.63,22.51) | |
| 155 | - 2015-05-22T22:06:43: === GCTAResponseIrf === | |
| 156 | - 2015-05-22T22:06:43: Caldb mission .............: cta | |
| 157 | - 2015-05-22T22:06:43: Caldb instrument ..........: prod2 | |
| 158 | - 2015-05-22T22:06:43: Response name .............: South_50h | |
| 159 | - 2015-05-22T22:06:43: Energy dispersion .........: Not used | |
| 160 | - 2015-05-22T22:06:43: Save energy range .........: undefined | |
| 174 | + 2015-12-07T22:22:18: +=================================+ | |
| 175 | + 2015-12-07T22:22:18: | Maximum likelihood optimisation | | |
| 176 | + 2015-12-07T22:22:18: +=================================+ | |
| 177 | + 2015-12-07T22:22:18: >Iteration 0: -logL=214691.468, Lambda=1.0e-03 | |
| 178 | + 2015-12-07T22:22:18: >Iteration 1: -logL=214679.380, Lambda=1.0e-03, delta=12.088, max(|grad|)=9.713100 [Index:3] | |
| 179 | + 2015-12-07T22:22:18: >Iteration 2: -logL=214679.365, Lambda=1.0e-04, delta=0.015, max(|grad|)=0.092975 [Index:3] | |
| 180 | + 2015-12-07T22:22:18: >Iteration 3: -logL=214679.365, Lambda=1.0e-05, delta=0.000, max(|grad|)=0.000749 [Index:3] | |
| 161 | 181 | ... |
| 162 | - 2015-05-22T22:06:43: +=================================+ | |
| 163 | - 2015-05-22T22:06:43: | Maximum likelihood optimisation | | |
| 164 | - 2015-05-22T22:06:43: +=================================+ | |
| 165 | - 2015-05-22T22:06:43: >Iteration 0: -logL=138039.472, Lambda=1.0e-03 | |
| 166 | - 2015-05-22T22:06:43: >Iteration 1: -logL=138035.501, Lambda=1.0e-03, delta=3.971, max(|grad|)=16.203761 [Index:7] | |
| 167 | - 2015-05-22T22:06:43: >Iteration 2: -logL=138035.496, Lambda=1.0e-04, delta=0.005, max(|grad|)=-0.053284 [Index:7] | |
| 168 | - 2015-05-22T22:06:43: >Iteration 3: -logL=138035.496, Lambda=1.0e-05, delta=0.000, max(|grad|)=0.001386 [Index:7] | |
| 169 | - 2015-05-22T22:06:44: | |
| 170 | - 2015-05-22T22:06:44: +=========================================+ | |
| 171 | - 2015-05-22T22:06:44: | Maximum likelihood optimization results | | |
| 172 | - 2015-05-22T22:06:44: +=========================================+ | |
| 173 | - 2015-05-22T22:06:44: === GOptimizerLM === | |
| 174 | - 2015-05-22T22:06:44: Optimized function value ..: 138035.496 | |
| 175 | - 2015-05-22T22:06:44: Absolute precision ........: 0.005 | |
| 176 | - 2015-05-22T22:06:44: Acceptable value decrease .: 2 | |
| 177 | - 2015-05-22T22:06:44: Optimization status .......: converged | |
| 178 | - 2015-05-22T22:06:44: Number of parameters ......: 10 | |
| 179 | - 2015-05-22T22:06:44: Number of free parameters .: 4 | |
| 180 | - 2015-05-22T22:06:44: Number of iterations ......: 3 | |
| 181 | - 2015-05-22T22:06:44: Lambda ....................: 1e-06 | |
| 182 | - 2015-05-22T22:06:44: Maximum log likelihood ....: -138035.496 | |
| 183 | - 2015-05-22T22:06:44: Observed events (Nobs) ...: 20814.000 | |
| 184 | - 2015-05-22T22:06:44: Predicted events (Npred) ..: 20814.000 (Nobs - Npred = 2.67698e-06) | |
| 185 | - 2015-05-22T22:06:44: === GModels === | |
| 186 | - 2015-05-22T22:06:44: Number of models ..........: 2 | |
| 187 | - 2015-05-22T22:06:44: Number of parameters ......: 10 | |
| 188 | - 2015-05-22T22:06:44: === GModelSky === | |
| 189 | - 2015-05-22T22:06:44: Name ......................: Crab | |
| 190 | - 2015-05-22T22:06:44: Instruments ...............: all | |
| 191 | - 2015-05-22T22:06:44: Instrument scale factors ..: unity | |
| 192 | - 2015-05-22T22:06:44: Observation identifiers ...: all | |
| 193 | - 2015-05-22T22:06:44: Model type ................: PointSource | |
| 194 | - 2015-05-22T22:06:44: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 195 | - 2015-05-22T22:06:44: Number of parameters ......: 6 | |
| 196 | - 2015-05-22T22:06:44: Number of spatial par's ...: 2 | |
| 197 | - 2015-05-22T22:06:44: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 198 | - 2015-05-22T22:06:44: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 199 | - 2015-05-22T22:06:44: Number of spectral par's ..: 3 | |
| 200 | - 2015-05-22T22:06:44: Prefactor ................: 5.9184e-16 +/- 9.68924e-18 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 201 | - 2015-05-22T22:06:44: Index ....................: -2.49569 +/- 0.0145376 [-0,-5] (free,scale=-1,gradient) | |
| 202 | - 2015-05-22T22:06:44: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 203 | - 2015-05-22T22:06:44: Number of temporal par's ..: 1 | |
| 204 | - 2015-05-22T22:06:44: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 205 | - 2015-05-22T22:06:44: === GCTAModelIrfBackground === | |
| 206 | - 2015-05-22T22:06:44: Name ......................: CTABackgroundModel | |
| 207 | - 2015-05-22T22:06:44: Instruments ...............: CTA | |
| 208 | - 2015-05-22T22:06:44: Instrument scale factors ..: unity | |
| 209 | - 2015-05-22T22:06:44: Observation identifiers ...: all | |
| 210 | - 2015-05-22T22:06:44: Model type ................: "PowerLaw" * "Constant" | |
| 211 | - 2015-05-22T22:06:44: Number of parameters ......: 4 | |
| 212 | - 2015-05-22T22:06:44: Number of spectral par's ..: 3 | |
| 213 | - 2015-05-22T22:06:44: Prefactor ................: 1.02524 +/- 0.0182054 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 214 | - 2015-05-22T22:06:44: Index ....................: 0.0229728 +/- 0.0104713 [-5,5] (free,scale=1,gradient) | |
| 215 | - 2015-05-22T22:06:44: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 216 | - 2015-05-22T22:06:44: Number of temporal par's ..: 1 | |
| 217 | - 2015-05-22T22:06:44: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 218 | - | |
| 219 | - | |
| 182 | + 2015-12-07T22:22:18: +=========================================+ | |
| 183 | + 2015-12-07T22:22:18: | Maximum likelihood optimisation results | | |
| 184 | + 2015-12-07T22:22:18: +=========================================+ | |
| 185 | + 2015-12-07T22:22:18: === GOptimizerLM === | |
| 186 | + 2015-12-07T22:22:18: Optimized function value ..: 214679.365 | |
| 187 | + 2015-12-07T22:22:18: Absolute precision ........: 0.005 | |
| 188 | + 2015-12-07T22:22:18: Acceptable value decrease .: 2 | |
| 189 | + 2015-12-07T22:22:18: Optimization status .......: converged | |
| 190 | + 2015-12-07T22:22:18: Number of parameters ......: 10 | |
| 191 | + 2015-12-07T22:22:18: Number of free parameters .: 4 | |
| 192 | + 2015-12-07T22:22:18: Number of iterations ......: 3 | |
| 193 | + 2015-12-07T22:22:18: Lambda ....................: 1e-06 | |
| 194 | + 2015-12-07T22:22:18: Maximum log likelihood ....: -214679.365 | |
| 195 | + 2015-12-07T22:22:18: Observed events (Nobs) ...: 30998.000 | |
| 196 | + 2015-12-07T22:22:18: Predicted events (Npred) ..: 30998.000 (Nobs - Npred = 1.02755e-06) | |
| 197 | + 2015-12-07T22:22:18: === GModels === | |
| 198 | + 2015-12-07T22:22:18: Number of models ..........: 2 | |
| 199 | + 2015-12-07T22:22:18: Number of parameters ......: 10 | |
| 200 | + 2015-12-07T22:22:18: === GModelSky === | |
| 201 | + 2015-12-07T22:22:18: Name ......................: Crab | |
| 202 | + 2015-12-07T22:22:18: Instruments ...............: all | |
| 203 | + 2015-12-07T22:22:18: Instrument scale factors ..: unity | |
| 204 | + 2015-12-07T22:22:18: Observation identifiers ...: all | |
| 205 | + 2015-12-07T22:22:18: Model type ................: PointSource | |
| 206 | + 2015-12-07T22:22:18: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 207 | + 2015-12-07T22:22:18: Number of parameters ......: 6 | |
| 208 | + 2015-12-07T22:22:18: Number of spatial par's ...: 2 | |
| 209 | + 2015-12-07T22:22:18: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 210 | + 2015-12-07T22:22:18: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 211 | + 2015-12-07T22:22:18: Number of spectral par's ..: 3 | |
| 212 | + 2015-12-07T22:22:18: Prefactor ................: 5.81237e-16 +/- 8.63534e-18 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 213 | + 2015-12-07T22:22:18: Index ....................: -2.53954 +/- 0.0137432 [-0,-5] (free,scale=-1,gradient) | |
| 214 | + 2015-12-07T22:22:18: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 215 | + 2015-12-07T22:22:18: Number of temporal par's ..: 1 | |
| 216 | + 2015-12-07T22:22:18: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 217 | + 2015-12-07T22:22:18: === GCTAModelIrfBackground === | |
| 218 | + 2015-12-07T22:22:18: Name ......................: CTABackgroundModel | |
| 219 | + 2015-12-07T22:22:18: Instruments ...............: CTA | |
| 220 | + 2015-12-07T22:22:18: Instrument scale factors ..: unity | |
| 221 | + 2015-12-07T22:22:18: Observation identifiers ...: all | |
| 222 | + 2015-12-07T22:22:18: Model type ................: "PowerLaw" * "Constant" | |
| 223 | + 2015-12-07T22:22:18: Number of parameters ......: 4 | |
| 224 | + 2015-12-07T22:22:18: Number of spectral par's ..: 3 | |
| 225 | + 2015-12-07T22:22:18: Prefactor ................: 1.01067 +/- 0.0103997 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 226 | + 2015-12-07T22:22:18: Index ....................: 0.0135414 +/- 0.0064452 [-5,5] (free,scale=1,gradient) | |
| 227 | + 2015-12-07T22:22:18: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 228 | + 2015-12-07T22:22:18: Number of temporal par's ..: 1 | |
| 229 | + 2015-12-07T22:22:18: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 220 | 230 | |
| 221 | 231 | A more fine grained control over the response function can be achieved by |
| 222 | 232 | specifying individual filenames for the various response components. |
| ... | ... | @@ -228,18 +238,18 @@ This is definitely expert mode, to be used with utmost care. |
| 228 | 238 | <?xml version="1.0" standalone="no"?> |
| 229 | 239 | <observation_list title="observation library"> |
| 230 | 240 | <observation name="Crab" id="00001" instrument="CTA"> |
| 231 | - <parameter name="EventList" file="events1.fits"/> | |
| 232 | - <parameter name="EffectiveArea" file="$(CALDB)/data/cta/prod2/bcf/North_50h/irf_file.fits.gz"/> | |
| 233 | - <parameter name="PointSpreadFunction" file="$(CALDB)/data/cta/prod2/bcf/North_50h/irf_file.fits.gz"/> | |
| 234 | - <parameter name="EnergyDispersion" file="$(CALDB)/data/cta/prod2/bcf/North_50h/irf_file.fits.gz"/> | |
| 235 | - <parameter name="Background" file="$(CALDB)/data/cta/prod2/bcf/North_50h/irf_file.fits.gz"/> | |
| 241 | + <parameter name="EventList" file="north.fits"/> | |
| 242 | + <parameter name="EffectiveArea" file="$(CALDB)/data/cta/prod2/bcf/North_0.5h/irf_file.fits.gz"/> | |
| 243 | + <parameter name="PointSpreadFunction" file="$(CALDB)/data/cta/prod2/bcf/North_0.5h/irf_file.fits.gz"/> | |
| 244 | + <parameter name="EnergyDispersion" file="$(CALDB)/data/cta/prod2/bcf/North_0.5h/irf_file.fits.gz"/> | |
| 245 | + <parameter name="Background" file="$(CALDB)/data/cta/prod2/bcf/North_0.5h/irf_file.fits.gz"/> | |
| 236 | 246 | </observation> |
| 237 | 247 | <observation name="Crab" id="00002" instrument="CTA"> |
| 238 | - <parameter name="EventList" file="events2.fits"/> | |
| 239 | - <parameter name="EffectiveArea" file="$(CALDB)/data/cta/prod2/bcf/South_50h/irf_file.fits.gz"/> | |
| 240 | - <parameter name="PointSpreadFunction" file="$(CALDB)/data/cta/prod2/bcf/South_50h/irf_file.fits.gz"/> | |
| 241 | - <parameter name="EnergyDispersion" file="$(CALDB)/data/cta/prod2/bcf/South_50h/irf_file.fits.gz"/> | |
| 242 | - <parameter name="Background" file="$(CALDB)/data/cta/prod2/bcf/South_50h/irf_file.fits.gz"/> | |
| 248 | + <parameter name="EventList" file="south.fits"/> | |
| 249 | + <parameter name="EffectiveArea" file="$(CALDB)/data/cta/prod2/bcf/South_0.5h/irf_file.fits.gz"/> | |
| 250 | + <parameter name="PointSpreadFunction" file="$(CALDB)/data/cta/prod2/bcf/South_0.5h/irf_file.fits.gz"/> | |
| 251 | + <parameter name="EnergyDispersion" file="$(CALDB)/data/cta/prod2/bcf/South_0.5h/irf_file.fits.gz"/> | |
| 252 | + <parameter name="Background" file="$(CALDB)/data/cta/prod2/bcf/South_0.5h/irf_file.fits.gz"/> | |
| 243 | 253 | </observation> |
| 244 | 254 | </observation_list> |
| 245 | 255 | |
| ... | ... | @@ -264,5 +274,3 @@ file is given below: |
| 264 | 274 | <parameter name="BkgCube" file="bkgcube2.fits"/> |
| 265 | 275 | </observation> |
| 266 | 276 | </observation_list> |
| 267 | - | |
| 268 | - | ... | ... |
doc/source/user_manual/getting_started/beyond_model.rst
| ... | ... | @@ -26,20 +26,15 @@ specified by the following observation definition XML file: |
| 26 | 26 | </observation> |
| 27 | 27 | </observation_list> |
| 28 | 28 | |
| 29 | -Each observation has a **unique identifier string** and we can use this | |
| 30 | -unique string to connect that observation to a specific model component. | |
| 29 | +Each observation has a **unique identifier string** and you can use this | |
| 30 | +unique string to connect an observation to a specific model component. | |
| 31 | 31 | This is illustrated in the model XML file below that now has two background |
| 32 | 32 | components. |
| 33 | -**Model components in a XML file need to have a unique name**, for this | |
| 34 | -reason we have named the components ``Background_00001`` and | |
| 35 | -``Background_00002``. | |
| 36 | -Both components now have an ``id`` attribute that ties the model to | |
| 37 | -an observation. | |
| 38 | -In other words, the model is only applicable to a specific observation | |
| 39 | -(it will be ignored for all other observations). | |
| 40 | -In our case, model ``Background_00001`` applies to the ``events1.fits`` | |
| 41 | -event list while model ``Background_00002`` applies to the ``events2.fits`` | |
| 42 | -event list. | |
| 33 | +Both components have an ``id`` attribute that ties the model to a specific | |
| 34 | +observation. | |
| 35 | +Using ``id="00001"``, the first background model is tied to the | |
| 36 | +``events1.fits`` file, using ``id="00002"``, the second background model is | |
| 37 | +tied to the ``events2.fits`` file. | |
| 43 | 38 | |
| 44 | 39 | .. code-block:: xml |
| 45 | 40 | |
| ... | ... | @@ -72,13 +67,21 @@ event list. |
| 72 | 67 | </source> |
| 73 | 68 | </source_library> |
| 74 | 69 | |
| 75 | -Note that both background model components distinguish in their event rate; | |
| 76 | -component ``Background_00002`` has a ten times larger background rate than | |
| 77 | -component ``Background_00001``. | |
| 78 | -To illustrate this difference, we simulated two observations offset by | |
| 79 | -+/- 2 degrees from the Crab nebulae using :ref:`ctobssim`. | |
| 80 | -We then performed a joint fit of the observations using :ref:`ctlike` | |
| 81 | -and created a resdiual map using :ref:`csresmap` that is shown below. | |
| 70 | +.. note:: | |
| 71 | + | |
| 72 | + **Model components in a XML file need to have a unique name.** | |
| 73 | + For this reason the components are named here ``Background_00001`` | |
| 74 | + and ``Background_00002``. | |
| 75 | + | |
| 76 | +Note that both background model components distinguish in their event rate. | |
| 77 | +``Background_00002`` has a ten times larger background rate than | |
| 78 | +``Background_00001``. | |
| 79 | +To illustrate this difference, two observations offset by +/- 2 degrees from | |
| 80 | +the Crab nebulae have been simulated using :ref:`ctobssim`. | |
| 81 | +A joint fit of the observations is then performed using :ref:`ctlike` and | |
| 82 | +a residual map is created using :ref:`csresmap`. | |
| 83 | + | |
| 84 | +The result is shown below. | |
| 82 | 85 | Obviously, the upper observation has larger residuals owing to the ten |
| 83 | 86 | times larger background rate that was used in the simulation of the |
| 84 | 87 | associated data. | ... | ... |
doc/source/user_manual/getting_started/beyond_residual.rst
| ... | ... | @@ -22,11 +22,11 @@ Suppose that you have done the following unbinned ``ctlike`` analysis: |
| 22 | 22 | .. code-block:: bash |
| 23 | 23 | |
| 24 | 24 | $ ctlike |
| 25 | - Event list, counts cube or observation definition file [events.fits] obs.xml | |
| 25 | + Input event list, counts cube or observation definition XML file [events.fits] obs.xml | |
| 26 | 26 | Calibration database [prod2] |
| 27 | - Instrument response function [South_50h] | |
| 28 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 29 | - Source model output file [crab_results.xml] | |
| 27 | + Instrument response function [South_0.5h] | |
| 28 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 29 | + Output model XML file [crab_results.xml] | |
| 30 | 30 | |
| 31 | 31 | The :ref:`csresmap` script is then used as follows: |
| 32 | 32 | |
| ... | ... | @@ -34,18 +34,19 @@ The :ref:`csresmap` script is then used as follows: |
| 34 | 34 | |
| 35 | 35 | $ csresmap |
| 36 | 36 | Parfile csresmap.par not found. Create default parfile. |
| 37 | - Event list, counts cube, or observation definition file [events.fits] obs.xml | |
| 37 | + Input event list, counts cube, or observation definition XML file [events.fits] obs.xml | |
| 38 | 38 | Calibration database [prod2] |
| 39 | - Instrument response function [South_50h] | |
| 40 | - Source model [$CTOOLS/share/models/crab.xml] crab_results.xml | |
| 41 | - Output residual map [resmap.fits] | |
| 42 | - First coordinate of image center in degrees (RA or galactic l) [83.63] | |
| 43 | - Second coordinate of image center in degrees (DEC or galactic b) [22.01] | |
| 39 | + Instrument response function [South_0.5h] | |
| 40 | + Input model XML file [$CTOOLS/share/models/crab.xml] crab_results.xml | |
| 41 | + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] | |
| 42 | + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01] | |
| 44 | 43 | Coordinate System (CEL|GAL) [CEL] |
| 45 | - Projection method e.g. AIT|AZP|CAR|MER|MOL|STG|TAN (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] | |
| 44 | + Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] | |
| 46 | 45 | Size of the X axis in pixels [200] |
| 47 | 46 | Size of the Y axis in pixels [200] |
| 48 | 47 | Pixel size (deg/pixel) [0.02] |
| 48 | + Output residual map file [resmap.fits] | |
| 49 | + Residual map computation algorithm (SUB|SUBDIV|SUBDIVSQRT) [SUBDIV] | |
| 49 | 50 | |
| 50 | 51 | In our example, the map will cover a field of 4 x 4 degrees centred on the |
| 51 | 52 | Crab nebula at a pixel scale of 0.02 degrees per pixel. | ... | ... |
doc/source/user_manual/getting_started/beyond_stacked.rst
| ... | ... | @@ -6,16 +6,15 @@ Performing a stacked analysis |
| 6 | 6 | A stacked analysis is a binned analysis where all data from multiple |
| 7 | 7 | observations are stacked into a single counts cube. |
| 8 | 8 | The event stacking is done using the :ref:`ctbin` tool. |
| 9 | -Instead of providing to :ref:`ctbin` an event list we | |
| 10 | -now specify the observation definition XML file ``obs.xml`` | |
| 11 | -on input. | |
| 9 | +Instead of providing to :ref:`ctbin` an event list you should now | |
| 10 | +specify the observation definition XML file ``obs.xml`` on input. | |
| 12 | 11 | :ref:`ctbin` will then loop over all observations and collect all events |
| 13 | 12 | into a single counts cube: |
| 14 | 13 | |
| 15 | 14 | .. code-block:: bash |
| 16 | 15 | |
| 17 | 16 | $ ctbin |
| 18 | - Event list or observation definition file [events.fits] obs.xml | |
| 17 | + Input event list or observation definition XML file [events.fits] obs.xml | |
| 19 | 18 | First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] |
| 20 | 19 | Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01] |
| 21 | 20 | Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] |
| ... | ... | @@ -27,37 +26,37 @@ into a single counts cube: |
| 27 | 26 | Start value for first energy bin in TeV [0.1] |
| 28 | 27 | Stop value for last energy bin in TeV [100.0] |
| 29 | 28 | Number of energy bins [20] |
| 30 | - Output counts cube [cntcube.fits] | |
| 29 | + Output counts cube file [cntcube.fits] | |
| 31 | 30 | |
| 32 | -We now have a stacked counts cube ``cntcube.fits`` on disk. | |
| 33 | -Before we can use that counts cube in a maximum likelihood | |
| 34 | -analysis, we have to compute the instrument response and the | |
| 31 | +You now have a stacked counts cube ``cntcube.fits`` on disk. | |
| 32 | +Before you can use that counts cube in a maximum likelihood | |
| 33 | +analysis, you have to compute the instrument response and the | |
| 35 | 34 | background model that are needed to describe the stacked data. |
| 36 | 35 | |
| 37 | -For the former, we have to compute the total exposure for the stacked | |
| 36 | +For the former, you have to compute the total exposure for the stacked | |
| 38 | 37 | cube (i.e. the sum of the effective areas for each observation multiplied |
| 39 | 38 | by the corresponding livetimes) and an effective point spread function |
| 40 | 39 | (i.e. the point spread function of the different observations weighted by |
| 41 | 40 | the corresponding exposures). |
| 42 | -To get both informations we use the :ref:`ctexpcube` and | |
| 41 | +To get both informations you use the :ref:`ctexpcube` and | |
| 43 | 42 | :ref:`ctpsfcube` tools: |
| 44 | 43 | |
| 45 | 44 | .. code-block:: bash |
| 46 | 45 | |
| 47 | 46 | $ ctexpcube |
| 48 | - Event list or observation definition file [NONE] obs.xml | |
| 47 | + Input event list or observation definition XML file [NONE] obs.xml | |
| 49 | 48 | Calibration database [prod2] |
| 50 | - Instrument response function [South_50h] | |
| 51 | - Counts cube for exposure cube definition [NONE] cntcube.fits | |
| 49 | + Instrument response function [South_0.5h] | |
| 50 | + Input counts cube file to extract exposure cube definition [NONE] cntcube.fits | |
| 52 | 51 | Output exposure cube file [expcube.fits] |
| 53 | 52 | |
| 54 | 53 | .. code-block:: bash |
| 55 | 54 | |
| 56 | 55 | $ ctpsfcube |
| 57 | - Event list or observation definition file [NONE] obs.xml | |
| 56 | + Input event list or observation definition XML file [NONE] obs.xml | |
| 58 | 57 | Calibration database [prod2] |
| 59 | - Instrument response function [South_50h] | |
| 60 | - Counts cube for psf cube definition [NONE] | |
| 58 | + Instrument response function [South_0.5h] | |
| 59 | + Input counts cube file to extract PSF cube definition [NONE] | |
| 61 | 60 | First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] |
| 62 | 61 | Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01] |
| 63 | 62 | Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] |
| ... | ... | @@ -68,42 +67,41 @@ To get both informations we use the :ref:`ctexpcube` and |
| 68 | 67 | Lower energy limit (TeV) [0.1] |
| 69 | 68 | Upper energy limit (TeV) [100.0] |
| 70 | 69 | Number of energy bins [20] |
| 71 | - Output psf cube file [psfcube.fits] | |
| 72 | - | |
| 73 | -We provide the ``obs.xml`` file on input to inform both tools which | |
| 74 | -observations have been combined. | |
| 75 | -For :ref:`ctexpcube` we further provide the counts cube so that the | |
| 76 | -tool can copy the exposure cube definition (number of spatial pixels | |
| 77 | -and pixel size, number of energy bins) from the counts cube. | |
| 78 | -This minimises the number of further user parameters that need to be | |
| 79 | -provided and assures an exposure cube that is compatible with the counts | |
| 80 | -cube. | |
| 81 | -For :ref:`ctpsfcube` we do not use the counts cube for the PSF cube | |
| 82 | -definition as this would lead to a hugh file owing to the fine spatial | |
| 70 | + Output PSF cube file [psfcube.fits] | |
| 71 | + | |
| 72 | +The ``obs.xml`` file has been provided on input to specify for both tools | |
| 73 | +which observations have been combined. | |
| 74 | +You further provided the counts cube on input so that :ref:`ctexpcube` can | |
| 75 | +read the cub definition from that file and apply it to the exposure cube. | |
| 76 | +This is a trick to reduce the number of user parameters that you need to | |
| 77 | +provide. | |
| 78 | + | |
| 79 | +You do not apply this trick when using :ref:`ctpsfcube` as this | |
| 80 | +would lead to a hugh output file owing to the fine spatial | |
| 83 | 81 | pixelisation of the counts cube. |
| 84 | -Since the PSF evolves only slowly over the field of fiew, we provide a | |
| 85 | -rather coarse spatial binning of 1 degree covering a grid of 10 x 10 | |
| 86 | -degrees around the centre of the counts cube. | |
| 87 | -For the energy binning, we use the same logarithmic binning that has | |
| 88 | -also been used for the counts cube. | |
| 82 | +Such a fine binning is not needed for the PSF cube, as the PSF evolves | |
| 83 | +only slowly over the field of view. | |
| 84 | +It is thus sufficient to compute a PSF cube with a rather coarse spatial | |
| 85 | +binning; here you used a spatial binning of 1 degree covering a grid of | |
| 86 | +10 x 10 degrees. | |
| 89 | 87 | |
| 90 | -As final step of the analysis preparation, we need to generate a | |
| 88 | +As final step of the analysis preparation, you need to generate a | |
| 91 | 89 | background cube using the :ref:`ctbkgcube` tool: |
| 92 | 90 | |
| 93 | 91 | .. code-block:: bash |
| 94 | 92 | |
| 95 | 93 | $ ctbkgcube |
| 96 | - Input event list or observation definition file [NONE] obs.xml | |
| 94 | + Input event list or observation definition XML file [NONE] obs.xml | |
| 97 | 95 | Calibration database [prod2] |
| 98 | - Instrument response function [South_50h] | |
| 99 | - Counts cube for background cube definition [NONE] cntcube.fits | |
| 96 | + Instrument response function [South_0.5h] | |
| 97 | + Input counts cube file to extract background cube definition [NONE] cntcube.fits | |
| 100 | 98 | Input model XML file [NONE] $CTOOLS/share/models/crab.xml |
| 101 | 99 | Output background cube file [bkgcube.fits] |
| 102 | 100 | Output model XML file [NONE] model.xml |
| 103 | 101 | |
| 104 | 102 | The usage of :ref:`ctbkgcube` is very similar to that of :ref:`ctexpcube`, |
| 105 | 103 | yet it takes the model XML file as an additional input parameter. |
| 106 | -We here use the usual ``$CTOOLS/share/models/crab.xml`` model | |
| 104 | +You used here the usual ``$CTOOLS/share/models/crab.xml`` model | |
| 107 | 105 | file that is shipped with the ctools. |
| 108 | 106 | :ref:`ctbkgcube` provides on output the background cube file |
| 109 | 107 | ``bkgcube.fits`` and the model XML file ``model.xml`` that can |
| ... | ... | @@ -115,7 +113,7 @@ modelling works: |
| 115 | 113 | |
| 116 | 114 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 117 | 115 | <source_library title="source library"> |
| 118 | - <source name="Crab" type="PointSource" tscalc="0"> | |
| 116 | + <source name="Crab" type="PointSource"> | |
| 119 | 117 | <spectrum type="PowerLaw"> |
| 120 | 118 | <parameter name="Prefactor" value="5.7" error="0" scale="1e-16" min="1e-07" max="1000" free="1" /> |
| 121 | 119 | <parameter name="Index" value="2.48" error="0" scale="-1" min="0" max="5" free="1" /> |
| ... | ... | @@ -157,88 +155,88 @@ as an appropriate multiplicator to the background cube. |
| 157 | 155 | Using the same binning for the exposure cube, the background cube and |
| 158 | 156 | the counts cube is only a convenience. |
| 159 | 157 | |
| 160 | -Now we have all files at hand to launch a stacked maximum likelihood | |
| 158 | +Now you have all files at hand to perform a stacked maximum likelihood | |
| 161 | 159 | analysis using the :ref:`ctlike` tool: |
| 162 | 160 | |
| 163 | 161 | .. code-block:: bash |
| 164 | 162 | |
| 165 | 163 | $ ctlike |
| 166 | - Event list, counts cube or observation definition file [obs.xml] cntcube.fits | |
| 167 | - Exposure cube file (only needed for stacked analysis) [NONE] expcube.fits | |
| 168 | - PSF cube file (only needed for stacked analysis) [NONE] psfcube.fits | |
| 169 | - Background cube file (only needed for stacked analysis) [NONE] bkgcube.fits | |
| 170 | - Source model [$CTOOLS/share/models/crab.xml] model.xml | |
| 171 | - Source model output file [crab_results.xml] | |
| 164 | + Input event list, counts cube or observation definition XML file [obs.xml] cntcube.fits | |
| 165 | + Input exposure cube file (only needed for stacked analysis) [NONE] expcube.fits | |
| 166 | + Input PSF cube file (only needed for stacked analysis) [NONE] psfcube.fits | |
| 167 | + Input background cube file (only needed for stacked analysis) [NONE] bkgcube.fits | |
| 168 | + Input model XML file [$CTOOLS/share/models/crab.xml] model.xml | |
| 169 | + Output model XML file [crab_results.xml] | |
| 172 | 170 | |
| 173 | 171 | :ref:`ctlike` recognises that a counts cube should be analysed and queries |
| 174 | 172 | for the exposure cube, the PSF cube, and the background cube file names. |
| 175 | -We specified the names of the files produced by the :ref:`ctexpcube`, | |
| 173 | +You specified here the names of the files produced by the :ref:`ctexpcube`, | |
| 176 | 174 | the :ref:`ctpsfcube` and the :ref:`ctbkgcube` tools. |
| 177 | -Furthermore we provided as model the ``model.xml`` file that has been | |
| 175 | +Furthermore you provided as model the ``model.xml`` file that has been | |
| 178 | 176 | generated by the :ref:`ctbkgcube` tool. |
| 179 | 177 | |
| 180 | 178 | The log file of the :ref:`ctlike` run is shown below. |
| 181 | 179 | Note that the spectral model that is multiplied with the background |
| 182 | -cube has a Prefactor of 1.09 +/- 0.02 and an Index of 0.03 +/- 0.01, | |
| 180 | +cube has a Prefactor of 0.998 +/- 0.011 and an Index of 0.006 +/- 0.007, | |
| 183 | 181 | indicating a very small correction to the actual spectrum of the background |
| 184 | 182 | cube. |
| 185 | 183 | Real life situations may of course require larger correction factors. |
| 186 | 184 | |
| 187 | 185 | .. code-block:: xml |
| 188 | 186 | |
| 189 | - 2015-05-22T21:10:09: +=================================+ | |
| 190 | - 2015-05-22T21:10:09: | Maximum likelihood optimisation | | |
| 191 | - 2015-05-22T21:10:09: +=================================+ | |
| 192 | - 2015-05-22T21:10:10: >Iteration 0: -logL=60663.798, Lambda=1.0e-03 | |
| 193 | - 2015-05-22T21:10:11: >Iteration 1: -logL=60642.413, Lambda=1.0e-03, delta=21.385, max(|grad|)=120.031102 [Index:7] | |
| 194 | - 2015-05-22T21:10:13: >Iteration 2: -logL=60642.233, Lambda=1.0e-04, delta=0.180, max(|grad|)=1.139187 [Index:7] | |
| 195 | - 2015-05-22T21:10:14: >Iteration 3: -logL=60642.233, Lambda=1.0e-05, delta=0.000, max(|grad|)=-0.001247 [Index:7] | |
| 196 | - 2015-05-22T21:10:16: | |
| 197 | - 2015-05-22T21:10:16: +=========================================+ | |
| 198 | - 2015-05-22T21:10:16: | Maximum likelihood optimization results | | |
| 199 | - 2015-05-22T21:10:16: +=========================================+ | |
| 200 | - 2015-05-22T21:10:16: === GOptimizerLM === | |
| 201 | - 2015-05-22T21:10:16: Optimized function value ..: 60642.233 | |
| 202 | - 2015-05-22T21:10:16: Absolute precision ........: 0.005 | |
| 203 | - 2015-05-22T21:10:16: Acceptable value decrease .: 2 | |
| 204 | - 2015-05-22T21:10:16: Optimization status .......: converged | |
| 205 | - 2015-05-22T21:10:16: Number of parameters ......: 10 | |
| 206 | - 2015-05-22T21:10:16: Number of free parameters .: 4 | |
| 207 | - 2015-05-22T21:10:16: Number of iterations ......: 3 | |
| 208 | - 2015-05-22T21:10:16: Lambda ....................: 1e-06 | |
| 209 | - 2015-05-22T21:10:16: Maximum log likelihood ....: -60642.233 | |
| 210 | - 2015-05-22T21:10:16: Observed events (Nobs) ...: 25963.000 | |
| 211 | - 2015-05-22T21:10:16: Predicted events (Npred) ..: 25963.000 (Nobs - Npred = 1.5749e-05) | |
| 212 | - 2015-05-22T21:10:16: === GModels === | |
| 213 | - 2015-05-22T21:10:16: Number of models ..........: 2 | |
| 214 | - 2015-05-22T21:10:16: Number of parameters ......: 10 | |
| 215 | - 2015-05-22T21:10:16: === GModelSky === | |
| 216 | - 2015-05-22T21:10:16: Name ......................: Crab | |
| 217 | - 2015-05-22T21:10:16: Instruments ...............: all | |
| 218 | - 2015-05-22T21:10:16: Instrument scale factors ..: unity | |
| 219 | - 2015-05-22T21:10:16: Observation identifiers ...: all | |
| 220 | - 2015-05-22T21:10:16: Model type ................: PointSource | |
| 221 | - 2015-05-22T21:10:16: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 222 | - 2015-05-22T21:10:16: Number of parameters ......: 6 | |
| 223 | - 2015-05-22T21:10:16: Number of spatial par's ...: 2 | |
| 224 | - 2015-05-22T21:10:16: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 225 | - 2015-05-22T21:10:16: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 226 | - 2015-05-22T21:10:16: Number of spectral par's ..: 3 | |
| 227 | - 2015-05-22T21:10:16: Prefactor ................: 5.8499e-16 +/- 8.02289e-18 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 228 | - 2015-05-22T21:10:16: Index ....................: -2.49909 +/- 0.0118976 [-0,-5] (free,scale=-1,gradient) | |
| 229 | - 2015-05-22T21:10:16: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 230 | - 2015-05-22T21:10:16: Number of temporal par's ..: 1 | |
| 231 | - 2015-05-22T21:10:16: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 232 | - 2015-05-22T21:10:16: === GCTAModelCubeBackground === | |
| 233 | - 2015-05-22T21:10:16: Name ......................: BackgroundModel | |
| 234 | - 2015-05-22T21:10:16: Instruments ...............: CTA, HESS, MAGIC, VERITAS | |
| 235 | - 2015-05-22T21:10:16: Instrument scale factors ..: unity | |
| 236 | - 2015-05-22T21:10:16: Observation identifiers ...: all | |
| 237 | - 2015-05-22T21:10:16: Model type ................: "PowerLaw" * "Constant" | |
| 238 | - 2015-05-22T21:10:16: Number of parameters ......: 4 | |
| 239 | - 2015-05-22T21:10:16: Number of spectral par's ..: 3 | |
| 240 | - 2015-05-22T21:10:16: Prefactor ................: 1.08781 +/- 0.0212678 [0,infty[ ph/cm2/s/MeV (free,scale=1,gradient) | |
| 241 | - 2015-05-22T21:10:16: Index ....................: 0.0269681 +/- 0.0111532 [-10,10] (free,scale=1,gradient) | |
| 242 | - 2015-05-22T21:10:16: PivotEnergy ..............: 1e+06 MeV (fixed,scale=1e+06,gradient) | |
| 243 | - 2015-05-22T21:10:16: Number of temporal par's ..: 1 | |
| 244 | - 2015-05-22T21:10:16: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 187 | + 2015-12-07T21:37:45: +=================================+ | |
| 188 | + 2015-12-07T21:37:45: | Maximum likelihood optimisation | | |
| 189 | + 2015-12-07T21:37:45: +=================================+ | |
| 190 | + 2015-12-07T21:37:46: >Iteration 0: -logL=83748.453, Lambda=1.0e-03 | |
| 191 | + 2015-12-07T21:37:47: >Iteration 1: -logL=83736.039, Lambda=1.0e-03, delta=12.413, max(|grad|)=15.134616 [Index:3] | |
| 192 | + 2015-12-07T21:37:48: >Iteration 2: -logL=83736.021, Lambda=1.0e-04, delta=0.018, max(|grad|)=0.108613 [Index:3] | |
| 193 | + 2015-12-07T21:37:49: >Iteration 3: -logL=83736.021, Lambda=1.0e-05, delta=0.000, max(|grad|)=0.000570 [Index:3] | |
| 194 | + ... | |
| 195 | + 2015-12-07T21:37:51: +=========================================+ | |
| 196 | + 2015-12-07T21:37:51: | Maximum likelihood optimisation results | | |
| 197 | + 2015-12-07T21:37:51: +=========================================+ | |
| 198 | + 2015-12-07T21:37:51: === GOptimizerLM === | |
| 199 | + 2015-12-07T21:37:51: Optimized function value ..: 83736.021 | |
| 200 | + 2015-12-07T21:37:51: Absolute precision ........: 0.005 | |
| 201 | + 2015-12-07T21:37:51: Acceptable value decrease .: 2 | |
| 202 | + 2015-12-07T21:37:51: Optimization status .......: converged | |
| 203 | + 2015-12-07T21:37:51: Number of parameters ......: 10 | |
| 204 | + 2015-12-07T21:37:51: Number of free parameters .: 4 | |
| 205 | + 2015-12-07T21:37:51: Number of iterations ......: 3 | |
| 206 | + 2015-12-07T21:37:51: Lambda ....................: 1e-06 | |
| 207 | + 2015-12-07T21:37:51: Maximum log likelihood ....: -83736.021 | |
| 208 | + 2015-12-07T21:37:51: Observed events (Nobs) ...: 35198.000 | |
| 209 | + 2015-12-07T21:37:51: Predicted events (Npred) ..: 35198.000 (Nobs - Npred = 7.6773e-07) | |
| 210 | + 2015-12-07T21:37:51: === GModels === | |
| 211 | + 2015-12-07T21:37:51: Number of models ..........: 2 | |
| 212 | + 2015-12-07T21:37:51: Number of parameters ......: 10 | |
| 213 | + 2015-12-07T21:37:51: === GModelSky === | |
| 214 | + 2015-12-07T21:37:51: Name ......................: Crab | |
| 215 | + 2015-12-07T21:37:51: Instruments ...............: all | |
| 216 | + 2015-12-07T21:37:51: Instrument scale factors ..: unity | |
| 217 | + 2015-12-07T21:37:51: Observation identifiers ...: all | |
| 218 | + 2015-12-07T21:37:51: Model type ................: PointSource | |
| 219 | + 2015-12-07T21:37:51: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 220 | + 2015-12-07T21:37:51: Number of parameters ......: 6 | |
| 221 | + 2015-12-07T21:37:51: Number of spatial par's ...: 2 | |
| 222 | + 2015-12-07T21:37:51: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 223 | + 2015-12-07T21:37:51: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 224 | + 2015-12-07T21:37:51: Number of spectral par's ..: 3 | |
| 225 | + 2015-12-07T21:37:51: Prefactor ................: 5.75289e-16 +/- 7.24749e-18 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 226 | + 2015-12-07T21:37:51: Index ....................: -2.53122 +/- 0.0113068 [-0,-5] (free,scale=-1,gradient) | |
| 227 | + 2015-12-07T21:37:51: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 228 | + 2015-12-07T21:37:51: Number of temporal par's ..: 1 | |
| 229 | + 2015-12-07T21:37:51: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 230 | + 2015-12-07T21:37:51: === GCTAModelCubeBackground === | |
| 231 | + 2015-12-07T21:37:51: Name ......................: BackgroundModel | |
| 232 | + 2015-12-07T21:37:51: Instruments ...............: CTA, HESS, MAGIC, VERITAS | |
| 233 | + 2015-12-07T21:37:51: Instrument scale factors ..: unity | |
| 234 | + 2015-12-07T21:37:51: Observation identifiers ...: all | |
| 235 | + 2015-12-07T21:37:51: Model type ................: "PowerLaw" * "Constant" | |
| 236 | + 2015-12-07T21:37:51: Number of parameters ......: 4 | |
| 237 | + 2015-12-07T21:37:51: Number of spectral par's ..: 3 | |
| 238 | + 2015-12-07T21:37:51: Prefactor ................: 0.998055 +/- 0.0114979 [0.01,100] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 239 | + 2015-12-07T21:37:51: Index ....................: 0.00648796 +/- 0.00697365 [-5,5] (free,scale=1,gradient) | |
| 240 | + 2015-12-07T21:37:51: PivotEnergy ..............: 1e+06 MeV (fixed,scale=1e+06,gradient) | |
| 241 | + 2015-12-07T21:37:51: Number of temporal par's ..: 1 | |
| 242 | + 2015-12-07T21:37:51: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | ... | ... |
doc/source/user_manual/getting_started/beyond_tsmap.rst
| ... | ... | @@ -3,13 +3,14 @@ |
| 3 | 3 | Generating a Test Statistic map |
| 4 | 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5 | 5 | |
| 6 | -In the above examples we were always considering that we knew exactly | |
| 6 | +In the above examples you have always considering that you knew exactly | |
| 7 | 7 | where the source is located, but in real life situations this may not |
| 8 | 8 | necessarily be the case. |
| 9 | -We thus need a means to search for significant excess emission in our data. | |
| 9 | +You thus need a means to search for significant excess emission in your data. | |
| 10 | 10 | One possibility to accomplish this task is to compute the Test Statistic |
| 11 | 11 | for a specific source at a grid of trial positions. |
| 12 | 12 | The :ref:`cttsmap` tool will exactly do that job. |
| 13 | + | |
| 13 | 14 | The Test Statistic is defined as twice the log-likelihood difference |
| 14 | 15 | between fitting a source at a given position on top of a model or fitting |
| 15 | 16 | no source. |
| ... | ... | @@ -18,7 +19,7 @@ the source detection significance in Gaussian sigmas, although the |
| 18 | 19 | exact relation depends somewhat on the formulation of the statistical |
| 19 | 20 | problem. |
| 20 | 21 | |
| 21 | -Here an example where we apply the :ref:`cttsmap` tool to our two | |
| 22 | +Here an example of how to apply the :ref:`cttsmap` tool to the two | |
| 22 | 23 | simulated observations of the Crab in unbinned mode. |
| 23 | 24 | On input we provide a source model XML file and the name of the source |
| 24 | 25 | in the XML file that should be moved on a grid of test positions. |
| ... | ... | @@ -31,11 +32,11 @@ nominal position of the Crab nebula with a grid spacing of 0.02 degrees. |
| 31 | 32 | .. code-block:: bash |
| 32 | 33 | |
| 33 | 34 | $ cttsmap |
| 34 | - Input event list, counts cube or observation definition file [events.fits] obs.xml | |
| 35 | + Input event list, counts cube or observation definition XML file [events.fits] obs.xml | |
| 35 | 36 | Calibration database [prod2] |
| 36 | - Instrument response function [South_50h] | |
| 37 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 38 | - Test source [Crab] | |
| 37 | + Instrument response function [South_0.5h] | |
| 38 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 39 | + Test source name [Crab] | |
| 39 | 40 | First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] |
| 40 | 41 | Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01] |
| 41 | 42 | Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] |
| ... | ... | @@ -43,14 +44,14 @@ nominal position of the Crab nebula with a grid spacing of 0.02 degrees. |
| 43 | 44 | Image scale (in degrees/pixel) [0.02] |
| 44 | 45 | Size of the X axis in pixels [200] 10 |
| 45 | 46 | Size of the Y axis in pixels [200] 10 |
| 46 | - Output Test Statistic map [tsmap.fits] | |
| 47 | + Output Test Statistic map file [tsmap.fits] | |
| 47 | 48 | |
| 48 | 49 | :ref:`cttsmap` writes the Test Statistic map in the ``tsmap.fits`` file |
| 49 | 50 | that contains one extension for the Test Statistic value and further |
| 50 | 51 | extensions for the spectral parameters that have been fitted for the |
| 51 | 52 | source at each position of the grid. |
| 52 | 53 | The figure below show the Test Statistic map which reaches a maximum |
| 53 | -value of 37484 near the centre of the map. | |
| 54 | +value of 40733 near the centre of the map. | |
| 54 | 55 | |
| 55 | 56 | .. figure:: tsmap-crab.png |
| 56 | 57 | :height: 400px | ... | ... |
doc/source/user_manual/getting_started/binning.rst
0 → 100644
| 1 | +.. _sec_binning_cta: | |
| 2 | + | |
| 3 | +Binning CTA data | |
| 4 | +~~~~~~~~~~~~~~~~ | |
| 5 | + | |
| 6 | +As next analysis step you will bin the data in a counts cube using | |
| 7 | +:ref:`ctbin`. | |
| 8 | +A counts cube is a 3 dimensional data cube, spanned by | |
| 9 | +Right Ascension (or Galactic longitude), Declination (or Galactic latitude), | |
| 10 | +and energy (typically logarithmically spaced, but this is under user | |
| 11 | +control). | |
| 12 | + | |
| 13 | +:ref:`ctbin` is executed by typing: | |
| 14 | + | |
| 15 | +.. code-block:: bash | |
| 16 | + | |
| 17 | + $ ctbin | |
| 18 | + Input event list or observation definition XML file [events.fits] | |
| 19 | + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] | |
| 20 | + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01] | |
| 21 | + Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] | |
| 22 | + Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL] | |
| 23 | + Image scale (in degrees/pixel) [0.02] | |
| 24 | + Size of the X axis in pixels [200] | |
| 25 | + Size of the Y axis in pixels [200] | |
| 26 | + Algorithm for defining energy bins (FILE|LIN|LOG) [LOG] | |
| 27 | + Start value for first energy bin in TeV [0.1] | |
| 28 | + Stop value for last energy bin in TeV [100.0] | |
| 29 | + Number of energy bins [20] | |
| 30 | + Output counts cube file [cntcube.fits] | |
| 31 | + | |
| 32 | +The counts cube will be centred on the location of the Crab (Right Ascension | |
| 33 | +83.63 degrees, Declination 22.01 degrees) and will be aligned in celestial | |
| 34 | +coordinates. A cartesian projection has been selected. The counts cube has | |
| 35 | +200 x 200 spatial pixels of 0.02 x 0.02 degrees in size, hence it covers a | |
| 36 | +total area of 4 x 4 degrees. | |
| 37 | + | |
| 38 | +The counts cube will contain 20 maps, which are logarithmically spaced | |
| 39 | +in energy, and which cover the energy range from 0.1 TeV to 100 TeV. In this | |
| 40 | +example, the counts cube will be saved as ``cntcube.fits`` in the working | |
| 41 | +directory. In addition to the counts cube, that is stored as the primary | |
| 42 | +image extension, the FITS file also contains an extension named ``EBOUNDS`` | |
| 43 | +that defines the energy boundaries that were used, and an extension ``GTI`` | |
| 44 | +that defines the Good Time Intervals that have been used. The following | |
| 45 | +image shows the resulting FITS file. The ``EBOUNDS`` table has 20 rows, one | |
| 46 | +for each energy bin, while the ``GTI`` table has just a single row, indicating | |
| 47 | +the start and stop time of the simulated data. | |
| 48 | + | |
| 49 | +.. figure:: cntmap-fits.jpg | |
| 50 | + :width: 600px | |
| 51 | + :align: center | |
| 52 | + | |
| 53 | + *Counts cube FITS file* | |
| 54 | + | |
| 55 | + | |
| 56 | +An image of the first bin, covering the energy range 100 - 141 GeV, is | |
| 57 | +shown below: | |
| 58 | + | |
| 59 | +.. figure:: cntmap-map.jpg | |
| 60 | + :height: 400px | |
| 61 | + :align: center | |
| 62 | + | |
| 63 | + *Counts cube for first energy bin* | |
| 64 | + | |
| 65 | +For illustration, the last few lines of the log file ``ctbin.log`` are | |
| 66 | +reproduced below: | |
| 67 | + | |
| 68 | +.. code-block:: xml | |
| 69 | + | |
| 70 | + 2015-12-07T20:52:41: +=================+ | |
| 71 | + 2015-12-07T20:52:41: | Bin observation | | |
| 72 | + 2015-12-07T20:52:41: +=================+ | |
| 73 | + 2015-12-07T20:52:41: === CTA observation === | |
| 74 | + 2015-12-07T20:52:41: Events in list ............: 22685 | |
| 75 | + 2015-12-07T20:52:41: Events in cube ............: 18195 | |
| 76 | + 2015-12-07T20:52:41: Event bins outside RoI ....: 0 | |
| 77 | + 2015-12-07T20:52:41: Events outside cube area ..: 4490 | |
| 78 | + 2015-12-07T20:52:41: Events outside energy bins : 0 | |
| 79 | + | |
| 80 | +From the 22685 events that have been simulated and stored in the | |
| 81 | +``events.fits`` file, 18195 lie within the cube boundaries and are thus put | |
| 82 | +into the resulting counts cube. The counts cube is stored in a cartesian | |
| 83 | +projection in a World Coordinate System (WCS) compliant format. | ... | ... |
doc/source/user_manual/getting_started/butterfly.rst
0 → 100644
| 1 | +.. _sec_butterfly_cta: | |
| 2 | + | |
| 3 | +Calculating and visualising a butterfly diagram | |
| 4 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 5 | + | |
| 6 | +To visualise the analysis results you can compute a butterfly diagram | |
| 7 | +which shows the confidence band of the spectral fit using the | |
| 8 | +:ref:`ctbutterfly` tool. | |
| 9 | +The butterfly diagram is the envelope of all power law models | |
| 10 | +that are within a given confidence limit compatible with the data. | |
| 11 | +By default a confidence level of 68% is used, but the level can be adjusted | |
| 12 | +using the hidden ``confidence`` parameter. | |
| 13 | +:ref:`ctbutterfly` computes this envelope by evaluating for each energy the | |
| 14 | +minimum and maximum intensity of all power law models that fall within the | |
| 15 | +error ellipse of the prefactor and index parameters. | |
| 16 | +The error ellipse is derived from the covariance matrix of a maximum | |
| 17 | +likelihood fit. | |
| 18 | + | |
| 19 | +The following example illustrates how you can use the :ref:`ctbutterfly` | |
| 20 | +tool: | |
| 21 | + | |
| 22 | +.. code-block:: bash | |
| 23 | + | |
| 24 | + $ ctbutterfly | |
| 25 | + Input event list, counts cube or observation definition XML file [events.fits] | |
| 26 | + Calibration database [prod2] | |
| 27 | + Instrument response function [South_0.5h] | |
| 28 | + Input model XML file [$CTOOLS/share/models/crab.xml] crab_results.xml | |
| 29 | + Source of interest [Crab] | |
| 30 | + Start value for first energy bin in TeV [0.1] | |
| 31 | + Stop value for last energy bin in TeV [100.0] | |
| 32 | + Output ASCII file [butterfly.txt] | |
| 33 | + | |
| 34 | +Now that you have computed the confidence band of the spectral fit and | |
| 35 | +that you will have an ASCII file named ``butterfly.txt`` on disk you can | |
| 36 | +visualise the butterfly using the script ``show_butterfly.py`` that is | |
| 37 | +in the ctools ``example`` folder. You will need matplotlib on your system | |
| 38 | +to make this work. To launch the script, type: | |
| 39 | + | |
| 40 | +.. code-block:: bash | |
| 41 | + | |
| 42 | + python $CTOOLS/share/examples/python/show_butterfly.py butterfly.txt | |
| 43 | + | |
| 44 | +This will result in a canvas which should look like the following: | |
| 45 | + | |
| 46 | +.. figure:: butterfly.jpg | |
| 47 | + :height: 400px | |
| 48 | + :align: center | |
| 49 | + | |
| 50 | + *Confidence band of the fit* | |
| 51 | + | |
| 0 | 52 | \ No newline at end of file | ... | ... |
doc/source/user_manual/getting_started/fitting.rst
0 → 100644
| 1 | +.. _sec_fitting_cta: | |
| 2 | + | |
| 3 | +Fitting CTA data | |
| 4 | +~~~~~~~~~~~~~~~~ | |
| 5 | + | |
| 6 | +Now we are ready to fit the simulated data with a model. For simplicity | |
| 7 | +we use in this example the same model that we used to simulate the data | |
| 8 | +with :ref:`ctobssim`. Model fitting is done using the :ref:`ctlike` tool, | |
| 9 | +and we do the fit by typing: | |
| 10 | + | |
| 11 | +.. code-block:: bash | |
| 12 | + | |
| 13 | + $ ctlike | |
| 14 | + Input event list, counts cube or observation definition XML file [events.fits] cntcube.fits | |
| 15 | + Input exposure cube file (only needed for stacked analysis) [NONE] | |
| 16 | + Input PSF cube file (only needed for stacked analysis) [NONE] | |
| 17 | + Input background cube file (only needed for stacked analysis) [NONE] | |
| 18 | + Calibration database [prod2] | |
| 19 | + Instrument response function [South_0.5h] | |
| 20 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 21 | + Output model XML file [crab_results.xml] | |
| 22 | + | |
| 23 | +The data are fitted in *binned* mode, which means that the events | |
| 24 | +have been binned into a counts cube and the fit computes the log-likelihood | |
| 25 | +function by summing over all 200 x 200 x 20 bins of the counts cube. There is | |
| 26 | +an alternative method, the so called *unbinned* mode, where the events are | |
| 27 | +not binned into a counts cube and the log-likelihood is computed directly by | |
| 28 | +summing over all events. We will explore the *unbinned* mode later. | |
| 29 | + | |
| 30 | +One of the parameters of :ref:`ctlike` is a source model output file | |
| 31 | +(we specified ``crab_results.xml`` in the example), and this file will be | |
| 32 | +a copy of the source model input XML file where the parameter values have | |
| 33 | +been replaced by the fit results. In addition, the statistical uncertainties | |
| 34 | +are added for each fitted parameter using the attribute ``error``. | |
| 35 | +Below we show the XML result file that has been produced by the run: | |
| 36 | + | |
| 37 | +.. code-block:: xml | |
| 38 | + | |
| 39 | + <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 40 | + <source_library title="source library"> | |
| 41 | + <source name="Crab" type="PointSource"> | |
| 42 | + <spectrum type="PowerLaw"> | |
| 43 | + <parameter name="Prefactor" value="5.78443" error="0.101348" scale="1e-16" min="1e-07" max="1000" free="1" /> | |
| 44 | + <parameter name="Index" value="2.50664" error="0.0153631" scale="-1" min="0" max="5" free="1" /> | |
| 45 | + <parameter name="Scale" value="0.3" scale="1e+06" min="0.01" max="1000" free="0" /> | |
| 46 | + </spectrum> | |
| 47 | + <spatialModel type="SkyDirFunction"> | |
| 48 | + <parameter name="RA" value="83.6331" scale="1" min="-360" max="360" free="0" /> | |
| 49 | + <parameter name="DEC" value="22.0145" scale="1" min="-90" max="90" free="0" /> | |
| 50 | + </spatialModel> | |
| 51 | + </source> | |
| 52 | + <source name="CTABackgroundModel" type="CTAIrfBackground" instrument="CTA"> | |
| 53 | + <spectrum type="PowerLaw"> | |
| 54 | + <parameter name="Prefactor" value="0.993018" error="0.0160113" scale="1" min="0.001" max="1000" free="1" /> | |
| 55 | + <parameter name="Index" value="0.00269761" error="0.00973921" scale="1" min="-5" max="5" free="1" /> | |
| 56 | + <parameter name="Scale" value="1" scale="1e+06" min="0.01" max="1000" free="0" /> | |
| 57 | + </spectrum> | |
| 58 | + </source> | |
| 59 | + </source_library> | |
| 60 | + | |
| 61 | +In this example, the ``Prefactor`` and ``Index`` of the spectral model for the | |
| 62 | +Crab as well as the ``Prefactor`` and ``Index`` of the background spectral | |
| 63 | +model have been fitted (all parameters having the attribute ``free="1"`` are | |
| 64 | +fitted). Now we see also the effect of having multiplied the background | |
| 65 | +model with a power law. In that way, the amplitude of the background as | |
| 66 | +well as it's spectral slope is adjusted by the fit. Obviously, in this | |
| 67 | +example the adjustment compensates only for the statistical fluctuations | |
| 68 | +of the background, but with real data, the adjustment may account also for | |
| 69 | +some of the systematic uncertainties. | |
| 70 | + | |
| 71 | +.. warning:: | |
| 72 | + | |
| 73 | + As good practice, the amplitude of the background model should always be | |
| 74 | + left as a free parameter of the fit. Otherwise, any uncertainty in the | |
| 75 | + background rate will immediately propagate into the flux estimate of the | |
| 76 | + source. | |
| 77 | + | |
| 78 | +To get more details about the model fitting you can inspect the log file. | |
| 79 | +Below the last lines of the ctlike.log log file that has been produced by | |
| 80 | +this run: | |
| 81 | + | |
| 82 | +.. code-block:: xml | |
| 83 | + | |
| 84 | + 2015-12-07T20:55:32: +=================================+ | |
| 85 | + 2015-12-07T20:55:32: | Maximum likelihood optimisation | | |
| 86 | + 2015-12-07T20:55:32: +=================================+ | |
| 87 | + 2015-12-07T20:55:33: >Iteration 0: -logL=54877.412, Lambda=1.0e-03 | |
| 88 | + 2015-12-07T20:55:35: >Iteration 1: -logL=54875.025, Lambda=1.0e-03, delta=2.387, max(|grad|)=1.856683 [Index:7] | |
| 89 | + 2015-12-07T20:55:36: >Iteration 2: -logL=54875.024, Lambda=1.0e-04, delta=0.001, max(|grad|)=-0.024661 [Index:3] | |
| 90 | + 2015-12-07T20:55:36: | |
| 91 | + ... | |
| 92 | + 2015-12-07T20:55:38: +=========================================+ | |
| 93 | + 2015-12-07T20:55:38: | Maximum likelihood optimisation results | | |
| 94 | + 2015-12-07T20:55:38: +=========================================+ | |
| 95 | + 2015-12-07T20:55:38: === GOptimizerLM === | |
| 96 | + 2015-12-07T20:55:38: Optimized function value ..: 54875.024 | |
| 97 | + 2015-12-07T20:55:38: Absolute precision ........: 0.005 | |
| 98 | + 2015-12-07T20:55:38: Acceptable value decrease .: 2 | |
| 99 | + 2015-12-07T20:55:38: Optimization status .......: converged | |
| 100 | + 2015-12-07T20:55:38: Number of parameters ......: 10 | |
| 101 | + 2015-12-07T20:55:38: Number of free parameters .: 4 | |
| 102 | + 2015-12-07T20:55:38: Number of iterations ......: 2 | |
| 103 | + 2015-12-07T20:55:38: Lambda ....................: 1e-05 | |
| 104 | + 2015-12-07T20:55:38: Maximum log likelihood ....: -54875.024 | |
| 105 | + 2015-12-07T20:55:38: Observed events (Nobs) ...: 18195.000 | |
| 106 | + 2015-12-07T20:55:38: Predicted events (Npred) ..: 18194.999 (Nobs - Npred = 0.00146383) | |
| 107 | + 2015-12-07T20:55:38: === GModels === | |
| 108 | + 2015-12-07T20:55:38: Number of models ..........: 2 | |
| 109 | + 2015-12-07T20:55:38: Number of parameters ......: 10 | |
| 110 | + 2015-12-07T20:55:38: === GModelSky === | |
| 111 | + 2015-12-07T20:55:38: Name ......................: Crab | |
| 112 | + 2015-12-07T20:55:38: Instruments ...............: all | |
| 113 | + 2015-12-07T20:55:38: Instrument scale factors ..: unity | |
| 114 | + 2015-12-07T20:55:38: Observation identifiers ...: all | |
| 115 | + 2015-12-07T20:55:38: Model type ................: PointSource | |
| 116 | + 2015-12-07T20:55:38: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 117 | + 2015-12-07T20:55:38: Number of parameters ......: 6 | |
| 118 | + 2015-12-07T20:55:38: Number of spatial par's ...: 2 | |
| 119 | + 2015-12-07T20:55:38: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 120 | + 2015-12-07T20:55:38: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 121 | + 2015-12-07T20:55:38: Number of spectral par's ..: 3 | |
| 122 | + 2015-12-07T20:55:38: Prefactor ................: 5.78443e-16 +/- 1.01348e-17 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 123 | + 2015-12-07T20:55:38: Index ....................: -2.50664 +/- 0.0153631 [-0,-5] (free,scale=-1,gradient) | |
| 124 | + 2015-12-07T20:55:38: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 125 | + 2015-12-07T20:55:38: Number of temporal par's ..: 1 | |
| 126 | + 2015-12-07T20:55:38: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 127 | + 2015-12-07T20:55:38: === GCTAModelIrfBackground === | |
| 128 | + 2015-12-07T20:55:38: Name ......................: CTABackgroundModel | |
| 129 | + 2015-12-07T20:55:38: Instruments ...............: CTA | |
| 130 | + 2015-12-07T20:55:38: Instrument scale factors ..: unity | |
| 131 | + 2015-12-07T20:55:38: Observation identifiers ...: all | |
| 132 | + 2015-12-07T20:55:38: Model type ................: "PowerLaw" * "Constant" | |
| 133 | + 2015-12-07T20:55:38: Number of parameters ......: 4 | |
| 134 | + 2015-12-07T20:55:38: Number of spectral par's ..: 3 | |
| 135 | + 2015-12-07T20:55:38: Prefactor ................: 0.993018 +/- 0.0160113 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 136 | + 2015-12-07T20:55:38: Index ....................: 0.00269761 +/- 0.00973921 [-5,5] (free,scale=1,gradient) | |
| 137 | + 2015-12-07T20:55:38: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 138 | + 2015-12-07T20:55:38: Number of temporal par's ..: 1 | |
| 139 | + 2015-12-07T20:55:38: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 140 | + | |
| 141 | +The maximum likelihood optimizer required 2 iterations to converge. This | |
| 142 | +is pretty fast, but recall that we used the same model file for the simulation | |
| 143 | +and for fitting, hence the initial parameter values were already very close | |
| 144 | +to the best fitting values. To see the impact of the initial parameters on | |
| 145 | +the fit result, you may re-run :ref:`ctlike` using another copy of the model | |
| 146 | +XML file where you change the value attributes of the parameters that should be | |
| 147 | +fitted. You will see that the optimizer requires a couple of more iterations, | |
| 148 | +but it should converge to the same solution (provided that the initial values | |
| 149 | +are not too far from the best fitting values). | |
| 150 | + | |
| 151 | +.. note:: | |
| 152 | + | |
| 153 | + As sanity check you should verify that the predicted number of events | |
| 154 | + (Npred) is equal to the observed number of events (Nobs). To facilitate | |
| 155 | + this comparison, :ref:`ctlike` provides the difference Nobs - Npred in | |
| 156 | + the log file. In real life situations, this difference may not always be | |
| 157 | + small, in particular if the source model is too constrained. You may | |
| 158 | + then free some of the model parameters so that the fit can correctly | |
| 159 | + describe the data. | |
| 160 | + | |
| 161 | +.. note:: | |
| 162 | + | |
| 163 | + The :ref:`ctlike` tool has the ability to estimate the detection | |
| 164 | + significance for sources in the XML model. This is done by computing | |
| 165 | + the Test Statistic value which is defined as twice the log-likelihood | |
| 166 | + difference between fitting a source at a given position on top of a | |
| 167 | + (background) model or fitting no source. Roughly speaken, the square | |
| 168 | + root of the Test Statistic value gives the source detection significance | |
| 169 | + in Gaussian sigmas, although the exact relation depends somewhat on | |
| 170 | + the formulation of the statistical problem. | |
| 171 | + | |
| 172 | + To instruct :ref:`ctlike` to compute the Test Statistic value for a | |
| 173 | + given source you need to add the attribute ``tscalc="1"`` to the XML | |
| 174 | + file: | |
| 175 | + | |
| 176 | + .. code-block:: xml | |
| 177 | + | |
| 178 | + <source name="Crab" type="PointSource" tscalc="1"> | |
| 179 | + | |
| 180 | + :ref:`ctlike` will then compute the Test Statistic value for that | |
| 181 | + source and dump the result in the log file: | |
| 182 | + | |
| 183 | + .. code-block:: xml | |
| 184 | + | |
| 185 | + 2015-12-07T20:58:45: === GModelSky === | |
| 186 | + 2015-12-07T20:58:45: Name ......................: Crab | |
| 187 | + 2015-12-07T20:58:45: Instruments ...............: all | |
| 188 | + 2015-12-07T20:58:45: Test Statistic ............: 21164.4 | |
| 189 | + | |
| 190 | + The Test Statistic value will also be added as new attribute | |
| 191 | + ``ts`` to the XML result file: | |
| 192 | + | |
| 193 | + .. code-block:: xml | |
| 194 | + | |
| 195 | + <source name="Crab" type="PointSource" ts="21164.384" tscalc="1"> | ... | ... |
doc/source/user_manual/getting_started/quickstart.rst
| 1 | 1 | .. _quickstart: |
| 2 | 2 | |
| 3 | -A quick ctools tutorial | |
| 4 | ------------------------ | |
| 5 | - | |
| 6 | 3 | First steps with ctools |
| 7 | -~~~~~~~~~~~~~~~~~~~~~~~ | |
| 8 | - | |
| 9 | -This section provides a step-by-step description of the CTA data analysis | |
| 10 | -procedure implemented in ctools. In this example we will simulate data for | |
| 11 | -the Crab nebula, observed on-axis, as a single source in the CTA field of | |
| 12 | -view. | |
| 13 | - | |
| 14 | -The example consists of the following analysis steps: | |
| 15 | - | |
| 16 | -- :ref:`sec_simulating_cta` | |
| 17 | - | |
| 18 | -- :ref:`sec_binning_cta` | |
| 19 | - | |
| 20 | -- :ref:`sec_fitting_cta` | |
| 21 | - | |
| 22 | -- :ref:`sec_unbinned_cta` | |
| 23 | - | |
| 24 | -- :ref:`sec_butterfly_cta` | |
| 25 | - | |
| 26 | - | |
| 27 | -.. _sec_simulating_cta: | |
| 28 | - | |
| 29 | -Simulating CTA data | |
| 30 | -~~~~~~~~~~~~~~~~~~~ | |
| 31 | - | |
| 32 | -CTA data are simulated using the :ref:`ctobssim` tool. To invoke the tool, | |
| 33 | -type :ref:`ctobssim` at the console prompt (which is denoted by ``$``). | |
| 34 | -:ref:`ctobssim` will query for a number of parameters: | |
| 35 | - | |
| 36 | -.. code-block:: bash | |
| 37 | - | |
| 38 | - $ ctobssim | |
| 39 | - RA of pointing (degrees) (0-360) [83.63] | |
| 40 | - Dec of pointing (degrees) (-90-90) [22.01] | |
| 41 | - Radius of FOV (degrees) (0-180) [5.0] | |
| 42 | - Start time (MET in s) [0.0] | |
| 43 | - End time (MET in s) [1800.0] | |
| 44 | - Lower energy limit (TeV) [0.1] | |
| 45 | - Upper energy limit (TeV) [100.0] | |
| 46 | - Calibration database [prod2] | |
| 47 | - Instrument response function [South_50h] | |
| 48 | - Model [$CTOOLS/share/models/crab.xml] | |
| 49 | - Output event data file or observation definition file [events.fits] | |
| 50 | - | |
| 51 | -Each line represents a query for one parameter value. | |
| 52 | -The line starts with a short description of the parameter, followed by | |
| 53 | -the default value proposed by ctobssim in squared brackets ``[ ]``. | |
| 54 | -**If no parameter is entered the default value will be used** | |
| 55 | -(which is the case for all parameters shown here). | |
| 56 | -Otherwise, the specified value will overwrite the default value. | |
| 57 | -The round brackets ``( )`` indicate the range of possible parameter | |
| 58 | -values (if applicable). | |
| 59 | - | |
| 60 | - | |
| 61 | -You may have recognised that the environment variable ``$CTOOLS`` has | |
| 62 | -been used in the path name of the model. ctools will automatically expand | |
| 63 | -the environment variables in parameter inputs. | |
| 64 | - | |
| 65 | -The CTA instrument properties (effective area, PSF width) are taken from | |
| 66 | -the prod2 database. The response for the southern array using the cuts | |
| 67 | -optimised for 50 hours of observing time are used. | |
| 68 | - | |
| 69 | -.. note:: | |
| 70 | - | |
| 71 | - ctools comes bundled with CTA response functions for the northern and | |
| 72 | - the southern array. The response functions are based on a Prod2 | |
| 73 | - analysis with cuts optimised for 0.5 hours, 5 hours and 50 hours of | |
| 74 | - observing time. The following Instrument Response Functions | |
| 75 | - (IRFs) are available: ``North_0.5h``, ``North_5h``, ``North_50h``, | |
| 76 | - ``South_0.5h``, ``South_5h``, and ``South_50h``. | |
| 77 | - | |
| 78 | -Events are simulated based on the instrument properties and based on a | |
| 79 | -source and background model. Only events that fall within the specified | |
| 80 | -region of interest (ROI), defined as a circle around a sky position in | |
| 81 | -Right Ascension and Declination (in degrees), will be stored in the output | |
| 82 | -event data file. The duration of the simulation is taken here to 30 minutes | |
| 83 | -(or 1800 seconds). Events are simulated for energies between 0.1 and 100 TeV. | |
| 84 | - | |
| 85 | -The source and background model is defined by the XML file | |
| 86 | -``$CTOOLS/share/models/crab.xml``: | |
| 87 | - | |
| 88 | -.. code-block:: xml | |
| 89 | - | |
| 90 | - <?xml version="1.0" standalone="no"?> | |
| 91 | - <source_library title="source library"> | |
| 92 | - <source name="Crab" type="PointSource"> | |
| 93 | - <spectrum type="PowerLaw"> | |
| 94 | - <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/> | |
| 95 | - <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | |
| 96 | - <parameter name="Scale" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | |
| 97 | - </spectrum> | |
| 98 | - <spatialModel type="SkyDirFunction"> | |
| 99 | - <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="0"/> | |
| 100 | - <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="0"/> | |
| 101 | - </spatialModel> | |
| 102 | - </source> | |
| 103 | - <source name="CTABackgroundModel" type="CTAIrfBackground" instrument="CTA"> | |
| 104 | - <spectrum type="PowerLaw"> | |
| 105 | - <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e+3" free="1"/> | |
| 106 | - <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/> | |
| 107 | - <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/> | |
| 108 | - </spectrum> | |
| 109 | - </source> | |
| 110 | - </source_library> | |
| 111 | - | |
| 112 | -The model consists of a source library that contains two components: | |
| 113 | -the Crab nebula and an instrumental background model. | |
| 114 | - | |
| 115 | -The Crab nebula is modelled by a factorized sky model that has a spectral | |
| 116 | -and a spatial component (tags ``<spectrum>`` and ``<spatialModel>``, | |
| 117 | -respectively). The spectrum is modelled by a power law, which is defined by | |
| 118 | -three parameters: the ``Prefactor``, the ``Index`` and the ``Scale``. | |
| 119 | -The spatial model has two parameters: Right Ascension in degrees (``RA``), and | |
| 120 | -Declination in degrees (``DEC``). Each parameter has a value and a scale factor, | |
| 121 | -the real value of the parameter being the product ``value * scale``. Typically, | |
| 122 | -``scale`` is chosen so that ``value`` is of the order of 1 (this is relevant for | |
| 123 | -model fitting). In addition, ``value`` is bound by a minimum (``min``) and | |
| 124 | -maximum (``max``) value, and a parameter may be free (``free="1"``) or fixed | |
| 125 | -(``free="0"``). The ``min``, ``max``, and ``free`` attributes are not | |
| 126 | -relevant here for the simulations, but they will be important for the model | |
| 127 | -fitting later. | |
| 128 | - | |
| 129 | -The spectral intensity I(E) (in units of photons/cm2/s/MeV) of the power | |
| 130 | -law is given by | |
| 131 | - | |
| 132 | -.. math:: | |
| 133 | - \frac{dN}{dE} = N_0 \left( \frac{E}{E_0} \right)^{\gamma} | |
| 134 | - | |
| 135 | -where the parameters in the XML definition have the following mappings: | |
| 136 | - | |
| 137 | -* :math:`N_0` = ``Prefactor`` | |
| 138 | -* :math:`\gamma` = ``Index`` | |
| 139 | -* :math:`E_0` = ``Scale`` | |
| 140 | - | |
| 141 | -.. warning:: | |
| 142 | - | |
| 143 | - Energies are given in the XML file in MeV units. This is a GammaLib | |
| 144 | - convention that can not be modified. **So make sure you always use | |
| 145 | - MeV as energy unit in an XML file.** | |
| 146 | - | |
| 147 | -The instrumental background of CTA is modelled using the background | |
| 148 | -information provided in the IRF (``CTAIrfBackground``) multipled | |
| 149 | -by a power law. As it is defined here, the power law represents a | |
| 150 | -constant of 1, hence the background IRF will be used without any | |
| 151 | -modification. The power law will become active when fitting the data | |
| 152 | -later and allows a spectral adjustment of the background model that | |
| 153 | -may account for uncertainties in the background information provided | |
| 154 | -in the IRF. | |
| 155 | - | |
| 156 | -:ref:`ctobssim` has a couple of hidden parameters, the most important one being | |
| 157 | -certainly ``seed``. ``seed`` is an integer that specifies the seed value | |
| 158 | -for the random number generator, and changing this parameter will allow to | |
| 159 | -generate statistically independent Monte Carlo samples of CTA event data. | |
| 160 | -To use for example a seed value of 41 you should type: | |
| 161 | - | |
| 162 | -.. code-block:: bash | |
| 163 | - | |
| 164 | - $ ctobssim seed=41 | |
| 165 | - | |
| 166 | -:ref:`ctobssim` will write 2 files in the working directory: ``events.fits`` | |
| 167 | -and ``ctobssim.log``. The first file contains the simulated events in FITS | |
| 168 | -format and can be inspected using ``fv`` or ``ds9``. The FITS file will | |
| 169 | -contain three extensions: an empty primary image, a binary table named | |
| 170 | -``EVENTS`` that holds the events (one row per event), and a binary table | |
| 171 | -named ``GTI`` holding the Good Time Intervals (for the moment a single row | |
| 172 | -with 2 columns providing the start and the stop time of the simulated time | |
| 173 | -interval). | |
| 174 | - | |
| 175 | -The second file produced by :ref:`ctobssim` is a human readable log file that | |
| 176 | -contains information about the job execution. As example, the last lines | |
| 177 | -from this file are shown here: | |
| 178 | - | |
| 179 | -.. code-block:: xml | |
| 180 | - | |
| 181 | - 2015-05-22T19:24:53: +======================+ | |
| 182 | - 2015-05-22T19:24:53: | Simulate observation | | |
| 183 | - 2015-05-22T19:24:53: +======================+ | |
| 184 | - 2015-05-22T19:24:53: === Observation === | |
| 185 | - 2015-05-22T19:24:53: Simulation area ...........: 1.9635e+11 cm2 | |
| 186 | - 2015-05-22T19:24:53: Simulation cone ...........: RA=83.63 deg, Dec=22.01 deg, r=5.5 deg | |
| 187 | - 2015-05-22T19:24:53: Time interval .............: 0 - 1800 s | |
| 188 | - 2015-05-22T19:24:53: Photon energy range .......: 100 GeV - 100 TeV | |
| 189 | - 2015-05-22T19:24:53: Event energy range ........: 100 GeV - 100 TeV | |
| 190 | - 2015-05-22T19:24:53: MC source photons .........: 207547 [Crab] | |
| 191 | - 2015-05-22T19:24:53: MC source events ..........: 2961 [Crab] | |
| 192 | - 2015-05-22T19:24:53: MC source events ..........: 2961 (all source models) | |
| 193 | - 2015-05-22T19:24:55: MC background events ......: 13003 | |
| 194 | - 2015-05-22T19:24:55: MC events .................: 15964 (all models) | |
| 195 | - | |
| 196 | -Each line starts with the UTC time at which the line has been written. In | |
| 197 | -this run, 207547 Crab photons have been thrown over an area of 19.6 square | |
| 198 | -kilometres during a time interval of 1800 seconds. 2961 of these photons have | |
| 199 | -been registered by CTA as events. In the same time interval, 13003 background | |
| 200 | -events have been registred by CTA. | |
| 201 | - | |
| 202 | -You may change the name of the log file using the hidden parameter | |
| 203 | -``logfile``: | |
| 204 | - | |
| 205 | -.. code-block:: bash | |
| 206 | - | |
| 207 | - $ ctobssim logfile=my-private-log-file | |
| 208 | - | |
| 209 | -Furthermore, you may decide on the amount of information provided in the | |
| 210 | -log file (the chattiness of the executable) using the hidden parameter | |
| 211 | -``chatter``: | |
| 212 | - | |
| 213 | -.. code-block:: bash | |
| 214 | - | |
| 215 | - $ ctobssim chatter=4 | |
| 216 | - | |
| 217 | -``chatter`` can vary between 0 and 4, 0 providing no information while 4 | |
| 218 | -provides the most detailed information. **By default, all ctools have a | |
| 219 | -chatter level of 2.** | |
| 220 | - | |
| 221 | -You may also duplicate the log file information into the console by setting | |
| 222 | -the hidden ``debug`` parameter to yes: | |
| 223 | - | |
| 224 | -.. code-block:: bash | |
| 225 | - | |
| 226 | - $ ctobssim debug=yes | |
| 227 | - | |
| 228 | - | |
| 229 | -.. _sec_binning_cta: | |
| 230 | - | |
| 231 | -Binning CTA data | |
| 232 | -~~~~~~~~~~~~~~~~ | |
| 233 | - | |
| 234 | -As next analysis step you will bin the data in a counts cube using | |
| 235 | -:ref:`ctbin`. | |
| 236 | -A counts cube is a 3 dimensional data cube, spanned by | |
| 237 | -Right Ascension (or Galactic longitude), Declination (or Galactic latitude), | |
| 238 | -and energy (typically logarithmically spaced, but this is under user | |
| 239 | -control). | |
| 240 | - | |
| 241 | -:ref:`ctbin` is executed by typing: | |
| 242 | - | |
| 243 | -.. code-block:: bash | |
| 244 | - | |
| 245 | - $ ctbin | |
| 246 | - Event list or observation definition file [events.fits] | |
| 247 | - First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] | |
| 248 | - Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01] | |
| 249 | - Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] | |
| 250 | - Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL] | |
| 251 | - Image scale (in degrees/pixel) [0.02] | |
| 252 | - Size of the X axis in pixels [200] | |
| 253 | - Size of the Y axis in pixels [200] | |
| 254 | - Algorithm for defining energy bins (FILE|LIN|LOG) [LOG] | |
| 255 | - Start value for first energy bin in TeV [0.1] | |
| 256 | - Stop value for last energy bin in TeV [100.0] | |
| 257 | - Number of energy bins [20] | |
| 258 | - Output counts cube [cntcube.fits] | |
| 259 | - | |
| 260 | -The counts cube will be centred on the location of the Crab (Right Ascension | |
| 261 | -83.63 degrees, Declination 22.01 degrees) and will be aligned in celestial | |
| 262 | -coordinates. A cartesian projection has been selected. The counts cube has | |
| 263 | -200 x 200 spatial pixels of 0.02 x 0.02 degrees in size, hence it covers a | |
| 264 | -total area of 4 x 4 degrees. | |
| 265 | - | |
| 266 | -The counts cube will contain 20 maps, which are logarithmically spaced | |
| 267 | -in energy, and which cover the energy range from 0.1 TeV to 100 TeV. In this | |
| 268 | -example, the counts cube will be saved as ``cntcube.fits`` in the working | |
| 269 | -directory. In addition to the counts cube, that is stored as the primary | |
| 270 | -image extension, the FITS file also contains an extension named ``EBOUNDS`` | |
| 271 | -that defines the energy boundaries that were used, and an extension ``GTI`` | |
| 272 | -that defines the Good Time Intervals that have been used. The following | |
| 273 | -image shows the resulting FITS file. The ``EBOUNDS`` table has 20 rows, one | |
| 274 | -for each energy bin, while the ``GTI`` table has just a single row, indicating | |
| 275 | -the start and stop time of the simulated data. | |
| 276 | - | |
| 277 | -.. figure:: cntmap-fits.jpg | |
| 278 | - :width: 600px | |
| 279 | - :align: center | |
| 280 | - | |
| 281 | - *Counts cube FITS file* | |
| 282 | - | |
| 283 | - | |
| 284 | -An image of the first bin, covering the energy range 100 - 141 GeV, is | |
| 285 | -shown below: | |
| 286 | - | |
| 287 | -.. figure:: cntmap-map.jpg | |
| 288 | - :height: 400px | |
| 289 | - :align: center | |
| 290 | - | |
| 291 | - *Counts cube for first energy bin* | |
| 292 | - | |
| 293 | - | |
| 294 | -For illustration, the last few lines of the log file ``ctbin.log`` are | |
| 295 | -reproduced below: | |
| 296 | - | |
| 297 | -.. code-block:: xml | |
| 298 | - | |
| 299 | - 2015-05-22T19:40:30: +=================+ | |
| 300 | - 2015-05-22T19:40:30: | Bin observation | | |
| 301 | - 2015-05-22T19:40:30: +=================+ | |
| 302 | - 2015-05-22T19:40:30: === Observation === | |
| 303 | - 2015-05-22T19:40:30: Events in list ............: 15964 | |
| 304 | - 2015-05-22T19:40:30: Events in cube ............: 13360 | |
| 305 | - 2015-05-22T19:40:30: Event bins outside RoI ....: 0 | |
| 306 | - 2015-05-22T19:40:30: Events outside cube area ..: 2604 | |
| 307 | - 2015-05-22T19:40:30: Events outside energy bins : 0 | |
| 308 | - | |
| 309 | -From the 15964 events that have been simulated and stored in the | |
| 310 | -``events.fits`` file, 13360 lie within the cube boundaries and are thus put | |
| 311 | -into the resulting counts cube. The counts cube is stored in a cartesian | |
| 312 | -projection in a World Coordinate System (WCS) compliant format. | |
| 313 | - | |
| 314 | - | |
| 315 | -.. _sec_fitting_cta: | |
| 316 | - | |
| 317 | -Fitting CTA data | |
| 318 | -~~~~~~~~~~~~~~~~ | |
| 319 | - | |
| 320 | -Now we are ready to fit the simulated data with a model. For simplicity | |
| 321 | -we use in this example the same model that we used to simulate the data | |
| 322 | -with :ref:`ctobssim`. Model fitting is done using the :ref:`ctlike` tool, | |
| 323 | -and we do the fit by typing: | |
| 324 | - | |
| 325 | -.. code-block:: bash | |
| 326 | - | |
| 327 | - $ ctlike | |
| 328 | - Event list, counts cube or observation definition file [events.fits] cntcube.fits | |
| 329 | - Exposure cube file (only needed for stacked analysis) [NONE] | |
| 330 | - PSF cube file (only needed for stacked analysis) [NONE] | |
| 331 | - Background cube file (only needed for stacked analysis) [NONE] | |
| 332 | - Calibration database [prod2] | |
| 333 | - Instrument response function [South_50h] | |
| 334 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 335 | - Source model output file [crab_results.xml] | |
| 336 | - | |
| 337 | -The data are fitted in *binned* mode, which means that the events | |
| 338 | -have been binned into a counts cube and the fit computes the log-likelihood | |
| 339 | -function by summing over all 200 x 200 x 20 bins of the counts cube. There is | |
| 340 | -an alternative method, the so called *unbinned* mode, where the events are | |
| 341 | -not binned into a counts cube and the log-likelihood is computed directly by | |
| 342 | -summing over all events. We will explore the *unbinned* mode later. | |
| 343 | - | |
| 344 | -One of the parameters of :ref:`ctlike` is a source model output file | |
| 345 | -(we specified ``crab_results.xml`` in the example), and this file will be | |
| 346 | -a copy of the source model input XML file where the parameter values have | |
| 347 | -been replaced by the fit results. In addition, the statistical uncertainties | |
| 348 | -are added for each fitted parameter using the attribute ``error``. | |
| 349 | -Below we show the XML result file that has been produced by the run: | |
| 350 | - | |
| 351 | -.. code-block:: xml | |
| 352 | - | |
| 353 | - <?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 354 | - <source_library title="source library"> | |
| 355 | - <source name="Crab" type="PointSource"> | |
| 356 | - <spectrum type="PowerLaw"> | |
| 357 | - <parameter name="Prefactor" value="5.78197" error="0.110889" scale="1e-16" min="1e-07" max="1000" free="1" /> | |
| 358 | - <parameter name="Index" value="2.49174" error="0.0164369" scale="-1" min="0" max="5" free="1" /> | |
| 359 | - <parameter name="Scale" value="0.3" scale="1e+06" min="0.01" max="1000" free="0" /> | |
| 360 | - </spectrum> | |
| 361 | - <spatialModel type="SkyDirFunction"> | |
| 362 | - <parameter name="RA" value="83.6331" scale="1" min="-360" max="360" free="0" /> | |
| 363 | - <parameter name="DEC" value="22.0145" scale="1" min="-90" max="90" free="0" /> | |
| 364 | - </spatialModel> | |
| 365 | - </source> | |
| 366 | - <source name="CTABackgroundModel" type="CTAIrfBackground" instrument="CTA"> | |
| 367 | - <spectrum type="PowerLaw"> | |
| 368 | - <parameter name="Prefactor" value="1.02048" error="0.0280684" scale="1" min="0.001" max="1000" free="1" /> | |
| 369 | - <parameter name="Index" value="0.0197856" error="0.0156686" scale="1" min="-5" max="5" free="1" /> | |
| 370 | - <parameter name="Scale" value="1" scale="1e+06" min="0.01" max="1000" free="0" /> | |
| 371 | - </spectrum> | |
| 372 | - </source> | |
| 373 | - </source_library> | |
| 374 | - | |
| 375 | -In this example, the ``Prefactor`` and ``Index`` of the spectral model for the | |
| 376 | -Crab as well as the ``Prefactor`` and ``Index`` of the background spectral | |
| 377 | -model have been fitted (all parameters having the attribute ``free="1"`` are | |
| 378 | -fitted). Now we see also the effect of having multiplied the background | |
| 379 | -model with a power law. In that way, the amplitude of the background as | |
| 380 | -well as it's spectral slope is adjusted by the fit. Obviously, in this | |
| 381 | -example the adjustment compensates only for the statistical fluctuations | |
| 382 | -of the background, but with real data, the adjustment may account also for | |
| 383 | -some of the systematic uncertainties. | |
| 384 | - | |
| 385 | -.. warning:: | |
| 386 | - | |
| 387 | - As good practice, the amplitude of the background model should always be | |
| 388 | - left as a free parameter of the fit. Otherwise, any uncertainty in the | |
| 389 | - background rate will immediately propagate into the flux estimate of the | |
| 390 | - source. | |
| 391 | - | |
| 392 | -To get more details about the model fitting you can inspect the log file. | |
| 393 | -Below the last lines of the ctlike.log log file that has been produced by | |
| 394 | -this run: | |
| 395 | - | |
| 396 | -.. code-block:: xml | |
| 397 | - | |
| 398 | - 2015-05-22T19:45:15: +=================================+ | |
| 399 | - 2015-05-22T19:45:15: | Maximum likelihood optimisation | | |
| 400 | - 2015-05-22T19:45:15: +=================================+ | |
| 401 | - 2015-05-22T19:45:16: >Iteration 0: -logL=39910.748, Lambda=1.0e-03 | |
| 402 | - 2015-05-22T19:45:18: >Iteration 1: -logL=39908.788, Lambda=1.0e-03, delta=1.960, max(|grad|)=6.701856 [Index:7] | |
| 403 | - 2015-05-22T19:45:19: >Iteration 2: -logL=39908.787, Lambda=1.0e-04, delta=0.001, max(|grad|)=-0.057041 [Index:3] | |
| 404 | - 2015-05-22T19:45:21: | |
| 405 | - 2015-05-22T19:45:21: +=========================================+ | |
| 406 | - 2015-05-22T19:45:21: | Maximum likelihood optimization results | | |
| 407 | - 2015-05-22T19:45:21: +=========================================+ | |
| 408 | - 2015-05-22T19:45:21: === GOptimizerLM === | |
| 409 | - 2015-05-22T19:45:21: Optimized function value ..: 39908.787 | |
| 410 | - 2015-05-22T19:45:21: Absolute precision ........: 0.005 | |
| 411 | - 2015-05-22T19:45:21: Acceptable value decrease .: 2 | |
| 412 | - 2015-05-22T19:45:21: Optimization status .......: converged | |
| 413 | - 2015-05-22T19:45:21: Number of parameters ......: 10 | |
| 414 | - 2015-05-22T19:45:21: Number of free parameters .: 4 | |
| 415 | - 2015-05-22T19:45:21: Number of iterations ......: 2 | |
| 416 | - 2015-05-22T19:45:21: Lambda ....................: 1e-05 | |
| 417 | - 2015-05-22T19:45:21: Maximum log likelihood ....: -39908.787 | |
| 418 | - 2015-05-22T19:45:21: Observed events (Nobs) ...: 13360.000 | |
| 419 | - 2015-05-22T19:45:21: Predicted events (Npred) ..: 13359.998 (Nobs - Npred = 0.00180799) | |
| 420 | - 2015-05-22T19:45:21: === GModels === | |
| 421 | - 2015-05-22T19:45:21: Number of models ..........: 2 | |
| 422 | - 2015-05-22T19:45:21: Number of parameters ......: 10 | |
| 423 | - 2015-05-22T19:45:21: === GModelSky === | |
| 424 | - 2015-05-22T19:45:21: Name ......................: Crab | |
| 425 | - 2015-05-22T19:45:21: Instruments ...............: all | |
| 426 | - 2015-05-22T19:45:21: Instrument scale factors ..: unity | |
| 427 | - 2015-05-22T19:45:21: Observation identifiers ...: all | |
| 428 | - 2015-05-22T19:45:21: Model type ................: PointSource | |
| 429 | - 2015-05-22T19:45:21: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 430 | - 2015-05-22T19:45:21: Number of parameters ......: 6 | |
| 431 | - 2015-05-22T19:45:21: Number of spatial par's ...: 2 | |
| 432 | - 2015-05-22T19:45:21: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 433 | - 2015-05-22T19:45:21: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 434 | - 2015-05-22T19:45:21: Number of spectral par's ..: 3 | |
| 435 | - 2015-05-22T19:45:21: Prefactor ................: 5.78197e-16 +/- 1.10889e-17 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 436 | - 2015-05-22T19:45:21: Index ....................: -2.49174 +/- 0.0164369 [-0,-5] (free,scale=-1,gradient) | |
| 437 | - 2015-05-22T19:45:21: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 438 | - 2015-05-22T19:45:21: Number of temporal par's ..: 1 | |
| 439 | - 2015-05-22T19:45:21: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 440 | - 2015-05-22T19:45:21: === GCTAModelIrfBackground === | |
| 441 | - 2015-05-22T19:45:21: Name ......................: CTABackgroundModel | |
| 442 | - 2015-05-22T19:45:21: Instruments ...............: CTA | |
| 443 | - 2015-05-22T19:45:21: Instrument scale factors ..: unity | |
| 444 | - 2015-05-22T19:45:21: Observation identifiers ...: all | |
| 445 | - 2015-05-22T19:45:21: Model type ................: "PowerLaw" * "Constant" | |
| 446 | - 2015-05-22T19:45:21: Number of parameters ......: 4 | |
| 447 | - 2015-05-22T19:45:21: Number of spectral par's ..: 3 | |
| 448 | - 2015-05-22T19:45:21: Prefactor ................: 1.02048 +/- 0.0280684 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 449 | - 2015-05-22T19:45:21: Index ....................: 0.0197856 +/- 0.0156686 [-5,5] (free,scale=1,gradient) | |
| 450 | - 2015-05-22T19:45:21: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 451 | - 2015-05-22T19:45:21: Number of temporal par's ..: 1 | |
| 452 | - 2015-05-22T19:45:21: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 453 | - | |
| 454 | -The maximum likelihood optimizer required 2 iterations to converge. This | |
| 455 | -is pretty fast, but recall that we used the same model file for the simulation | |
| 456 | -and for fitting, hence the initial parameter values were already very close | |
| 457 | -to the best fitting values. To see the impact of the initial parameters on | |
| 458 | -the fit result, you may re-run :ref:`ctlike` using another copy of the model | |
| 459 | -XML file where you change the value attributes of the parameters that should be | |
| 460 | -fitted. You will see that the optimizer requires a couple of more iterations, | |
| 461 | -but it should converge to the same solution (provided that the initial values | |
| 462 | -are not too far from the best fitting values). | |
| 463 | - | |
| 464 | -.. note:: | |
| 465 | - | |
| 466 | - As sanity check you should verify that the predicted number of events | |
| 467 | - (Npred) is equal to the observed number of events (Nobs). To facilitate | |
| 468 | - this comparison, :ref:`ctlike` provides the difference Nobs - Npred in | |
| 469 | - the log file. In real life situations, this difference may not always be | |
| 470 | - small, in particular if the source model is too constrained. You may | |
| 471 | - then free some of the model parameters so that the fit can correctly | |
| 472 | - describe the data. | |
| 473 | - | |
| 474 | -.. note:: | |
| 475 | - | |
| 476 | - The :ref:`ctlike` tool has the ability to estimate the detection | |
| 477 | - significance for sources in the XML model. This is done by computing | |
| 478 | - the Test Statistic value which is defined as twice the log-likelihood | |
| 479 | - difference between fitting a source at a given position on top of a | |
| 480 | - (background) model or fitting no source. Roughly speaken, the square | |
| 481 | - root of the Test Statistic value gives the source detection significance | |
| 482 | - in Gaussian sigmas, although the exact relation depends somewhat on | |
| 483 | - the formulation of the statistical problem. | |
| 484 | - | |
| 485 | - To instruct :ref:`ctlike` to compute the Test Statistic value for a | |
| 486 | - given source you need to add the attribute ``tscalc="1"`` to the XML | |
| 487 | - file: | |
| 488 | - | |
| 489 | - .. code-block:: xml | |
| 490 | - | |
| 491 | - <source name="Crab" type="PointSource" tscalc="1"> | |
| 492 | - | |
| 493 | - :ref:`ctlike` will then compute the Test Statistic value for that | |
| 494 | - source and dump the result in the log file: | |
| 495 | - | |
| 496 | - .. code-block:: xml | |
| 497 | - | |
| 498 | - 2015-05-22T19:58:43: === GModelSky === | |
| 499 | - 2015-05-22T19:58:43: Name ......................: Crab | |
| 500 | - 2015-05-22T19:58:43: Instruments ...............: all | |
| 501 | - 2015-05-22T19:58:43: Test Statistic ............: 18662.6 | |
| 502 | - | |
| 503 | - The Test Statistic value will also be added as new attribute | |
| 504 | - ``ts`` to the XML result file: | |
| 505 | - | |
| 506 | - .. code-block:: xml | |
| 507 | - | |
| 508 | - <source name="Crab" type="PointSource" ts="18662.576" tscalc="1"> | |
| 509 | - | |
| 510 | - | |
| 511 | -.. _sec_unbinned_cta: | |
| 512 | - | |
| 513 | -Doing an unbinned analysis | |
| 514 | -~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 515 | - | |
| 516 | -As gamma-ray events are rare, the counts cubes generated by :ref:`ctbin` | |
| 517 | -will in general be sparsly populated, having many empty pixels, in | |
| 518 | -particular at high energies. | |
| 519 | -An alternative analysis technique consists of working directly on the event | |
| 520 | -list without binning the events in a counts cube. We will see the benefit of | |
| 521 | -such an analysis later once you re-run :ref:`ctlike` in unbinned mode. | |
| 522 | - | |
| 523 | -For unbinned analysis you first have to define the data space region over | |
| 524 | -which the analysis is done. This is similiar to the :ref:`ctbin` step for | |
| 525 | -a binned analysis where you defined the size of the counts cube, the energy | |
| 526 | -range, and the time interval. For unbinned analysis you have no such thing | |
| 527 | -as a counts cube, but you have to define over which region of the data space | |
| 528 | -the selected events are spread (because the ctools have to integrate over | |
| 529 | -this region to compute the total number of predicted events in the data space | |
| 530 | -that you analyse). Furthermore, you have to define what energy range is | |
| 531 | -covered, and what time interval is spanned by the data. All this is done | |
| 532 | -by the :ref:`ctselect` tool, which replaces the :ref:`ctbin` step in an | |
| 533 | -unbinned analysis. | |
| 534 | - | |
| 535 | -:ref:`ctselect` performs an event selection by choosing only events within | |
| 536 | -a given region-of-interest (ROI), within a given energy band, and within a | |
| 537 | -given time interval from the input event list. The ROI is a circular region on | |
| 538 | -the sky, for which you define the centre (in celestial coordinates) and the | |
| 539 | -radius. Such a circular ROI is sometimes also called an acceptance cone. The | |
| 540 | -following example shows how to run ctselect: | |
| 541 | - | |
| 542 | -.. code-block:: bash | |
| 543 | - | |
| 544 | - $ ctselect | |
| 545 | - Input event list or observation definition file [events.fits] | |
| 546 | - RA for ROI centre (degrees) (0-360) [83.63] | |
| 547 | - Dec for ROI centre (degrees) (-90-90) [22.01] | |
| 548 | - Radius of ROI (degrees) (0-180) [3.0] | |
| 549 | - Start time (CTA MET in seconds) [0.0] | |
| 550 | - End time (CTA MET in seconds) [0.0] | |
| 551 | - Lower energy limit (TeV) [0.1] | |
| 552 | - Upper energy limit (TeV) [100.0] | |
| 553 | - Output event list or observation definition file [selected_events.fits] | |
| 554 | - | |
| 555 | -:ref:`ctselect` takes the input event list ``events.fits``, performs an | |
| 556 | -event selection, and writes the selected event into the file | |
| 557 | -``selected_events.fits``. The parameters it will query for are the centre | |
| 558 | -of the ROI, the radius of the ROI, the start and stop time (in seconds), | |
| 559 | -and the energy lower and upper limits (in TeV). The event selection information | |
| 560 | -is also written as a set of data selection keywords to the output events | |
| 561 | -file ``selected_events.fits``, by respecting the same syntax that has been | |
| 562 | -implemented for Fermi/LAT. The following image is a screen dump of the data | |
| 563 | -selection keywords that have been written to the ``EVENTS`` header in the | |
| 564 | -file ``selected_events.fits``: | |
| 565 | - | |
| 566 | -.. figure:: dskeys.jpg | |
| 567 | - :width: 400px | |
| 568 | - :align: center | |
| 569 | - | |
| 570 | - *Data selection keywords* | |
| 571 | - | |
| 572 | -**It is mandatory for an unbinned analysis that these data selection keywords | |
| 573 | -exist in the FITS file.** | |
| 574 | -If they don't exist, :ref:`ctlike` will not execute in unbinned mode. | |
| 575 | - | |
| 576 | -Below some lines of the ``ctselect.log`` file that show the data selection | |
| 577 | -part: | |
| 578 | - | |
| 579 | -.. code-block:: xml | |
| 580 | - | |
| 581 | - 2015-05-22T20:01:46: +=================+ | |
| 582 | - 2015-05-22T20:01:46: | Event selection | | |
| 583 | - 2015-05-22T20:01:46: +=================+ | |
| 584 | - 2015-05-22T20:01:46: === Observation === | |
| 585 | - 2015-05-22T20:01:47: Selected energy range .....: 0.1 - 100 TeV | |
| 586 | - 2015-05-22T20:01:47: Requested ROI .............: Centre(RA,DEC)=(83.63, 22.01) deg, Radius=3 deg | |
| 587 | - 2015-05-22T20:01:47: ROI of data ...............: Centre(RA,DEC)=(83.63, 22.01) deg, Radius=5 deg | |
| 588 | - 2015-05-22T20:01:47: Selected ROI ..............: Centre(RA,DEC)=(83.63, 22.01) deg, Radius=3 deg | |
| 589 | - 2015-05-22T20:01:47: cfitsio selection .........: ENERGY >= 0.10000000 && ENERGY <= 100.00000000 && ANGSEP(83.630000,22.010000,RA,DEC) <= 3.000000 | |
| 590 | - 2015-05-22T20:01:47: FITS filename .............: /var/tmp/tmp.0.rRgLpO[EVENTS][ENERGY >= 0.10000000 && ENERGY <= 100.00000000 && ANGSEP(83.630000,22.010000,RA,DEC) <= 3.000000] | |
| 591 | - | |
| 592 | -.. note:: | |
| 593 | - | |
| 594 | - :ref:`ctobssim` will also write data selection keywords in the event | |
| 595 | - list FITS file, hence you can run :ref:`ctlike` directly on a FITS file | |
| 596 | - produced by :ref:`ctobssim`. Any selection performed by :ref:`ctselect` | |
| 597 | - needs to be fully enclosed within any previous selection, e.g. the ROI | |
| 598 | - needs to be fully enclosed in the acceptance cone used for event | |
| 599 | - simulation, the energy selection must be fully comprised in the | |
| 600 | - range of simulated energies, the same applies for the temporal selection. | |
| 601 | - :ref:`ctselect` will automatically adjust | |
| 602 | - the selection parameters to guarantee full enclosure. To keep track of | |
| 603 | - this adjustment, the :ref:`ctselect` log file quotes the requested | |
| 604 | - selection, any existing selections, and the selection that was finally | |
| 605 | - applied. | |
| 606 | - | |
| 607 | -.. warning:: | |
| 608 | - | |
| 609 | - :ref:`ctselect` may of course also be used for event selection prior to | |
| 610 | - binned analysis, for example to select events for a given period in | |
| 611 | - time. **If you use** :ref:`ctselect` **however to make a spatial or energy | |
| 612 | - selection, make sure that the counts cube is fully enclosed in the | |
| 613 | - selection intervals.** Otherwise you will get empty zones in the counts | |
| 614 | - cube of which the ctools are not aware of, and the subsequent analysis | |
| 615 | - results will be wrong. | |
| 616 | - | |
| 617 | -Now that you have selected the events of interest, you can run ctlike in | |
| 618 | -unbinned mode. To do this you have to specify the selected event list | |
| 619 | -instead of the counts cube: | |
| 620 | - | |
| 621 | -.. code-block:: bash | |
| 622 | - | |
| 623 | - $ ctlike | |
| 624 | - Event list, counts cube or observation definition file [cntcube.fits] selected_events.fits | |
| 625 | - Calibration database [prod2] | |
| 626 | - Instrument response function [South_50h] | |
| 627 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 628 | - Source model output file [crab_results.xml] | |
| 629 | - | |
| 630 | -You will recognise that :ref:`ctlike` runs much faster in unbinned mode | |
| 631 | -compared to binned mode. | |
| 632 | -This is understandable as the selected event list contains | |
| 633 | -only 15312 events, while the binned counts cube we used before had | |
| 634 | -200 x 200 x 20 = 800000 pixels. As unbinned maximum likelihood fitting loops | |
| 635 | -over the events (while binned maximum likelihood loops over the pixels), | |
| 636 | -there are much less operations to perform in unbinned than in binned mode | |
| 637 | -(there is some additional overhead in unbinned mode that comes from | |
| 638 | -integrating the models over the region of interest, yet this is negligible | |
| 639 | -compared to the operations needed when looping over all pixels). So as long | |
| 640 | -as you work with small event lists, unbinned mode is faster (this | |
| 641 | -typically holds up to 100 hours of observing time). | |
| 642 | -Unbinned :ref:`ctlike` should also be more precise as no binning is performed, | |
| 643 | -hence there is no loss of information due to histogramming. | |
| 644 | - | |
| 645 | -Below you see the corresponding output from the ctlike.log file. The fitted | |
| 646 | -parameters are essentially identical to the ones found in binned mode. | |
| 647 | -The slight difference with respect to the binned analysis may be explained | |
| 648 | -by the different event sample that has been used for the analysis: while | |
| 649 | -binned likelihood works on rectangular counts cubes, unbinned likelihood works | |
| 650 | -on circular event selection regions. It is thus not possible to select exactly | |
| 651 | -the same events for both analyses. | |
| 652 | - | |
| 653 | -.. code-block:: xml | |
| 654 | - | |
| 655 | - 2015-05-22T20:05:54: +=================================+ | |
| 656 | - 2015-05-22T20:05:54: | Maximum likelihood optimisation | | |
| 657 | - 2015-05-22T20:05:54: +=================================+ | |
| 658 | - 2015-05-22T20:05:54: >Iteration 0: -logL=93854.543, Lambda=1.0e-03 | |
| 659 | - 2015-05-22T20:05:54: >Iteration 1: -logL=93848.595, Lambda=1.0e-03, delta=5.948, max(|grad|)=22.480581 [Index:7] | |
| 660 | - 2015-05-22T20:05:54: >Iteration 2: -logL=93848.587, Lambda=1.0e-04, delta=0.008, max(|grad|)=-0.081846 [Index:3] | |
| 661 | - 2015-05-22T20:05:54: >Iteration 3: -logL=93848.587, Lambda=1.0e-05, delta=0.000, max(|grad|)=-0.003485 [Index:3] | |
| 662 | - 2015-05-22T20:05:54: | |
| 663 | - 2015-05-22T20:05:54: +=========================================+ | |
| 664 | - 2015-05-22T20:05:54: | Maximum likelihood optimization results | | |
| 665 | - 2015-05-22T20:05:54: +=========================================+ | |
| 666 | - 2015-05-22T20:05:54: === GOptimizerLM === | |
| 667 | - 2015-05-22T20:05:54: Optimized function value ..: 93848.587 | |
| 668 | - 2015-05-22T20:05:54: Absolute precision ........: 0.005 | |
| 669 | - 2015-05-22T20:05:54: Acceptable value decrease .: 2 | |
| 670 | - 2015-05-22T20:05:54: Optimization status .......: converged | |
| 671 | - 2015-05-22T20:05:54: Number of parameters ......: 10 | |
| 672 | - 2015-05-22T20:05:54: Number of free parameters .: 4 | |
| 673 | - 2015-05-22T20:05:54: Number of iterations ......: 3 | |
| 674 | - 2015-05-22T20:05:54: Lambda ....................: 1e-06 | |
| 675 | - 2015-05-22T20:05:54: Maximum log likelihood ....: -93848.587 | |
| 676 | - 2015-05-22T20:05:54: Observed events (Nobs) ...: 15312.000 | |
| 677 | - 2015-05-22T20:05:54: Predicted events (Npred) ..: 15312.000 (Nobs - Npred = 3.03823e-06) | |
| 678 | - 2015-05-22T20:05:54: === GModels === | |
| 679 | - 2015-05-22T20:05:54: Number of models ..........: 2 | |
| 680 | - 2015-05-22T20:05:54: Number of parameters ......: 10 | |
| 681 | - 2015-05-22T20:05:54: === GModelSky === | |
| 682 | - 2015-05-22T20:05:54: Name ......................: Crab | |
| 683 | - 2015-05-22T20:05:54: Instruments ...............: all | |
| 684 | - 2015-05-22T20:05:54: Instrument scale factors ..: unity | |
| 685 | - 2015-05-22T20:05:54: Observation identifiers ...: all | |
| 686 | - 2015-05-22T20:05:54: Model type ................: PointSource | |
| 687 | - 2015-05-22T20:05:54: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 688 | - 2015-05-22T20:05:54: Number of parameters ......: 6 | |
| 689 | - 2015-05-22T20:05:54: Number of spatial par's ...: 2 | |
| 690 | - 2015-05-22T20:05:54: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 691 | - 2015-05-22T20:05:54: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 692 | - 2015-05-22T20:05:54: Number of spectral par's ..: 3 | |
| 693 | - 2015-05-22T20:05:54: Prefactor ................: 5.80619e-16 +/- 1.11149e-17 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 694 | - 2015-05-22T20:05:54: Index ....................: -2.49282 +/- 0.0163467 [-0,-5] (free,scale=-1,gradient) | |
| 695 | - 2015-05-22T20:05:54: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 696 | - 2015-05-22T20:05:54: Number of temporal par's ..: 1 | |
| 697 | - 2015-05-22T20:05:54: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 698 | - 2015-05-22T20:05:54: === GCTAModelIrfBackground === | |
| 699 | - 2015-05-22T20:05:54: Name ......................: CTABackgroundModel | |
| 700 | - 2015-05-22T20:05:54: Instruments ...............: CTA | |
| 701 | - 2015-05-22T20:05:54: Instrument scale factors ..: unity | |
| 702 | - 2015-05-22T20:05:54: Observation identifiers ...: all | |
| 703 | - 2015-05-22T20:05:54: Model type ................: "PowerLaw" * "Constant" | |
| 704 | - 2015-05-22T20:05:54: Number of parameters ......: 4 | |
| 705 | - 2015-05-22T20:05:54: Number of spectral par's ..: 3 | |
| 706 | - 2015-05-22T20:05:54: Prefactor ................: 1.03511 +/- 0.024311 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 707 | - 2015-05-22T20:05:54: Index ....................: 0.0333176 +/- 0.0134386 [-5,5] (free,scale=1,gradient) | |
| 708 | - 2015-05-22T20:05:54: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 709 | - 2015-05-22T20:05:54: Number of temporal par's ..: 1 | |
| 710 | - 2015-05-22T20:05:54: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 711 | - | |
| 712 | - | |
| 713 | -.. _sec_butterfly_cta: | |
| 714 | - | |
| 715 | -Calculating and visualising a butterfly | |
| 716 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 717 | - | |
| 718 | -To visualise the analysis results retrieved above, one can calculate the | |
| 719 | -confidence band of the spectral fit. | |
| 720 | -The :ref:`ctbutterfly` tool takes the optimised source model as input. | |
| 721 | -It takes the covariance matrix from the fit to conduct a | |
| 722 | -Gaussian error propagation for each energy value. It will write the | |
| 723 | -butterfly information into an ASCII file. | |
| 724 | -The following example shows how to compute such a butterfly from the command | |
| 725 | -line. | |
| 726 | - | |
| 727 | -.. code-block:: bash | |
| 728 | - | |
| 729 | - $ ctbutterfly | |
| 730 | - Input event list, counts cube or observation definition file [events.fits] | |
| 731 | - Calibration database [prod2] | |
| 732 | - Instrument response function [South_50h] | |
| 733 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 734 | - Source of interest [Crab] | |
| 735 | - Start value for first energy bin in TeV [0.1] | |
| 736 | - Stop value for last energy bin in TeV [100.0] | |
| 737 | - Output ascii file [butterfly.txt] | |
| 738 | - | |
| 739 | -Now that you have computed the confidence band of the spectral fit and | |
| 740 | -that you will have an ASCII file named ``butterfly.txt`` on disk you can | |
| 741 | -visualise the butterfly using the script ``show_butterfly.py`` that is | |
| 742 | -in the ctools ``example`` folder. You will need matplotlib on your system | |
| 743 | -to make this work. To launch the script, type: | |
| 744 | - | |
| 745 | -.. code-block:: bash | |
| 746 | - | |
| 747 | - python $CTOOLS/share/examples/python/show_butterfly.py butterfly.txt | |
| 748 | - | |
| 749 | -This will result in a canvas which should look like the following: | |
| 750 | - | |
| 751 | -.. figure:: butterfly.jpg | |
| 752 | - :height: 400px | |
| 753 | - :align: center | |
| 4 | +----------------------- | |
| 754 | 5 | |
| 755 | - *Confidence band of the fit* | |
| 756 | - | |
| 757 | 6 | \ No newline at end of file |
| 7 | +This section provides a step-by-step description of a simple CTA data | |
| 8 | +analysis example using the ctools. In this example we will simulate a | |
| 9 | +half an hour long CTA observation of the Crab nebula as the single | |
| 10 | +point source within the CTA field of view. You will learn how to bin the | |
| 11 | +event data into a counts cube and how to fit a spatial and spectral model | |
| 12 | +to the data. You will also learn how to analyse directly event lists | |
| 13 | +without binning the events into a counts cube. Finally we will show how | |
| 14 | +you can create a butterfly diagram that shows the confidence band of the | |
| 15 | +fitted spectral model. | |
| 16 | + | |
| 17 | +.. toctree:: | |
| 18 | + :maxdepth: 2 | |
| 19 | + | |
| 20 | + simulating | |
| 21 | + binning | |
| 22 | + fitting | |
| 23 | + unbinned | |
| 24 | + butterfly | ... | ... |
doc/source/user_manual/getting_started/resmap-crab.png
doc/source/user_manual/getting_started/response.rst
| ... | ... | @@ -99,7 +99,7 @@ Specifying the response function as input parameters |
| 99 | 99 | ctools that require instrument response functions have two parameters |
| 100 | 100 | to specify the calibration database name and the response function name. |
| 101 | 101 | The following example shows a ``ctobssim`` run using the ``prod2`` |
| 102 | -calibration database and the ``South_50h`` response function: | |
| 102 | +calibration database and the ``South_0.5h`` response function: | |
| 103 | 103 | |
| 104 | 104 | .. code-block:: bash |
| 105 | 105 | |
| ... | ... | @@ -112,8 +112,9 @@ calibration database and the ``South_50h`` response function: |
| 112 | 112 | Lower energy limit (TeV) [0.1] |
| 113 | 113 | Upper energy limit (TeV) [100.0] |
| 114 | 114 | Calibration database [prod2] |
| 115 | - Instrument response function [South_50h] | |
| 116 | - Model [$CTOOLS/share/models/crab.xml] | |
| 115 | + Instrument response function [South_0.5h] | |
| 116 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 117 | + Output event data file or observation definition XML file [events.fits] | |
| 117 | 118 | |
| 118 | 119 | Running the other tools is equivalent. |
| 119 | 120 | |
| ... | ... | @@ -131,7 +132,7 @@ definition file: |
| 131 | 132 | <observation_list title="observation library"> |
| 132 | 133 | <observation name="Crab" id="00001" instrument="CTA"> |
| 133 | 134 | <parameter name="EventList" file="events.fits"/> |
| 134 | - <parameter name="Calibration" database="prod2" response="South_50h"/> | |
| 135 | + <parameter name="Calibration" database="prod2" response="South_0.5h"/> | |
| 135 | 136 | </observation> |
| 136 | 137 | </observation_list> |
| 137 | 138 | |
| ... | ... | @@ -141,9 +142,9 @@ response name. You can then pass this file directly to, e.g., ``ctlike``: |
| 141 | 142 | .. code-block:: bash |
| 142 | 143 | |
| 143 | 144 | $ ctlike |
| 144 | - Event list, counts cube or observation definition file [events.fits] obs_irf.xml | |
| 145 | - Source model [$CTOOLS/share/models/crab.xml] | |
| 146 | - Source model output file [crab_results.xml] | |
| 145 | + Input event list, counts cube or observation definition XML file [events.fits] obs_irf.xml | |
| 146 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 147 | + Output model XML file [crab_results.xml] | |
| 147 | 148 | |
| 148 | 149 | Note that ``ctlike`` does not ask for the calibration database and |
| 149 | 150 | response name as it found the relevant information in the XML file. |
| ... | ... | @@ -181,11 +182,11 @@ and response name from within Python: |
| 181 | 182 | import gammalib |
| 182 | 183 | obs = gammalib.GCTAObservation() |
| 183 | 184 | caldb = gammalib.GCaldb("cta", "prod2") |
| 184 | - irf = "South_50h" | |
| 185 | + irf = "South_0.5h" | |
| 185 | 186 | obs.response(irf, caldb) |
| 186 | 187 | |
| 187 | 188 | The calibration database is set by creating a ``GCaldb`` object. The |
| 188 | 189 | constructor takes as argument the mission (always ``cta``) and the |
| 189 | 190 | database name, in our case ``prod2``. The response function is then set |
| 190 | -by passing the response name (here ``South_50h``) and the calibration | |
| 191 | +by passing the response name (here ``South_0.5h``) and the calibration | |
| 191 | 192 | database object to the ``response`` method. | ... | ... |
doc/source/user_manual/getting_started/simulating.rst
0 → 100644
| 1 | +.. _sec_simulating_cta: | |
| 2 | + | |
| 3 | +Simulating CTA data | |
| 4 | +~~~~~~~~~~~~~~~~~~~ | |
| 5 | + | |
| 6 | +You can simulate a CTA observation with the :ref:`ctobssim` tool. | |
| 7 | + | |
| 8 | +To invoke the tool, type :ref:`ctobssim` at the console prompt | |
| 9 | +(which is denoted by ``$``). | |
| 10 | +:ref:`ctobssim` will query for a number of parameters: | |
| 11 | + | |
| 12 | +.. code-block:: bash | |
| 13 | + | |
| 14 | + $ ctobssim | |
| 15 | + RA of pointing (degrees) (0-360) [83.63] | |
| 16 | + Dec of pointing (degrees) (-90-90) [22.01] | |
| 17 | + Radius of FOV (degrees) (0-180) [5.0] | |
| 18 | + Start time (MET in s) [0.0] | |
| 19 | + End time (MET in s) [1800.0] | |
| 20 | + Lower energy limit (TeV) [0.1] | |
| 21 | + Upper energy limit (TeV) [100.0] | |
| 22 | + Calibration database [prod2] | |
| 23 | + Instrument response function [South_0.5h] | |
| 24 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 25 | + Output event data file or observation definition XML file [events.fits] | |
| 26 | + | |
| 27 | +Each line represents a query for one parameter value. | |
| 28 | +The line starts with a short description of the parameter, followed by | |
| 29 | +the default value proposed by ctobssim in squared brackets ``[ ]``. | |
| 30 | + | |
| 31 | +**If no parameter is entered the default value will be used** | |
| 32 | +(which is the case for all parameters shown here). | |
| 33 | +Otherwise, the specified value will overwrite the default value. | |
| 34 | +The round brackets ``( )`` indicate the range of possible parameter | |
| 35 | +values (if applicable). | |
| 36 | + | |
| 37 | + | |
| 38 | +You may have recognised that the environment variable ``$CTOOLS`` has | |
| 39 | +been used in the path name of the model. ctools will automatically expand | |
| 40 | +the environment variables in parameter inputs. | |
| 41 | + | |
| 42 | +The CTA instrument properties (effective area, PSF width) are taken from | |
| 43 | +the prod2 database. The response for the southern array using the cuts | |
| 44 | +optimised for 50 hours of observing time are used. | |
| 45 | + | |
| 46 | +.. note:: | |
| 47 | + | |
| 48 | + ctools comes bundled with CTA response functions for the northern and | |
| 49 | + the southern array. The response functions are based on a Prod2 | |
| 50 | + analysis with cuts optimised for 0.5 hours, 5 hours and 50 hours of | |
| 51 | + observing time. The following Instrument Response Functions | |
| 52 | + (IRFs) are available: ``North_0.5h``, ``North_5h``, ``North_50h``, | |
| 53 | + ``South_0.5h``, ``South_5h``, and ``South_50h``. | |
| 54 | + | |
| 55 | +Events are simulated based on the instrument properties and based on a | |
| 56 | +source and background model. Only events that fall within the specified | |
| 57 | +region of interest (ROI), defined as a circle around a sky position in | |
| 58 | +Right Ascension and Declination (in degrees), will be stored in the output | |
| 59 | +event data file. The duration of the simulation is taken here to 30 minutes | |
| 60 | +(or 1800 seconds). Events are simulated for energies between 0.1 and 100 TeV. | |
| 61 | + | |
| 62 | +The source and background model is defined by the XML file | |
| 63 | +``$CTOOLS/share/models/crab.xml``: | |
| 64 | + | |
| 65 | +.. code-block:: xml | |
| 66 | + | |
| 67 | + <?xml version="1.0" standalone="no"?> | |
| 68 | + <source_library title="source library"> | |
| 69 | + <source name="Crab" type="PointSource"> | |
| 70 | + <spectrum type="PowerLaw"> | |
| 71 | + <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/> | |
| 72 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | |
| 73 | + <parameter name="Scale" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | |
| 74 | + </spectrum> | |
| 75 | + <spatialModel type="SkyDirFunction"> | |
| 76 | + <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="0"/> | |
| 77 | + <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="0"/> | |
| 78 | + </spatialModel> | |
| 79 | + </source> | |
| 80 | + <source name="CTABackgroundModel" type="CTAIrfBackground" instrument="CTA"> | |
| 81 | + <spectrum type="PowerLaw"> | |
| 82 | + <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e+3" free="1"/> | |
| 83 | + <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/> | |
| 84 | + <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/> | |
| 85 | + </spectrum> | |
| 86 | + </source> | |
| 87 | + </source_library> | |
| 88 | + | |
| 89 | +The model consists of a source library that contains two components: | |
| 90 | +the Crab nebula and an instrumental background model. | |
| 91 | + | |
| 92 | +The Crab nebula is modelled by a factorized sky model that has a spectral | |
| 93 | +and a spatial component (tags ``<spectrum>`` and ``<spatialModel>``, | |
| 94 | +respectively). The spectrum is modelled by a power law, which is defined by | |
| 95 | +three parameters: the ``Prefactor``, the ``Index`` and the ``Scale``. | |
| 96 | +The spatial model has two parameters: Right Ascension in degrees (``RA``), and | |
| 97 | +Declination in degrees (``DEC``). Each parameter has a value and a scale factor, | |
| 98 | +the real value of the parameter being the product ``value * scale``. Typically, | |
| 99 | +``scale`` is chosen so that ``value`` is of the order of 1 (this is relevant for | |
| 100 | +model fitting). In addition, ``value`` is bound by a minimum (``min``) and | |
| 101 | +maximum (``max``) value, and a parameter may be free (``free="1"``) or fixed | |
| 102 | +(``free="0"``). The ``min``, ``max``, and ``free`` attributes are not | |
| 103 | +relevant here for the simulations, but they will be important for the model | |
| 104 | +fitting later. | |
| 105 | + | |
| 106 | +The spectral intensity I(E) (in units of photons/cm2/s/MeV) of the power | |
| 107 | +law is given by | |
| 108 | + | |
| 109 | +.. math:: | |
| 110 | + \frac{dN}{dE} = N_0 \left( \frac{E}{E_0} \right)^{\gamma} | |
| 111 | + | |
| 112 | +where the parameters in the XML definition have the following mappings: | |
| 113 | + | |
| 114 | +* :math:`N_0` = ``Prefactor`` | |
| 115 | +* :math:`\gamma` = ``Index`` | |
| 116 | +* :math:`E_0` = ``Scale`` | |
| 117 | + | |
| 118 | +.. warning:: | |
| 119 | + | |
| 120 | + Energies are given in the XML file in MeV units. This is a GammaLib | |
| 121 | + convention that can not be modified. **So make sure you always use | |
| 122 | + MeV as energy unit in an XML file.** | |
| 123 | + | |
| 124 | +The instrumental background of CTA is modelled using the background | |
| 125 | +information provided in the IRF (``CTAIrfBackground``) multipled | |
| 126 | +by a power law. As it is defined here, the power law represents a | |
| 127 | +constant of 1, hence the background IRF will be used without any | |
| 128 | +modification. The power law will become active when fitting the data | |
| 129 | +later and allows a spectral adjustment of the background model that | |
| 130 | +may account for uncertainties in the background information provided | |
| 131 | +in the IRF. | |
| 132 | + | |
| 133 | +:ref:`ctobssim` has a couple of hidden parameters, the most important one being | |
| 134 | +certainly ``seed``. ``seed`` is an integer that specifies the seed value | |
| 135 | +for the random number generator, and changing this parameter will allow to | |
| 136 | +generate statistically independent Monte Carlo samples of CTA event data. | |
| 137 | +To use for example a seed value of 41 you should type: | |
| 138 | + | |
| 139 | +.. code-block:: bash | |
| 140 | + | |
| 141 | + $ ctobssim seed=41 | |
| 142 | + | |
| 143 | +:ref:`ctobssim` will write 2 files in the working directory: ``events.fits`` | |
| 144 | +and ``ctobssim.log``. The first file contains the simulated events in FITS | |
| 145 | +format and can be inspected using ``fv`` or ``ds9``. The FITS file will | |
| 146 | +contain three extensions: an empty primary image, a binary table named | |
| 147 | +``EVENTS`` that holds the events (one row per event), and a binary table | |
| 148 | +named ``GTI`` holding the Good Time Intervals (for the moment a single row | |
| 149 | +with 2 columns providing the start and the stop time of the simulated time | |
| 150 | +interval). | |
| 151 | + | |
| 152 | +The second file produced by :ref:`ctobssim` is a human readable log file that | |
| 153 | +contains information about the job execution. As example, the last lines | |
| 154 | +from this file are shown here: | |
| 155 | + | |
| 156 | +.. code-block:: xml | |
| 157 | + | |
| 158 | + 2015-12-07T20:48:30: +======================+ | |
| 159 | + 2015-12-07T20:48:30: | Simulate observation | | |
| 160 | + 2015-12-07T20:48:30: +======================+ | |
| 161 | + 2015-12-07T20:48:30: === CTA observation === | |
| 162 | + 2015-12-07T20:48:30: Simulation area ...........: 1.9635e+11 cm2 | |
| 163 | + 2015-12-07T20:48:30: Simulation cone ...........: RA=83.63 deg, Dec=22.01 deg, r=5.5 deg | |
| 164 | + 2015-12-07T20:48:30: Time interval .............: 0 - 1800 s | |
| 165 | + 2015-12-07T20:48:30: Photon energy range .......: 100 GeV - 100 TeV | |
| 166 | + 2015-12-07T20:48:30: Event energy range ........: 100 GeV - 100 TeV | |
| 167 | + 2015-12-07T20:48:30: Use model .................: Crab | |
| 168 | + 2015-12-07T20:48:30: Normalization .............: 1 [Crab] | |
| 169 | + 2015-12-07T20:48:30: Flux ......................: 5.87297e-10 [Crab] photons/cm2/s | |
| 170 | + 2015-12-07T20:48:30: Normalized flux ...........: 5.87297e-10 [Crab] photons/cm2/s | |
| 171 | + 2015-12-07T20:48:30: Photon rate ...............: 115.316 photons/s [Crab] | |
| 172 | + 2015-12-07T20:48:31: MC source photons .........: 207547 [Crab] | |
| 173 | + 2015-12-07T20:48:31: MC source events ..........: 3646 [Crab] | |
| 174 | + 2015-12-07T20:48:31: MC source events ..........: 3646 (all source models) | |
| 175 | + 2015-12-07T20:48:33: MC events outside ROI .....: 0 | |
| 176 | + 2015-12-07T20:48:33: MC background events ......: 19039 | |
| 177 | + 2015-12-07T20:48:33: MC events .................: 22685 (all models) | |
| 178 | + | |
| 179 | +Each line starts with the UTC time at which the line has been written. In | |
| 180 | +this run, 207547 Crab photons have been thrown over an area of 19.6 square | |
| 181 | +kilometres during a time interval of 1800 seconds. 3646 of these photons have | |
| 182 | +been registered by CTA as events. In the same time interval, 19039 background | |
| 183 | +events have been registred by CTA. | |
| 184 | + | |
| 185 | +You may change the name of the log file using the hidden parameter | |
| 186 | +``logfile``: | |
| 187 | + | |
| 188 | +.. code-block:: bash | |
| 189 | + | |
| 190 | + $ ctobssim logfile=my-private-log-file | |
| 191 | + | |
| 192 | +Furthermore, you may decide on the amount of information provided in the | |
| 193 | +log file (the chattiness of the executable) using the hidden parameter | |
| 194 | +``chatter``: | |
| 195 | + | |
| 196 | +.. code-block:: bash | |
| 197 | + | |
| 198 | + $ ctobssim chatter=4 | |
| 199 | + | |
| 200 | +``chatter`` can vary between 0 and 4, 0 providing no information while 4 | |
| 201 | +provides the most detailed information. | |
| 202 | + | |
| 203 | +**By default, all ctools have a chatter level of 2.** | |
| 204 | + | |
| 205 | +You may also duplicate the log file information into the console by setting | |
| 206 | +the hidden ``debug`` parameter to yes: | |
| 207 | + | |
| 208 | +.. code-block:: bash | |
| 209 | + | |
| 210 | + $ ctobssim debug=yes | ... | ... |
doc/source/user_manual/getting_started/tsmap-crab.png
doc/source/user_manual/getting_started/unbinned.rst
0 → 100644
| 1 | +.. _sec_unbinned_cta: | |
| 2 | + | |
| 3 | +Doing an unbinned analysis | |
| 4 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 5 | + | |
| 6 | +As gamma-ray events are rare, the counts cubes generated by :ref:`ctbin` | |
| 7 | +will in general be sparsly populated, having many empty pixels, in | |
| 8 | +particular at high energies. | |
| 9 | +An alternative analysis technique consists of working directly on the event | |
| 10 | +list without binning the events in a counts cube. We will see the benefit of | |
| 11 | +such an analysis later once you re-run :ref:`ctlike` in unbinned mode. | |
| 12 | + | |
| 13 | +For unbinned analysis you first have to define the data space region over | |
| 14 | +which the analysis is done. This is similiar to the :ref:`ctbin` step for | |
| 15 | +a binned analysis where you defined the size of the counts cube, the energy | |
| 16 | +range, and the time interval. For unbinned analysis you have no such thing | |
| 17 | +as a counts cube, but you have to define over which region of the data space | |
| 18 | +the selected events are spread (because the ctools have to integrate over | |
| 19 | +this region to compute the total number of predicted events in the data space | |
| 20 | +that you analyse). Furthermore, you have to define what energy range is | |
| 21 | +covered, and what time interval is spanned by the data. All this is done | |
| 22 | +by the :ref:`ctselect` tool, which replaces the :ref:`ctbin` step in an | |
| 23 | +unbinned analysis. | |
| 24 | + | |
| 25 | +:ref:`ctselect` performs an event selection by choosing only events within | |
| 26 | +a given region-of-interest (ROI), within a given energy band, and within a | |
| 27 | +given time interval from the input event list. The ROI is a circular region on | |
| 28 | +the sky, for which you define the centre (in celestial coordinates) and the | |
| 29 | +radius. Such a circular ROI is sometimes also called an acceptance cone. The | |
| 30 | +following example shows how to run ctselect: | |
| 31 | + | |
| 32 | +.. code-block:: bash | |
| 33 | + | |
| 34 | + $ ctselect | |
| 35 | + Input event list or observation definition XML file [events.fits] | |
| 36 | + RA for ROI centre (degrees) (0-360) [83.63] | |
| 37 | + Dec for ROI centre (degrees) (-90-90) [22.01] | |
| 38 | + Radius of ROI (degrees) (0-180) [3.0] | |
| 39 | + Start time (CTA MET in seconds) [0.0] | |
| 40 | + End time (CTA MET in seconds) [0.0] | |
| 41 | + Lower energy limit (TeV) [0.1] | |
| 42 | + Upper energy limit (TeV) [100.0] | |
| 43 | + Output event list or observation definition XML file [selected_events.fits] | |
| 44 | + | |
| 45 | +:ref:`ctselect` takes the input event list ``events.fits``, performs an | |
| 46 | +event selection, and writes the selected event into the file | |
| 47 | +``selected_events.fits``. The parameters it will query for are the centre | |
| 48 | +of the ROI, the radius of the ROI, the start and stop time (in seconds), | |
| 49 | +and the energy lower and upper limits (in TeV). The event selection information | |
| 50 | +is also written as a set of data selection keywords to the output events | |
| 51 | +file ``selected_events.fits``, by respecting the same syntax that has been | |
| 52 | +implemented for Fermi/LAT. The following image is a screen dump of the data | |
| 53 | +selection keywords that have been written to the ``EVENTS`` header in the | |
| 54 | +file ``selected_events.fits``: | |
| 55 | + | |
| 56 | +.. figure:: dskeys.jpg | |
| 57 | + :width: 400px | |
| 58 | + :align: center | |
| 59 | + | |
| 60 | + *Data selection keywords* | |
| 61 | + | |
| 62 | +**It is mandatory for an unbinned analysis that these data selection keywords | |
| 63 | +exist in the FITS file.** | |
| 64 | +If they don't exist, :ref:`ctlike` will not execute in unbinned mode. | |
| 65 | + | |
| 66 | +Below some lines of the ``ctselect.log`` file that show the data selection | |
| 67 | +part: | |
| 68 | + | |
| 69 | +.. code-block:: xml | |
| 70 | + | |
| 71 | + 2015-12-06T23:44:52: +=================+ | |
| 72 | + 2015-12-06T23:44:52: | Event selection | | |
| 73 | + 2015-12-06T23:44:52: +=================+ | |
| 74 | + 2015-12-06T23:44:52: === CTA observation === | |
| 75 | + 2015-12-06T23:44:52: Selected energy range .....: 0.1 - 100 TeV | |
| 76 | + 2015-12-06T23:44:52: Requested ROI .............: Centre(RA,DEC)=(83.63, 22.01) deg, Radius=3 deg | |
| 77 | + 2015-12-06T23:44:52: ROI of data ...............: Centre(RA,DEC)=(83.63, 22.01) deg, Radius=5 deg | |
| 78 | + 2015-12-06T23:44:52: Selected ROI ..............: Centre(RA,DEC)=(83.63, 22.01) deg, Radius=3 deg | |
| 79 | + 2015-12-06T23:44:52: cfitsio selection .........: ENERGY >= 0.10000000 && ENERGY <= 100.00000000 && ANGSEP(83.630000,22.010000,RA,DEC) <= 3.000000 | |
| 80 | + 2015-12-06T23:44:52: FITS filename .............: /var/tmp/tmp.0.jHg5hJ[EVENTS][ENERGY >= 0.10000000 && ENERGY <= 100.00000000 && ANGSEP(83.630000,22.010000,RA,DEC) <= 3.000000] | |
| 81 | + | |
| 82 | +.. note:: | |
| 83 | + | |
| 84 | + :ref:`ctobssim` will also write data selection keywords in the event | |
| 85 | + list FITS file, hence you can run :ref:`ctlike` directly on a FITS file | |
| 86 | + produced by :ref:`ctobssim`. Any selection performed by :ref:`ctselect` | |
| 87 | + needs to be fully enclosed within any previous selection, e.g. the ROI | |
| 88 | + needs to be fully enclosed in the acceptance cone used for event | |
| 89 | + simulation, the energy selection must be fully comprised in the | |
| 90 | + range of simulated energies, the same applies for the temporal selection. | |
| 91 | + :ref:`ctselect` will automatically adjust | |
| 92 | + the selection parameters to guarantee full enclosure. To keep track of | |
| 93 | + this adjustment, the :ref:`ctselect` log file quotes the requested | |
| 94 | + selection, any existing selections, and the selection that was finally | |
| 95 | + applied. | |
| 96 | + | |
| 97 | +.. warning:: | |
| 98 | + | |
| 99 | + :ref:`ctselect` may of course also be used for event selection prior to | |
| 100 | + binned analysis, for example to select events for a given period in | |
| 101 | + time. **If you use** :ref:`ctselect` **however to make a spatial or energy | |
| 102 | + selection, make sure that the counts cube is fully enclosed in the | |
| 103 | + selection intervals.** Otherwise you will get empty zones in the counts | |
| 104 | + cube of which the ctools are not aware of, and the subsequent analysis | |
| 105 | + results will be wrong. | |
| 106 | + | |
| 107 | +Now that you have selected the events of interest, you can run ctlike in | |
| 108 | +unbinned mode. To do this you have to specify the selected event list | |
| 109 | +instead of the counts cube: | |
| 110 | + | |
| 111 | +.. code-block:: bash | |
| 112 | + | |
| 113 | + $ ctlike | |
| 114 | + Input event list, counts cube or observation definition XML file [cntcube.fits] selected_events.fits | |
| 115 | + Calibration database [prod2] | |
| 116 | + Instrument response function [South_0.5h] | |
| 117 | + Input model XML file [$CTOOLS/share/models/crab.xml] | |
| 118 | + Output model XML file [crab_results.xml] | |
| 119 | + | |
| 120 | +You will recognise that :ref:`ctlike` runs much faster in unbinned mode | |
| 121 | +compared to binned mode. | |
| 122 | +This is understandable as the selected event list contains | |
| 123 | +only 21203 events, while the binned counts cube we used before had | |
| 124 | +200 x 200 x 20 = 800000 pixels. As unbinned maximum likelihood fitting loops | |
| 125 | +over the events (while binned maximum likelihood loops over the pixels), | |
| 126 | +there are much less operations to perform in unbinned than in binned mode | |
| 127 | +(there is some additional overhead in unbinned mode that comes from | |
| 128 | +integrating the models over the region of interest, yet this is negligible | |
| 129 | +compared to the operations needed when looping over all pixels). So as long | |
| 130 | +as you work with small event lists, unbinned mode is faster (this | |
| 131 | +typically holds up to 100 hours of observing time). | |
| 132 | +Unbinned :ref:`ctlike` should also be more precise as no binning is performed, | |
| 133 | +hence there is no loss of information due to histogramming. | |
| 134 | + | |
| 135 | +Below you see the corresponding output from the ctlike.log file. The fitted | |
| 136 | +parameters are essentially identical to the ones found in binned mode. | |
| 137 | +The slight difference with respect to the binned analysis may be explained | |
| 138 | +by the different event sample that has been used for the analysis: while | |
| 139 | +binned likelihood works on rectangular counts cubes, unbinned likelihood works | |
| 140 | +on circular event selection regions. It is thus not possible to select exactly | |
| 141 | +the same events for both analyses. | |
| 142 | + | |
| 143 | +.. code-block:: xml | |
| 144 | + | |
| 145 | + 2015-12-07T21:02:17: +=================================+ | |
| 146 | + 2015-12-07T21:02:17: | Maximum likelihood optimisation | | |
| 147 | + 2015-12-07T21:02:17: +=================================+ | |
| 148 | + 2015-12-07T21:02:17: >Iteration 0: -logL=135278.644, Lambda=1.0e-03 | |
| 149 | + 2015-12-07T21:02:17: >Iteration 1: -logL=135274.475, Lambda=1.0e-03, delta=4.168, max(|grad|)=5.806873 [Index:7] | |
| 150 | + 2015-12-07T21:02:17: >Iteration 2: -logL=135274.474, Lambda=1.0e-04, delta=0.001, max(|grad|)=-0.009463 [Index:7] | |
| 151 | + 2015-12-07T21:02:17: | |
| 152 | + ... | |
| 153 | + 2015-12-07T21:02:17: +=========================================+ | |
| 154 | + 2015-12-07T21:02:17: | Maximum likelihood optimisation results | | |
| 155 | + 2015-12-07T21:02:17: +=========================================+ | |
| 156 | + 2015-12-07T21:02:17: === GOptimizerLM === | |
| 157 | + 2015-12-07T21:02:17: Optimized function value ..: 135274.474 | |
| 158 | + 2015-12-07T21:02:17: Absolute precision ........: 0.005 | |
| 159 | + 2015-12-07T21:02:17: Acceptable value decrease .: 2 | |
| 160 | + 2015-12-07T21:02:17: Optimization status .......: converged | |
| 161 | + 2015-12-07T21:02:17: Number of parameters ......: 10 | |
| 162 | + 2015-12-07T21:02:17: Number of free parameters .: 4 | |
| 163 | + 2015-12-07T21:02:17: Number of iterations ......: 2 | |
| 164 | + 2015-12-07T21:02:17: Lambda ....................: 1e-05 | |
| 165 | + 2015-12-07T21:02:17: Maximum log likelihood ....: -135274.474 | |
| 166 | + 2015-12-07T21:02:17: Observed events (Nobs) ...: 21203.000 | |
| 167 | + 2015-12-07T21:02:17: Predicted events (Npred) ..: 21202.998 (Nobs - Npred = 0.00198937) | |
| 168 | + 2015-12-07T21:02:17: === GModels === | |
| 169 | + 2015-12-07T21:02:17: Number of models ..........: 2 | |
| 170 | + 2015-12-07T21:02:17: Number of parameters ......: 10 | |
| 171 | + 2015-12-07T21:02:17: === GModelSky === | |
| 172 | + 2015-12-07T21:02:17: Name ......................: Crab | |
| 173 | + 2015-12-07T21:02:17: Instruments ...............: all | |
| 174 | + 2015-12-07T21:02:17: Instrument scale factors ..: unity | |
| 175 | + 2015-12-07T21:02:17: Observation identifiers ...: all | |
| 176 | + 2015-12-07T21:02:17: Model type ................: PointSource | |
| 177 | + 2015-12-07T21:02:17: Model components ..........: "SkyDirFunction" * "PowerLaw" * "Constant" | |
| 178 | + 2015-12-07T21:02:17: Number of parameters ......: 6 | |
| 179 | + 2015-12-07T21:02:17: Number of spatial par's ...: 2 | |
| 180 | + 2015-12-07T21:02:17: RA .......................: 83.6331 [-360,360] deg (fixed,scale=1) | |
| 181 | + 2015-12-07T21:02:17: DEC ......................: 22.0145 [-90,90] deg (fixed,scale=1) | |
| 182 | + 2015-12-07T21:02:17: Number of spectral par's ..: 3 | |
| 183 | + 2015-12-07T21:02:17: Prefactor ................: 5.81583e-16 +/- 1.01727e-17 [1e-23,1e-13] ph/cm2/s/MeV (free,scale=1e-16,gradient) | |
| 184 | + 2015-12-07T21:02:17: Index ....................: -2.50611 +/- 0.0153542 [-0,-5] (free,scale=-1,gradient) | |
| 185 | + 2015-12-07T21:02:17: PivotEnergy ..............: 300000 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 186 | + 2015-12-07T21:02:17: Number of temporal par's ..: 1 | |
| 187 | + 2015-12-07T21:02:17: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | |
| 188 | + 2015-12-07T21:02:17: === GCTAModelIrfBackground === | |
| 189 | + 2015-12-07T21:02:17: Name ......................: CTABackgroundModel | |
| 190 | + 2015-12-07T21:02:17: Instruments ...............: CTA | |
| 191 | + 2015-12-07T21:02:17: Instrument scale factors ..: unity | |
| 192 | + 2015-12-07T21:02:17: Observation identifiers ...: all | |
| 193 | + 2015-12-07T21:02:17: Model type ................: "PowerLaw" * "Constant" | |
| 194 | + 2015-12-07T21:02:17: Number of parameters ......: 4 | |
| 195 | + 2015-12-07T21:02:17: Number of spectral par's ..: 3 | |
| 196 | + 2015-12-07T21:02:17: Prefactor ................: 0.990866 +/- 0.0136406 [0.001,1000] ph/cm2/s/MeV (free,scale=1,gradient) | |
| 197 | + 2015-12-07T21:02:17: Index ....................: 0.00536014 +/- 0.00839916 [-5,5] (free,scale=1,gradient) | |
| 198 | + 2015-12-07T21:02:17: PivotEnergy ..............: 1e+06 [10000,1e+09] MeV (fixed,scale=1e+06,gradient) | |
| 199 | + 2015-12-07T21:02:17: Number of temporal par's ..: 1 | |
| 200 | + 2015-12-07T21:02:17: Normalization ............: 1 (relative value) (fixed,scale=1,gradient) | ... | ... |
doc/source/user_manual/glossary.rst
doc/source/user_manual/index.rst
doc/source/user_manual/introduction.rst
| ... | ... | @@ -22,6 +22,13 @@ also be specified as arguments separated by a whitespace to the ctool: |
| 22 | 22 | |
| 23 | 23 | $ ctobssim ra=83.63 dec=22.01 rad=5.0 tmin=0 tmax=1800 emin=0.1 emax=100.0 caldb=prod2 irf=South_50h inmodel=$CTOOLS/share/models/crab.xml outevents=events.fits |
| 24 | 24 | |
| 25 | +If you need help about the usage of a ctool or a cscript, type the name of | |
| 26 | +the ctool or cscript followed by the ``--help`` option: | |
| 27 | + | |
| 28 | +.. code-block:: bash | |
| 29 | + | |
| 30 | + $ ctobssim --help | |
| 31 | + | |
| 25 | 32 | ctools includes also a Python module that declares every ctool as a |
| 26 | 33 | Python class. The following example illustrates the usage: |
| 27 | 34 | |
| ... | ... | @@ -47,7 +54,7 @@ command line or used as Python classes, as illustrated below: |
| 47 | 54 | |
| 48 | 55 | In this User Manual you will now learn how to install and use the ctools |
| 49 | 56 | package. |
| 50 | -If you encounter any problems, please read the :ref:`issues` section. | |
| 51 | -If you're desperate, you may need :ref:`help`. | |
| 57 | +If you encounter any problems, please read the :ref:`faq` and :ref:`issues` | |
| 58 | +sections. If you're desperate, you may need :ref:`help`. | |
| 52 | 59 | And you should read the :ref:`develop` section if you would like to |
| 53 | 60 | contribute to the ctools developments. | ... | ... |
doc/source/user_manual/plotting.rst
| 1 | 1 | Plotting |
| 2 | 2 | ======== |
| 3 | 3 | |
| 4 | -Gammalib and ctools currently do not include classes and scripts to make plots. | |
| 4 | +Gammalib and ctools do not include classes and scripts to make plots. | |
| 5 | 5 | |
| 6 | -This is intentional because creating and maintaining plotting tools that work on most user's machines | |
| 7 | -and cover most user's needs is a big project in itself, and deciding to support a | |
| 8 | -plotting package that is popular now as part of the CTA science tools could become very problematic in the future. | |
| 6 | +This is intentional because creating and maintaining plotting tools that | |
| 7 | +work on most user's machines and cover most user's needs is a big project | |
| 8 | +in itself, and deciding to support a plotting package that is popular now | |
| 9 | +as part of the CTA science tools could become very problematic in the | |
| 10 | +future. | |
| 11 | + | |
| 12 | +But we realise that most ctools users need to create plots for their | |
| 13 | +high-level science results, so on this page we provide a few pointers | |
| 14 | +to external packages and tools. | |
| 9 | 15 | |
| 10 | -But we realise that most ctools users need to create plots for their high-level science results, | |
| 11 | -so on this page we provide a few pointers to external packages and tools. | |
| 12 | 16 | |
| 13 | 17 | General |
| 14 | 18 | ------- |
| 15 | 19 | |
| 16 | -The most common way to create publication-quality astronomy plots at the moment is to use the `matplotlib`_ | |
| 17 | -Python plotting package. As illustrated by the `matplotlib gallery`_, virtually any plot can be constructed, | |
| 18 | -but matplotlib doesn't have built-in easy-to-use classes or functions to create the common plots for gamma-ray | |
| 19 | -astronomy, which are sky maps and spectra, so in the sections below we give some specific pointers for those. | |
| 20 | +The most common way to create publication-quality astronomy plots at the | |
| 21 | +moment is to use the `matplotlib`_ Python plotting package. As illustrated | |
| 22 | +by the `matplotlib gallery`_, virtually any plot can be constructed, | |
| 23 | +but matplotlib doesn't have built-in easy-to-use classes or functions to | |
| 24 | +create the common plots for gamma-ray astronomy, which are sky maps and | |
| 25 | +spectra, so in the sections below we give some specific pointers for those. | |
| 26 | + | |
| 20 | 27 | |
| 21 | 28 | Sky maps |
| 22 | 29 | -------- |
| 23 | 30 | |
| 24 | -For creating publication quality sky map plots via a Python script a good choice is to use `APLPy`_, `WCSAxes`_ | |
| 25 | -or `kapteyn`_, which are all based on matplotlib. | |
| 31 | +For creating publication quality sky map plots via a Python script a good | |
| 32 | +choice is to use `APLPy`_, `WCSAxes`_ or `kapteyn`_, which are all based on | |
| 33 | +matplotlib. | |
| 26 | 34 | |
| 27 | -You can also use interactive astronomy image viewers like `DS9`_, `Aladin`_ or `Ginga`_ | |
| 28 | -which allow you to save the image to a PNG or PDF file after customising it interactively, | |
| 29 | -but also contain command line options to create the plot, i.e. you can write a bash or Python script | |
| 30 | -to make the plot reproducible (DS9 and Ginga also feature direct communication with Python, | |
| 31 | -but that is a bit harder to use and usually used for interactive image analysis, not plotting scripts). | |
| 35 | +You can also use interactive astronomy image viewers like `DS9`_, `Aladin`_ | |
| 36 | +or `Ginga`_ which allow you to save the image to a PNG or PDF file after | |
| 37 | +customising it interactively, but also contain command line options to create | |
| 38 | +the plot, i.e. you can write a bash or Python script to make the plot | |
| 39 | +reproducible (DS9 and Ginga also feature direct communication with Python, | |
| 40 | +but that is a bit harder to use and usually used for interactive image | |
| 41 | +analysis, not plotting scripts). | |
| 32 | 42 | |
| 33 | 43 | |
| 34 | 44 | Spectra and light curves |
| 35 | 45 | ------------------------ |
| 36 | 46 | |
| 37 | -To plot spectra or spectral energy distributions (including flux model curves, flux model error bands, | |
| 38 | -flux points and residuals) and light curves, you can use matplotlib directly, | |
| 39 | -or use the classes and scripts in `Gammapy`_. | |
| 40 | - | |
| 41 | -Another option is to use virtual observatory interactive spectrum tools like `IRIS`_, `CASSIS`_ or `VOSpec`_ | |
| 42 | -which allow you to save the plot to a PNG or PDF file after creating it interactively. | |
| 47 | +To plot spectra or spectral energy distributions (including flux model curves, | |
| 48 | +flux model error bands, flux points and residuals) and light curves, you can | |
| 49 | +use matplotlib directly, or use the classes and scripts in `Gammapy`_. | |
| 43 | 50 | |
| 51 | +Another option is to use virtual observatory interactive spectrum tools | |
| 52 | +like `IRIS`_, `CASSIS`_ or `VOSpec`_ which allow you to save the plot to a | |
| 53 | +PNG or PDF file after creating it interactively. | |
| 44 | 54 | |
| 45 | 55 | .. _DS9: http://ds9.si.edu/ |
| 46 | 56 | .. _Aladin: http://aladin.u-strasbg.fr/ | ... | ... |
pyext/Makefile.am
| ... | ... | @@ -94,6 +94,15 @@ all-local: build |
| 94 | 94 | # this. |
| 95 | 95 | build: ctools/tools_wrap.cpp ctools/tools.py |
| 96 | 96 | $(PYTHON) setup.py build |
| 97 | +if IS_ELCAPITAN | |
| 98 | + -for f in build/ctools/ctools/_*.so; do \ | |
| 99 | + echo "Post process module "$$f; \ | |
| 100 | + install_name_tool -change $(libdir)/libctools.1.dylib @rpath/libctools.1.dylib $$f; \ | |
| 101 | + install_name_tool -change $(libdir)/libgamma.1.dylib @rpath/libgamma.1.dylib $$f; \ | |
| 102 | + install_name_tool -add_rpath $(libdir) $$f; \ | |
| 103 | + install_name_tool -add_rpath $(abs_top_srcdir)/src/.libs $$f; \ | |
| 104 | + done | |
| 105 | +endif | |
| 97 | 106 | |
| 98 | 107 | install-exec-local: |
| 99 | 108 | $(PYTHON) setup.py install --prefix=$(prefix) | ... | ... |
pyext/ctool.i
| ... | ... | @@ -99,6 +99,8 @@ public: |
| 99 | 99 | |
| 100 | 100 | // Protected methods that check user parameters |
| 101 | 101 | void require_inobs(const std::string& method); |
| 102 | + void require_inobs_nolist(const std::string& method); | |
| 103 | + void require_inobs_nocube(const std::string& method); | |
| 102 | 104 | |
| 103 | 105 | // Protected support methods |
| 104 | 106 | void set_response(GObservations& obs); | ... | ... |
pyext/ctools/__init__.py renamed to pyext/ctools/__init__.py.in
pyext/setup.py.in
| ... | ... | @@ -114,6 +114,10 @@ else: |
| 114 | 114 | extra_compile_args = [] |
| 115 | 115 | extra_link_args = [] |
| 116 | 116 | |
| 117 | +# Optionally add link flag for El Capitan post-processing of modules | |
| 118 | +if '@IS_ELCAPITAN_TRUE@' != '#': | |
| 119 | + extra_link_args.append('-headerpad_max_install_names') | |
| 120 | + | |
| 117 | 121 | # Setup |
| 118 | 122 | setup(name='@PACKAGE_NAME@', |
| 119 | 123 | version='@PACKAGE_VERSION@', | ... | ... |
src/Makefile.am
| ... | ... | @@ -46,6 +46,7 @@ libctools_la_LIBADD = support/libsupport.la \ |
| 46 | 46 | ctbutterfly/libctbutterfly.la \ |
| 47 | 47 | ctulimit/libctulimit.la \ |
| 48 | 48 | cterror/libcterror.la |
| 49 | +libctools_la_LDFLAGS = -version-info $(CTOOLS_LT_VERSION) @OPENMP_LIB_LDFLAGS@ | |
| 49 | 50 | |
| 50 | 51 | # Distribute scripts |
| 51 | 52 | EXTRA_DIST = $(scripts) | ... | ... |
src/ctbin/Makefile.am
| ... | ... | @@ -12,6 +12,7 @@ sources = ctbin.cpp |
| 12 | 12 | # Libtool library |
| 13 | 13 | noinst_LTLIBRARIES = libctbin.la |
| 14 | 14 | libctbin_la_SOURCES = $(sources) |
| 15 | +libctbin_la_LDFLAGS = -version-info $(CTOOLS_LT_VERSION) @OPENMP_LIB_LDFLAGS@ | |
| 15 | 16 | |
| 16 | 17 | # Program definition |
| 17 | 18 | ctbin_SOURCES = main.cpp | ... | ... |
src/ctbin/ctbin.cpp
| ... | ... | @@ -434,6 +434,9 @@ void ctbin::get_parameters(void) |
| 434 | 434 | // Throw exception if no input observation file is given |
| 435 | 435 | require_inobs(G_GET_PARAMETERS); |
| 436 | 436 | |
| 437 | + // Throw exception if counts cube is given | |
| 438 | + require_inobs_nocube(G_GET_PARAMETERS); | |
| 439 | + | |
| 437 | 440 | // Get observation container without response (not needed) |
| 438 | 441 | m_obs = get_observations(false); |
| 439 | 442 | ... | ... |
src/ctbin/ctbin.par
| ... | ... | @@ -17,8 +17,9 @@ |
| 17 | 17 | # |
| 18 | 18 | # General parameters |
| 19 | 19 | #=================== |
| 20 | -inobs, f, a, "events.fits",,, "Event list or observation definition file" | |
| 21 | -outcube, f, a, "cntcube.fits",,, "Output counts cube" | |
| 20 | +inobs, f, a, "events.fits",,, "Input event list or observation definition XML file" | |
| 21 | +outcube, f, a, "cntcube.fits",,, "Output counts cube file" | |
| 22 | + | |
| 22 | 23 | # |
| 23 | 24 | # Energy binning parameters |
| 24 | 25 | #========================== |
| ... | ... | @@ -27,6 +28,7 @@ emin, r, a, 0.1,,, "Start value for first energy bin in TeV" |
| 27 | 28 | emax, r, a, 100.0,,, "Stop value for last energy bin in TeV" |
| 28 | 29 | enumbins, i, a, 20,,, "Number of energy bins" |
| 29 | 30 | ebinfile, f, a, "NONE",,, "Name of the file containing the energy bin definition" |
| 31 | + | |
| 30 | 32 | # |
| 31 | 33 | # Spatial binning parameters |
| 32 | 34 | #=========================== |
| ... | ... | @@ -38,6 +40,7 @@ coordsys, s, a, "CEL", CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galac |
| 38 | 40 | xref, r, a, 83.63,0,360, "First coordinate of image center in degrees (RA or galactic l)" |
| 39 | 41 | yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DEC or galactic b)" |
| 40 | 42 | proj, s, a, "CAR",AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method" |
| 43 | + | |
| 41 | 44 | # |
| 42 | 45 | # Standard parameters |
| 43 | 46 | #==================== | ... | ... |
src/ctbkgcube/Makefile.am
| ... | ... | @@ -12,6 +12,7 @@ sources = ctbkgcube.cpp |
| 12 | 12 | # Libtool library |
| 13 | 13 | noinst_LTLIBRARIES = libctbkgcube.la |
| 14 | 14 | libctbkgcube_la_SOURCES = $(sources) |
| 15 | +libctbkgcube_la_LDFLAGS = -version-info $(CTOOLS_LT_VERSION) @OPENMP_LIB_LDFLAGS@ | |
| 15 | 16 | |
| 16 | 17 | # Program definition |
| 17 | 18 | ctbkgcube_SOURCES = main.cpp | ... | ... |
src/ctbkgcube/ctbkgcube.cpp
| ... | ... | @@ -450,6 +450,9 @@ void ctbkgcube::get_parameters(void) |
| 450 | 450 | // Throw exception if no input observation file is given |
| 451 | 451 | require_inobs(G_GET_PARAMETERS); |
| 452 | 452 | |
| 453 | + // Throw exception if counts cube is given | |
| 454 | + require_inobs_nocube(G_GET_PARAMETERS); | |
| 455 | + | |
| 453 | 456 | // Build observation container |
| 454 | 457 | m_obs = get_observations(); |
| 455 | 458 | ... | ... |
src/ctbkgcube/ctbkgcube.par
| ... | ... | @@ -15,15 +15,16 @@ |
| 15 | 15 | # # |
| 16 | 16 | ############################################################################# |
| 17 | 17 | # |
| 18 | -# Observational parameters | |
| 18 | +# General parameters | |
| 19 | 19 | #=================== |
| 20 | -inobs, f, a, "NONE",,, "Input event list or observation definition file" | |
| 20 | +inobs, f, a, "NONE",,, "Input event list or observation definition XML file" | |
| 21 | 21 | inmodel, f, a, "NONE",,, "Input model XML file" |
| 22 | -incube, f, a, "NONE",,, "Counts cube for background cube definition" | |
| 22 | +incube, f, a, "NONE",,, "Input counts cube file to extract background cube definition" | |
| 23 | +caldb, s, a, "prod2",,, "Calibration database" | |
| 24 | +irf, s, a, "South_0.5h",,, "Instrument response function" | |
| 23 | 25 | outcube, f, a, "bkgcube.fits",,, "Output background cube file" |
| 24 | 26 | outmodel, f, a, "NONE",,, "Output model XML file" |
| 25 | -caldb, s, a, "prod2",,, "Calibration database" | |
| 26 | -irf, s, a, "South_50h",,, "Instrument response function" | |
| 27 | + | |
| 27 | 28 | # |
| 28 | 29 | # Energy binning parameters |
| 29 | 30 | #========================== |
| ... | ... | @@ -32,6 +33,7 @@ emin, r, a, 0.1,,, "Lower energy limit (TeV)" |
| 32 | 33 | emax, r, a, 100.0,,, "Upper energy limit (TeV)" |
| 33 | 34 | enumbins, i, a, 20,,, "Number of energy bins" |
| 34 | 35 | ebinfile, f, h, "NONE",,, "Name of the file containing the energy bin definition" |
| 36 | + | |
| 35 | 37 | # |
| 36 | 38 | # Spatial binning parameters |
| 37 | 39 | #=========================== |
| ... | ... | @@ -43,6 +45,7 @@ coordsys, s, a, "CEL", CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galac |
| 43 | 45 | xref, r, a, 83.63,0,360, "First coordinate of image center in degrees (RA or galactic l)" |
| 44 | 46 | yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DEC or galactic b)" |
| 45 | 47 | proj, s, a, "CAR", AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method" |
| 48 | + | |
| 46 | 49 | # |
| 47 | 50 | # Standard parameters |
| 48 | 51 | #==================== | ... | ... |
src/ctbutterfly/Makefile.am
| ... | ... | @@ -12,6 +12,7 @@ sources = ctbutterfly.cpp |
| 12 | 12 | # Libtool library |
| 13 | 13 | noinst_LTLIBRARIES = libctbutterfly.la |
| 14 | 14 | libctbutterfly_la_SOURCES = $(sources) |
| 15 | +libctbutterfly_la_LDFLAGS = -version-info $(CTOOLS_LT_VERSION) @OPENMP_LIB_LDFLAGS@ | |
| 15 | 16 | |
| 16 | 17 | # Program definition |
| 17 | 18 | ctbutterfly_SOURCES = main.cpp | ... | ... |
src/ctbutterfly/ctbutterfly.cpp
| ... | ... | @@ -241,8 +241,8 @@ void ctbutterfly::run(void) |
| 241 | 241 | log << m_obs << std::endl; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - // If refit is selected then do maximum likelihood fit | |
| 245 | - if (m_refit) { | |
| 244 | + // If fit is selected then do maximum likelihood fit | |
| 245 | + if (m_fit) { | |
| 246 | 246 | |
| 247 | 247 | // Write header |
| 248 | 248 | if (logTerse()) { |
| ... | ... | @@ -267,14 +267,14 @@ void ctbutterfly::run(void) |
| 267 | 267 | log << m_covariance << std::endl; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - } // endif: refit selected | |
| 270 | + } // endif: fit selected | |
| 271 | 271 | |
| 272 | 272 | // Get model instance for further computations |
| 273 | 273 | GModels models = m_obs.models(); |
| 274 | 274 | |
| 275 | - // If no refit is selected and no covariance matrix has been specified | |
| 275 | + // If no fit is selected and no covariance matrix has been specified | |
| 276 | 276 | // then compute now the covariance matrix |
| 277 | - if (!m_refit && m_covariance.size() == 0) { | |
| 277 | + if (!m_fit && m_covariance.size() == 0) { | |
| 278 | 278 | |
| 279 | 279 | // Write header |
| 280 | 280 | if (logTerse()) { |
| ... | ... | @@ -542,7 +542,7 @@ void ctbutterfly::init_members(void) |
| 542 | 542 | m_confidence = 0.68; |
| 543 | 543 | m_max_iter = 50; |
| 544 | 544 | m_apply_edisp = false; |
| 545 | - m_refit = false; | |
| 545 | + m_fit = false; | |
| 546 | 546 | m_ebounds.clear(); |
| 547 | 547 | m_outfile.clear(); |
| 548 | 548 | |
| ... | ... | @@ -576,7 +576,7 @@ void ctbutterfly::copy_members(const ctbutterfly& app) |
| 576 | 576 | m_confidence = app.m_confidence; |
| 577 | 577 | m_max_iter = app.m_max_iter; |
| 578 | 578 | m_apply_edisp = app.m_apply_edisp; |
| 579 | - m_refit = app.m_refit; | |
| 579 | + m_fit = app.m_fit; | |
| 580 | 580 | m_ebounds = app.m_ebounds; |
| 581 | 581 | m_outfile = app.m_outfile; |
| 582 | 582 | |
| ... | ... | @@ -668,7 +668,7 @@ void ctbutterfly::get_parameters(void) |
| 668 | 668 | |
| 669 | 669 | // Read other parameters |
| 670 | 670 | m_confidence = (*this)["confidence"].real(); |
| 671 | - m_refit = (*this)["refit"].boolean(); | |
| 671 | + m_fit = (*this)["fit"].boolean(); | |
| 672 | 672 | |
| 673 | 673 | // Optionally read ahead parameters so that they get correctly |
| 674 | 674 | // dumped into the log file | ... | ... |
src/ctbutterfly/ctbutterfly.hpp
| ... | ... | @@ -93,7 +93,7 @@ protected: |
| 93 | 93 | double m_confidence; //!< Confidence level |
| 94 | 94 | int m_max_iter; //!< Maximum number of iterations |
| 95 | 95 | bool m_apply_edisp; //!< Apply energy dispersion? |
| 96 | - bool m_refit; //!< Do refit? | |
| 96 | + bool m_fit; //!< Do fit? | |
| 97 | 97 | GEbounds m_ebounds; //!< Energy binning definition |
| 98 | 98 | std::string m_outfile; //!< Output ascii file |
| 99 | 99 | ... | ... |
src/ctbutterfly/ctbutterfly.par
| ... | ... | @@ -17,17 +17,21 @@ |
| 17 | 17 | # |
| 18 | 18 | # General parameters |
| 19 | 19 | #=================== |
| 20 | -inobs, f, a, "events.fits",,,"Input event list, counts cube or observation definition file" | |
| 21 | -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" | |
| 20 | +inobs, f, a, "events.fits",,,"Input event list, counts cube or observation definition XML file" | |
| 21 | +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Input model XML file" | |
| 22 | 22 | srcname, s, a, "Crab",,,"Source of interest" |
| 23 | -expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)" | |
| 24 | -psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)" | |
| 25 | -bkgcube, f, a, "NONE",,, "Background cube file (only needed for stacked analysis)" | |
| 23 | +expcube, f, a, "NONE",,, "Input exposure cube file (only needed for stacked analysis)" | |
| 24 | +psfcube, f, a, "NONE",,, "Input PSF cube file (only needed for stacked analysis)" | |
| 25 | +bkgcube, f, a, "NONE",,, "Input background cube file (only needed for stacked analysis)" | |
| 26 | 26 | caldb, s, a, "prod2",,, "Calibration database" |
| 27 | -irf, s, a, "South_50h",,, "Instrument response function" | |
| 27 | +irf, s, a, "South_0.5h",,, "Instrument response function" | |
| 28 | 28 | edisp, b, h, no,,, "Apply energy dispersion?" |
| 29 | -outfile, f, a, "butterfly.txt",,, "Output ascii file" | |
| 30 | -refit, b, h, no,,, "Do refitting?" | |
| 29 | +outfile, f, a, "butterfly.txt",,, "Output ASCII file" | |
| 30 | + | |
| 31 | +# | |
| 32 | +# Butterfly parameters | |
| 33 | +#===================== | |
| 34 | +fit, b, h, no,,, "Perform maximum likelihood fitting?" | |
| 31 | 35 | confidence, r, h, 0.68,0.0,1.0, "Confidence level" |
| 32 | 36 | matrix, f, h, "NONE",,, "Input covariance Matrix FITS file" |
| 33 | 37 | ... | ... |
src/ctcubemask/Makefile.am
| ... | ... | @@ -12,6 +12,7 @@ sources = ctcubemask.cpp |
| 12 | 12 | # Libtool library (only needed for python bindings) |
| 13 | 13 | noinst_LTLIBRARIES = libctcubemask.la |
| 14 | 14 | libctcubemask_la_SOURCES = $(sources) |
| 15 | +libctcubemask_la_LDFLAGS = -version-info $(CTOOLS_LT_VERSION) @OPENMP_LIB_LDFLAGS@ | |
| 15 | 16 | |
| 16 | 17 | # Program definition |
| 17 | 18 | ctcubemask_SOURCES = main.cpp | ... | ... |
src/ctcubemask/ctcubemask.cpp
| ... | ... | @@ -221,7 +221,7 @@ void ctcubemask::run(void) |
| 221 | 221 | // Write observation(s) into logger |
| 222 | 222 | if (logTerse()) { |
| 223 | 223 | log << std::endl; |
| 224 | - log.header1("Observations for applying mask"); | |
| 224 | + log.header1("Observations"); | |
| 225 | 225 | log << m_obs << std::endl; |
| 226 | 226 | } |
| 227 | 227 | |
| ... | ... | @@ -349,20 +349,19 @@ void ctcubemask::save(void) |
| 349 | 349 | ***************************************************************************/ |
| 350 | 350 | void ctcubemask::get_parameters(void) |
| 351 | 351 | { |
| 352 | + // Initialise selection flags | |
| 353 | + m_select_energy = true; | |
| 354 | + m_select_roi = true; | |
| 355 | + | |
| 352 | 356 | // If there are no observations in container then load them via user |
| 353 | 357 | // parameters |
| 354 | 358 | if (m_obs.size() == 0) { |
| 355 | 359 | |
| 356 | - // Throw exception if no infile is given | |
| 357 | - if ((*this)["inobs"].filename() == "NONE" || | |
| 358 | - (*this)["inobs"].filename() == "") { | |
| 359 | - std::string msg = "A valid file needs to be specified for the " | |
| 360 | - "\"inobs\" parameter, yet \""+ | |
| 361 | - (*this)["inobs"].filename()+"\" was given." | |
| 362 | - " Specify a vaild observation definition or " | |
| 363 | - "event list FITS file to proceed."; | |
| 364 | - throw GException::invalid_value(G_GET_PARAMETERS, msg); | |
| 365 | - } | |
| 360 | + // Throw exception if no input observation file is given | |
| 361 | + require_inobs(G_GET_PARAMETERS); | |
| 362 | + | |
| 363 | + // Throw exception if event list is given | |
| 364 | + require_inobs_nolist(G_GET_PARAMETERS); | |
| 366 | 365 | |
| 367 | 366 | // Build observation container without response (not needed) |
| 368 | 367 | m_obs = get_observations(false); |
| ... | ... | @@ -373,13 +372,36 @@ void ctcubemask::get_parameters(void) |
| 373 | 372 | m_regfile = (*this)["regfile"].filename(); |
| 374 | 373 | m_usepnt = (*this)["usepnt"].boolean(); |
| 375 | 374 | if (!m_usepnt) { |
| 376 | - m_ra = (*this)["ra"].real(); | |
| 377 | - m_dec = (*this)["dec"].real(); | |
| 375 | + | |
| 376 | + // Check RA/DEC parameters for validity to read | |
| 377 | + if ((*this)["ra"].is_valid() && (*this)["dec"].is_valid()) { | |
| 378 | + m_ra = (*this)["ra"].real(); | |
| 379 | + m_dec = (*this)["dec"].real(); | |
| 380 | + m_select_roi = true; | |
| 381 | + } | |
| 382 | + else { | |
| 383 | + m_select_roi = false; | |
| 384 | + } | |
| 385 | + } | |
| 386 | + | |
| 387 | + // Check if radius is valid for a RoI selection | |
| 388 | + if (m_select_roi && (*this)["rad"].is_valid()) { | |
| 389 | + m_rad = (*this)["rad"].real(); | |
| 378 | 390 | } |
| 379 | - m_rad = (*this)["rad"].real(); | |
| 380 | - m_emin = (*this)["emin"].real(); | |
| 381 | - m_emax = (*this)["emax"].real(); | |
| 382 | - | |
| 391 | + else { | |
| 392 | + m_select_roi = false; | |
| 393 | + } | |
| 394 | + | |
| 395 | + // Check for sanity of energy selection parameters | |
| 396 | + if ((*this)["emin"].is_valid() && (*this)["emax"].is_valid()) { | |
| 397 | + m_emin = (*this)["emin"].real(); | |
| 398 | + m_emax = (*this)["emax"].real(); | |
| 399 | + m_select_energy = true; | |
| 400 | + } | |
| 401 | + else { | |
| 402 | + m_select_energy = false; | |
| 403 | + } | |
| 404 | + | |
| 383 | 405 | // Optionally read ahead parameters so that they get correctly |
| 384 | 406 | // dumped into the log file |
| 385 | 407 | if (read_ahead()) { |
| ... | ... | @@ -410,11 +432,28 @@ void ctcubemask::apply_mask(GCTAObservation* obs) |
| 410 | 432 | GSkyMap map = cube->map(); |
| 411 | 433 | const GEbounds& ebounds = cube->ebounds(); |
| 412 | 434 | |
| 435 | + // If no energy selection is required set energy boundaries to cube boundaries | |
| 436 | + if (!m_select_energy) { | |
| 437 | + m_emin = ebounds.emin().TeV(); | |
| 438 | + m_emax = ebounds.emax().TeV(); | |
| 439 | + } | |
| 440 | + | |
| 413 | 441 | // Initialise energy selection |
| 442 | + int npix = map.npix(); | |
| 414 | 443 | int n_ebin = ebounds.size(); |
| 415 | 444 | int e_idx1 = 0; |
| 416 | 445 | int e_idx2 = n_ebin; |
| 417 | 446 | |
| 447 | + // Determine number of events before masking | |
| 448 | + double sum_before = 0.0; | |
| 449 | + for (int i = 0; i < n_ebin; ++i) { | |
| 450 | + for (int pixel = 0; pixel < npix; ++pixel) { | |
| 451 | + if (map(pixel, i) >= 0.0) { | |
| 452 | + sum_before += map(pixel, i); | |
| 453 | + } | |
| 454 | + } | |
| 455 | + } | |
| 456 | + | |
| 418 | 457 | // Loop over ebounds to find the first valid energy band |
| 419 | 458 | for (int i = 0; i < n_ebin; ++i) { |
| 420 | 459 | double emin = ebounds.emin(i).TeV() + 1.0e-6; // Rounding tolerance |
| ... | ... | @@ -434,7 +473,6 @@ void ctcubemask::apply_mask(GCTAObservation* obs) |
| 434 | 473 | } |
| 435 | 474 | |
| 436 | 475 | // Set all pixels outside the desired energy bands to -1.0 |
| 437 | - int npix = map.npix(); | |
| 438 | 476 | for (int i = 0; i < e_idx1; ++i) { |
| 439 | 477 | for (int pixel = 0; pixel < npix; ++pixel) { |
| 440 | 478 | map(pixel,i) = -1.0; |
| ... | ... | @@ -455,24 +493,26 @@ void ctcubemask::apply_mask(GCTAObservation* obs) |
| 455 | 493 | } |
| 456 | 494 | |
| 457 | 495 | // Set all pixels inside selected energy bands but outside ROI |
| 458 | - // to -1.0 | |
| 459 | - GSkyRegionCircle roi(m_ra, m_dec, m_rad); | |
| 460 | - for (int i = e_idx1; i <= e_idx2; ++i) { | |
| 461 | - for (int pixel = 0; pixel < npix; ++pixel) { | |
| 462 | - GSkyDir dir = map.inx2dir(pixel); | |
| 463 | - if (!roi.contains(dir)) { | |
| 464 | - map(pixel,i) = -1.0; | |
| 496 | + // to -1.0 if requested | |
| 497 | + if (m_select_roi) { | |
| 498 | + GSkyRegionCircle roi(m_ra, m_dec, m_rad); | |
| 499 | + for (int i = e_idx1; i <= e_idx2; ++i) { | |
| 500 | + for (int pixel = 0; pixel < npix; ++pixel) { | |
| 501 | + GSkyDir dir = map.inx2dir(pixel); | |
| 502 | + if (!roi.contains(dir)) { | |
| 503 | + map(pixel,i) = -1.0; | |
| 504 | + } | |
| 465 | 505 | } |
| 466 | 506 | } |
| 467 | - } | |
| 468 | 507 | |
| 469 | - // Log selected energy band | |
| 470 | - if (logTerse()) { | |
| 471 | - log << gammalib::parformat("Selected ROI"); | |
| 472 | - log << "RA=" << m_ra << " deg, "; | |
| 473 | - log << "DEC=" << m_dec << " deg, "; | |
| 474 | - log << "Radius=" << m_rad << " deg"; | |
| 475 | - log << std::endl; | |
| 508 | + // Log selected energy band | |
| 509 | + if (logTerse()) { | |
| 510 | + log << gammalib::parformat("Selected ROI"); | |
| 511 | + log << "RA=" << m_ra << " deg, "; | |
| 512 | + log << "DEC=" << m_dec << " deg, "; | |
| 513 | + log << "Radius=" << m_rad << " deg"; | |
| 514 | + log << std::endl; | |
| 515 | + } | |
| 476 | 516 | } |
| 477 | 517 | |
| 478 | 518 | // Set all pixels inside selected energy bands and inside exclusion |
| ... | ... | @@ -503,6 +543,24 @@ void ctcubemask::apply_mask(GCTAObservation* obs) |
| 503 | 543 | } |
| 504 | 544 | } |
| 505 | 545 | |
| 546 | + // Determine number of events after masking | |
| 547 | + double sum_after = 0.0; | |
| 548 | + for (int i = 0; i < n_ebin; ++i) { | |
| 549 | + for (int pixel = 0; pixel < npix; ++pixel) { | |
| 550 | + if (map(pixel, i) >= 0.0) { | |
| 551 | + sum_after += map(pixel, i); | |
| 552 | + } | |
| 553 | + } | |
| 554 | + } | |
| 555 | + | |
| 556 | + // Dump number of events before and after masking | |
| 557 | + if (logTerse()) { | |
| 558 | + log << gammalib::parformat("Events before masking"); | |
| 559 | + log << sum_before << std::endl; | |
| 560 | + log << gammalib::parformat("Events after masking"); | |
| 561 | + log << sum_after << std::endl; | |
| 562 | + } | |
| 563 | + | |
| 506 | 564 | // Put back map into the event cube |
| 507 | 565 | cube->map(map); |
| 508 | 566 | |
| ... | ... | @@ -538,6 +596,8 @@ void ctcubemask::init_members(void) |
| 538 | 596 | // Initialise protected members |
| 539 | 597 | m_obs.clear(); |
| 540 | 598 | m_infiles.clear(); |
| 599 | + m_select_energy = true; | |
| 600 | + m_select_roi = true; | |
| 541 | 601 | |
| 542 | 602 | // Return |
| 543 | 603 | return; |
| ... | ... | @@ -563,8 +623,10 @@ void ctcubemask::copy_members(const ctcubemask& app) |
| 563 | 623 | m_emax = app.m_emax; |
| 564 | 624 | |
| 565 | 625 | // Copy protected members |
| 566 | - m_obs = app.m_obs; | |
| 567 | - m_infiles = app.m_infiles; | |
| 626 | + m_obs = app.m_obs; | |
| 627 | + m_infiles = app.m_infiles; | |
| 628 | + m_select_energy = app.m_select_energy; | |
| 629 | + m_select_roi = app.m_select_roi; | |
| 568 | 630 | |
| 569 | 631 | // Return |
| 570 | 632 | return; | ... | ... |
src/ctcubemask/ctcubemask.hpp
| ... | ... | @@ -90,8 +90,10 @@ protected: |
| 90 | 90 | double m_emax; //!< Upper energy |
| 91 | 91 | |
| 92 | 92 | // Protected members |
| 93 | - GObservations m_obs; //!< Observations container | |
| 94 | - std::vector<std::string> m_infiles; //!< Input event filenames | |
| 93 | + GObservations m_obs; //!< Observations container | |
| 94 | + std::vector<std::string> m_infiles; //!< Input event filenames | |
| 95 | + bool m_select_energy; //!< Perform energy selection | |
| 96 | + bool m_select_roi; //!< Perform ROI selection | |
| 95 | 97 | }; |
| 96 | 98 | |
| 97 | 99 | ... | ... |