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