From f894f15c119a5e4c66d2cb826eaba1053aef5572 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Mon, 26 Oct 2015 22:47:59 +0100 Subject: [PATCH] Change "from gammalib import *" to "import gammalib" --- ChangeLog | 3 ++- NEWS | 2 +- test/test_GLinalg.py | 17 ++++++++--------- test/test_GModel.py | 9 ++++----- test/test_GNumerics.py | 9 ++++----- test/test_GOptimizer.py | 13 ++++++------- test/test_GSky.py | 33 ++++++++++++++++----------------- test/test_GSupport.py | 32 +++++++++++++++----------------- test/test_GTest.py | 10 ++++------ test/test_GVO.py | 12 +++++------- test/test_GXml.py | 10 ++++------ test/test_GXspec.py | 24 +++++++++++------------- 12 files changed, 80 insertions(+), 94 deletions(-) diff --git a/ChangeLog b/ChangeLog index 923665d..cd97071 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2015-10-16 Juergen Knoedlseder +2015-10-26 Juergen Knoedlseder * Version 0.11.0 released ========================= + Add Python unit test function to gammalib module (#1486) Increase CTA IRF integration precision for shell model (#1521) Correctly handle MC simulations for unnormalized diffuse maps (#1548) Improve precision of shell model in unbinned analysis (#1521) diff --git a/NEWS b/NEWS index e74e767..0b7138f 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 0.11.0 Author(s) : Juergen Knoedlseder -16 October 2015 +26 October 2015 1. Introduction diff --git a/test/test_GLinalg.py b/test/test_GLinalg.py index e0c3d58..9036595 100755 --- a/test/test_GLinalg.py +++ b/test/test_GLinalg.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib linalg module. # -# Copyright (C) 2012-2014 Juergen Knoedlseder +# Copyright (C) 2012-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,14 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * +import gammalib import os # ===================================== # # Test class for GammaLib linalg module # # ===================================== # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib linalg module. """ @@ -35,7 +34,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return @@ -63,7 +62,7 @@ class Test(GPythonTestSuite): Test GVector class. """ # Setup vectors - vector = GVector(3) + vector = gammalib.GVector(3) vector[0] = 1.0 vector[1] = 2.0 vector[2] = 3.0 @@ -165,7 +164,7 @@ class Test(GPythonTestSuite): ncols = 5 # Allocate matrix - m = GMatrix(nrows, ncols) + m = gammalib.GMatrix(nrows, ncols) # Fill elements for i in range(nrows): @@ -191,7 +190,7 @@ class Test(GPythonTestSuite): ncols = 3 # Allocate matrix - m = GMatrixSparse(nrows, ncols) + m = gammalib.GMatrixSparse(nrows, ncols) # Fill elements for i in range(nrows): @@ -217,7 +216,7 @@ class Test(GPythonTestSuite): ncols = 3 # Allocate matrix - m = GMatrixSymmetric(nrows, ncols) + m = gammalib.GMatrixSymmetric(nrows, ncols) # Fill elements for i in range(nrows): diff --git a/test/test_GModel.py b/test/test_GModel.py index 357cfcf..c033b3b 100755 --- a/test/test_GModel.py +++ b/test/test_GModel.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib model module. # -# Copyright (C) 2012 Juergen Knoedlseder +# Copyright (C) 2012-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,14 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * +import gammalib import os # ==================================== # # Test class for GammaLib model module # # ==================================== # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib model module. """ @@ -35,7 +34,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return diff --git a/test/test_GNumerics.py b/test/test_GNumerics.py index 3f9b195..a9296e4 100755 --- a/test/test_GNumerics.py +++ b/test/test_GNumerics.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib numerics module. # -# Copyright (C) 2012 Juergen Knoedlseder +# Copyright (C) 2012-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,14 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * +import gammalib import os # ======================================= # # Test class for GammaLib numerics module # # ======================================= # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib numerics module. """ @@ -35,7 +34,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return diff --git a/test/test_GOptimizer.py b/test/test_GOptimizer.py index 77171b8..a326a4c 100755 --- a/test/test_GOptimizer.py +++ b/test/test_GOptimizer.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib optimizer module. # -# Copyright (C) 2012 Juergen Knoedlseder +# Copyright (C) 2012-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,14 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * +import gammalib import os -# ================================== # +# ======================================== # # Test class for GammaLib optimizer module # -# ================================== # -class Test(GPythonTestSuite): +# ======================================== # +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib optimizer module. """ @@ -35,7 +34,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return diff --git a/test/test_GSky.py b/test/test_GSky.py index cf46a50..4f21ac9 100755 --- a/test/test_GSky.py +++ b/test/test_GSky.py @@ -17,9 +17,9 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * +import gammalib import os +import math # =========== # @@ -49,7 +49,7 @@ def loadtxt(filename): # ================================== # # Test class for GammaLib sky module # # ================================== # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib sky module. """ @@ -58,7 +58,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return @@ -82,7 +82,6 @@ class Test(GPythonTestSuite): self.append(self.test_fk5_to_galactic, "Test FK5 to Galactic coordinate conversion") self.append(self.test_operators, "Test skymap operators") - # Return return @@ -97,17 +96,17 @@ class Test(GPythonTestSuite): inx = pixels.dir2inx(dir) msg = map + " inx2dir/dir2inx check for pixel " + str(i) err = map + " GSkyMap trouble with pixel " + str(i) + " (" + str(inx) + \ - "), RA=" + str(dir.ra() * 180 / pi) + ", Dec=" + str(dir.dec() * 180 / pi) + "), RA=" + str(dir.ra() * 180 / math.pi) + ", Dec=" + str(dir.dec() * 180 / math.pi) self.test_assert(i == inx, msg, err) # Control SkyDir coordinate transformation for all pixels for i in range(pixels.npix()): dir = pixels.inx2dir(i) - dir_new = GSkyDir() + dir_new = gammalib.GSkyDir() dir_new.lb(dir.l(), dir.b()) dra = abs(dir.ra() - dir_new.ra()) if (dra >= 5.0): - dra -= 2.0 * pi + dra -= 2.0 * math.pi ddec = abs(dir.dec() - dir_new.dec()) msg = map + " dir check for pixel " + str(i) err = map + " GSkyMap trouble with pixel " + str(i) + " (" + str(dra) + \ @@ -132,7 +131,7 @@ class Test(GPythonTestSuite): pass # Create skymap - pixels = GSkyMap(proj, "CEL", 83.6331, 22.0145, -3.7, 2.6, 5, 5, 20) + pixels = gammalib.GSkyMap(proj, "CEL", 83.6331, 22.0145, -3.7, 2.6, 5, 5, 20) for map in range(pixels.nmaps()): for i in range(pixels.npix()): pixels[i, map] = i + map * pixels.npix() @@ -161,14 +160,14 @@ class Test(GPythonTestSuite): pass # Create HEALPix skymap - pixels = GSkyMap("GAL", 2, "RING", 2) + pixels = gammalib.GSkyMap("GAL", 2, "RING", 2) for i in range(pixels.npix()): pixels[i] = i + 1.0 pixels[i, 1] = i + 1.0 + 1000.0 pixels.save(file1) # Load HEALPix skymap - pixels = GSkyMap(file1) + pixels = gammalib.GSkyMap(file1) # Control coordinate and pixel transformations self.test_skymap_pixels(pixels, "HEALPix") @@ -184,7 +183,7 @@ class Test(GPythonTestSuite): pixels.save(file2, True) # Load again HEALPix skymap - pixels = GSkyMap(file1) + pixels = gammalib.GSkyMap(file1) # Return return @@ -288,21 +287,21 @@ class Test(GPythonTestSuite): for (ra, dec), (glon, glat) in coordinates: # Create point A in FK5 J2000 coordinates - input_point = GSkyDir() + input_point = gammalib.GSkyDir() input_point.radec_deg(ra, dec) # Convert point A to Galactic coordinates ll, bb = input_point.l_deg(), input_point.b_deg() - actual_point = GSkyDir() + actual_point = gammalib.GSkyDir() actual_point.lb_deg(ll, bb) # Compute offset to reference result - reference_point = GSkyDir() + reference_point = gammalib.GSkyDir() reference_point.lb_deg(glon, glat) # Compute distance and remember maximum this_dist = actual_point.dist_deg(reference_point) - max_dist = max(max_dist, this_dist) + max_dist = max(max_dist, this_dist) # Convert max_dist from deg to milli-arcsec max_dist *= 1e3 * 3600 @@ -323,7 +322,7 @@ class Test(GPythonTestSuite): Test the skymap operators. """ # Setup skymaps - map = GSkyMap("CAR", "CEL", 83.6331, 22.0145, -3.7, 2.6, 2, 2) + map = gammalib.GSkyMap("CAR", "CEL", 83.6331, 22.0145, -3.7, 2.6, 2, 2) map[0] = 1.0 map[1] = 2.0 map[2] = 3.0 diff --git a/test/test_GSupport.py b/test/test_GSupport.py index dea7358..2b28a9b 100755 --- a/test/test_GSupport.py +++ b/test/test_GSupport.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib support module. # -# Copyright (C) 2012 Juergen Knoedlseder +# Copyright (C) 2012-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,14 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * -import os +import gammalib +import math # =============================== # # Test class for GammaLib support # # =============================== # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib support. """ @@ -35,7 +34,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return @@ -62,15 +61,15 @@ class Test(GPythonTestSuite): Test GNodeArray class. """ # Set-up vector and data array. Test all vector elements. - vector = GVector(20) - data = GVector(20) + vector = gammalib.GVector(20) + data = gammalib.GVector(20) for i in range(20): vector[i] = 10.0 + i * 5.0 - data[i] = sin(0.15 * (vector[i] - 10.0)) - self.test_value(data[i], sin(0.15 * i * 5.0)) + data[i] = math.sin(0.15 * (vector[i] - 10.0)) + self.test_value(data[i], math.sin(0.15 * i * 5.0)) # Set-up node array - array = GNodeArray() + array = gammalib.GNodeArray() array.nodes(vector) # Get values @@ -79,9 +78,9 @@ class Test(GPythonTestSuite): for i in range(100): x = i - 10 array.set_value(x) - inx_left = array.inx_left() + inx_left = array.inx_left() inx_right = array.inx_right() - wgt_left = array.wgt_left() + wgt_left = array.wgt_left() wgt_right = array.wgt_right() y = wgt_left * data[inx_left] + wgt_right * data[inx_right] x_val.append(x) @@ -90,21 +89,20 @@ class Test(GPythonTestSuite): # Return return - # Test GUrlFile class def test_url_file(self): """ Test GUrlFile class. """ # Test file writing - url = GUrlFile("test_url.dat", "w") + url = gammalib.GUrlFile("test_url.dat", "w") self.test_value(url.write("abcd", 4), 4) url.put_char(ord("e")) url.close() # Test file reading buffer = "" - url = GUrlFile("test_url.dat", "r") + url = gammalib.GUrlFile("test_url.dat", "r") buffer = url.read(99) self.test_assert(buffer == "abcde", "Expected \"abcde\" in file, found \""+ @@ -120,7 +118,7 @@ class Test(GPythonTestSuite): Test GUrlString class. """ # Test writing - url = GUrlString() + url = gammalib.GUrlString() self.test_value(url.write("abcd", 4), 4) url.put_char(ord("e")) diff --git a/test/test_GTest.py b/test/test_GTest.py index 50abf73..f1b68f2 100755 --- a/test/test_GTest.py +++ b/test/test_GTest.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib test module. # -# Copyright (C) 2012 Juergen Knoedlseder +# Copyright (C) 2012-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,13 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * -import os +import gammalib # =================================== # # Test class for GammaLib test module # # =================================== # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib test module. """ @@ -35,7 +33,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return diff --git a/test/test_GVO.py b/test/test_GVO.py index 3bd4ba9..344940a 100755 --- a/test/test_GVO.py +++ b/test/test_GVO.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib vo module. # -# Copyright (C) 2014 Juergen Knoedlseder +# Copyright (C) 2014-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,13 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * -import os +import gammalib # ================================= # # Test class for GammaLib vo module # # ================================= # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib vo module. """ @@ -35,7 +33,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return @@ -60,7 +58,7 @@ class Test(GPythonTestSuite): Test GVOClient class. """ # Allocate GVOClient object - client = GVOClient() + client = gammalib.GVOClient() # Return return diff --git a/test/test_GXml.py b/test/test_GXml.py index 6097ed2..24522ea 100755 --- a/test/test_GXml.py +++ b/test/test_GXml.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib xml module. # -# Copyright (C) 2012 Juergen Knoedlseder +# Copyright (C) 2012-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,13 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * -import os +import gammalib # ================================== # # Test class for GammaLib xml module # # ================================== # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib xml module. """ @@ -35,7 +33,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return diff --git a/test/test_GXspec.py b/test/test_GXspec.py index 7896e06..63ee077 100755 --- a/test/test_GXspec.py +++ b/test/test_GXspec.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib xspec module. # -# Copyright (C) 2013 Juergen Knoedlseder +# Copyright (C) 2013-2015 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,15 +17,13 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * -from math import * -import os +import gammalib # ==================================== # # Test class for GammaLib xspec module # # ==================================== # -class Test(GPythonTestSuite): +class Test(gammalib.GPythonTestSuite): """ Test class for GammaLib xspec module. """ @@ -35,7 +33,7 @@ class Test(GPythonTestSuite): Constructor. """ # Call base class constructor - GPythonTestSuite.__init__(self) + gammalib.GPythonTestSuite.__init__(self) # Return return @@ -63,8 +61,8 @@ class Test(GPythonTestSuite): """ # Allocate GPha object and check its size nmeasured = 10 - emeasured = GEbounds(nmeasured, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) - pha = GPha(emeasured) + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) + pha = gammalib.GPha(emeasured) self.test_value(pha.size(), nmeasured) # Set and retrieve a value @@ -82,8 +80,8 @@ class Test(GPythonTestSuite): """ # Allocate GArf object and check its size nmeasured = 10 - emeasured = GEbounds(nmeasured, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) - arf = GArf(emeasured) + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) + arf = gammalib.GArf(emeasured) self.test_value(arf.size(), nmeasured) # Set and retrieve a value @@ -102,9 +100,9 @@ class Test(GPythonTestSuite): # Allocate GRmf object and check its size ntrue = 20 nmeasured = 10 - etrue = GEbounds(ntrue, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) - emeasured = GEbounds(nmeasured, GEnergy(1.0, "TeV"), GEnergy(10.0, "TeV")) - rmf = GRmf(etrue, emeasured) + etrue = gammalib.GEbounds(ntrue, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), gammalib.GEnergy(10.0, "TeV")) + rmf = gammalib.GRmf(etrue, emeasured) self.test_value(rmf.size(), ntrue*nmeasured) self.test_value(rmf.ntrue(), ntrue) self.test_value(rmf.nmeasured(), nmeasured) -- libgit2 0.21.4