Commit 1985a10ddffafc19a29c03f82d3fd17822e70f31

Authored by Jürgen Knödlseder
1 parent 90f39c2e

Add modules for Python unit tests.

test/test_GApp.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib app module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ================================== #
  26 +# Test class for GammaLib app module #
  27 +# ================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib app module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("app")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...
test/test_GFits.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib FITS module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +import sys
  24 +
  25 +
  26 +# =================================== #
  27 +# Test class for GammaLib FITS module #
  28 +# =================================== #
  29 +class Test(GPythonTestSuite):
  30 + """
  31 + Test class for GammaLib FITS module.
  32 + """
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 + def set(self):
  44 + """
  45 + Set all test functions.
  46 + """
  47 + # Set test name
  48 + self.name("fits")
  49 +
  50 + # Append tests
  51 + self.append(self.test_fits, "Test GFits")
  52 +
  53 + # Return
  54 + return
  55 +
  56 + def test_fits(self):
  57 + """
  58 + Test FITS interface.
  59 + """
  60 + # Set filenames
  61 + file1 = "test_python_fits_v1.fits"
  62 + file2 = "test_python_fits_v2.fits"
  63 +
  64 + # Remove test files
  65 + try:
  66 + os.remove(file1)
  67 + os.remove(file2)
  68 + except:
  69 + pass
  70 +
  71 + # Create FITS file
  72 + fits = GFits(file1, True)
  73 + sys.stdout.write(".")
  74 +
  75 + # Create images
  76 + nx = 10
  77 + 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)
  87 + for x in range(nx):
  88 + for y in range(ny):
  89 + img1[x,y] = x+y*nx
  90 + img2[x,y] = x+y*nx
  91 + img3[x,y] = x+y*nx
  92 + img4[x,y] = x+y*nx
  93 + img5[x,y] = x+y*nx
  94 + img6[x,y] = x+y*nx
  95 + img7[x,y] = x+y*nx
  96 + img8[x,y] = x+y*nx
  97 + img9[x,y] = x+y*nx
  98 + img1.extname("Byte")
  99 + img2.extname("Double")
  100 + img3.extname("Float")
  101 + img4.extname("Long")
  102 + img5.extname("LongLong")
  103 + img6.extname("SByte")
  104 + img7.extname("Short")
  105 + img8.extname("ULong")
  106 + img9.extname("UShort")
  107 + sys.stdout.write(".")
  108 +
  109 + # Append images to FITS file
  110 + fits.append(img1)
  111 + fits.append(img2)
  112 + fits.append(img3)
  113 + fits.append(img4)
  114 + fits.append(img5)
  115 + #fits.append(img6) # Not supported in older cfitsio
  116 + fits.append(img7)
  117 + fits.append(img8)
  118 + fits.append(img9)
  119 + sys.stdout.write(".")
  120 +
  121 + # Set header keywords
  122 + img_byte = fits.image(0)
  123 + img_byte.card("test", "test-value", "this is for testing")
  124 + img_byte.card("real", 3.1415, "a real value")
  125 + img_byte.card("int", 41, "an integer value")
  126 + sys.stdout.write(".")
  127 +
  128 + # Create table columns
  129 + 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)
  141 + for i in range(nrows):
  142 + col1[i] = i % 2
  143 + col2[i] = i % 2
  144 + col3[i] = i
  145 + col4[i] = i*0.01
  146 + col5[i] = i*0.01
  147 + col6[i] = i*100
  148 + col7[i] = i*10000
  149 + col8[i] = i*100
  150 + col9[i] = str(i*100)
  151 + col10[i] = i*100
  152 + col11[i] = i*100
  153 + sys.stdout.write(".")
  154 +
  155 + # Set ASCII table
  156 + tbl_ascii = GFitsAsciiTable()
  157 + #tbl_ascii.append_column(col1) # Need to implement ?/!
  158 + #tbl_ascii.append_column(col2) # Need to implement ?/!
  159 + tbl_ascii.append_column(col3)
  160 + tbl_ascii.append_column(col4)
  161 + tbl_ascii.append_column(col5)
  162 + tbl_ascii.append_column(col6)
  163 + tbl_ascii.append_column(col7)
  164 + tbl_ascii.append_column(col8)
  165 + tbl_ascii.append_column(col9)
  166 + tbl_ascii.append_column(col10)
  167 + tbl_ascii.append_column(col11)
  168 + tbl_ascii.extname("ASCII table")
  169 + fits.append(tbl_ascii)
  170 + sys.stdout.write(".")
  171 +
  172 + # Set binary table
  173 + tbl_bin = GFitsBinTable()
  174 + tbl_bin.append_column(col1)
  175 + tbl_bin.append_column(col2)
  176 + tbl_bin.append_column(col3)
  177 + tbl_bin.append_column(col4)
  178 + tbl_bin.append_column(col5)
  179 + tbl_bin.append_column(col6)
  180 + tbl_bin.append_column(col7)
  181 + tbl_bin.append_column(col8)
  182 + tbl_bin.append_column(col9)
  183 + tbl_bin.append_column(col10)
  184 + tbl_bin.append_column(col11)
  185 + tbl_bin.extname("Binary table")
  186 + fits.append(tbl_bin)
  187 + sys.stdout.write(".")
  188 +
  189 + # Save FITS file
  190 + #sys.stdout.write(fits+"\n")
  191 + fits.save()
  192 + sys.stdout.write(".")
  193 +
  194 + # Close FITS file
  195 + fits.close()
  196 + sys.stdout.write(".")
  197 +
  198 + # Re-open FITS file
  199 + fits = GFits(file1)
  200 + sys.stdout.write(".")
  201 +
  202 + # Get double precision image, take square root of pixel and save in
  203 + # another file
  204 + img_double = cast_GFitsImageDouble(fits.image("Double"))
  205 + for x in range(nx):
  206 + for y in range(ny):
  207 + img_double[x,y] = sqrt(img_double[x,y])
  208 + #img_byte = cast_GFitsImageByte(fits.image("Double"))
  209 + sys.stdout.write(".")
  210 +
  211 + # Save into another FITS file
  212 + fits.saveto(file2)
  213 + sys.stdout.write(".")
  214 +
  215 + # Close FITS file
  216 + fits.close()
  217 + sys.stdout.write(".")
  218 +
  219 + # Return
  220 + return
... ...
test/test_GLinalg.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib linalg module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ===================================== #
  26 +# Test class for GammaLib linalg module #
  27 +# ===================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib linalg module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("linalg")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...
test/test_GModel.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib model module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ==================================== #
  26 +# Test class for GammaLib model module #
  27 +# ==================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib model module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("model")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...
test/test_GNumerics.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib numerics module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ======================================= #
  26 +# Test class for GammaLib numerics module #
  27 +# ======================================= #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib numerics module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("numerics")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...
test/test_GObs.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib obs module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ================================== #
  26 +# Test class for GammaLib obs module #
  27 +# ================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib obs module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("obs")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...
test/test_GOpt.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib opt module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ================================== #
  26 +# Test class for GammaLib opt module #
  27 +# ================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib opt module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("opt")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...
test/test_GSky.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib sky module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ================================== #
  26 +# Test class for GammaLib sky module #
  27 +# ================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib sky module.
  31 + """
  32 + def __init__(self):
  33 + """
  34 + Constructor.
  35 + """
  36 + # Call base class constructor
  37 + GPythonTestSuite.__init__(self)
  38 +
  39 + # Return
  40 + return
  41 +
  42 + def set(self):
  43 + """
  44 + Set all test functions.
  45 + """
  46 + # Set test name
  47 + self.name("sky")
  48 +
  49 + # Append tests
  50 + self.append(self.test_skymap_healpix, "Test HEALPix map")
  51 + self.append(self.test_skymap_car, "Test CAR projection map")
  52 + self.append(self.test_skymap_tan, "Test TAN projection map")
  53 + self.append(self.test_skymap_stg, "Test STG projection map")
  54 + self.append(self.test_skymap_azp, "Test AZP projection map")
  55 +
  56 + # Return
  57 + return
  58 +
  59 +
  60 + # Generic skymap pixel transformation test
  61 + def test_skymap_pixels(self, pixels, map):
  62 + """
  63 + Control coordinate and pixel transformation methods.
  64 + """
  65 + # Control pix2dir / dir2pix methods for all pixels
  66 + for i in range(pixels.npix()):
  67 + dir = pixels.pix2dir(i)
  68 + ipix = pixels.dir2pix(dir)
  69 + msg = map + " pix2dir/dir2pix check for pixel "+str(i)
  70 + err = map + " GSkymap trouble with pixel "+str(i)+" ("+str(ipix)+ \
  71 + "), RA="+str(dir.ra()*180/pi)+", Dec="+str(dir.dec()*180/pi)
  72 + self.test_assert(i == ipix, msg, err)
  73 +
  74 + # Control SkyDir coordinate transformation for all pixels
  75 + for i in range(pixels.npix()):
  76 + dir = pixels.pix2dir(i)
  77 + dir_new = GSkyDir()
  78 + dir_new.lb(dir.l(),dir.b())
  79 + dra = abs(dir.ra() - dir_new.ra())
  80 + if (dra >= 5.0):
  81 + dra -= 2.0*pi
  82 + ddec = abs(dir.dec() - dir_new.dec())
  83 + msg = map + " dir check for pixel "+str(i)
  84 + err = map + " GSkymap trouble with pixel "+str(i)+" ("+str(dra)+ \
  85 + ","+str(ddec)+")"
  86 + self.test_assert(not (dra > 1.0e-9 or ddec > 1.0e-9), msg, err)
  87 +
  88 + # Return
  89 + return
  90 +
  91 +
  92 + # Generic skymap projection test
  93 + def test_skymap_proj(self, proj):
  94 + """
  95 + Test skymap projection.
  96 + """
  97 + # Set filename
  98 + file = "test_python_skymap_"+proj+".fits"
  99 +
  100 + # Remove test files
  101 + try:
  102 + os.remove(file)
  103 + except:
  104 + pass
  105 +
  106 + # Create skymap
  107 + pixels = GSkymap(proj, "CEL", 83.6331, 22.0145, -3.7, 2.6, 5, 5, 20)
  108 + for map in range(pixels.nmaps()):
  109 + for i in range(pixels.npix()):
  110 + pixels[i,map] = i+map*pixels.npix()
  111 + pixels.save(file)
  112 +
  113 + # Test coordinate and pixel transformations
  114 + self.test_skymap_pixels(pixels, proj)
  115 +
  116 + # Return
  117 + return
  118 +
  119 +
  120 + # Test HEALPix projection
  121 + def test_skymap_healpix(self):
  122 + """
  123 + Test HEALPix interface.
  124 + """
  125 + # Set filenames
  126 + file1 = "test_python_skymap_hpx_v1.fits"
  127 + file2 = "test_python_skymap_hpx_v2.fits"
  128 +
  129 + # Remove test files
  130 + try:
  131 + os.remove(file1)
  132 + os.remove(file2)
  133 + except:
  134 + pass
  135 +
  136 + # Create HEALPix skymap
  137 + pixels = GSkymap("HPX", "GAL", 2, "RING", 2)
  138 + for i in range(pixels.npix()):
  139 + pixels[i] = i+1.0
  140 + pixels[i,1] = i+1.0 + 1000.0
  141 + pixels.save(file1)
  142 +
  143 + # Load HEALPix skymap
  144 + pixels = GSkymap(file1)
  145 +
  146 + # Control coordinate and pixel transformations
  147 + self.test_skymap_pixels(pixels, "HEALPix")
  148 +
  149 + # Save HEALPix skymap twice. The second saving should fail.
  150 + try:
  151 + pixels.save(file2, True)
  152 + pixels.save(file2)
  153 + except RuntimeError:
  154 + pass
  155 + else:
  156 + raise RuntimeError("*** TEST ERROR: FITS file overwritten!")
  157 + pixels.save(file2, True)
  158 +
  159 + # Load again HEALPix skymap
  160 + pixels = GSkymap(file1)
  161 +
  162 + # Return
  163 + return
  164 +
  165 +
  166 + # Test CAR projection
  167 + def test_skymap_car(self):
  168 + """
  169 + Test CAR projection.
  170 + """
  171 + # Execute generic test
  172 + self.test_skymap_proj("CAR")
  173 +
  174 + # Return
  175 + return
  176 +
  177 +
  178 + # Test TAN projection
  179 + def test_skymap_tan(self):
  180 + """
  181 + Test TAN projection.
  182 + """
  183 + # Execute generic test
  184 + self.test_skymap_proj("TAN")
  185 +
  186 + # Return
  187 + return
  188 +
  189 +
  190 + # Test STG projection
  191 + def test_skymap_stg(self):
  192 + """
  193 + Test STG projection.
  194 + """
  195 + # Execute generic test
  196 + self.test_skymap_proj("STG")
  197 +
  198 + # Return
  199 + return
  200 +
  201 +
  202 + # Test AZP projection
  203 + def test_skymap_azp(self):
  204 + """
  205 + Test AZP projection.
  206 + """
  207 + # Execute generic test
  208 + self.test_skymap_proj("AZP")
  209 +
  210 + # Return
  211 + return
... ...
test/test_GSupport.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib support module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# =============================== #
  26 +# Test class for GammaLib support #
  27 +# =============================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib support.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 + # Set all test functions
  44 + def set(self):
  45 + """
  46 + Set all test functions.
  47 + """
  48 + # Set test name
  49 + self.name("support")
  50 +
  51 + # Append tests
  52 + self.append(self.test_node_array, "Test GNodeArray")
  53 +
  54 + # Return
  55 + return
  56 +
  57 + # Test GNodeArray class
  58 + def test_node_array(self):
  59 + """
  60 + Test GNodeArray class.
  61 + """
  62 + # Set-up vector and data array. Test all vector elements.
  63 + vector = GVector(20)
  64 + data = GVector(20)
  65 + for i in range(20):
  66 + vector[i] = 10.0 + i*5.0
  67 + data[i] = sin(0.15*(vector[i]-10.0))
  68 + self.test_value(data[i], sin(0.15*i*5.0))
  69 +
  70 + # Set-up node array
  71 + array = GNodeArray()
  72 + array.nodes(vector)
  73 +
  74 + # Get values
  75 + x_val = []
  76 + y_val = []
  77 + for i in range(100):
  78 + x = i-10
  79 + array.set_value(x)
  80 + inx_left = array.inx_left()
  81 + inx_right = array.inx_right()
  82 + wgt_left = array.wgt_left()
  83 + wgt_right = array.wgt_right()
  84 + y = wgt_left*data[inx_left] + wgt_right*data[inx_right]
  85 + x_val.append(x)
  86 + y_val.append(y)
  87 +
  88 + # Return
  89 + return
... ...
test/test_GTest.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib test module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# =================================== #
  26 +# Test class for GammaLib test module #
  27 +# =================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib test module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("test")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...
test/test_GXml.py 0 → 100755
  1 +# ==========================================================================
  2 +# This module performs unit tests for the GammaLib xml module.
  3 +#
  4 +# Copyright (C) 2012 Juergen Knoedlseder
  5 +#
  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
  8 +# the Free Software Foundation, either version 3 of the License, or
  9 +# (at your option) any later version.
  10 +#
  11 +# This program is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU General Public License for more details.
  15 +#
  16 +# You should have received a copy of the GNU General Public License
  17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  18 +#
  19 +# ==========================================================================
  20 +from gammalib import *
  21 +from math import *
  22 +import os
  23 +
  24 +
  25 +# ================================== #
  26 +# Test class for GammaLib xml module #
  27 +# ================================== #
  28 +class Test(GPythonTestSuite):
  29 + """
  30 + Test class for GammaLib xml module.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + GPythonTestSuite.__init__(self)
  39 +
  40 + # Return
  41 + return
  42 +
  43 +
  44 + # Set test functions
  45 + def set(self):
  46 + """
  47 + Set all test functions.
  48 + """
  49 + # Set test name
  50 + self.name("xml")
  51 +
  52 + # Append tests
  53 + self.append(self.test, "Dummy test")
  54 +
  55 + # Return
  56 + return
  57 +
  58 +
  59 + # Test function
  60 + def test(self):
  61 + """
  62 + Test function.
  63 + """
  64 + # Return
  65 + return
... ...