Commit c75683e9213be319f930d7b3687027f5c491a7b8
1 parent
7f1dc4d6
Clean-up the clean up :-)
Showing
4 changed files
with
36 additions
and
36 deletions
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 |
| ... | ... | @@ -19,7 +19,6 @@ |
| 19 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | 20 | # ===================================================================== |
| 21 | 21 | import gammalib |
| 22 | -from gammalib import GEnergy | |
| 23 | 22 | |
| 24 | 23 | # |
| 25 | 24 | # Set the location / centre of the source model to |
| ... | ... | @@ -34,7 +33,7 @@ centre.radec_deg(42.0, 43.0) |
| 34 | 33 | # Spectral index: -2.1 |
| 35 | 34 | # =================================================== |
| 36 | 35 | point_spatial = gammalib.GModelSpatialPointSource(centre) |
| 37 | -point_spectrum = gammalib.GModelSpectralPlaw(1.0e-7, -2.1, GEnergy(100.0, "MeV")) | |
| 36 | +point_spectrum = gammalib.GModelSpectralPlaw(1.0e-7, -2.1, gammalib.GEnergy(100.0, "MeV")) | |
| 38 | 37 | point = gammalib.GModelSky(point_spatial, point_spectrum) |
| 39 | 38 | point.name('My point source') |
| 40 | 39 | |
| ... | ... | @@ -45,7 +44,7 @@ point.name('My point source') |
| 45 | 44 | # Spectral index: -2.4 |
| 46 | 45 | # =================================================== |
| 47 | 46 | gauss_spatial = gammalib.GModelSpatialRadialGauss(centre, 3.0) |
| 48 | -gauss_spectrum = gammalib.GModelSpectralPlaw(4.2e-7, -2.4, GEnergy(100.0, "MeV")) | |
| 47 | +gauss_spectrum = gammalib.GModelSpectralPlaw(4.2e-7, -2.4, gammalib.GEnergy(100.0, "MeV")) | |
| 49 | 48 | gauss = gammalib.GModelSky(gauss_spatial, gauss_spectrum) |
| 50 | 49 | gauss.name('My Gaussian source') |
| 51 | 50 | ... | ... |
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,13 +17,13 @@ |
| 17 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | 18 | # |
| 19 | 19 | # ========================================================================== |
| 20 | -from gammalib import GPythonTestSuite, GLog, GApplicationPars | |
| 20 | +import gammalib | |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | # ========================================== # |
| 24 | 24 | # Test class for GammaLib application module # |
| 25 | 25 | # ========================================== # |
| 26 | -class Test(GPythonTestSuite): | |
| 26 | +class Test(gammalib.GPythonTestSuite): | |
| 27 | 27 | """ |
| 28 | 28 | Test class for GammaLib application module. |
| 29 | 29 | """ |
| ... | ... | @@ -33,7 +33,7 @@ class Test(GPythonTestSuite): |
| 33 | 33 | Constructor. |
| 34 | 34 | """ |
| 35 | 35 | # Call base class constructor |
| 36 | - GPythonTestSuite.__init__(self) | |
| 36 | + gammalib.GPythonTestSuite.__init__(self) | |
| 37 | 37 | |
| 38 | 38 | # Set members |
| 39 | 39 | self.logfile = "test_logger.log" |
| ... | ... | @@ -62,7 +62,7 @@ class Test(GPythonTestSuite): |
| 62 | 62 | Test GLog. |
| 63 | 63 | """ |
| 64 | 64 | # Allocate logger |
| 65 | - log = GLog(self.logfile, True) | |
| 65 | + log = gammalib.GLog(self.logfile, True) | |
| 66 | 66 | |
| 67 | 67 | # Test print methods |
| 68 | 68 | log("Test __call__(std::string)") |
| ... | ... | @@ -158,7 +158,7 @@ class Test(GPythonTestSuite): |
| 158 | 158 | # Test GApplicationPars constructor with bad filename. |
| 159 | 159 | self.test_try("Test GApplicationPars constructor with bad filename") |
| 160 | 160 | try: |
| 161 | - pars = GApplicationPars("testme.par") | |
| 161 | + pars = gammalib.GApplicationPars("testme.par") | |
| 162 | 162 | self.test_try_failure("Exception not thrown.") |
| 163 | 163 | except: |
| 164 | 164 | self.test_try_success() | ... | ... |
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 |
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | # |
| 24 | 24 | # ========================================================================== |
| 25 | 25 | import math |
| 26 | -from gammalib import GEnergy, GTime, GRan, GModels, GEbounds, GSkyDir | |
| 26 | +import gammalib | |
| 27 | 27 | |
| 28 | 28 | # ======================== # |
| 29 | 29 | # Simulate CTA observation # |
| ... | ... | @@ -33,20 +33,20 @@ def simulate(xmlname, e_min, e_max, area, duration, dir, radius): |
| 33 | 33 | Simulate CTA observation. |
| 34 | 34 | """ |
| 35 | 35 | # Allocate MC parameters |
| 36 | - emin = GEnergy() | |
| 37 | - emax = GEnergy() | |
| 38 | - tmin = GTime(0.0) | |
| 39 | - tmax = GTime(duration) | |
| 36 | + emin = gammalib.GEnergy() | |
| 37 | + emax = gammalib.GEnergy() | |
| 38 | + tmin = gammalib.GTime(0.0) | |
| 39 | + tmax = gammalib.GTime(duration) | |
| 40 | 40 | |
| 41 | 41 | # Define MC parameters |
| 42 | 42 | emin.TeV(e_min) |
| 43 | 43 | emax.TeV(e_max) |
| 44 | 44 | |
| 45 | 45 | # Allocate random number generator |
| 46 | - ran = GRan() | |
| 46 | + ran = gammalib.GRan() | |
| 47 | 47 | |
| 48 | 48 | # Load models and extract first model |
| 49 | - models = GModels(xmlname) | |
| 49 | + models = gammalib.GModels(xmlname) | |
| 50 | 50 | model = models[0] |
| 51 | 51 | #print(model) |
| 52 | 52 | #print(model.spatial()) |
| ... | ... | @@ -79,7 +79,8 @@ def show_photons(photons, xmlname, e_min, e_max, area, duration, dir, radius, eb |
| 79 | 79 | plt.title("MC simulated photon spectrum (" + str(e_min) + '-' + str(e_max) + " TeV)") |
| 80 | 80 | |
| 81 | 81 | # Setup energy range covered by data |
| 82 | - 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")) | |
| 83 | 84 | |
| 84 | 85 | # Create energy axis |
| 85 | 86 | energy = [] |
| ... | ... | @@ -96,10 +97,10 @@ def show_photons(photons, xmlname, e_min, e_max, area, duration, dir, radius, eb |
| 96 | 97 | error = [math.sqrt(c) for c in counts] |
| 97 | 98 | |
| 98 | 99 | # Get model values |
| 99 | - models = GModels(xmlname) | |
| 100 | + models = gammalib.GModels(xmlname) | |
| 100 | 101 | mod = models[0] |
| 101 | 102 | model = [] |
| 102 | - t = GTime() | |
| 103 | + t = gammalib.GTime() | |
| 103 | 104 | mod.spatial().set_mc_cone(dir, radius) |
| 104 | 105 | for i in range(ebds.size()): |
| 105 | 106 | eng = ebds.elogmean(i) |
| ... | ... | @@ -172,7 +173,7 @@ if __name__ == '__main__': |
| 172 | 173 | e_max = 100.0 # 100 TeV |
| 173 | 174 | area = 1.0 # 1 cm2 |
| 174 | 175 | duration = 1.0 # 1 sec |
| 175 | - dir = GSkyDir() | |
| 176 | + dir = gammalib.GSkyDir() | |
| 176 | 177 | dir.radec_deg(84.17263, 22.01444) |
| 177 | 178 | radius = 1.0 |
| 178 | 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 |
| ... | ... | @@ -19,7 +19,7 @@ |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | 21 | import math |
| 22 | -from gammalib import GEnergy, GModelSpectralFunc, GRan, GModelSpectralPlaw | |
| 22 | +import gammalib | |
| 23 | 23 | |
| 24 | 24 | # ================================= # |
| 25 | 25 | # Generate file function from model # |
| ... | ... | @@ -36,14 +36,14 @@ def make_file_function(model, emin=0.1e6, emax=100.0e6, nodes=10): |
| 36 | 36 | file = open(filename, "w") |
| 37 | 37 | for i in range(nodes): |
| 38 | 38 | energy = math.pow(10.0, math.log10(emin) + i * dloge) |
| 39 | - eng = GEnergy() | |
| 39 | + eng = gammalib.GEnergy() | |
| 40 | 40 | eng.MeV(energy) |
| 41 | 41 | value = model.eval(eng) |
| 42 | 42 | file.write(str(energy) + " " + str(value) + "\n") |
| 43 | 43 | file.close() |
| 44 | 44 | |
| 45 | 45 | # Generate file function |
| 46 | - file_function = GModelSpectralFunc(filename) | |
| 46 | + file_function = gammalib.GModelSpectralFunc(filename) | |
| 47 | 47 | |
| 48 | 48 | # Return |
| 49 | 49 | return file_function |
| ... | ... | @@ -61,8 +61,8 @@ def compare_photon_flux(model, file_function, emin=8.7, emax=1123.0, steps=13): |
| 61 | 61 | n_violate = 0 |
| 62 | 62 | |
| 63 | 63 | # Allocate boundaries |
| 64 | - e_min = GEnergy() | |
| 65 | - e_max = GEnergy() | |
| 64 | + e_min = gammalib.GEnergy() | |
| 65 | + e_max = gammalib.GEnergy() | |
| 66 | 66 | |
| 67 | 67 | # Ramp up emax from below first node |
| 68 | 68 | e_min.MeV(emin) |
| ... | ... | @@ -71,7 +71,7 @@ def compare_photon_flux(model, file_function, emin=8.7, emax=1123.0, steps=13): |
| 71 | 71 | energy = math.pow(10.0, math.log10(emin) + i * dloge) |
| 72 | 72 | e_max.MeV(energy) |
| 73 | 73 | flux_model = model.flux(e_min, e_max) |
| 74 | - flux_ff = file_function.flux(e_min, e_max) | |
| 74 | + flux_ff = file_function.flux(e_min, e_max) | |
| 75 | 75 | if (abs(flux_model - flux_ff) > eps): |
| 76 | 76 | print(e_min, e_max, flux_model, flux_ff, flux_model - flux_ff) |
| 77 | 77 | n_violate += 1 |
| ... | ... | @@ -136,8 +136,8 @@ def compare_energy_flux(model, file_function, emin=8.7, emax=1123.0, steps=13): |
| 136 | 136 | n_violate = 0 |
| 137 | 137 | |
| 138 | 138 | # Allocate boundaries |
| 139 | - e_min = GEnergy() | |
| 140 | - e_max = GEnergy() | |
| 139 | + e_min = gammalib.GEnergy() | |
| 140 | + e_max = gammalib.GEnergy() | |
| 141 | 141 | |
| 142 | 142 | # Ramp up emax from below first node |
| 143 | 143 | e_min.MeV(emin) |
| ... | ... | @@ -207,15 +207,15 @@ def test_mc(file_function, trials=10): |
| 207 | 207 | Print a bunch of Monte Carlo energies. |
| 208 | 208 | """ |
| 209 | 209 | # Allocate boundaries |
| 210 | - e_min = GEnergy() | |
| 211 | - e_max = GEnergy() | |
| 212 | - ran = GRan() | |
| 210 | + e_min = gammalib.GEnergy() | |
| 211 | + e_max = gammalib.GEnergy() | |
| 212 | + ran = GRan() | |
| 213 | 213 | |
| 214 | 214 | # Set energy range |
| 215 | 215 | e_min.TeV(0.1) |
| 216 | 216 | e_max.TeV(100.0) |
| 217 | 217 | |
| 218 | -# Loop over trials | |
| 218 | + # Loop over trials | |
| 219 | 219 | for i in range(trials): |
| 220 | 220 | print(file_function.mc(e_min, e_max, ran)) |
| 221 | 221 | |
| ... | ... | @@ -231,7 +231,7 @@ if __name__ == '__main__': |
| 231 | 231 | Main entry point |
| 232 | 232 | """ |
| 233 | 233 | # Allocate power law |
| 234 | - model = GModelSpectralPlaw(5.7, -2.48) | |
| 234 | + model = gammalib.GModelSpectralPlaw(5.7, -2.48) | |
| 235 | 235 | model["Prefactor"].scale(1.0e-16) |
| 236 | 236 | model["PivotEnergy"].value(0.3) |
| 237 | 237 | model["PivotEnergy"].scale(1.0e6) | ... | ... |