Commit 02c80053145f9f6d6f12f715cd6dc97c7983cb5d

Authored by Jürgen Knödlseder
1 parent 739c5af5

Add Python interface for GCTAModelSpatialGradient and GCTAModelSpatialMultiplicative classes (#2694)

inst/cta/include/GCTAModelSpatialMultiplicative.hpp
... ... @@ -30,11 +30,6 @@
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include <string>
32 32 #include <vector>
33   -//#include "GBase.hpp"
34   -//#include "GFunction.hpp"
35   -//#include "GEnergy.hpp"
36   -//#include "GTime.hpp"
37   -//#include "GModelPar.hpp"
38 33 #include "GCTAModelSpatial.hpp"
39 34  
40 35 /* __ Forward declarations _______________________________________________ */
... ...
inst/cta/pyext/GCTAModelSpatialGradient.i 0 → 100644
  1 +/***************************************************************************
  2 + * GCTAModelSpatialGradient.i - Spatial gradient CTA model class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2018 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  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 +/**
  22 + * @file GCTAModelSpatialGradient.i
  23 + * @brief Spatial gradient CTA interface definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GCTAModelSpatialGradient.hpp"
  29 +%}
  30 +
  31 +
  32 +/***********************************************************************//**
  33 + * @class GCTAModelSpatialGradient
  34 + *
  35 + * @brief Spatial gradient CTA model class
  36 + ***************************************************************************/
  37 +class GCTAModelSpatialGradient : public GCTAModelSpatial {
  38 +
  39 +public:
  40 + // Constructors and destructors
  41 + GCTAModelSpatialGradient(void);
  42 + explicit GCTAModelSpatialGradient(const GXmlElement& xml);
  43 + GCTAModelSpatialGradient(const GCTAModelSpatialGradient& model);
  44 + virtual ~GCTAModelSpatialGradient(void);
  45 +
  46 + // Operators
  47 + virtual GCTAModelSpatialGradient& operator=(const GCTAModelSpatialGradient& model);
  48 +
  49 + // Implemented pure virtual methods
  50 + virtual void clear(void);
  51 + virtual GCTAModelSpatialGradient* clone(void) const;
  52 + virtual std::string classname(void) const;
  53 + virtual std::string type(void) const;
  54 + virtual double eval(const GCTAInstDir& dir,
  55 + const GEnergy& energy,
  56 + const GTime& time,
  57 + const bool& gradients = false) const;
  58 + virtual GCTAInstDir mc(const GEnergy& energy,
  59 + const GTime& time,
  60 + GRan& ran) const;
  61 + virtual void read(const GXmlElement& xml);
  62 + virtual void write(GXmlElement& xml) const;
  63 +
  64 + // Other methods
  65 + double detx_gradient(void) const;
  66 + double dety_gradient(void) const;
  67 + void detx_gradient(const double& detx_gradient);
  68 + void dety_gradient(const double& dety_gradient);
  69 +};
  70 +
  71 +
  72 +/***********************************************************************//**
  73 + * @brief GCTAModelSpatialGradient class extension
  74 + ***************************************************************************/
  75 +%extend GCTAModelSpatialGradient {
  76 + GCTAModelSpatialGradient copy() {
  77 + return (*self);
  78 + }
  79 +%pythoncode {
  80 + def __getstate__(self):
  81 + xml = gammalib.GXmlElement()
  82 + self.write(xml)
  83 + state = (xml,)
  84 + return state
  85 + def __setstate__(self, state):
  86 + if state[0].elements('parameter') == 0:
  87 + self.__init__()
  88 + else:
  89 + self.__init__(state[0])
  90 +}
  91 +};
... ...
inst/cta/pyext/GCTAModelSpatialMultiplicative.i 0 → 100644
  1 +/***************************************************************************
  2 + * GCTAModelSpatialMultiplicative.i - Multiplicative spatial model class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2018 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  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 +/**
  22 + * @file GCTAModelSpatialMultiplicative.i
  23 + * @brief Multiplicative spatial model class interface definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GCTAModelSpatialMultiplicative.hpp"
  29 +%}
  30 +
  31 +
  32 +/***********************************************************************//**
  33 + * @class GCTAModelSpatialMultiplicative
  34 + *
  35 + * @brief Multiplicative spatial model class
  36 + ***************************************************************************/
  37 +class GCTAModelSpatialMultiplicative : public GCTAModelSpatial {
  38 +
  39 +public:
  40 + // Constructors and destructors
  41 + GCTAModelSpatialMultiplicative(void);
  42 + explicit GCTAModelSpatialMultiplicative(const GXmlElement& xml);
  43 + GCTAModelSpatialMultiplicative(const GCTAModelSpatialMultiplicative& model);
  44 + virtual ~GCTAModelSpatialMultiplicative(void);
  45 +
  46 + // Operators
  47 + virtual GCTAModelSpatialMultiplicative& operator=(const GCTAModelSpatialMultiplicative& model);
  48 +
  49 + // Pure virtual methods
  50 + virtual void clear(void);
  51 + virtual GCTAModelSpatialMultiplicative* clone(void) const;
  52 + virtual std::string classname(void) const;
  53 + virtual std::string type(void) const;
  54 + virtual double eval(const GCTAInstDir& dir,
  55 + const GEnergy& energy,
  56 + const GTime& time,
  57 + const bool& gradients = false) const;
  58 + virtual GCTAInstDir mc(const GEnergy& energy,
  59 + const GTime& time,
  60 + GRan& ran) const;
  61 + virtual void read(const GXmlElement& xml);
  62 + virtual void write(GXmlElement& xml) const;
  63 +
  64 + // Other methods
  65 + void append(const GCTAModelSpatial& spatial,
  66 + const std::string& name="");
  67 + int components(void) const;
  68 + const GCTAModelSpatial* component(const int& index) const;
  69 + const GCTAModelSpatial* component(const std::string& name) const;
  70 +};
  71 +
  72 +
  73 +/***********************************************************************//**
  74 + * @brief GCTAModelSpatialMultiplicative class extension
  75 + ***************************************************************************/
  76 +%extend GCTAModelSpatialMultiplicative {
  77 + GCTAModelSpatialMultiplicative copy() {
  78 + return (*self);
  79 + }
  80 +%pythoncode {
  81 + def __getstate__(self):
  82 + xml = gammalib.GXmlElement()
  83 + self.write(xml)
  84 + state = (xml,)
  85 + return state
  86 + def __setstate__(self, state):
  87 + if state[0].elements('parameter') == 0:
  88 + self.__init__()
  89 + else:
  90 + self.__init__(state[0])
  91 +}
  92 +};
... ...
inst/cta/pyext/cta.i
... ... @@ -307,6 +307,8 @@
307 307 %include "GCTAModelIrfBackground.i"
308 308 %include "GCTAModelAeffBackground.i"
309 309 %include "GCTAModelSpatial.i"
  310 +%include "GCTAModelSpatialGradient.i"
  311 +%include "GCTAModelSpatialMultiplicative.i"
310 312 %include "GCTAModelSpatialRegistry.i"
311 313 %include "GCTAModelRadial.i"
312 314 %include "GCTAModelRadialRegistry.i"
... ...