Commit e8e560d5583ad1198b6ecbde8befbedd7475ed8a
Merge branch '2422-add-edisp-integration-methods' into integration
Showing
6 changed files
with
149 additions
and
4 deletions
ChangeLog
| 1 | -2018-02-14 | |
| 1 | +2018-04-09 | |
| 2 | 2 | |
| 3 | 3 | * Version 1.6.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add show_rmf.py example script | |
| 6 | 7 | Allow specifying of input sky map in ctskymap (#2311) |
| 7 | 8 | Add ras() and decs() methods to csobsinfo (#2313) |
| 8 | 9 | Accelerate IRF and RING background methods in ctskymap (#2309) | ... | ... |
NEWS
doc/source/admin/release_history/1.6.rst
| ... | ... | @@ -22,6 +22,7 @@ Bug fixes |
| 22 | 22 | Improvements |
| 23 | 23 | ------------ |
| 24 | 24 | |
| 25 | +* Add ``show_rmf.py`` example script | |
| 25 | 26 | * [`2313 <https://cta-redmine.irap.omp.eu/issues/2313>`_] - |
| 26 | 27 | Add `ras()` and `decs()` methods to :ref:`csobsinfo` |
| 27 | 28 | * [`2311 <https://cta-redmine.irap.omp.eu/issues/2311>`_] - | ... | ... |
examples/Makefile.am
| ... | ... | @@ -26,6 +26,7 @@ scripts = README.md \ |
| 26 | 26 | show_irf.py \ |
| 27 | 27 | show_model.py \ |
| 28 | 28 | show_pha.py \ |
| 29 | + show_rmf.py \ | |
| 29 | 30 | show_pull_evolution.py \ |
| 30 | 31 | show_pull_histogram.py \ |
| 31 | 32 | show_residuals.py \ |
| ... | ... | @@ -51,4 +52,4 @@ install-data-hook: |
| 51 | 52 | for p in $$list; do \ |
| 52 | 53 | chmod +x "$(DESTDIR)$(scriptsdir)/$$p"; \ |
| 53 | 54 | done |
| 54 | - | |
| 55 | + | ... | ... |
examples/show_rmf.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Display Redistribution Matrix File | |
| 4 | +# | |
| 5 | +# Copyright (C) 2018 Juergen Knoedlseder | |
| 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 gammalib | |
| 23 | +import cscripts | |
| 24 | +try: | |
| 25 | + import matplotlib.pyplot as plt | |
| 26 | + plt.figure() | |
| 27 | + plt.close() | |
| 28 | +except (ImportError, RuntimeError): | |
| 29 | + print('This script needs the "matplotlib" module') | |
| 30 | + sys.exit() | |
| 31 | + | |
| 32 | + | |
| 33 | +# ======== # | |
| 34 | +# Plot RMF # | |
| 35 | +# ======== # | |
| 36 | +def plot_rmf(rmf, plotfile): | |
| 37 | + """ | |
| 38 | + Plot Redistribution Matrix File | |
| 39 | + | |
| 40 | + Parameters | |
| 41 | + ---------- | |
| 42 | + rmf : `~gammalib.GRmf` | |
| 43 | + Redistribution Matrix File | |
| 44 | + plotfile : str | |
| 45 | + Plot filename | |
| 46 | + """ | |
| 47 | + # Build title | |
| 48 | + | |
| 49 | + # Set energy range | |
| 50 | + etrue_min = rmf.etrue().emin().log10TeV() | |
| 51 | + etrue_max = rmf.etrue().emax().log10TeV() | |
| 52 | + ereco_min = rmf.emeasured().emin().log10TeV() | |
| 53 | + ereco_max = rmf.emeasured().emax().log10TeV() | |
| 54 | + aspect = (etrue_max-etrue_min)/(ereco_max-ereco_min) | |
| 55 | + | |
| 56 | + # Set number of bins | |
| 57 | + netrue = rmf.etrue().size() | |
| 58 | + nereco = rmf.emeasured().size() | |
| 59 | + | |
| 60 | + # Set image | |
| 61 | + image = [] | |
| 62 | + for ireco in range(nereco-1,-1,-1): | |
| 63 | + row = [] | |
| 64 | + for itrue in range(netrue): | |
| 65 | + row.append(rmf[itrue,ireco]) | |
| 66 | + image.append(row) | |
| 67 | + | |
| 68 | + # Create figure | |
| 69 | + fig = plt.figure() | |
| 70 | + | |
| 71 | + # Plot image | |
| 72 | + c = plt.imshow(image, extent=[etrue_min,etrue_max,ereco_min,ereco_max], | |
| 73 | + interpolation='nearest', aspect=aspect) | |
| 74 | + cbar = plt.colorbar(c, orientation='vertical', shrink=0.8) | |
| 75 | + | |
| 76 | + # Plot title and axis | |
| 77 | + plt.title('Redistribution Matrix File') | |
| 78 | + plt.xlabel('log10(Etrue/TeV)') | |
| 79 | + plt.ylabel('log10(Ereco/TeV)') | |
| 80 | + | |
| 81 | + # Show plots or save it into file | |
| 82 | + if len(plotfile) > 0: | |
| 83 | + plt.savefig(plotfile) | |
| 84 | + else: | |
| 85 | + plt.show() | |
| 86 | + | |
| 87 | + # Return | |
| 88 | + return | |
| 89 | + | |
| 90 | + | |
| 91 | +# ======== # | |
| 92 | +# Show RMF # | |
| 93 | +# ======== # | |
| 94 | +def show_rmf(): | |
| 95 | + """ | |
| 96 | + Show Redistribution Matrix File | |
| 97 | + """ | |
| 98 | + # Set usage string | |
| 99 | + usage = 'show_rmf.py [-p plotfile] file' | |
| 100 | + | |
| 101 | + # Set default options | |
| 102 | + options = [{'option': '-p', 'value': ''}] | |
| 103 | + | |
| 104 | + # Get arguments and options from command line arguments | |
| 105 | + args, options = cscripts.ioutils.get_args_options(options, usage) | |
| 106 | + | |
| 107 | + # Extract script parameters from options | |
| 108 | + plotfile = options[0]['value'] | |
| 109 | + | |
| 110 | + # Get RMF | |
| 111 | + rmf = gammalib.GRmf(args[0]) | |
| 112 | + | |
| 113 | + # Plot RMF | |
| 114 | + plot_rmf(rmf, plotfile) | |
| 115 | + | |
| 116 | + # Return | |
| 117 | + return | |
| 118 | + | |
| 119 | + | |
| 120 | +# ======================== # | |
| 121 | +# Main routine entry point # | |
| 122 | +# ======================== # | |
| 123 | +if __name__ == '__main__': | |
| 124 | + | |
| 125 | + # Show RMF | |
| 126 | + show_rmf() | ... | ... |
test/test_examples.py.in
| ... | ... | @@ -109,6 +109,8 @@ class Test(gammalib.GPythonTestSuite): |
| 109 | 109 | 'Test show_residuals.py') |
| 110 | 110 | self.append(self.test_show_response, |
| 111 | 111 | 'Test show_response.py') |
| 112 | + self.append(self.test_show_rmf, | |
| 113 | + 'Test show_rmf.py') | |
| 112 | 114 | self.append(self.test_show_sensitivity, |
| 113 | 115 | 'Test show_sensitivity.py') |
| 114 | 116 | self.append(self.test_show_spectrum, |
| ... | ... | @@ -403,6 +405,20 @@ class Test(gammalib.GPythonTestSuite): |
| 403 | 405 | # Return |
| 404 | 406 | return |
| 405 | 407 | |
| 408 | + # Test show_rmf | |
| 409 | + def test_show_rmf(self): | |
| 410 | + """ | |
| 411 | + Test show_rmf | |
| 412 | + """ | |
| 413 | + # Set arguments | |
| 414 | + args = ('-p example_show_rmf.eps %s/onoff_rmf.fits' % self._datadir) | |
| 415 | + | |
| 416 | + # Execute script | |
| 417 | + self._execute_python('show_rmf', args=args) | |
| 418 | + | |
| 419 | + # Return | |
| 420 | + return | |
| 421 | + | |
| 406 | 422 | # Test show_sensitivity |
| 407 | 423 | def test_show_sensitivity(self): |
| 408 | 424 | """ | ... | ... |