Commit bca7af9eee5f7e4a04b174a7ce89991c783f2baf

Authored by Jürgen Knödlseder
2 parents 520c7d16 c75683e9

Merge branch 'python-cleanup' into integration

.gitignore
... ... @@ -6,6 +6,7 @@ pyext/build/
6 6 .libs
7 7 .deps
8 8 test/*.fits
  9 +examples/python/*.fits
9 10 inst/cta/test/*.xml
10 11 inst/cta/test/*.fits
11 12 inst/cta/test/*.fits.gz
... ...
test/example_model_xml_io.py renamed to examples/python/example_model_xml_io.py
... ... @@ -3,7 +3,7 @@
3 3 # This script builds a set of models, saves the models into an XML file
4 4 # and loads the models back into memory.
5 5 #
6   -# Copyright (C) 2011-2013 Juergen Knoedlseder
  6 +# Copyright (C) 2011-2015 Juergen Knoedlseder
7 7 #
8 8 # This program is free software: you can redistribute it and/or modify
9 9 # it under the terms of the GNU General Public License as published by
... ... @@ -18,13 +18,13 @@
18 18 # You should have received a copy of the GNU General Public License
19 19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20 # =====================================================================
21   -from gammalib import *
  21 +import gammalib
22 22  
23 23 #
24 24 # Set the location / centre of the source model to
25 25 # Right Ascension = 42.0 deg and Declination = 43 deg
26 26 # ===================================================
27   -centre = GSkyDir()
  27 +centre = gammalib.GSkyDir()
28 28 centre.radec_deg(42.0, 43.0)
29 29  
30 30 #
... ... @@ -32,9 +32,9 @@ centre.radec_deg(42.0, 43.0)
32 32 # Normalization: 1.0e-7 ph/cm2/s/MeV @ 100 MeV
33 33 # Spectral index: -2.1
34 34 # ===================================================
35   -point_spatial = GModelSpatialPointSource(centre)
36   -point_spectrum = GModelSpectralPlaw(1.0e-7, -2.1, GEnergy(100.0, "MeV"))
37   -point = GModelSky(point_spatial, point_spectrum)
  35 +point_spatial = gammalib.GModelSpatialPointSource(centre)
  36 +point_spectrum = gammalib.GModelSpectralPlaw(1.0e-7, -2.1, gammalib.GEnergy(100.0, "MeV"))
  37 +point = gammalib.GModelSky(point_spatial, point_spectrum)
38 38 point.name('My point source')
39 39  
40 40 #
... ... @@ -43,9 +43,9 @@ point.name(&#39;My point source&#39;)
43 43 # Normalization: 4.2e-7 ph/cm2/s/MeV @ 100 MeV
44 44 # Spectral index: -2.4
45 45 # ===================================================
46   -gauss_spatial = GModelSpatialRadialGauss(centre, 3.0)
47   -gauss_spectrum = GModelSpectralPlaw(4.2e-7, -2.4, GEnergy(100.0, "MeV"))
48   -gauss = GModelSky(gauss_spatial, gauss_spectrum)
  46 +gauss_spatial = gammalib.GModelSpatialRadialGauss(centre, 3.0)
  47 +gauss_spectrum = gammalib.GModelSpectralPlaw(4.2e-7, -2.4, gammalib.GEnergy(100.0, "MeV"))
  48 +gauss = gammalib.GModelSky(gauss_spatial, gauss_spectrum)
49 49 gauss.name('My Gaussian source')
50 50  
51 51 #
... ... @@ -53,7 +53,7 @@ gauss.name(&#39;My Gaussian source&#39;)
53 53 # models to the model container. Print the content of the
54 54 # container
55 55 # =========================================================
56   -models = GModels()
  56 +models = gammalib.GModels()
57 57 models.append(point)
58 58 models.append(gauss)
59 59 print(models)
... ... @@ -70,6 +70,6 @@ del models
70 70 # Now read the models back from the XML file into the container.
71 71 # Print again the content of the container.
72 72 # ==============================================================
73   -models2 = GModels(filename)
  73 +models2 = gammalib.GModels(filename)
74 74 print("")
75 75 print(models2)
... ...
test/example_radial_models.py renamed to examples/python/example_radial_models.py
... ... @@ -18,7 +18,7 @@
18 18 # You should have received a copy of the GNU General Public License
19 19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20 # =====================================================================
21   -from gammalib import *
  21 +import gammalib
22 22  
23 23  
24 24 # ============================ #
... ... @@ -30,11 +30,11 @@ def test_radial_model(name, model, clobber=True):
30 30 """
31 31 # Make a 2D FITS image (cartesian projection, celestial coordinates)
32 32 ra, dec, binsz, npix = 0, 0, 0.01, 300
33   - image = GSkymap("CAR", "CEL", ra, dec, -binsz, binsz, npix, npix, 1)
  33 + image = gammalib.GSkymap("CAR", "CEL", ra, dec, -binsz, binsz, npix, npix, 1)
34 34  
35 35 # Fill the image
36   - energy = GEnergy()
37   - time = GTime()
  36 + energy = gammalib.GEnergy()
  37 + time = gammalib.GTime()
38 38 for inx in range(image.npix()):
39 39 dir = image.inx2dir(inx)
40 40 theta = centre.dist(dir)
... ... @@ -62,10 +62,15 @@ if __name__ == &#39;__main__&#39;:
62 62 Test radial model integration.
63 63 """
64 64 # Set model location / centre
65   - centre = GSkyDir()
  65 + centre = gammalib.GSkyDir()
66 66 centre.radec_deg(0.3, 0.1)
67 67  
68 68 # Test models
69   - test_radial_model(name='gauss', model=GModelSpatialRadialGauss(centre, 0.3))
70   - test_radial_model(name='disk', model=GModelSpatialRadialDisk(centre, 0.8))
71   - test_radial_model(name='shell', model=GModelSpatialRadialShell(centre, 0.5, 0.1))
  69 + model = gammalib.GModelSpatialRadialGauss(centre, 0.3)
  70 + test_radial_model(name='gauss', model=model)
  71 +
  72 + model = gammalib.GModelSpatialRadialDisk(centre, 0.8)
  73 + test_radial_model(name='disk', model=model)
  74 +
  75 + model = gammalib.GModelSpatialRadialShell(centre, 0.5, 0.1)
  76 + test_radial_model(name='shell', model=model)
... ...
test/test_GApplication.py
1 1 # ==========================================================================
2 2 # This module performs unit tests for the GammaLib application module.
3 3 #
4   -# Copyright (C) 2012 Juergen Knoedlseder
  4 +# Copyright (C) 2012-2015 Juergen Knoedlseder
5 5 #
6 6 # This program is free software: you can redistribute it and/or modify
7 7 # it under the terms of the GNU General Public License as published by
... ... @@ -17,16 +17,13 @@
17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 #
19 19 # ==========================================================================
20   -from gammalib import *
21   -from math import *
22   -import os
23   -import sys
  20 +import gammalib
24 21  
25 22  
26 23 # ========================================== #
27 24 # Test class for GammaLib application module #
28 25 # ========================================== #
29   -class Test(GPythonTestSuite):
  26 +class Test(gammalib.GPythonTestSuite):
30 27 """
31 28 Test class for GammaLib application module.
32 29 """
... ... @@ -36,7 +33,7 @@ class Test(GPythonTestSuite):
36 33 Constructor.
37 34 """
38 35 # Call base class constructor
39   - GPythonTestSuite.__init__(self)
  36 + gammalib.GPythonTestSuite.__init__(self)
40 37  
41 38 # Set members
42 39 self.logfile = "test_logger.log"
... ... @@ -65,7 +62,7 @@ class Test(GPythonTestSuite):
65 62 Test GLog.
66 63 """
67 64 # Allocate logger
68   - log = GLog(self.logfile, True)
  65 + log = gammalib.GLog(self.logfile, True)
69 66  
70 67 # Test print methods
71 68 log("Test __call__(std::string)")
... ... @@ -161,7 +158,7 @@ class Test(GPythonTestSuite):
161 158 # Test GApplicationPars constructor with bad filename.
162 159 self.test_try("Test GApplicationPars constructor with bad filename")
163 160 try:
164   - pars = GApplicationPars("testme.par")
  161 + pars = gammalib.GApplicationPars("testme.par")
165 162 self.test_try_failure("Exception not thrown.")
166 163 except:
167 164 self.test_try_success()
... ...
test/test_GFits.py
... ... @@ -17,16 +17,15 @@
17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 #
19 19 # ==========================================================================
20   -from gammalib import *
21   -from math import *
  20 +import math
22 21 import os
23 22 import sys
24   -
  23 +import gammalib
25 24  
26 25 # =================================== #
27 26 # Test class for GammaLib FITS module #
28 27 # =================================== #
29   -class Test(GPythonTestSuite):
  28 +class Test(gammalib.GPythonTestSuite):
30 29 """
31 30 Test class for GammaLib FITS module.
32 31 """
... ... @@ -35,7 +34,7 @@ class Test(GPythonTestSuite):
35 34 Constructor.
36 35 """
37 36 # Call base class constructor
38   - GPythonTestSuite.__init__(self)
  37 + gammalib.GPythonTestSuite.__init__(self)
39 38  
40 39 # Return
41 40 return
... ... @@ -69,21 +68,21 @@ class Test(GPythonTestSuite):
69 68 pass
70 69  
71 70 # Create FITS file
72   - fits = GFits(file1, True)
  71 + fits = gammalib.GFits(file1, True)
73 72 sys.stdout.write(".")
74 73  
75 74 # Create images
76 75 nx = 10
77 76 ny = 10
78   - img1 = GFitsImageByte(nx, ny)
79   - img2 = GFitsImageDouble(nx, ny)
80   - img3 = GFitsImageFloat(nx, ny)
81   - img4 = GFitsImageLong(nx, ny)
82   - img5 = GFitsImageLongLong(nx, ny)
83   - img6 = GFitsImageSByte(nx, ny)
84   - img7 = GFitsImageShort(nx, ny)
85   - img8 = GFitsImageULong(nx, ny)
86   - img9 = GFitsImageUShort(nx, ny)
  77 + img1 = gammalib.GFitsImageByte(nx, ny)
  78 + img2 = gammalib.GFitsImageDouble(nx, ny)
  79 + img3 = gammalib.GFitsImageFloat(nx, ny)
  80 + img4 = gammalib.GFitsImageLong(nx, ny)
  81 + img5 = gammalib.GFitsImageLongLong(nx, ny)
  82 + img6 = gammalib.GFitsImageSByte(nx, ny)
  83 + img7 = gammalib.GFitsImageShort(nx, ny)
  84 + img8 = gammalib.GFitsImageULong(nx, ny)
  85 + img9 = gammalib.GFitsImageUShort(nx, ny)
87 86 for x in range(nx):
88 87 for y in range(ny):
89 88 img1[x, y] = x + y * nx
... ... @@ -127,17 +126,17 @@ class Test(GPythonTestSuite):
127 126  
128 127 # Create table columns
129 128 nrows = 10
130   - col1 = GFitsTableBitCol("BIT", nrows)
131   - col2 = GFitsTableBoolCol("BOOLEAN", nrows)
132   - col3 = GFitsTableByteCol("BYTE", nrows)
133   - col4 = GFitsTableDoubleCol("DOUBLE", nrows)
134   - col5 = GFitsTableFloatCol("FLOAT", nrows)
135   - col6 = GFitsTableLongCol("LONG", nrows)
136   - col7 = GFitsTableLongLongCol("LONGLONG", nrows)
137   - col8 = GFitsTableShortCol("SHORT", nrows)
138   - col9 = GFitsTableStringCol("STRING", nrows, 20)
139   - col10 = GFitsTableULongCol("ULONG", nrows)
140   - col11 = GFitsTableUShortCol("USHORT", nrows)
  129 + col1 = gammalib.GFitsTableBitCol("BIT", nrows)
  130 + col2 = gammalib.GFitsTableBoolCol("BOOLEAN", nrows)
  131 + col3 = gammalib.GFitsTableByteCol("BYTE", nrows)
  132 + col4 = gammalib.GFitsTableDoubleCol("DOUBLE", nrows)
  133 + col5 = gammalib.GFitsTableFloatCol("FLOAT", nrows)
  134 + col6 = gammalib.GFitsTableLongCol("LONG", nrows)
  135 + col7 = gammalib.GFitsTableLongLongCol("LONGLONG", nrows)
  136 + col8 = gammalib.GFitsTableShortCol("SHORT", nrows)
  137 + col9 = gammalib.GFitsTableStringCol("STRING", nrows, 20)
  138 + col10 = gammalib.GFitsTableULongCol("ULONG", nrows)
  139 + col11 = gammalib.GFitsTableUShortCol("USHORT", nrows)
141 140 for i in range(nrows):
142 141 col1[i] = i % 2
143 142 col2[i] = i % 2
... ... @@ -153,7 +152,7 @@ class Test(GPythonTestSuite):
153 152 sys.stdout.write(".")
154 153  
155 154 # Set ASCII table
156   - tbl_ascii = GFitsAsciiTable()
  155 + tbl_ascii = gammalib.GFitsAsciiTable()
157 156 # tbl_ascii.append(col1) # Need to implement ?/!
158 157 # tbl_ascii.append(col2) # Need to implement ?/!
159 158 tbl_ascii.append(col3)
... ... @@ -170,7 +169,7 @@ class Test(GPythonTestSuite):
170 169 sys.stdout.write(".")
171 170  
172 171 # Set binary table
173   - tbl_bin = GFitsBinTable()
  172 + tbl_bin = gammalib.GFitsBinTable()
174 173 tbl_bin.append(col1)
175 174 tbl_bin.append(col2)
176 175 tbl_bin.append(col3)
... ... @@ -196,7 +195,7 @@ class Test(GPythonTestSuite):
196 195 sys.stdout.write(".")
197 196  
198 197 # Re-open FITS file
199   - fits = GFits(file1)
  198 + fits = gammalib.GFits(file1)
200 199 sys.stdout.write(".")
201 200  
202 201 # Get double precision image, take square root of pixel and save in
... ... @@ -204,7 +203,7 @@ class Test(GPythonTestSuite):
204 203 img_double = fits.image("Double")
205 204 for x in range(nx):
206 205 for y in range(ny):
207   - img_double[x, y] = sqrt(img_double[x, y])
  206 + img_double[x, y] = math.sqrt(img_double[x, y])
208 207 sys.stdout.write(".")
209 208  
210 209 # Save into another FITS file
... ...
test/test_column_insert_remove.py
1 1 #! /usr/bin/env python
2 2  
3   -from gammalib import *
4   -
  3 +import gammalib
5 4  
6 5 def test_one(a):
7 6 a[0] = 1
8 7 a[1] = 2
9 8 a[2] = 3
10   - print a
  9 + print(a)
11 10 return a
12 11  
13 12  
... ... @@ -18,18 +17,18 @@ def test_two(a):
18 17 a.remove(1, 2)
19 18 a.remove(1, 1)
20 19 a.remove(0, 1)
21   - print a
  20 + print(a)
22 21 return a
23 22  
24 23  
25 24 def test_three(a):
26 25 a.insert(0, 10)
27   - print a
  26 + print(a)
28 27 a[7] = 99
29 28 a.remove(8, 2)
30 29 a[0] = 99
31 30 a.remove(1, 5)
32   - print a
  31 + print(a)
33 32 return a
34 33  
35 34  
... ... @@ -38,7 +37,7 @@ def set(a):
38 37 a[1] = 65536
39 38 a[2] = True
40 39 # a[3] = "Hallo"
41   - print a[1]
  40 + print(a[1])
42 41  
43 42  
44 43 #==========================#
... ... @@ -49,17 +48,17 @@ if __name__ == &#39;__main__&#39;:
49 48 Perform testing.
50 49 """
51 50 # Perform tests
52   - # a = GFitsTableBitCol("Test",4)
53   - # a = GFitsTableBoolCol("Test",4)
54   - # a = GFitsTableByteCol("Test",4)
55   - # a = GFitsTableDoubleCol("Test",4)
56   - # a = GFitsTableFloatCol("Test",4)
57   - # a = GFitsTableLongCol("Test",4)
58   - # a = GFitsTableLongLongCol("Test",4)
59   - # a = GFitsTableShortCol("Test",4)
60   - # a = GFitsTableStringCol("Test",4,10)
61   - # a = GFitsTableULongCol("Test",4)
62   - a = GFitsTableUShortCol("Test", 4)
  51 + # a = gammalib.GFitsTableBitCol("Test",4)
  52 + # a = gammalib.GFitsTableBoolCol("Test",4)
  53 + # a = gammalib.GFitsTableByteCol("Test",4)
  54 + # a = gammalib.GFitsTableDoubleCol("Test",4)
  55 + # a = gammalib.GFitsTableFloatCol("Test",4)
  56 + # a = gammalib.GFitsTableLongCol("Test",4)
  57 + # a = gammalib.GFitsTableLongLongCol("Test",4)
  58 + # a = gammalib.GFitsTableShortCol("Test",4)
  59 + # a = gammalib.GFitsTableStringCol("Test",4,10)
  60 + # a = gammalib.GFitsTableULongCol("Test",4)
  61 + a = gammalib.GFitsTableUShortCol("Test", 4)
63 62 a = test_one(a)
64 63 a = test_two(a)
65 64 a = test_three(a)
... ...
test/test_diffuse_cube.py
... ... @@ -6,7 +6,7 @@
6 6 #
7 7 # --------------------------------------------------------------------------
8 8 #
9   -# Copyright (C) 2013 Juergen Knoedlseder
  9 +# Copyright (C) 2013-2015 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
... ... @@ -22,9 +22,8 @@
22 22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 23 #
24 24 # ==========================================================================
25   -from gammalib import *
26   -from math import *
27   -
  25 +import math
  26 +import gammalib
28 27  
29 28 # ======================== #
30 29 # Simulate CTA observation #
... ... @@ -34,20 +33,20 @@ def simulate(xmlname, e_min, e_max, area, duration, dir, radius):
34 33 Simulate CTA observation.
35 34 """
36 35 # Allocate MC parameters
37   - emin = GEnergy()
38   - emax = GEnergy()
39   - tmin = GTime(0.0)
40   - tmax = GTime(duration)
  36 + emin = gammalib.GEnergy()
  37 + emax = gammalib.GEnergy()
  38 + tmin = gammalib.GTime(0.0)
  39 + tmax = gammalib.GTime(duration)
41 40  
42 41 # Define MC parameters
43 42 emin.TeV(e_min)
44 43 emax.TeV(e_max)
45 44  
46 45 # Allocate random number generator
47   - ran = GRan()
  46 + ran = gammalib.GRan()
48 47  
49 48 # Load models and extract first model
50   - models = GModels(xmlname)
  49 + models = gammalib.GModels(xmlname)
51 50 model = models[0]
52 51 #print(model)
53 52 #print(model.spatial())
... ... @@ -80,7 +79,8 @@ def show_photons(photons, xmlname, e_min, e_max, area, duration, dir, radius, eb
80 79 plt.title("MC simulated photon spectrum (" + str(e_min) + '-' + str(e_max) + " TeV)")
81 80  
82 81 # Setup energy range covered by data
83   - ebds = GEbounds(ebins, GEnergy(e_min, "TeV"), GEnergy(e_max, "TeV"))
  82 + ebds = gammalib.GEbounds(ebins, gammalib.GEnergy(e_min, "TeV"),
  83 + gammalib.GEnergy(e_max, "TeV"))
84 84  
85 85 # Create energy axis
86 86 energy = []
... ... @@ -94,13 +94,13 @@ def show_photons(photons, xmlname, e_min, e_max, area, duration, dir, radius, eb
94 94 counts[index] = counts[index] + 1.0
95 95  
96 96 # Create error bars
97   - error = [sqrt(c) for c in counts]
  97 + error = [math.sqrt(c) for c in counts]
98 98  
99 99 # Get model values
100   - models = GModels(xmlname)
  100 + models = gammalib.GModels(xmlname)
101 101 mod = models[0]
102 102 model = []
103   - t = GTime()
  103 + t = gammalib.GTime()
104 104 mod.spatial().set_mc_cone(dir, radius)
105 105 for i in range(ebds.size()):
106 106 eng = ebds.elogmean(i)
... ... @@ -173,7 +173,7 @@ if __name__ == &#39;__main__&#39;:
173 173 e_max = 100.0 # 100 TeV
174 174 area = 1.0 # 1 cm2
175 175 duration = 1.0 # 1 sec
176   - dir = GSkyDir()
  176 + dir = gammalib.GSkyDir()
177 177 dir.radec_deg(84.17263, 22.01444)
178 178 radius = 1.0
179 179  
... ...
test/test_file_function.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This script tests the GModelSpectralFunc file function spectral model.
4 4 #
5   -# Copyright (C) 2011 Jurgen Knodlseder
  5 +# Copyright (C) 2011-2015 Jurgen Knodlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -18,9 +18,8 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
21   -from gammalib import *
22 21 import math
23   -
  22 +import gammalib
24 23  
25 24 # ================================= #
26 25 # Generate file function from model #
... ... @@ -37,14 +36,14 @@ def make_file_function(model, emin=0.1e6, emax=100.0e6, nodes=10):
37 36 file = open(filename, "w")
38 37 for i in range(nodes):
39 38 energy = math.pow(10.0, math.log10(emin) + i * dloge)
40   - eng = GEnergy()
  39 + eng = gammalib.GEnergy()
41 40 eng.MeV(energy)
42 41 value = model.eval(eng)
43 42 file.write(str(energy) + " " + str(value) + "\n")
44 43 file.close()
45 44  
46 45 # Generate file function
47   - file_function = GModelSpectralFunc(filename)
  46 + file_function = gammalib.GModelSpectralFunc(filename)
48 47  
49 48 # Return
50 49 return file_function
... ... @@ -62,8 +61,8 @@ def compare_photon_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
62 61 n_violate = 0
63 62  
64 63 # Allocate boundaries
65   - e_min = GEnergy()
66   - e_max = GEnergy()
  64 + e_min = gammalib.GEnergy()
  65 + e_max = gammalib.GEnergy()
67 66  
68 67 # Ramp up emax from below first node
69 68 e_min.MeV(emin)
... ... @@ -72,9 +71,9 @@ def compare_photon_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
72 71 energy = math.pow(10.0, math.log10(emin) + i * dloge)
73 72 e_max.MeV(energy)
74 73 flux_model = model.flux(e_min, e_max)
75   - flux_ff = file_function.flux(e_min, e_max)
  74 + flux_ff = file_function.flux(e_min, e_max)
76 75 if (abs(flux_model - flux_ff) > eps):
77   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  76 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
78 77 n_violate += 1
79 78  
80 79 # Ramp up emax from above first node
... ... @@ -87,7 +86,7 @@ def compare_photon_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
87 86 flux_model = model.flux(e_min, e_max)
88 87 flux_ff = file_function.flux(e_min, e_max)
89 88 if (abs(flux_model - flux_ff) > eps):
90   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  89 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
91 90 n_violate += 1
92 91  
93 92 # Ramp down emin from above last node
... ... @@ -99,7 +98,7 @@ def compare_photon_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
99 98 flux_model = model.flux(e_min, e_max)
100 99 flux_ff = file_function.flux(e_min, e_max)
101 100 if (abs(flux_model - flux_ff) > eps):
102   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  101 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
103 102 n_violate += 1
104 103  
105 104 # Ramp down emin from below last node
... ... @@ -112,14 +111,14 @@ def compare_photon_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
112 111 flux_model = model.flux(e_min, e_max)
113 112 flux_ff = file_function.flux(e_min, e_max)
114 113 if (abs(flux_model - flux_ff) > eps):
115   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  114 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
116 115 n_violate += 1
117 116  
118 117 # Print summary
119 118 if n_violate == 0:
120   - print "compare_photon_flux: All tests satisfied accuracy."
  119 + print("compare_photon_flux: All tests satisfied accuracy.")
121 120 else:
122   - print "compare_photon_flux: " + str(n_violate) + " tests exceeded accuracy."
  121 + print("compare_photon_flux: " + str(n_violate) + " tests exceeded accuracy.")
123 122  
124 123 # Return
125 124 return
... ... @@ -137,8 +136,8 @@ def compare_energy_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
137 136 n_violate = 0
138 137  
139 138 # Allocate boundaries
140   - e_min = GEnergy()
141   - e_max = GEnergy()
  139 + e_min = gammalib.GEnergy()
  140 + e_max = gammalib.GEnergy()
142 141  
143 142 # Ramp up emax from below first node
144 143 e_min.MeV(emin)
... ... @@ -149,7 +148,7 @@ def compare_energy_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
149 148 flux_model = model.eflux(e_min, e_max)
150 149 flux_ff = file_function.eflux(e_min, e_max)
151 150 if (abs(flux_model - flux_ff) > eps):
152   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  151 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
153 152 n_violate += 1
154 153  
155 154 # Ramp up emax from above first node
... ... @@ -162,7 +161,7 @@ def compare_energy_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
162 161 flux_model = model.eflux(e_min, e_max)
163 162 flux_ff = file_function.eflux(e_min, e_max)
164 163 if (abs(flux_model - flux_ff) > eps):
165   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  164 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
166 165 n_violate += 1
167 166  
168 167 # Ramp down emin from above last node
... ... @@ -174,7 +173,7 @@ def compare_energy_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
174 173 flux_model = model.eflux(e_min, e_max)
175 174 flux_ff = file_function.eflux(e_min, e_max)
176 175 if (abs(flux_model - flux_ff) > eps):
177   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  176 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
178 177 n_violate += 1
179 178  
180 179 # Ramp down emin from below last node
... ... @@ -187,14 +186,14 @@ def compare_energy_flux(model, file_function, emin=8.7, emax=1123.0, steps=13):
187 186 flux_model = model.eflux(e_min, e_max)
188 187 flux_ff = file_function.eflux(e_min, e_max)
189 188 if (abs(flux_model - flux_ff) > eps):
190   - print e_min, e_max, flux_model, flux_ff, flux_model - flux_ff
  189 + print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff)
191 190 n_violate += 1
192 191  
193 192 # Print summary
194 193 if n_violate == 0:
195   - print "compare_energy_flux: All tests satisfied accuracy."
  194 + print("compare_energy_flux: All tests satisfied accuracy.")
196 195 else:
197   - print "compare_energy_flux: " + str(n_violate) + " tests exceeded accuracy."
  196 + print("compare_energy_flux: " + str(n_violate) + " tests exceeded accuracy.")
198 197  
199 198 # Return
200 199 return
... ... @@ -208,17 +207,17 @@ def test_mc(file_function, trials=10):
208 207 Print a bunch of Monte Carlo energies.
209 208 """
210 209 # Allocate boundaries
211   - e_min = GEnergy()
212   - e_max = GEnergy()
213   - ran = GRan()
  210 + e_min = gammalib.GEnergy()
  211 + e_max = gammalib.GEnergy()
  212 + ran = GRan()
214 213  
215 214 # Set energy range
216 215 e_min.TeV(0.1)
217 216 e_max.TeV(100.0)
218 217  
219   -# Loop over trials
  218 + # Loop over trials
220 219 for i in range(trials):
221   - print file_function.mc(e_min, e_max, ran)
  220 + print(file_function.mc(e_min, e_max, ran))
222 221  
223 222 # Return
224 223 return
... ... @@ -232,7 +231,7 @@ if __name__ == &#39;__main__&#39;:
232 231 Main entry point
233 232 """
234 233 # Allocate power law
235   - model = GModelSpectralPlaw(5.7, -2.48)
  234 + model = gammalib.GModelSpectralPlaw(5.7, -2.48)
236 235 model["Prefactor"].scale(1.0e-16)
237 236 model["PivotEnergy"].value(0.3)
238 237 model["PivotEnergy"].scale(1.0e6)
... ...