Commit 5df975a625f5e97c8b4f12f3aa4728b59aecde02

Authored by Jürgen Knödlseder
1 parent d5a4fca2

Add test cases for cttsmap

test/test_ctools.sh
... ... @@ -36,6 +36,7 @@ $ECHO "***************"
36 36 # ==================
37 37 ctbin=../src/ctbin/ctbin
38 38 ctlike=../src/ctlike/ctlike
  39 +cttsmap=../src/cttsmap/cttsmap
39 40 ctmodel=../src/ctmodel/ctmodel
40 41 ctobssim=../src/ctobssim/ctobssim
41 42 ctselect=../src/ctselect/ctselect
... ... @@ -347,6 +348,34 @@ $ECHO " ok"
347 348  
348 349  
349 350 #
  351 +# Test cttsmap
  352 +# ============
  353 +$ECHO -n "Test cttsmap: "
  354 +$cttsmap infile="selected_events.fits" \
  355 + srcmdl="data/crab.xml" \
  356 + srcname="Crab" \
  357 + caldb="irf" \
  358 + irf="cta_dummy_irf" \
  359 + outfile="tsmap.fits" \
  360 + nxpix=5 \
  361 + nypix=5 \
  362 + binsz=0.05 \
  363 + coordsys="CEL" \
  364 + xref=83.63 \
  365 + yref=22.01 \
  366 + proj="CAR"
  367 +$ECHO -n "."
  368 +if [ -s "tsmap.fits" ]
  369 +then
  370 + $ECHO -n "."
  371 +else
  372 + $ECHO " tsmap.fits file is not valid"
  373 + exit 1
  374 +fi
  375 +$ECHO " ok"
  376 +
  377 +
  378 +#
350 379 # Test ctexpcube
351 380 # ==============
352 381 $ECHO -n "Test ctexpcube: "
... ...
test/test_cttsmap.py 0 → 100755
  1 +#! /usr/bin/env python
  2 +# ==========================================================================
  3 +# This scripts performs unit tests for the cttsmap tool.
  4 +#
  5 +# Copyright (C) 2014 Juergen Knoedlseder
  6 +#
  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
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +import gammalib
  22 +import ctools
  23 +
  24 +
  25 +# ========================== #
  26 +# Test class for cttsmap tool #
  27 +# ========================== #
  28 +class Test(gammalib.GPythonTestSuite):
  29 + """
  30 + Test class for cttsmap tool.
  31 + """
  32 + # Constructor
  33 + def __init__(self):
  34 + """
  35 + Constructor.
  36 + """
  37 + # Call base class constructor
  38 + gammalib.GPythonTestSuite.__init__(self)
  39 +
  40 + # Set members
  41 + self.events_name = "data/crab_events.fits"
  42 + self.model_name = "data/crab.xml"
  43 + self.caldb = "irf"
  44 + self.irf = "cta_dummy_irf"
  45 +
  46 + # Return
  47 + return
  48 +
  49 + # Set test functions
  50 + def set(self):
  51 + """
  52 + Set all test functions.
  53 + """
  54 + # Set test name
  55 + self.name("cttsmap")
  56 +
  57 + # Append tests
  58 + self.append(self.test_functional, "Test cttsmap functionality")
  59 +
  60 + # Return
  61 + return
  62 +
  63 + # Test cttsmap functionnality
  64 + def test_functional(self):
  65 + """
  66 + Test cttsmap functionnality.
  67 + """
  68 + # Set-up cttsmap
  69 + tsmap = ctools.cttsmap()
  70 + tsmap["infile"].filename(self.events_name)
  71 + tsmap["srcmdl"].filename(self.model_name)
  72 + tsmap["srcname"].string("Crab")
  73 + tsmap["caldb"].string(self.caldb)
  74 + tsmap["irf"].string(self.irf)
  75 + tsmap["outfile"].filename("tsmap.fits")
  76 + tsmap["nxpix"].integer(5)
  77 + tsmap["nypix"].integer(5)
  78 + tsmap["binsz"].real(0.02)
  79 + tsmap["coordsys"].string("CEL")
  80 + tsmap["proj"].string("CAR")
  81 + tsmap["xref"].real(83.63)
  82 + tsmap["yref"].real(22.01)
  83 +
  84 + # Run tool
  85 + self.test_try("Run cttsmap")
  86 + try:
  87 + tsmap.run()
  88 + self.test_try_success()
  89 + except:
  90 + self.test_try_failure("Exception occured in cttsmap.")
  91 +
  92 + # Save results
  93 + self.test_try("Save results")
  94 + try:
  95 + tsmap.save()
  96 + self.test_try_success()
  97 + except:
  98 + self.test_try_failure("Exception occured in saving results.")
  99 +
  100 + # Return
  101 + return
... ...
test/test_python.py
... ... @@ -26,6 +26,7 @@ import test_ctobssim
26 26 import test_ctselect
27 27 import test_ctbin
28 28 import test_ctlike
  29 +import test_cttsmap
29 30 import test_ctmodel
30 31 import test_ctskymap
31 32 import test_ctexpcube
... ... @@ -50,6 +51,7 @@ if __name__ == &#39;__main__&#39;:
50 51 suite_ctselect = test_ctselect.Test()
51 52 suite_ctbin = test_ctbin.Test()
52 53 suite_ctlike = test_ctlike.Test()
  54 + suite_cttsmap = test_cttsmap.Test()
53 55 suite_ctmodel = test_ctmodel.Test()
54 56 suite_ctskymap = test_ctskymap.Test()
55 57 suite_ctexpcube = test_ctexpcube.Test()
... ... @@ -63,6 +65,7 @@ if __name__ == &#39;__main__&#39;:
63 65 suite_ctselect.set()
64 66 suite_ctbin.set()
65 67 suite_ctlike.set()
  68 + suite_cttsmap.set()
66 69 suite_ctmodel.set()
67 70 suite_ctskymap.set()
68 71 suite_ctexpcube.set()
... ... @@ -76,6 +79,7 @@ if __name__ == &#39;__main__&#39;:
76 79 suites.append(suite_ctselect)
77 80 suites.append(suite_ctbin)
78 81 suites.append(suite_ctlike)
  82 + suites.append(suite_cttsmap)
79 83 suites.append(suite_ctmodel)
80 84 suites.append(suite_ctskymap)
81 85 suites.append(suite_ctexpcube)
... ...