Commit 1937fcb0b60acec82cf96523270a8636bf1f48e8

Authored by knodlseder
1 parent a6db57bd

Initial version (will not work in current distribution)

inst/cta/test/test_response_table.py 0 → 100755
  1 +#! /usr/bin/env python
  2 +
  3 +from gammalib import *
  4 +from math import *
  5 +import os
  6 +import sys
  7 +
  8 +
  9 +# ======================= #
  10 +# Test CTA response table #
  11 +# ======================= #
  12 +def cta_response_table(index=1):
  13 + """
  14 + """
  15 + # Import modules for plotting
  16 + import numpy as np
  17 + import matplotlib.pyplot as plt
  18 + import matplotlib.cm as cm
  19 +
  20 + #
  21 + t = GCTAResponseTable()
  22 + print t
  23 +
  24 + #
  25 + fits = GFits('/Users/jurgen/cta/dc1/psf/psf.fits')
  26 + table = fits.table('POINT SPREAD FUNCTION')
  27 + psf = GCTAResponseTable(table)
  28 + print psf
  29 +
  30 + # Set limits for 2D plot
  31 + emin = 0.05
  32 + emax = 80.0
  33 + thetamin = 0.0
  34 + thetamax = 2.5
  35 + neng = 100
  36 + ntheta = 100
  37 + logemin = log10(emin)
  38 + logemax = log10(emax)
  39 + dlogeng = (logemax-logemin)/(neng-1)
  40 + dtheta = (thetamax-thetamin)/(ntheta-1)
  41 +
  42 + # Fill image. Note that X and Y are inversed with respect to
  43 + # traditional orientation
  44 + image = np.zeros((ntheta,neng))
  45 + for ieng in range(neng):
  46 + eng = pow(10.0,logemin+ieng*dlogeng)
  47 + for itheta in range(ntheta):
  48 + theta = thetamin+itheta*dtheta
  49 + pars = psf(eng, theta)
  50 + #print eng, theta, pars[index]
  51 + image[itheta,ieng] = pars[index]
  52 +
  53 + def format_coord(x, y):
  54 + col = int(x+0.5)
  55 + row = int(y+0.5)
  56 + if col>=0 and col<ntheta and row>=0 and row<neng:
  57 + z = image[row,col]
  58 + return 'x=%1.4f, y=%1.4f, z=%1.4f'%(x, y, z)
  59 + else:
  60 + return 'x=%1.4f, y=%1.4f'%(x, y)
  61 +
  62 + # Show image
  63 + fig = plt.figure()
  64 + ax = fig.add_subplot(111)
  65 + ax.imshow(image, cmap=cm.jet, interpolation='nearest', origin='lower')
  66 + ax.format_coord = format_coord
  67 + plt.show()
  68 +
  69 + # Return
  70 + return
  71 +
  72 +
  73 +# ======================== #
  74 +# Main routine entry point #
  75 +# ======================== #
  76 +if __name__ == '__main__':
  77 + """
  78 + Perform testing.
  79 + """
  80 + # Dump result
  81 + print
  82 + print "********************************"
  83 + print "* CTA Python interface testing *"
  84 + print "********************************"
  85 +
  86 + # Initialise success counter
  87 + tests = 0
  88 + success = 0
  89 +
  90 + # Perform tests
  91 + cta_response_table()
  92 +
... ...