Commit f337400962d8ba7e5b4cdcebbf4a074c27bcfbaf

Authored by Jürgen Knödlseder
1 parent 470f02df

Adapt to Python 3.

inst/cta/test/example_binned_ml_fit.py
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 - 2 +# ==========================================================================
  3 +# This script performs a binned maximum likelihood analysis of CTA data.
  4 +#
  5 +# Copyright (C) 2012 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 +# ==========================================================================
3 from gammalib import * 21 from gammalib import *
4 from math import * 22 from math import *
5 23
@@ -45,7 +63,7 @@ def binned_analysis(model, cntmap, irf, caldb): @@ -45,7 +63,7 @@ def binned_analysis(model, cntmap, irf, caldb):
45 models = obs.models().copy() 63 models = obs.models().copy()
46 64
47 # Print optimizer results 65 # Print optimizer results
48 - print opt 66 + print(opt)
49 67
50 # Create now a copy of the source model without background 68 # Create now a copy of the source model without background
51 # only 69 # only
@@ -67,10 +85,10 @@ def binned_analysis(model, cntmap, irf, caldb): @@ -67,10 +85,10 @@ def binned_analysis(model, cntmap, irf, caldb):
67 ts = 2.0 * (logL - logL0) 85 ts = 2.0 * (logL - logL0)
68 86
69 # Print optimizer results 87 # Print optimizer results
70 - print opt 88 + print(opt)
71 89
72 # Print TS 90 # Print TS
73 - print " Test statistics ...........:", ts 91 + print(" Test statistics ...........:", ts)
74 92
75 # Return models 93 # Return models
76 return models 94 return models
@@ -84,20 +102,20 @@ if __name__ == &#39;__main__&#39;: @@ -84,20 +102,20 @@ if __name__ == &#39;__main__&#39;:
84 Example illustrating a binned data analysis. 102 Example illustrating a binned data analysis.
85 """ 103 """
86 # Dump header 104 # Dump header
87 - print  
88 - print "*********************************************************"  
89 - print "* Perform binned maximum likelihood fitting of CTA data *"  
90 - print "*********************************************************"  
91 - print "... please wait for a few seconds" 105 + print("")
  106 + print("*********************************************************")
  107 + print("* Perform binned maximum likelihood fitting of CTA data *")
  108 + print("*********************************************************")
  109 + print("... please wait for a few seconds")
92 110
93 # Set parameters 111 # Set parameters
94 - irf = "kb_E_50h_v3"  
95 - caldb = "../caldb"  
96 - model = "data/crab.xml" 112 + irf = "kb_E_50h_v3"
  113 + caldb = "../caldb"
  114 + model = "data/crab.xml"
97 cntmap = "data/crab_cntmap.fits" 115 cntmap = "data/crab_cntmap.fits"
98 116
99 -# Perform binned analysis 117 + # Perform binned analysis
100 result = binned_analysis(model, cntmap, irf, caldb) 118 result = binned_analysis(model, cntmap, irf, caldb)
101 119
102 # Print model results 120 # Print model results
103 - print result 121 + print(result)