From dc4df07ca1bc85ad3e69bec35d233f4ee03cbed1 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 3 Jul 2018 10:44:09 +0200 Subject: [PATCH] Integrate code and add exponential spectral model test to science verification (#2454) --- ChangeLog | 3 ++- NEWS | 2 +- doc/source/users/user_manual/models_spectral.rst | 57 +++++++++++++++++++++++++++++++++++++++------------------ test/data/sciver/crab_exponential.xml | 28 ++++++++++++++++++++++++++++ test/data/sciver/opacity.txt | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/science_verification.py | 18 ++++++++++++++++-- 6 files changed, 186 insertions(+), 22 deletions(-) create mode 100755 test/data/sciver/crab_exponential.xml create mode 100644 test/data/sciver/opacity.txt diff --git a/ChangeLog b/ChangeLog index 47cea52..998a99e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2018-06-20 +2018-07-03 * Version 1.6.0 released ======================== @@ -6,6 +6,7 @@ Transparently update parameter files (#2513) Change formula for number of true energy bins in csphagen (#2490) Remove ctools::is_valid_filename() method + Add Exponential spectral model to science verification (#2454) Fix bug when using precomputed model in csresspec (#2448) Keep existing library path in installation script on Mac OS X (#2420) csphagen produces Xspec compliant data (#2404) diff --git a/NEWS b/NEWS index d6a70a1..096648b 100755 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.6.0 -20 June 2018 +3 July 2018 Introduction diff --git a/doc/source/users/user_manual/models_spectral.rst b/doc/source/users/user_manual/models_spectral.rst index 2d39a71..8e75d40 100644 --- a/doc/source/users/user_manual/models_spectral.rst +++ b/doc/source/users/user_manual/models_spectral.rst @@ -503,34 +503,49 @@ Multiplicative model model components that are multiplied. -Exponential model: EBL absorption -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - This spectral model component implements the exponential of an - arbitrary spectral model. It can be used to model a spectrum with - EBL absorption based on a tabulated model of opacity as a function - of photon energy. +Exponential model +^^^^^^^^^^^^^^^^^ .. code-block:: xml - - - - - - - + - - This example corresponds to a spectrum + This spectral model component implements the exponential of an arbitrary + spectral model and computes + + .. math:: + M_{\rm spectral}(E) = \exp \left( M_{\rm spectral}(E) \right) + + where :math:`M_{\rm spectral}(E)` is any spectral model component. + + The model can be used to describe a spectrum with EBL absorption based on a + tabulated model of opacity as a function of photon energy. The corresponding + XML file structure for such a model is shown below: + + .. code-block:: xml - .. math:: + + + + + + + + + + + + + + This example corresponds to the function + + .. math:: M_{\rm spectral}(E) = k_0 \left( \frac{E}{E_0} \right)^{\gamma} - \times \exp\left( -\alpha \tau\left( E \right) \right) + \times \exp\left( -\alpha \, \tau(E) \right) where @@ -540,3 +555,9 @@ Exponential model: EBL absorption as first column and opacity :math:`\tau` as second column, respectively; * the parameter :math:`\alpha` = ``Normalization`` represents an opacity scaling factor. + + .. note:: + The ``Exponential`` model implements the function :math:`y=\exp(x)`, + hence in the example the ``scale`` attribute of the ``Normalization`` + parameter was set to ``-1`` to implement the form + :math:`y=\exp(-x)`. diff --git a/test/data/sciver/crab_exponential.xml b/test/data/sciver/crab_exponential.xml new file mode 100755 index 0000000..6d5ad50 --- /dev/null +++ b/test/data/sciver/crab_exponential.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/data/sciver/opacity.txt b/test/data/sciver/opacity.txt new file mode 100644 index 0000000..525e58c --- /dev/null +++ b/test/data/sciver/opacity.txt @@ -0,0 +1,100 @@ +1.000000000000000000e+03 2.130514478920406932e-04 +1.149756995397735636e+03 2.518904850653095901e-04 +1.321941148466028608e+03 2.978098346395106704e-04 +1.519911082952933157e+03 3.521002295303738675e-04 +1.747528400007682876e+03 4.162877017994022770e-04 +2.009233002565047855e+03 4.921764774211230195e-04 +2.310129700083160515e+03 5.818996907177256166e-04 +2.656087782946686730e+03 6.879793439775886213e-04 +3.053855508833415570e+03 8.133971976442146796e-04 +3.511191734215130964e+03 9.616785837061616292e-04 +4.037017258596553802e+03 1.136991498172844079e-03 +4.641588833612781855e+03 1.344263757996223352e-03 +5.336699231206313016e+03 1.589321515566356410e-03 +6.135907273413175972e+03 1.879053024242312688e-03 +7.054802310718645458e+03 2.221602258153513362e-03 +8.111308307896872066e+03 2.626597828671136097e-03 +9.326033468832200015e+03 3.105423632092475100e-03 +1.072267222010323167e+04 3.671538836091017399e-03 +1.232846739442065882e+04 4.340856199333244930e-03 +1.417474162926804820e+04 5.132189358332243760e-03 +1.629750834620643400e+04 6.067781654187125867e-03 +1.873817422860383158e+04 7.173931363836940321e-03 +2.154434690031886566e+04 8.481730910262627252e-03 +2.477076355991714081e+04 1.002794082986985247e-02 +2.848035868435804878e+04 1.185602306313406941e-02 +3.274549162877731578e+04 1.401736261295742636e-02 +3.764935806792470976e+04 1.657271190995783169e-02 +4.328761281083061476e+04 1.959389848391105901e-02 +4.977023564332113892e+04 2.316584394175889502e-02 +5.722367659350220492e+04 2.738895100301691130e-02 +6.579332246575682075e+04 3.238192568902821533e-02 +7.564633275546290679e+04 3.828511399411545918e-02 +8.697490026177834079e+04 4.526444682809729891e-02 +1.000000000000000000e+05 5.351610411734870898e-02 +1.149756995397735591e+05 6.327202916619174833e-02 +1.321941148466028681e+05 7.480644828010984959e-02 +1.519911082952933211e+05 8.844357890887546980e-02 +1.747528400007683085e+05 1.045667429754224553e-01 +2.009233002565045899e+05 1.236291415542298683e-01 +2.310129700083158095e+05 1.461665937613474131e-01 +2.656087782946684165e+05 1.728125979296164794e-01 +3.053855508833412314e+05 2.043161384190416152e-01 +3.511191734215127653e+05 2.415627385884853706e-01 +4.037017258596549509e+05 2.855993517002112791e-01 +4.641588833612782182e+05 3.376637894080791180e-01 +5.336699231206312543e+05 3.992195150257371594e-01 +6.135907273413175717e+05 4.719967795681307421e-01 +7.054802310718644876e+05 5.580412568466853740e-01 +8.111308307896872284e+05 6.597715446871550427e-01 +9.326033468832198996e+05 7.800471485542282979e-01 +1.072267222010323079e+06 9.222488585137500472e-01 +1.232846739442065824e+06 1.090373778823942263e+00 +1.417474162926804740e+06 1.289147681313261629e+00 +1.629750834620646900e+06 1.524157840651543472e+00 +1.873817422860386781e+06 1.802010085340306489e+00 +2.154434690031886566e+06 2.130514478920409349e+00 +2.477076355991714168e+06 2.518904850653099992e+00 +2.848035868435804732e+06 2.978098346395110951e+00 +3.274549162877731491e+06 3.521002295303742535e+00 +3.764935806792471092e+06 4.162877017994027540e+00 +4.328761281083061360e+06 4.921764774211230709e+00 +4.977023564332113601e+06 5.818996907177255373e+00 +5.722367659350220114e+06 6.879793439775887087e+00 +6.579332246575682424e+06 8.133971976442145646e+00 +7.564633275546290912e+06 9.616785837061614828e+00 +8.697490026177834719e+06 1.136991498172844395e+01 +1.000000000000000000e+07 1.344263757996222175e+01 +1.149756995397735573e+07 1.589321515566354392e+01 +1.321941148466028646e+07 1.879053024242310599e+01 +1.519911082952933200e+07 2.221602258153511400e+01 +1.747528400007683039e+07 2.626597828671133072e+01 +2.009233002565046027e+07 3.105423632092470854e+01 +2.310129700083158165e+07 3.671538836091013280e+01 +2.656087782946689427e+07 4.340856199333251197e+01 +3.053855508833418787e+07 5.132189358332250606e+01 +3.511191734215134382e+07 6.067781654187132290e+01 +4.037017258596558124e+07 7.173931363836948094e+01 +4.641588833612781763e+07 8.481730910262618295e+01 +5.336699231206312776e+07 1.002794082986983994e+02 +6.135907273413176090e+07 1.185602306313405592e+02 +7.054802310718645155e+07 1.401736261295741031e+02 +8.111308307896871865e+07 1.657271190995780898e+02 +9.326033468832199275e+07 1.959389848391103612e+02 +1.072267222010325342e+08 2.316584394175892214e+02 +1.232846739442063421e+08 2.738895100301680827e+02 +1.417474162926807702e+08 3.238192568902825315e+02 +1.629750834620640278e+08 3.828511399411532921e+02 +1.873817422860386968e+08 4.526444682809735696e+02 +2.154434690031886697e+08 5.351610411734878880e+02 +2.477076355991714001e+08 6.327202916619185089e+02 +2.848035868435804844e+08 7.480644828010995298e+02 +3.274549162877731919e+08 8.844357890887558824e+02 +3.764935806792471409e+08 1.045667429754226077e+03 +4.328761281083061695e+08 1.236291415542300228e+03 +4.977023564332113862e+08 1.461665937613475762e+03 +5.722367659350219965e+08 1.728125979296166861e+03 +6.579332246575682163e+08 2.043161384190418630e+03 +7.564633275546290874e+08 2.415627385884856722e+03 +8.697490026177834272e+08 2.855993517002116278e+03 +1.000000000000000000e+09 3.376637894080786737e+03 diff --git a/test/science_verification.py b/test/science_verification.py index 15fd381..8e18f31 100755 --- a/test/science_verification.py +++ b/test/science_verification.py @@ -11,7 +11,7 @@ # # -------------------------------------------------------------------------- # -# Copyright (C) 2015-2017 Juergen Knoedlseder +# Copyright (C) 2015-2018 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 @@ -251,6 +251,7 @@ class sciver(gammalib.GPythonTestSuite): self.append(self.spec_gauss, 'Test Gaussian model') self.append(self.spec_filefct, 'Test file function model') self.append(self.spec_nodes, 'Test nodes model') + self.append(self.spec_exponential, 'Test exponential model') # Append spatial tests self.append(self.spat_ptsrc, 'Test point source model') @@ -339,7 +340,7 @@ class sciver(gammalib.GPythonTestSuite): mean_max = +lim_mean std_min = 1.0-lim_std std_max = 1.0+lim_std - + # Test mean mean = self.results[name]['mean'] valid = (mean >= mean_min) and (mean <= mean_max) @@ -529,6 +530,19 @@ class sciver(gammalib.GPythonTestSuite): self.test('Pull_Background_Index') return + # Test exponential model + def spec_exponential(self): + """ + Test exponential model + """ + self.pull('data/sciver/crab_exponential') + self.test('Pull_Crab_1:Prefactor') + self.test('Pull_Crab_1:Index') + self.test('Pull_Crab_2:Normalization') + self.test('Pull_Background_Prefactor') + self.test('Pull_Background_Index') + return + # Test point source model def spat_ptsrc(self): """ -- libgit2 0.21.4