Commit 30f876362e5b9260dde83786c6602f03020063f9
Merge branch 'integration' into devel
Showing
4 changed files
with
211 additions
and
7 deletions
ChangeLog
| 1 | -2015-07-02 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | 1 | +2015-07-03 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> |
| 2 | 2 | ||
| 3 | * Version 0.10.0 released | 3 | * Version 0.10.0 released |
| 4 | ========================= | 4 | ========================= |
| 5 | 5 | ||
| 6 | + Add csinfo script (#1489) | ||
| 6 | Removed obsutils.spectrum() function (replaced by csspec) | 7 | Removed obsutils.spectrum() function (replaced by csspec) |
| 7 | Add cterror tool | 8 | Add cterror tool |
| 8 | Check existence of ROI in ctbin (#1476) | 9 | Check existence of ROI in ctbin (#1476) |
NEWS
| @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 0.10.0 | @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 0.10.0 | ||
| 2 | 2 | ||
| 3 | Author(s) : Juergen Knoedlseder | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | ||
| 5 | -2 July 2015 | 5 | +3 July 2015 |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 1. Introduction | 8 | 1. Introduction |
| @@ -112,7 +112,8 @@ None | @@ -112,7 +112,8 @@ None | ||
| 112 | 112 | ||
| 113 | 20. Scripts | 113 | 20. Scripts |
| 114 | ----------- | 114 | ----------- |
| 115 | -None | 115 | +Added csinfo script to provide some information about the GammaLib and ctools |
| 116 | +installation. To be run in case of problems to help diagnostics. | ||
| 116 | 117 | ||
| 117 | 118 | ||
| 118 | 21. caldb | 119 | 21. caldb |
scripts/Makefile.am
| @@ -5,14 +5,15 @@ binscripts = cta_kb_bkgrates.py cta_root2irf.py cta_make_nodes.py \ | @@ -5,14 +5,15 @@ binscripts = cta_kb_bkgrates.py cta_root2irf.py cta_make_nodes.py \ | ||
| 5 | tsmerge.py | 5 | tsmerge.py |
| 6 | 6 | ||
| 7 | # Scripts to be distributed in pythondir | 7 | # Scripts to be distributed in pythondir |
| 8 | -pythonscripts = cspull.py cssens.py cstsdist.py cscaldb.py csresmap.py cshessobs.py \ | ||
| 9 | - csobsdef.py csspec.py cslightcrv.py \ | 8 | +pythonscripts = cspull.py cssens.py cstsdist.py cscaldb.py csresmap.py \ |
| 9 | + cshessobs.py csobsdef.py csspec.py cslightcrv.py \ | ||
| 10 | + csinfo.py \ | ||
| 10 | lsmodel.py | 11 | lsmodel.py |
| 11 | 12 | ||
| 12 | # Scripts for which symbolic links will be created in bindir | 13 | # Scripts for which symbolic links will be created in bindir |
| 13 | linkscripts = cspull cssens cstsdist cscaldb csresmap \ | 14 | linkscripts = cspull cssens cstsdist cscaldb csresmap \ |
| 14 | - csobsdef csspec cshessobs cslightcrv \ | ||
| 15 | - lsmodel | 15 | + cshessobs csobsdef csspec cslightcrv \ |
| 16 | + csinfo lsmodel | ||
| 16 | 17 | ||
| 17 | # Distribute scripts | 18 | # Distribute scripts |
| 18 | EXTRA_DIST = $(binscripts) $(pythonscripts) | 19 | EXTRA_DIST = $(binscripts) $(pythonscripts) |
scripts/csinfo.py
0 → 100755
| 1 | +#!/usr/bin/env python | ||
| 2 | +# ========================================================================== | ||
| 3 | +# Print info about Gammalib / ctools to the console. | ||
| 4 | +# | ||
| 5 | +# Copyright (C) 2015 Christoph Deil | ||
| 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 sys | ||
| 22 | +import os | ||
| 23 | +import commands | ||
| 24 | + | ||
| 25 | +# Copied and edited a bit from the `doc/source/reference_manual/index.rst` file | ||
| 26 | +# The list there and here needs to be manually updated and kept in sync. | ||
| 27 | +CTOOL_LIST = """ | ||
| 28 | + ctbin Generates counts cube | ||
| 29 | + ctbkgcube Generates background cube | ||
| 30 | + ctbutterfly Compute butterfly | ||
| 31 | + ctcubemask Filter counts cube | ||
| 32 | + ctexpcube Generates exposure cube | ||
| 33 | + ctlike Performs maximum likelihood fitting | ||
| 34 | + ctmodel Computes model counts cube | ||
| 35 | + ctobssim Simulate CTA observations | ||
| 36 | + ctpsfcube Generates point spread function cube | ||
| 37 | + ctselect Selects event data | ||
| 38 | + ctskymap Generates sky map | ||
| 39 | + cttsmap Generates Test Statistics map | ||
| 40 | + ctulimit Calculates upper limit | ||
| 41 | + cterror Calculates likelihood profile errors | ||
| 42 | +""" | ||
| 43 | +CSCRIPT_LIST = """ | ||
| 44 | + cscaldb Lists available instrument response functions | ||
| 45 | + csinfo Checks ctools and GammaLib installations | ||
| 46 | + csobsdef Generates observation definition file | ||
| 47 | + cslightcrv Computes lightcurve | ||
| 48 | + cspull Generates pull distribution | ||
| 49 | + cssens Computes CTA sensitivity | ||
| 50 | + csspec Computes spectral points | ||
| 51 | + csresmap Generates residual map | ||
| 52 | + cstsdist Generates TS distribution | ||
| 53 | +""" | ||
| 54 | + | ||
| 55 | +def log(text, end='\n'): | ||
| 56 | + """Print text to console. | ||
| 57 | + | ||
| 58 | + Workaround to have an `end=''` option on old Pythons: | ||
| 59 | + http://stackoverflow.com/a/493399/498873 | ||
| 60 | + """ | ||
| 61 | + sys.stdout.write(text + end) | ||
| 62 | + | ||
| 63 | + | ||
| 64 | +def csinfo_list_tools(): | ||
| 65 | + """Print available ctools with one-line description to the console. | ||
| 66 | + """ | ||
| 67 | + print('\nAvailable ctools:') | ||
| 68 | + print(CTOOL_LIST) | ||
| 69 | + print('Available cscripts:') | ||
| 70 | + print(CSCRIPT_LIST) | ||
| 71 | + | ||
| 72 | + | ||
| 73 | +def csinfo_setup_check(): | ||
| 74 | + print('\nGammalib / ctools setup check:\n') | ||
| 75 | + | ||
| 76 | + all_ok = True | ||
| 77 | + gammalib_environ = False | ||
| 78 | + ctools_environ = False | ||
| 79 | + gammalib_python = False | ||
| 80 | + ctools_python = False | ||
| 81 | + | ||
| 82 | + log(' GAMMALIB environment variable ... ', end='') | ||
| 83 | + try: | ||
| 84 | + gammalib_env = os.environ['GAMMALIB'] | ||
| 85 | + print('ok') | ||
| 86 | + except KeyError: | ||
| 87 | + print('NOT OK') | ||
| 88 | + all_ok = False | ||
| 89 | + gammalib_environ = True | ||
| 90 | + | ||
| 91 | + log(' CTOOLS environment variable ... ', end='') | ||
| 92 | + try: | ||
| 93 | + ctools_env = os.environ['CTOOLS'] | ||
| 94 | + print('ok') | ||
| 95 | + except KeyError: | ||
| 96 | + print('NOT_OK') | ||
| 97 | + all_ok = False | ||
| 98 | + ctools_environ = True | ||
| 99 | + | ||
| 100 | + log(' gammalib Python import .......... ', end='') | ||
| 101 | + try: | ||
| 102 | + import gammalib | ||
| 103 | + print('ok') | ||
| 104 | + except: | ||
| 105 | + print('NOT OK') | ||
| 106 | + all_ok = False | ||
| 107 | + gammalib_python = True | ||
| 108 | + | ||
| 109 | + log(' ctools Python import .......... ', end='') | ||
| 110 | + try: | ||
| 111 | + import ctools | ||
| 112 | + print('ok') | ||
| 113 | + except: | ||
| 114 | + print('NOT OK') | ||
| 115 | + all_ok = False | ||
| 116 | + ctools_python = True | ||
| 117 | + | ||
| 118 | + if all_ok: | ||
| 119 | + print('\n Your Gammalib / ctools setup is OK.') | ||
| 120 | + else: | ||
| 121 | + print('\n WARNING: Your Gammalib / ctools setup is NOT OK!\n') | ||
| 122 | + if gammalib_environ: | ||
| 123 | + print(' - Have you set the GAMMALIB environment variable?') | ||
| 124 | + print(' - Did you source gammalib-init.sh?') | ||
| 125 | + if ctools_environ: | ||
| 126 | + print(' - Have you set the CTOOLS environment variable?') | ||
| 127 | + print(' - Did you source ctools-init.sh ?') | ||
| 128 | + if gammalib_python or ctools_python: | ||
| 129 | + print(' - Are you using the correct Python ?') | ||
| 130 | + | ||
| 131 | + print('') | ||
| 132 | + | ||
| 133 | +def csinfo_setup_info(): | ||
| 134 | + print('\nGammalib / ctools setup info:\n') | ||
| 135 | + | ||
| 136 | + log(' CTOOLS environment variable ... ', end='') | ||
| 137 | + try: | ||
| 138 | + ctools_env = os.environ['CTOOLS'] | ||
| 139 | + print(' $CTOOLS = {0}'.format(ctools_env)) | ||
| 140 | + except KeyError: | ||
| 141 | + print('WARNING: $CTOOLS environment variable not set. Did you source ctools-init.sh?') | ||
| 142 | + all_ok = False | ||
| 143 | + | ||
| 144 | + try: | ||
| 145 | + import gammalib | ||
| 146 | + print(' Python `gammalib` path: {0}'.format(gammalib.__path__[0])) | ||
| 147 | + except: | ||
| 148 | + print('WARNING: Python `gammalib` import failed. Are you using the right Python?') | ||
| 149 | + | ||
| 150 | + try: | ||
| 151 | + import ctools | ||
| 152 | + print(' Python `ctools` path: {0}'.format(ctools.__path__[0])) | ||
| 153 | + except: | ||
| 154 | + print('WARNING: Python `ctools` import failed. Are you using the right Python?') | ||
| 155 | + | ||
| 156 | + print(' GAMMALIB CFLAGS: {0}'.format(get_pkg_config_info('cflags', 'gammalib'))) | ||
| 157 | + print(' CTOOLS CFLAGS: {0}'.format(get_pkg_config_info('cflags', 'ctools'))) | ||
| 158 | + | ||
| 159 | + print('') | ||
| 160 | + | ||
| 161 | + | ||
| 162 | +def get_pkg_config_info(info, library): | ||
| 163 | + cmd = 'pkg-config --{0} {1}'.format(info, library) | ||
| 164 | + out = commands.getoutput(cmd) | ||
| 165 | + if 'was not found' in out: | ||
| 166 | + return 'Not available' | ||
| 167 | + else: | ||
| 168 | + return out | ||
| 169 | + | ||
| 170 | + | ||
| 171 | +def csinfo_print_help(): | ||
| 172 | + print('\nPrint info about Gammalib and ctools to the console.\n') | ||
| 173 | + print('Available commands:') | ||
| 174 | + print(' csinfo list List available ctools and cscripts') | ||
| 175 | + print(' csinfo check Check Gammalib / ctools setup') | ||
| 176 | + print(' csinfo info Print Gammalib / ctools setup info') | ||
| 177 | + print('') | ||
| 178 | + | ||
| 179 | + | ||
| 180 | +def csinfo(argv): | ||
| 181 | + """Print info about Gammalib / ctools to the console. | ||
| 182 | + """ | ||
| 183 | + if len(argv) <= 1: | ||
| 184 | + csinfo_print_help() | ||
| 185 | + sys.exit(0) | ||
| 186 | + | ||
| 187 | + cmd = argv[1] | ||
| 188 | + if cmd == 'list': | ||
| 189 | + csinfo_list_tools() | ||
| 190 | + elif cmd == 'check': | ||
| 191 | + csinfo_setup_check() | ||
| 192 | + elif cmd == 'info': | ||
| 193 | + csinfo_setup_info() | ||
| 194 | + else: | ||
| 195 | + print('\nERROR: invalid command: `{0}`'.format(cmd)) | ||
| 196 | + csinfo_print_help() | ||
| 197 | + sys.exit(-1) | ||
| 198 | + | ||
| 199 | + | ||
| 200 | +if __name__ == '__main__': | ||
| 201 | + csinfo(sys.argv) |