From aad290d7073c24042ab2ef7185e82042acd96def Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 18 Dec 2012 20:55:30 +0100 Subject: [PATCH] Adapt filepath and make Python 3 compatible. --- inst/cta/test/test_response_table.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/inst/cta/test/test_response_table.py b/inst/cta/test/test_response_table.py index 15aeb78..2757e04 100755 --- a/inst/cta/test/test_response_table.py +++ b/inst/cta/test/test_response_table.py @@ -1,43 +1,63 @@ #! /usr/bin/env python - +# ========================================================================== +# This script displays the CTA PSF using a response table. +# +# Requires: +# - matplotlib +# - numpy +# +# Copyright (C) 2012 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 . +# +# ========================================================================== from gammalib import * from math import * import os import sys +import numpy as np +import matplotlib.pyplot as plt +import matplotlib.cm as cm -# ======================= # -# Test CTA response table # -# ======================= # -def cta_response_table(index=1): +# ====================== # +# Display response table # +# ====================== # +def display_response_table(index=1): """ + Display CTA response table. + + Keywords: + index - Response parameter to display (starting from 0) """ - # Import modules for plotting - import numpy as np - import matplotlib.pyplot as plt - import matplotlib.cm as cm - - # - t = GCTAResponseTable() - print t - - # - fits = GFits('/Users/jurgen/cta/dc1/psf/psf.fits') + # Load PSF into response table + fits = GFits('../caldb/data/cta/e/bcf/000001/irf_test.fits') table = fits.table('POINT SPREAD FUNCTION') - psf = GCTAResponseTable(table) - print psf + psf = GCTAResponseTable(table) + print(psf) # Set limits for 2D plot - emin = 0.05 - emax = 80.0 + emin = 0.05 + emax = 80.0 thetamin = 0.0 thetamax = 2.5 - neng = 100 - ntheta = 100 - logemin = log10(emin) - logemax = log10(emax) - dlogeng = (logemax - logemin) / (neng - 1) - dtheta = (thetamax - thetamin) / (ntheta - 1) + neng = 100 + ntheta = 100 + logemin = log10(emin) + logemax = log10(emax) + dlogeng = (logemax - logemin) / (neng - 1) + dtheta = (thetamax - thetamin) / (ntheta - 1) # Fill image. Note that X and Y are inversed with respect to # traditional orientation @@ -45,9 +65,8 @@ def cta_response_table(index=1): for ieng in range(neng): eng = pow(10.0, logemin + ieng * dlogeng) for itheta in range(ntheta): - theta = thetamin + itheta * dtheta - pars = psf(eng, theta) - # print eng, theta, pars[index] + theta = thetamin + itheta * dtheta + pars = psf(eng, theta) image[itheta, ieng] = pars[index] def format_coord(x, y): @@ -61,7 +80,7 @@ def cta_response_table(index=1): # Show image fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot(111) ax.imshow(image, cmap=cm.jet, interpolation='nearest', origin='lower') ax.format_coord = format_coord plt.show() @@ -78,14 +97,10 @@ if __name__ == '__main__': Perform testing. """ # Dump result - print - print "********************************" - print "* CTA Python interface testing *" - print "********************************" - - # Initialise success counter - tests = 0 - success = 0 + print("") + print("******************************") + print("* Display CTA response table *") + print("******************************") - # Perform tests - cta_response_table() + # Display response table + display_response_table() -- libgit2 0.21.4