diff --git a/ChangeLog b/ChangeLog index 57ccf57..7965091 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,18 +1,21 @@ -2018-02-14 +2018-04-10 * Version 1.6.0 released ======================== + Keep existing library path in installation script on Mac OS X (#2420) + Add show_rmf.py example script Allow specifying of input sky map in ctskymap (#2311) Add ras() and decs() methods to csobsinfo (#2313) Accelerate IRF and RING background methods in ctskymap (#2309) -2018-02-16 +2018-03-26 * Bug fix version 1.5.1 released ================================ + Fix MANPATH for Mac OS X systems (#2420) Take energy dispersion in csresspec modelling into account (#2341) Enable using csphagen for HESS, VERITAS and MAGIC observations (#2307) diff --git a/NEWS b/NEWS index ae35b87..c1d5783 100755 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.6.0 -14 February 2018 +10 April 2018 Introduction @@ -11,7 +11,7 @@ ctools release with respect to the precedent release. Configuration ------------- -None +Keep existing library path in installation script on Mac OS X (#2420) Python interface @@ -306,7 +306,7 @@ None Examples -------- -None +Added show_rmf.py script. caldb diff --git a/cscripts/csresspec.py b/cscripts/csresspec.py index ad95ef4..67ae830 100755 --- a/cscripts/csresspec.py +++ b/cscripts/csresspec.py @@ -253,42 +253,15 @@ class csresspec(ctools.csobservation): cntcube['ebinfile'] = self['ebinfile'].filename() else: cntcube['enumbins'] = self['enumbins'].integer() - cntcube['emin'] = self['emin'].real() - cntcube['emax'] = self['emax'].real() + cntcube['emin'] = self['emin'].real() + cntcube['emax'] = self['emax'].real() cntcube.run() # Retrieve the binned observation container binned_obs = cntcube.obs().copy() - # Log response computation - self._log_string(gammalib.EXPLICIT, 'Computing binned response') - - # Compute binned response - response = obsutils.get_stacked_response(obs, ra, dec, - binsz=0.02, - nxpix=npix, - nypix=npix, - coordsys='CEL', - proj='TAN', - emin=self['emin'].real(), - emax=self['emax'].real(), - edisp=self['edisp'].boolean()) - - if self['edisp'].boolean(): - binned_obs[0].response(response['expcube'], response['psfcube'], - response['edispcube'], response['bkgcube']) - else: - binned_obs[0].response(response['expcube'], response['psfcube'], - response['bkgcube']) - - # Get new models - models = response['models'] - - # Set models for observation container - binned_obs.models(models) - - # Check if energy boundaries provided by user extend beyond - # the content of the event list + # Check if energy boundaries provided by user extend beyond the + # content of the event list if self['emin'].real() > obs[0].events().emin().TeV(): emin = 'INDEF' else: @@ -601,21 +574,24 @@ class csresspec(ctools.csobservation): # Calculate models of individual components if requested if self['components'].boolean(): for component in obs.models(): + + # Log component self._log_value(gammalib.NORMAL, - 'Computing model for component', + 'Computing model component', component.name()) - # Set model cube models to - # individual component + + # Set model cube models to individual component model_cont = gammalib.GModels() model_cont.append(component) modelcube.obs().models(model_cont) # Run model cube + modelcube['edisp'] = self['edisp'].boolean() modelcube.run() # Extract spectrum of individual component modcube = modelcube.cube().copy() - model = self._cube_to_spectrum(modcube, evlist_info) + model = self._cube_to_spectrum(modcube, evlist_info) # append component to table table = self._append_column(table, component.name(), diff --git a/doc/source/admin/download.rst b/doc/source/admin/download.rst index 3a0f350..427ea20 100755 --- a/doc/source/admin/download.rst +++ b/doc/source/admin/download.rst @@ -3,7 +3,7 @@ Download ======== -The latest ctools release is ``ctools-1.5.0`` (28 January 2018). +The latest ctools release is ``ctools-1.5.1`` (26 March 2018). Below a table of ctools releases. Please read the :ref:`sec_release` to learn more about new features and corrected bugs in a given release. @@ -23,6 +23,9 @@ learn more about new features and corrected bugs in a given release. * - ctools - gammalib - Mac OS X (10.7+) binary disk image + * - `1.5.1 `_ + - `1.5.1 `_ + - `ctools-1.5.1-macosx10.7.dmg `_ * - `1.5.0 `_ - `1.5.0 `_ - `ctools-1.5.0-macosx10.7.dmg `_ diff --git a/doc/source/admin/release_history/1.5.1.rst b/doc/source/admin/release_history/1.5.1.rst index da8dcaf..7a99ea3 100644 --- a/doc/source/admin/release_history/1.5.1.rst +++ b/doc/source/admin/release_history/1.5.1.rst @@ -1,7 +1,7 @@ .. _1.5.1: -ctools 1.5.1 release -==================== +ctools 1.5.1 release (26 March 2018) +==================================== Overview -------- @@ -10,6 +10,8 @@ ctools 1.5.1 is a bug fix release for ctools release 1.5. The following bugs were fixed: +* [`2420 `_] - + Fix ``MANPATH`` for Mac OS X systems * [`2341 `_] - Take energy dispersion in :ref:`csresspec` modelling into account diff --git a/doc/source/admin/release_history/1.6.rst b/doc/source/admin/release_history/1.6.rst index 5d72ffa..c9ec0eb 100644 --- a/doc/source/admin/release_history/1.6.rst +++ b/doc/source/admin/release_history/1.6.rst @@ -16,12 +16,14 @@ In particular, this release provides: Bug fixes --------- -* ... +* [`2420 `_] - + Keep existing library path in installation script on Mac OS X Improvements ------------ +* Add ``show_rmf.py`` example script * [`2313 `_] - Add `ras()` and `decs()` methods to :ref:`csobsinfo` * [`2311 `_] - diff --git a/examples/Makefile.am b/examples/Makefile.am index 7ec9cc2..18f5860 100755 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -26,6 +26,7 @@ scripts = README.md \ show_irf.py \ show_model.py \ show_pha.py \ + show_rmf.py \ show_pull_evolution.py \ show_pull_histogram.py \ show_residuals.py \ @@ -51,4 +52,4 @@ install-data-hook: for p in $$list; do \ chmod +x "$(DESTDIR)$(scriptsdir)/$$p"; \ done - + diff --git a/examples/show_rmf.py b/examples/show_rmf.py new file mode 100755 index 0000000..263a958 --- /dev/null +++ b/examples/show_rmf.py @@ -0,0 +1,126 @@ +#! /usr/bin/env python +# ========================================================================== +# Display Redistribution Matrix File +# +# Copyright (C) 2018 Juergen Knoedlseder +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# ========================================================================== +import sys +import gammalib +import cscripts +try: + import matplotlib.pyplot as plt + plt.figure() + plt.close() +except (ImportError, RuntimeError): + print('This script needs the "matplotlib" module') + sys.exit() + + +# ======== # +# Plot RMF # +# ======== # +def plot_rmf(rmf, plotfile): + """ + Plot Redistribution Matrix File + + Parameters + ---------- + rmf : `~gammalib.GRmf` + Redistribution Matrix File + plotfile : str + Plot filename + """ + # Build title + + # Set energy range + etrue_min = rmf.etrue().emin().log10TeV() + etrue_max = rmf.etrue().emax().log10TeV() + ereco_min = rmf.emeasured().emin().log10TeV() + ereco_max = rmf.emeasured().emax().log10TeV() + aspect = (etrue_max-etrue_min)/(ereco_max-ereco_min) + + # Set number of bins + netrue = rmf.etrue().size() + nereco = rmf.emeasured().size() + + # Set image + image = [] + for ireco in range(nereco-1,-1,-1): + row = [] + for itrue in range(netrue): + row.append(rmf[itrue,ireco]) + image.append(row) + + # Create figure + fig = plt.figure() + + # Plot image + c = plt.imshow(image, extent=[etrue_min,etrue_max,ereco_min,ereco_max], + interpolation='nearest', aspect=aspect) + cbar = plt.colorbar(c, orientation='vertical', shrink=0.8) + + # Plot title and axis + plt.title('Redistribution Matrix File') + plt.xlabel('log10(Etrue/TeV)') + plt.ylabel('log10(Ereco/TeV)') + + # Show plots or save it into file + if len(plotfile) > 0: + plt.savefig(plotfile) + else: + plt.show() + + # Return + return + + +# ======== # +# Show RMF # +# ======== # +def show_rmf(): + """ + Show Redistribution Matrix File + """ + # Set usage string + usage = 'show_rmf.py [-p plotfile] file' + + # Set default options + options = [{'option': '-p', 'value': ''}] + + # Get arguments and options from command line arguments + args, options = cscripts.ioutils.get_args_options(options, usage) + + # Extract script parameters from options + plotfile = options[0]['value'] + + # Get RMF + rmf = gammalib.GRmf(args[0]) + + # Plot RMF + plot_rmf(rmf, plotfile) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Show RMF + show_rmf() diff --git a/src/ctools-init.csh b/src/ctools-init.csh index 4d5d06d..efa10b8 100755 --- a/src/ctools-init.csh +++ b/src/ctools-init.csh @@ -1,4 +1,4 @@ -# Filename: ctools-init.csh +# Filename: ctools-init.csh # Description: C-shell flavor initialization for ctools # runs ctools-setup to generate a temporary csh script # tailored specifically to this user and ctools diff --git a/src/ctools-init.sh b/src/ctools-init.sh index 285c2e2..5e99240 100755 --- a/src/ctools-init.sh +++ b/src/ctools-init.sh @@ -1,4 +1,4 @@ -# Filename: ctools-init.sh +# Filename: ctools-init.sh # Description: Bourne-shell flavor initialization for ctools. # Runs ctools-setup to generate a sh script tailored # specifically to this user and ctools installation, diff --git a/src/ctools-setup.in b/src/ctools-setup.in index f4359fb..5c460c8 100755 --- a/src/ctools-setup.in +++ b/src/ctools-setup.in @@ -1,5 +1,4 @@ -#! /bin/sh -# Filename: ctools-setup(.in) +# Filename: ctools-setup(.in) # Description: Writes an initialization script for ctools software # which is custom fit to the user and the particular # software installation. Note that this script is @@ -98,12 +97,10 @@ fi # # Set LD_LIBRARY_PATH # =================== -if [ "x$LD_LIBRARY_PATH" = x ]; then - LD_LIBRARY_PATH="$ctools_lib" +if [ -z "${LD_LIBRARY_PATH}" ]; then + LD_LIBRARY_PATH=$ctools_lib else - LD_LIBRARY_PATH=`echo ":$LD_LIBRARY_PATH:" | \ - sed "s%:$ctools_lib:%:%g" | sed "s%::*$%%"` - LD_LIBRARY_PATH="$ctools_lib$LD_LIBRARY_PATH" + LD_LIBRARY_PATH=$ctools_lib:$LD_LIBRARY_PATH fi # @@ -111,20 +108,17 @@ fi # ================================= case $uname_system in Darwin*) - if [ "x$DYLD_LIBRARY_PATH" = x ]; then - DYLD_LIBRARY_PATH="$ctools_lib" + if [ -z "${DYLD_LIBRARY_PATH}" ]; then + DYLD_LIBRARY_PATH=$ctools_lib else - DYLD_LIBRARY_PATH=`echo ":$DYLD_LIBRARY_PATH:" | \ - sed "s%:$ctools_lib:%:%g" | sed "s%::*$%%"` - DYLD_LIBRARY_PATH="$ctools_lib$DYLD_LIBRARY_PATH" + DYLD_LIBRARY_PATH=$ctools_lib:$DYLD_LIBRARY_PATH fi ;; CYGWIN*) - if [ "x$PATH" = x ]; then - PATH="$ctools_lib" + if [ -z "${PATH}" ]; then + PATH=$ctools_lib else - PATH=`echo ":$PATH:" | sed "s%:$ctools_lib:%:%g" | sed "s%::*$%%"` - PATH="$ctools_lib$PATH" + PATH=$ctools_lib:$PATH fi ;; esac @@ -132,60 +126,51 @@ esac # # Set PYTHONPATH # ============== -if [ "x$PYTHONPATH" = x ]; then - PYTHONPATH="$python_dir" +if [ -z "${PYTHONPATH}" ]; then + PYTHONPATH=$python_dir:$python_exec_dir else - PYTHONPATH=`echo ":$PYTHONPATH:" | \ - sed "s%:$python_dir:%:%g" | sed "s%::*$%%"` - PYTHONPATH="$python_dir$PYTHONPATH" -fi -if [ "x$PYTHONPATH" = x ]; then - PYTHONPATH="$python_exec_dir" -else - PYTHONPATH=`echo ":$PYTHONPATH:" | \ - sed "s%:$python_exec_dir:%:%g" | sed "s%::*$%%"` - PYTHONPATH="$python_exec_dir$PYTHONPATH" + PYTHONPATH=$python_dir:$python_exec_dir:$PYTHONPATH fi # # Set PKG_CONFIG_PATH # =================== -if [ "x$PKG_CONFIG_PATH" = x ]; then - PKG_CONFIG_PATH="$pkgconfig_dir" +if [ -z "${PKG_CONFIG_PATH}" ]; then + PKG_CONFIG_PATH=$pkgconfig_dir else - PKG_CONFIG_PATH=`echo ":$PKG_CONFIG_PATH:" | \ - sed "s%:$pkgconfig_dir:%:%g" | sed "s%::*$%%"` - PKG_CONFIG_PATH="$pkgconfig_dir$PKG_CONFIG_PATH" + PKG_CONFIG_PATH=$pkgconfig_dir:$PKG_CONFIG_PATH fi # # Set PATH # ======== -if [ "x$PATH" = x ]; then - PATH="$ctools_bin" +if [ -z "${PATH}" ]; then + PATH=$ctools_bin else - PATH=`echo ":$PATH:" | \ - sed "s%:$ctools_bin:%:%g" | sed "s%::*$%%"` - PATH="$ctools_bin$PATH" + PATH=$ctools_bin:$PATH fi # # Set MANPATH # ============== -if [ "x$MANPATH" = x ]; then - manpath=${manpath:-} - MANPATH="$man_dir:${manpath}" +if [ -z "${MANPATH}" ]; then + if `which manpath > /dev/null 2>&1` ; then + default_manpath=`manpath` + else + default_manpath=`man -w 2> /dev/null` + fi +fi +if [ -z "${MANPATH}" ]; then + MANPATH=$man_dir:${default_manpath}; export MANPATH else - MANPATH=`echo ":$MANPATH:" | \ - sed "s%:$man_dir:%:%g" | sed "s%::*$%%"` - MANPATH="$man_dir$MANPATH" + MANPATH=$man_dir:$MANPATH; export MANPATH fi # # Set CALDB (if not yet set) # ========================== -if [ "x$CALDB" = x ]; then - CALDB="$caldb_dir" +if [ -z "${CALDB}" ]; then + CALDB=$caldb_dir fi # diff --git a/test/test_examples.py.in b/test/test_examples.py.in index a05e773..3218fec 100755 --- a/test/test_examples.py.in +++ b/test/test_examples.py.in @@ -109,6 +109,8 @@ class Test(gammalib.GPythonTestSuite): 'Test show_residuals.py') self.append(self.test_show_response, 'Test show_response.py') + self.append(self.test_show_rmf, + 'Test show_rmf.py') self.append(self.test_show_sensitivity, 'Test show_sensitivity.py') self.append(self.test_show_spectrum, @@ -403,6 +405,20 @@ class Test(gammalib.GPythonTestSuite): # Return return + # Test show_rmf + def test_show_rmf(self): + """ + Test show_rmf + """ + # Set arguments + args = ('-p example_show_rmf.eps %s/onoff_rmf.fits' % self._datadir) + + # Execute script + self._execute_python('show_rmf', args=args) + + # Return + return + # Test show_sensitivity def test_show_sensitivity(self): """ diff --git a/test/test_obsutils.py b/test/test_obsutils.py index fd44e89..5683604 100755 --- a/test/test_obsutils.py +++ b/test/test_obsutils.py @@ -214,7 +214,7 @@ class Test(test): # Check simulation results self.test_value(res.size(), 1, 'Check number of observations') self.test_value(res.models().size(), 2, 'Check number of models') - self.test_value(res.nobserved(), 23, 'Check number of observed events') + self.test_value(res.nobserved(), 20, 'Check number of observed events') self.test_value(res.npred(), 0.0, 'Check number of predicted events') self.test_value(res[0].eventtype(), 'CountsCube', 'Check event type') self.test_value(res[0].events().ebounds().emin().TeV(), 1.0, @@ -223,7 +223,7 @@ class Test(test): 'Check minimum energy') self.test_value(res[0].events().ebounds().size(), 5, 'Check number of energy bins') - self.test_value(res[0].events().number(), 23, + self.test_value(res[0].events().number(), 20, 'Check number of events in cube') # Check energy dispersion flag