From 673710bd23e5215f2ba77b235caf5eeef211bbd1 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 19 Jul 2016 22:11:43 +0200 Subject: [PATCH] Adapt model definition XML file to new format --- cscripts/csiactobs.py | 10 +++++----- dev/testreport.py | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ models/crab.xml | 12 ++++++------ models/crab_poly.xml | 12 ++++++------ models/crab_profile.xml | 12 ++++++------ models/disk.xml | 12 ++++++------ models/gauss.xml | 12 ++++++------ models/shell.xml | 12 ++++++------ test/data/crab.xml | 12 ++++++------ test/data/crab_bkgcube.xml | 16 ++++++++-------- test/data/disk.xml | 12 ++++++------ test/data/gauss.xml | 12 ++++++------ test/data/model_cube_background.xml | 6 +++--- test/data/model_cube_background2.xml | 6 +++--- test/data/sciver/bgd.xml | 6 +++--- test/data/sciver/crab_const.xml | 14 +++++++------- test/data/sciver/crab_cube.xml | 12 ++++++------ test/data/sciver/crab_edisk.xml | 12 ++++++------ test/data/sciver/crab_egauss.xml | 12 ++++++------ test/data/sciver/crab_eplaw.xml | 14 +++++++------- test/data/sciver/crab_filefct.xml | 8 ++++---- test/data/sciver/crab_gauss.xml | 6 +++--- test/data/sciver/crab_logparabola.xml | 14 +++++++------- test/data/sciver/crab_map.xml | 14 +++++++------- test/data/sciver/crab_map_nn.xml | 14 +++++++------- test/data/sciver/crab_map_roi.xml | 14 +++++++------- test/data/sciver/crab_nodes.xml | 6 +++--- test/data/sciver/crab_plaw.xml | 12 ++++++------ test/data/sciver/crab_plaw2.xml | 10 +++++----- test/data/sciver/crab_plaw_edisp.xml | 12 ++++++------ test/data/sciver/crab_ptsrc.xml | 12 ++++++------ test/data/sciver/crab_rdisk.xml | 12 ++++++------ test/data/sciver/crab_rgauss.xml | 12 ++++++------ test/data/sciver/crab_rshell.xml | 12 ++++++------ test/data/sciver/crab_supeplaw.xml | 16 ++++++++-------- test/data/shell.xml | 12 ++++++------ test/data/source1.xml | 10 +++++----- 37 files changed, 430 insertions(+), 206 deletions(-) create mode 100755 dev/testreport.py diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index 27d9e89..278548d 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -233,13 +233,13 @@ class csiactobs(ctools.cscript): # Handle constant spectral model if index == 0.0 and self._bkgpars <= 1: spec = gammalib.GModelSpectralConst() - spec['Value'].min(prefactor / self._bkg_range_factor) - spec['Value'].max(prefactor * self._bkg_range_factor) - spec['Value'].value(prefactor) + spec['Normalization'].min(prefactor / self._bkg_range_factor) + spec['Normalization'].max(prefactor * self._bkg_range_factor) + spec['Normalization'].value(prefactor) if self._bkgpars == 0: - spec['Value'].fix() + spec['Normalization'].fix() else: - spec['Value'].free() + spec['Normalization'].free() else: diff --git a/dev/testreport.py b/dev/testreport.py new file mode 100755 index 0000000..3b36917 --- /dev/null +++ b/dev/testreport.py @@ -0,0 +1,224 @@ +#! /usr/bin/env python +# ========================================================================== +# Display test reports +# +# Copyright (C) 2016 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# ========================================================================== +import glob +import gammalib + + +# ====================== # +# Report test case error # +# ====================== # +def report_one_error(name, xml): + """ + Report test case error + + Parameters + ---------- + name : str + Test case name + xml : gammalib.GXmlElement + Error XML element + """ + # Extract information + message = xml.attribute('message') + type = xml.attribute('type') + + # Print error information + print(' Error in %s:\n "%s" (%s)' % (name, message, type)) + + # Return + return + + +# ======================== # +# Report test case failure # +# ======================== # +def report_one_failure(name, xml): + """ + Report test case failure + + Parameters + ---------- + name : str + Test case name + xml : gammalib.GXmlElement + Failure XML element + """ + # Extract information + message = xml.attribute('message') + type = xml.attribute('type') + + # Print failure information + print(' Failure in %s:\n "%s" (%s)' % (name, message, type)) + + # Return + return + + +# ======================= # +# Report test case result # +# ======================= # +def report_one_test_case(xml): + """ + Report test case result + + Parameters + ---------- + xml : gammalib.GXmlElement + Test case XML element + """ + # Extract test case information + name = xml.attribute('name') + errors = int(xml.elements('error')) + failures = int(xml.elements('failure')) + + # If there are errors then display them + if errors > 0: + num = int(xml.elements('error')) + for i in range(num): + error = xml.element('error[%d]' % i) + report_one_error(name, error) + + # If there are failures then display them + if failures > 0: + num = int(xml.elements('failure')) + for i in range(num): + failure = xml.element('failure[%d]' % i) + report_one_failure(name, failure) + + # Return + return + + +# ========================= # +# Report test suite results # +# ========================= # +def report_one_test_suite(xml): + """ + Report test suite result + + Parameters + ---------- + xml : gammalib.GXmlElement + Test suite XML element + """ + # Extract test suite information + name = xml.attribute('name') + errors = int(xml.attribute('errors')) + failures = int(xml.attribute('failures')) + + # If there are errors or failures then print them + if errors > 0 or failures > 0: + + # Print header + if errors == 0: + print('%d failures occured in module "%s":' % + (failures, name)) + elif failures == 0: + print('%d errors occured in module "%s":' % + (errors, name)) + else: + print('%d errors and %d failures occured in module "%s":' % + (errors, failures, name)) + + # Determine number of test cases + num = int(xml.elements('testcase')) + + # Loop over all test cases + for i in range(num): + + # Get test case + case = xml.element('testcase[%d]' % i) + + # Report test case result + report_one_test_case(case) + + # Return + return + + +# ====================== # +# Report one test result # +# ====================== # +def report_one_test_result(file): + """ + Report one test result + + Parameters + ---------- + file : str + Test result file + """ + # Open XML file + xml = gammalib.GXml(file) + + # Determine number of testsuites + num = int(xml.element('testsuites').elements('testsuite')) + + # Loop over all test suites + for i in range(num): + + # Get test suite + suite = xml.element('testsuites > testsuite[%d]' % i) + + # Report test suite result + report_one_test_suite(suite) + + # Return + return + + +# =================== # +# Report test results # +# =================== # +def report_test_results(path, pattern="*.xml"): + """ + Report test results + + Parameters + ---------- + path : str + Directory containing test results + pattern : str, optional + Test report pattern + """ + # Get list of test reports + reports = glob.glob(path+'/'+pattern) + + # Loop over all reports + for report in reports: + report_one_test_result(report) + + # Return + return + + +# ======================== # +# Main routine entry point # +# ======================== # +if __name__ == '__main__': + + # Print header + print('') + print('ctools test reports') + print('===================') + + # Report test results + report_test_results('test/reports') diff --git a/models/crab.xml b/models/crab.xml index 627c43e..4a73e2b 100644 --- a/models/crab.xml +++ b/models/crab.xml @@ -2,9 +2,9 @@ - - - + + + @@ -13,9 +13,9 @@ - - - + + + diff --git a/models/crab_poly.xml b/models/crab_poly.xml index 6d1b1f8..faee3c5 100644 --- a/models/crab_poly.xml +++ b/models/crab_poly.xml @@ -2,9 +2,9 @@ - - - + + + @@ -13,9 +13,9 @@ - - - + + + diff --git a/models/crab_profile.xml b/models/crab_profile.xml index 1ffa630..2506b47 100644 --- a/models/crab_profile.xml +++ b/models/crab_profile.xml @@ -2,9 +2,9 @@ - - - + + + @@ -13,9 +13,9 @@ - - - + + + diff --git a/models/disk.xml b/models/disk.xml index 093198d..3ae69cd 100644 --- a/models/disk.xml +++ b/models/disk.xml @@ -2,9 +2,9 @@ - - - + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/models/gauss.xml b/models/gauss.xml index b1da6fe..acbc9c5 100644 --- a/models/gauss.xml +++ b/models/gauss.xml @@ -2,9 +2,9 @@ - - - + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/models/shell.xml b/models/shell.xml index a13776b..b97ac9b 100644 --- a/models/shell.xml +++ b/models/shell.xml @@ -2,9 +2,9 @@ - - - + + + @@ -15,9 +15,9 @@ - - - + + + diff --git a/test/data/crab.xml b/test/data/crab.xml index dbed891..b65f128 100644 --- a/test/data/crab.xml +++ b/test/data/crab.xml @@ -2,9 +2,9 @@ - - - + + + @@ -13,9 +13,9 @@ - - - + + + diff --git a/test/data/crab_bkgcube.xml b/test/data/crab_bkgcube.xml index 2889676..9fa334f 100644 --- a/test/data/crab_bkgcube.xml +++ b/test/data/crab_bkgcube.xml @@ -2,20 +2,20 @@ - - - + + + - - + + - - - + + + diff --git a/test/data/disk.xml b/test/data/disk.xml index ba4a2ea..2b99025 100644 --- a/test/data/disk.xml +++ b/test/data/disk.xml @@ -2,9 +2,9 @@ - - - + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/test/data/gauss.xml b/test/data/gauss.xml index 2d3fd0d..889764f 100644 --- a/test/data/gauss.xml +++ b/test/data/gauss.xml @@ -2,9 +2,9 @@ - - - + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/test/data/model_cube_background.xml b/test/data/model_cube_background.xml index 2cea6fe..b76b9ce 100644 --- a/test/data/model_cube_background.xml +++ b/test/data/model_cube_background.xml @@ -2,9 +2,9 @@ - - - + + + diff --git a/test/data/model_cube_background2.xml b/test/data/model_cube_background2.xml index 82e839b..2254612 100644 --- a/test/data/model_cube_background2.xml +++ b/test/data/model_cube_background2.xml @@ -2,9 +2,9 @@ - - - + + + diff --git a/test/data/sciver/bgd.xml b/test/data/sciver/bgd.xml index 56c3074..44ed248 100644 --- a/test/data/sciver/bgd.xml +++ b/test/data/sciver/bgd.xml @@ -2,9 +2,9 @@ - - - + + + diff --git a/test/data/sciver/crab_const.xml b/test/data/sciver/crab_const.xml index 2d1a2ac..c47dfee 100644 --- a/test/data/sciver/crab_const.xml +++ b/test/data/sciver/crab_const.xml @@ -2,19 +2,19 @@ - - - + + + - + - - - + + + diff --git a/test/data/sciver/crab_cube.xml b/test/data/sciver/crab_cube.xml index bfaafa3..371a10b 100644 --- a/test/data/sciver/crab_cube.xml +++ b/test/data/sciver/crab_cube.xml @@ -2,9 +2,9 @@ - - - + + + @@ -12,9 +12,9 @@ - - - + + + diff --git a/test/data/sciver/crab_edisk.xml b/test/data/sciver/crab_edisk.xml index 7bad7ca..0e4c41b 100644 --- a/test/data/sciver/crab_edisk.xml +++ b/test/data/sciver/crab_edisk.xml @@ -2,9 +2,9 @@ - - - + + + @@ -16,9 +16,9 @@ - - - + + + diff --git a/test/data/sciver/crab_egauss.xml b/test/data/sciver/crab_egauss.xml index 4e63a01..b7364a2 100644 --- a/test/data/sciver/crab_egauss.xml +++ b/test/data/sciver/crab_egauss.xml @@ -2,9 +2,9 @@ - - - + + + @@ -16,9 +16,9 @@ - - - + + + diff --git a/test/data/sciver/crab_eplaw.xml b/test/data/sciver/crab_eplaw.xml index 009241a..eb0ba7d 100644 --- a/test/data/sciver/crab_eplaw.xml +++ b/test/data/sciver/crab_eplaw.xml @@ -2,10 +2,10 @@ - - - - + + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/test/data/sciver/crab_filefct.xml b/test/data/sciver/crab_filefct.xml index b7f460b..4772263 100644 --- a/test/data/sciver/crab_filefct.xml +++ b/test/data/sciver/crab_filefct.xml @@ -2,7 +2,7 @@ - + @@ -11,9 +11,9 @@ - - - + + + diff --git a/test/data/sciver/crab_gauss.xml b/test/data/sciver/crab_gauss.xml index 0c0d074..ac9ee43 100644 --- a/test/data/sciver/crab_gauss.xml +++ b/test/data/sciver/crab_gauss.xml @@ -13,9 +13,9 @@ - - - + + + diff --git a/test/data/sciver/crab_logparabola.xml b/test/data/sciver/crab_logparabola.xml index b20b09c..3f35e77 100644 --- a/test/data/sciver/crab_logparabola.xml +++ b/test/data/sciver/crab_logparabola.xml @@ -2,10 +2,10 @@ - - - - + + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/test/data/sciver/crab_map.xml b/test/data/sciver/crab_map.xml index 8fdcb35..d8c1cc7 100644 --- a/test/data/sciver/crab_map.xml +++ b/test/data/sciver/crab_map.xml @@ -2,19 +2,19 @@ - - - + + + - + - - - + + + diff --git a/test/data/sciver/crab_map_nn.xml b/test/data/sciver/crab_map_nn.xml index 11769d6..cd9eb6f 100644 --- a/test/data/sciver/crab_map_nn.xml +++ b/test/data/sciver/crab_map_nn.xml @@ -2,19 +2,19 @@ - - - + + + - + - - - + + + diff --git a/test/data/sciver/crab_map_roi.xml b/test/data/sciver/crab_map_roi.xml index 8fdcb35..d8c1cc7 100644 --- a/test/data/sciver/crab_map_roi.xml +++ b/test/data/sciver/crab_map_roi.xml @@ -2,19 +2,19 @@ - - - + + + - + - - - + + + diff --git a/test/data/sciver/crab_nodes.xml b/test/data/sciver/crab_nodes.xml index 2db71f8..09b4414 100644 --- a/test/data/sciver/crab_nodes.xml +++ b/test/data/sciver/crab_nodes.xml @@ -26,9 +26,9 @@ - - - + + + diff --git a/test/data/sciver/crab_plaw.xml b/test/data/sciver/crab_plaw.xml index fb122ed..76c69c6 100644 --- a/test/data/sciver/crab_plaw.xml +++ b/test/data/sciver/crab_plaw.xml @@ -2,9 +2,9 @@ - - - + + + @@ -13,9 +13,9 @@ - - - + + + diff --git a/test/data/sciver/crab_plaw2.xml b/test/data/sciver/crab_plaw2.xml index 117eefe..274ee57 100644 --- a/test/data/sciver/crab_plaw2.xml +++ b/test/data/sciver/crab_plaw2.xml @@ -1,8 +1,8 @@ - - + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/test/data/sciver/crab_plaw_edisp.xml b/test/data/sciver/crab_plaw_edisp.xml index fb122ed..76c69c6 100644 --- a/test/data/sciver/crab_plaw_edisp.xml +++ b/test/data/sciver/crab_plaw_edisp.xml @@ -2,9 +2,9 @@ - - - + + + @@ -13,9 +13,9 @@ - - - + + + diff --git a/test/data/sciver/crab_ptsrc.xml b/test/data/sciver/crab_ptsrc.xml index f45413b..4cad53d 100644 --- a/test/data/sciver/crab_ptsrc.xml +++ b/test/data/sciver/crab_ptsrc.xml @@ -2,9 +2,9 @@ - - - + + + @@ -13,9 +13,9 @@ - - - + + + diff --git a/test/data/sciver/crab_rdisk.xml b/test/data/sciver/crab_rdisk.xml index 26aaeb8..2938637 100644 --- a/test/data/sciver/crab_rdisk.xml +++ b/test/data/sciver/crab_rdisk.xml @@ -2,9 +2,9 @@ - - - + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/test/data/sciver/crab_rgauss.xml b/test/data/sciver/crab_rgauss.xml index aab30ac..ebf8cfc 100644 --- a/test/data/sciver/crab_rgauss.xml +++ b/test/data/sciver/crab_rgauss.xml @@ -2,9 +2,9 @@ - - - + + + @@ -14,9 +14,9 @@ - - - + + + diff --git a/test/data/sciver/crab_rshell.xml b/test/data/sciver/crab_rshell.xml index 3a60206..377ce8b 100644 --- a/test/data/sciver/crab_rshell.xml +++ b/test/data/sciver/crab_rshell.xml @@ -2,9 +2,9 @@ - - - + + + @@ -15,9 +15,9 @@ - - - + + + diff --git a/test/data/sciver/crab_supeplaw.xml b/test/data/sciver/crab_supeplaw.xml index c157012..03369b0 100644 --- a/test/data/sciver/crab_supeplaw.xml +++ b/test/data/sciver/crab_supeplaw.xml @@ -2,11 +2,11 @@ - - - - - + + + + + @@ -15,9 +15,9 @@ - - - + + + diff --git a/test/data/shell.xml b/test/data/shell.xml index 571922a..5fc7c0a 100644 --- a/test/data/shell.xml +++ b/test/data/shell.xml @@ -2,9 +2,9 @@ - - - + + + @@ -15,9 +15,9 @@ - - - + + + diff --git a/test/data/source1.xml b/test/data/source1.xml index ed5ab84..ca07f3b 100644 --- a/test/data/source1.xml +++ b/test/data/source1.xml @@ -2,13 +2,13 @@ - - - + + + - - + + -- libgit2 0.21.4