Commit 5cec33c1baedf0ad10b4b84b1f320984576a50e2
1 parent
3fb7f249
Rewrite script avoiding the use of a cast.
It was not possible to avoid the cast when reading the models from the XML file, but it was possible to directly allocate the models and to display them.
Showing
1 changed file
with
21 additions
and
24 deletions
inst/cta/test/test_radial_acceptance.py
| 1 | 1 | #! /usr/bin/env python |
| 2 | -# ===========================================================================================# | |
| 3 | -# This script displays the radial acceptance model that may be used to model the | |
| 4 | -# CTA radial acceptance. | |
| 2 | +# ========================================================================== | |
| 3 | +# This script displays the radial acceptance model that may be used to model | |
| 4 | +# the CTA radial acceptance. | |
| 5 | 5 | # |
| 6 | -# Required 3rd party modules: | |
| 6 | +# Requires: | |
| 7 | 7 | # - matplotlib |
| 8 | 8 | # |
| 9 | -# Copyright (C) 2011 Jurgen Knodlseder | |
| 9 | +# Copyright (C) 2011-2012 Juergen Knoedlseder | |
| 10 | 10 | # |
| 11 | 11 | # This program is free software: you can redistribute it and/or modify |
| 12 | 12 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -20,7 +20,8 @@ |
| 20 | 20 | # |
| 21 | 21 | # You should have received a copy of the GNU General Public License |
| 22 | 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | -# ===========================================================================================# | |
| 23 | +# | |
| 24 | +# ========================================================================== | |
| 24 | 25 | import matplotlib.pyplot as plt |
| 25 | 26 | from gammalib import * |
| 26 | 27 | from math import * |
| ... | ... | @@ -29,26 +30,20 @@ from math import * |
| 29 | 30 | # ========== # |
| 30 | 31 | # Show model # |
| 31 | 32 | # ========== # |
| 32 | -def show_model(xmlfile): | |
| 33 | +def show_model(model): | |
| 33 | 34 | """ |
| 34 | - Show radial acceptance model from the XML file using matplotlib. | |
| 35 | + Show radial acceptance model using matplotlib. | |
| 35 | 36 | """ |
| 36 | - # Load the model | |
| 37 | - models = GModels(xmlfile) | |
| 38 | - | |
| 39 | - # Extract radial acceptance model | |
| 40 | - radial = cast_GCTAModelRadialAcceptance(models["Background"]).radial() | |
| 41 | - | |
| 42 | 37 | # Create angular axis (from 0 to 4 deg) |
| 43 | 38 | thetas = [i * 0.05 for i in range(80)] |
| 44 | 39 | |
| 45 | 40 | # Get model values |
| 46 | - values = [radial.eval(theta) for theta in thetas] | |
| 47 | - values_grad = [radial.eval_gradients(theta) for theta in thetas] | |
| 41 | + values = [model.eval(theta) for theta in thetas] | |
| 42 | + values_grad = [model.eval_gradients(theta) for theta in thetas] | |
| 48 | 43 | |
| 49 | 44 | # Create figure |
| 50 | 45 | plt.figure(1) |
| 51 | - plt.title("Radial acceptance model (" + radial.type() + ")") | |
| 46 | + plt.title("Radial acceptance model (" + model.type() + ")") | |
| 52 | 47 | |
| 53 | 48 | # Plot data |
| 54 | 49 | plt.plot(thetas, values, 'r-') |
| ... | ... | @@ -74,11 +69,13 @@ if __name__ == '__main__': |
| 74 | 69 | """ |
| 75 | 70 | # Dump header |
| 76 | 71 | |
| 77 | - print "*********************************" | |
| 78 | - print "* Show radial acceptance models *" | |
| 79 | - print "*********************************" | |
| 72 | + print "*************************************" | |
| 73 | + print "* Show CTA radial acceptance models *" | |
| 74 | + print "*************************************" | |
| 80 | 75 | |
| 81 | -# Display various models | |
| 82 | - show_model("data/crab.xml") | |
| 83 | - show_model("data/crab_poly.xml") | |
| 84 | - show_model("data/crab_profile.xml") | |
| 76 | + # Display various models | |
| 77 | + show_model(GCTAModelRadialGauss(3.0)) | |
| 78 | + show_model(GCTAModelRadialProfile(1.5, 3.0, 5.0)) | |
| 79 | + show_model(GCTAModelRadialPolynom([1.0, -0.1239176, +0.9751791, | |
| 80 | + -3.0584577, +2.9089535, -1.3535372, | |
| 81 | + +0.3413752, -0.0449642, +0.0024321])) | ... | ... |