diff --git a/ChangeLog b/ChangeLog index b20804c..887e1e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2018-02-14 +2018-04-09 * Version 1.6.0 released ======================== + 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) diff --git a/NEWS b/NEWS index ae35b87..f388f70 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.6.0 -14 February 2018 +9 April 2018 Introduction @@ -306,7 +306,7 @@ None Examples -------- -None +Added show_rmf.py script. caldb diff --git a/doc/source/admin/release_history/1.6.rst b/doc/source/admin/release_history/1.6.rst index 5d72ffa..08bac5a 100644 --- a/doc/source/admin/release_history/1.6.rst +++ b/doc/source/admin/release_history/1.6.rst @@ -22,6 +22,7 @@ Bug fixes 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 100644 --- 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/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): """