Browse Source

Updates for python wrapping of LemmaCore

iss7
Trevor Irons 5 years ago
parent
commit
a277c26d1f

+ 3
- 2
Modules/FDEM1D/python/pyFDEM1D.cpp View File

@@ -35,11 +35,11 @@ PYBIND11_MODULE(FDEM1D, m) {
35 35
 
36 36
         // lifecycle
37 37
         WireAntenna.def(py::init(&Lemma::WireAntenna::NewSP))
38
+        .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
39
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::WireAntenna::DeSerialize), "Construct object from yaml representation")
38 40
 
39 41
         // print
40 42
         .def("__repr__", &Lemma::WireAntenna::Print)
41
-        .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
42
-        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::WireAntenna::DeSerialize), "Construct object from yaml representation")
43 43
 
44 44
         // modifiers
45 45
         .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
@@ -67,6 +67,7 @@ PYBIND11_MODULE(FDEM1D, m) {
67 67
 
68 68
         // lifecycle
69 69
         PolygonalWireAntenna.def(py::init(&Lemma::PolygonalWireAntenna::NewSP))
70
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::PolygonalWireAntenna::DeSerialize), "Construct object from yaml representation")
70 71
 
71 72
         // print
72 73
         .def("__repr__", &Lemma::PolygonalWireAntenna::Print)

+ 8
- 0
Modules/LemmaCore/include/ASCIIParser.h View File

@@ -75,6 +75,14 @@ class ASCIIParser : public LemmaObject {
75 75
     static std::shared_ptr< ASCIIParser >  DeSerialize( const YAML::Node& node );
76 76
 
77 77
     /**
78
+     *   Constructs an object from a string representation of a YAML::Node. This is primarily
79
+     *   used in Python wrapping
80
+     */
81
+    static std::shared_ptr<ASCIIParser> DeSerialize( const std::string& node ) {
82
+        return ASCIIParser::DeSerialize(YAML::Load(node));
83
+    }
84
+
85
+    /**
78 86
      *  Uses YAML to serialize this object.
79 87
      *  @return a YAML::Node
80 88
      */

+ 8
- 0
Modules/LemmaCore/include/CubicSplineInterpolator.h View File

@@ -97,6 +97,14 @@ class CubicSplineInterpolator : public LemmaObject {
97 97
      */
98 98
     static std::shared_ptr< CubicSplineInterpolator > DeSerialize(const YAML::Node& node);
99 99
 
100
+    /**
101
+     *   Constructs an object from a string representation of a YAML::Node. This is primarily
102
+     *   used in Python wrapping
103
+     */
104
+    static std::shared_ptr<CubicSplineInterpolator> DeSerialize( const std::string& node ) {
105
+        return CubicSplineInterpolator::DeSerialize(YAML::Load(node));
106
+    }
107
+
100 108
     // ====================  OPERATORS     =======================
101 109
 
102 110
     // ====================  OPERATIONS    =======================

+ 8
- 0
Modules/LemmaCore/include/RectilinearGrid.h View File

@@ -82,6 +82,14 @@ namespace Lemma {
82 82
              */
83 83
             static std::shared_ptr< RectilinearGrid > DeSerialize(const YAML::Node& node);
84 84
 
85
+            /**
86
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
87
+             *   used in Python wrapping
88
+             */
89
+            static std::shared_ptr<RectilinearGrid> DeSerialize( const std::string& node ) {
90
+                return RectilinearGrid::DeSerialize(YAML::Load(node));
91
+            }
92
+
85 93
             // ====================  OPERATORS     =======================
86 94
 
87 95
             // ====================  OPERATIONS    =======================

+ 47
- 20
Modules/LemmaCore/python/pyLemmaCore.cpp View File

@@ -30,10 +30,11 @@ PYBIND11_MODULE(LemmaCore, m) {
30 30
 
31 31
     m.doc() = "Python binding of LemmaCore, additional details can be found at https://lemmasoftware.org";
32 32
 
33
-    py::class_<Lemma::RectilinearGrid, std::shared_ptr<Lemma::RectilinearGrid> >(m, "RectilinearGrid")
33
+    py::class_<Lemma::RectilinearGrid, std::shared_ptr<Lemma::RectilinearGrid> > RectilinearGrid(m, "RectilinearGrid");
34 34
 
35 35
         // lifecycle
36
-        .def(py::init(&Lemma::RectilinearGrid::NewSP))
36
+        RectilinearGrid.def(py::init(&Lemma::RectilinearGrid::NewSP))
37
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGrid::DeSerialize), "Construct object from yaml representation")
37 38
 
38 39
         // print
39 40
         .def("__repr__", &Lemma::RectilinearGrid::Print)
@@ -54,12 +55,14 @@ PYBIND11_MODULE(LemmaCore, m) {
54 55
         // modifiers
55 56
         .def("SetDimensions", &Lemma::RectilinearGrid::SetDimensions, "Sets the number of cells in x, y, and z")
56 57
         .def("SetOffset", &Lemma::RectilinearGrid::SetOffset, "Sets the origin offset in x, y, and z")
57
-        .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z");
58
+        .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z")
59
+    ;
58 60
 
59
-    py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> >(m, "ASCIIParser")
61
+    py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> > ASCIIParser(m, "ASCIIParser");
60 62
 
61 63
         // lifecycle
62
-        .def(py::init(&Lemma::ASCIIParser::NewSP))
64
+        ASCIIParser.def(py::init(&Lemma::ASCIIParser::NewSP))
65
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::ASCIIParser::DeSerialize), "Construct object from yaml representation")
63 66
 
64 67
         // print
65 68
         .def("__repr__", &Lemma::ASCIIParser::Print)
@@ -82,26 +85,50 @@ PYBIND11_MODULE(LemmaCore, m) {
82 85
         .def("JumpToLocation", &Lemma::ASCIIParser::JumpToLocation, "File object jumps to specified location")
83 86
 
84 87
     ;
85
-}
86
-
87 88
 
88
-/*
89
-BOOST_PYTHON_MODULE(pyLemmaCore)
90
-{
91
-    Py_Initialize();
92
-    np::initialize();
89
+    py::class_<Lemma::CubicSplineInterpolator, std::shared_ptr<Lemma::CubicSplineInterpolator> >(m, "CubicSplineInterpolator")
93 90
 
94
- 	bp::class_<Lemma::RectilinearGrid, boost::noncopyable> ("RectilinearGrid", boost::python::no_init)
91
+        // lifecycle
92
+        .def(py::init(&Lemma::CubicSplineInterpolator::NewSP))
93
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::CubicSplineInterpolator::DeSerialize), "Construct object from yaml representation")
95 94
 
96 95
         // print
97
-        .def(boost::python::self_ns::str(bp::self))
96
+        .def("__repr__", &Lemma::CubicSplineInterpolator::Print)
97
+        .def("Serialize", &Lemma::CubicSplineInterpolator::Print, "YAML representation of the class")
98
+
99
+        // accessors
100
+        .def("GetName", &Lemma::CubicSplineInterpolator::GetName, "Returns the name of the class")
101
+        .def("GetKnotAbscissa", &Lemma::CubicSplineInterpolator::GetKnotAbscissa, "Returns the knot abscissa values")
102
+        .def("GetKnotOrdinate", &Lemma::CubicSplineInterpolator::GetKnotOrdinate, "Returns the knot ordinate values")
103
+
104
+        // modifiers
105
+        .def("SetKnots", &Lemma::CubicSplineInterpolator::SetKnots, "Sets the knots to use for interpolation")
106
+        .def("ResetKnotOrdinate", &Lemma::CubicSplineInterpolator::ResetKnotOrdinate, "Resets the knots to use for interpolation, when abscissa values haven't changed")
107
+
108
+        // methods
109
+        .def("InterpolateOrderedSet", &Lemma::CubicSplineInterpolator::InterpolateOrderedSet, "Interpolate a monotonically increasing ordered set.")
110
+        .def("Integrate", py::overload_cast<const Lemma::Real&, const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Integrate), "Integrates between the arguments using cubic spline values.")
111
+        .def("IntegrateN", py::overload_cast<const Lemma::Real&, const Lemma::Real&, const int& >(&Lemma::CubicSplineInterpolator::Integrate), "Integrates the spline from x0 to x1. Uses composite Simpson's rule and n is the number of segments")
112
+        .def("Interpolate", py::overload_cast<const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Interpolate), "Interpolation at a single point, x is the interpolation abscissa point, returns the ordinate value at x")
113
+        .def("InterpolateI", py::overload_cast<const Lemma::Real&, int& >(&Lemma::CubicSplineInterpolator::Interpolate), "Interpolation at a single point, x is the interpolation abscissa point and i is the knot to begin searchin at returns the ordinate value at x")
114
+
115
+    ;
98 116
 
99
-        // Lifecycle
100
-        .def("__init__", boost::python::make_constructor(&Lemma::RectilinearGrid::NewSP))
101
-        //.def("Serialize", &Lemma::RectilinearGrid::Serialize)
102
-        //.def("DeSerialize", &Lemma::RectilinearGrid::DeSerialize)
117
+    // ABC
118
+    //py::class_<Lemma::EarthModel, std::shared_ptr<Lemma::EarthModel> >(m, "EarthModel")
119
+
120
+    /*
121
+    py::class_<Lemma::LayeredEarth, std::shared_ptr<Lemma::LayeredEarth> >(m, "LayeredEarth")
122
+
123
+        // lifecycle
124
+        .def(py::init(&Lemma::LayeredEarth::NewSP))
125
+        //.def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::LayeredEarth::DeSerialize), "Construct object from yaml representation")
126
+
127
+        // print
128
+        .def("__repr__", &Lemma::LayeredEarth::Print)
129
+        .def("Serialize", &Lemma::LayeredEarth::Print, "YAML representation of the class")
103 130
 
104
-        // Accessors
105 131
     ;
132
+    */
106 133
 }
107
-*/
134
+

+ 3
- 0
python/pyLemma/__init__.py View File

@@ -0,0 +1,3 @@
1
+# Import the most used portions of Lemma automatically 
2
+from . import LemmaCore 
3
+from . import FDEM1D 

Loading…
Cancel
Save