Browse Source

More work on Python wrapper

iss7
Trevor Irons 5 years ago
parent
commit
dd85c872aa

+ 1
- 0
Modules/FDEM1D/include/DipoleSource.h View File

41
     ///           dipoles.
41
     ///           dipoles.
42
     // ==========================================================================
42
     // ==========================================================================
43
     class DipoleSource : public std::enable_shared_from_this<DipoleSource>,  LemmaObject {
43
     class DipoleSource : public std::enable_shared_from_this<DipoleSource>,  LemmaObject {
44
+    //class DipoleSource : public LemmaObject {
44
 
45
 
45
         // ====================    FRIENDS     ======================
46
         // ====================    FRIENDS     ======================
46
 
47
 

+ 27
- 12
Modules/FDEM1D/python/pyFDEM1D.cpp View File

31
     m.doc() = "Python binding of Lemma::FDEM1D, additional details can be found at https://lemmasoftware.org";
31
     m.doc() = "Python binding of Lemma::FDEM1D, additional details can be found at https://lemmasoftware.org";
32
 
32
 
33
 
33
 
34
-    py::class_<Lemma::WireAntenna, std::shared_ptr<Lemma::WireAntenna> > WireAntenna(m, "WireAntenna"); //, py::dynamic_attr());
34
+    py::class_<Lemma::WireAntenna, std::shared_ptr<Lemma::WireAntenna> > WireAntenna(m, "WireAntenna");
35
 
35
 
36
         // lifecycle
36
         // lifecycle
37
         WireAntenna.def(py::init(&Lemma::WireAntenna::NewSP))
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
         .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::WireAntenna::DeSerialize), "Construct object from yaml representation")
40
 
39
 
41
         // print
40
         // print
41
+        .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
42
         .def("__repr__", &Lemma::WireAntenna::Print)
42
         .def("__repr__", &Lemma::WireAntenna::Print)
43
 
43
 
44
         // modifiers
44
         // modifiers
45
         .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
45
         .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
46
         .def("SetPoint", py::overload_cast<const int&, const Lemma::Real&, const Lemma::Real&, const Lemma::Real&>(&Lemma::WireAntenna::SetPoint), "Sets a point in the antenna")
46
         .def("SetPoint", py::overload_cast<const int&, const Lemma::Real&, const Lemma::Real&, const Lemma::Real&>(&Lemma::WireAntenna::SetPoint), "Sets a point in the antenna")
47
-        .def("SetPoint", py::overload_cast<const int&, const Lemma::Vector3r&>(&Lemma::WireAntenna::SetPoint), "Sets a point in the antenna")
47
+        .def("SetPoint", py::overload_cast<const int&, const Lemma::Vector3r&>(&Lemma::WireAntenna::SetPoint),
48
+            "Sets a point in the antenna")
48
         .def("SetNumberOfTurns", &Lemma::WireAntenna::SetNumberOfTurns, "Sets the number of turns of the antenna")
49
         .def("SetNumberOfTurns", &Lemma::WireAntenna::SetNumberOfTurns, "Sets the number of turns of the antenna")
49
-        .def("SetNumberOfFrequencies", &Lemma::WireAntenna::SetNumberOfFrequencies, "Sets the number of frequencies of the transmitter")
50
+        .def("SetNumberOfFrequencies", &Lemma::WireAntenna::SetNumberOfFrequencies,
51
+            "Sets the number of frequencies of the transmitter")
50
         .def("SetFrequency", &Lemma::WireAntenna::SetFrequency, "Sets a single frequency of the transmitter")
52
         .def("SetFrequency", &Lemma::WireAntenna::SetFrequency, "Sets a single frequency of the transmitter")
51
         .def("SetCurrent", &Lemma::WireAntenna::SetCurrent, "Sets the current of the transmitter in amps")
53
         .def("SetCurrent", &Lemma::WireAntenna::SetCurrent, "Sets the current of the transmitter in amps")
52
 
54
 
54
         .def("GetCurrent", &Lemma::WireAntenna::GetCurrent, "Returns the current of the transmitter in amps")
56
         .def("GetCurrent", &Lemma::WireAntenna::GetCurrent, "Returns the current of the transmitter in amps")
55
         .def("GetPoints", &Lemma::WireAntenna::GetPoints, "Returns the points defining the transmitter")
57
         .def("GetPoints", &Lemma::WireAntenna::GetPoints, "Returns the points defining the transmitter")
56
         .def("GetNumberOfDipoles", &Lemma::WireAntenna::GetNumberOfDipoles, "Returns the number of dipoles defining the transmitter")
58
         .def("GetNumberOfDipoles", &Lemma::WireAntenna::GetNumberOfDipoles, "Returns the number of dipoles defining the transmitter")
57
-        .def("GetNumberOfFrequencies", &Lemma::WireAntenna::GetNumberOfFrequencies, "Returns the number of frequencies for the transmitter")
59
+        .def("GetNumberOfFrequencies", &Lemma::WireAntenna::GetNumberOfFrequencies,
60
+            "Returns the number of frequencies for the transmitter")
58
         .def("IsHorizontallyPlanar", &Lemma::WireAntenna::IsHorizontallyPlanar, "Returns true if the transmitter is flat")
61
         .def("IsHorizontallyPlanar", &Lemma::WireAntenna::IsHorizontallyPlanar, "Returns true if the transmitter is flat")
59
         .def("GetName", &Lemma::WireAntenna::GetName, "Returns the class name of the object")
62
         .def("GetName", &Lemma::WireAntenna::GetName, "Returns the class name of the object")
60
 
63
 
61
         // operations
64
         // operations
62
-        .def("ApproximateWithElectricDipoles", &Lemma::WireAntenna::ApproximateWithElectricDipoles, "Approximates loop with electric dipoles")
65
+        .def("ApproximateWithElectricDipoles", &Lemma::WireAntenna::ApproximateWithElectricDipoles,
66
+            "Approximates loop with electric dipoles")
63
 
67
 
64
     ;
68
     ;
65
 
69
 
66
-    py::class_<Lemma::PolygonalWireAntenna, std::shared_ptr<Lemma::PolygonalWireAntenna> > PolygonalWireAntenna(m, "PolygonalWireAntenna", WireAntenna); //, py::dynamic_attr())
70
+    py::class_<Lemma::PolygonalWireAntenna, std::shared_ptr<Lemma::PolygonalWireAntenna> > PolygonalWireAntenna(m,
71
+            "PolygonalWireAntenna", WireAntenna);
67
 
72
 
68
         // lifecycle
73
         // lifecycle
69
         PolygonalWireAntenna.def(py::init(&Lemma::PolygonalWireAntenna::NewSP))
74
         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")
75
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::PolygonalWireAntenna::DeSerialize),
76
+            "Construct object from yaml representation")
71
 
77
 
72
         // print
78
         // print
73
         .def("__repr__", &Lemma::PolygonalWireAntenna::Print)
79
         .def("__repr__", &Lemma::PolygonalWireAntenna::Print)
76
         // accessors
82
         // accessors
77
         .def("GetName", &Lemma::PolygonalWireAntenna::GetName, "Returns the name of the class")
83
         .def("GetName", &Lemma::PolygonalWireAntenna::GetName, "Returns the name of the class")
78
 
84
 
79
-        // modifiers
80
-        //.def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
81
-
82
         // operations
85
         // operations
83
-        .def("ApproximateWithElectricDipoles", &Lemma::PolygonalWireAntenna::ApproximateWithElectricDipoles, "Approximates loop with series of electric dipoles around loop")
86
+        .def("ApproximateWithElectricDipoles", &Lemma::PolygonalWireAntenna::ApproximateWithElectricDipoles,
87
+            "Approximates loop with series of electric dipoles around loop")
84
 
88
 
85
     ;
89
     ;
86
 
90
 
91
+    //py::class_<Lemma::DipoleSource, std::shared_ptr<Lemma::DipoleSource> > DipoleSource(m, "DipoleSource");
92
+
93
+        // lifecycle
94
+        //DipoleSource.def(py::init(&Lemma::DipoleSource::NewSP))
95
+        //.def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::DipoleSource::DeSerialize), "Construct object from yaml representation")
96
+
97
+        // print
98
+        //.def("Serialize", &Lemma::DipoleSource::Print, "YAML representation of the class")
99
+        //.def("__repr__", &Lemma::DipoleSource::Print)
100
+
101
+        //;
87
 }
102
 }
88
 
103
 
89
 
104
 

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

78
             static std::shared_ptr< RectilinearGridReader >  DeSerialize( const YAML::Node& node );
78
             static std::shared_ptr< RectilinearGridReader >  DeSerialize( const YAML::Node& node );
79
 
79
 
80
             /**
80
             /**
81
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
82
+             *   used in Python wrapping
83
+             */
84
+            static std::shared_ptr<RectilinearGridReader> DeSerialize( const std::string& node ) {
85
+                return RectilinearGridReader::DeSerialize(YAML::Load(node));
86
+            }
87
+
88
+            /**
81
              *  Uses YAML to serialize this object.
89
              *  Uses YAML to serialize this object.
82
              *  @return a YAML::Node
90
              *  @return a YAML::Node
83
              */
91
              */

+ 39
- 8
Modules/LemmaCore/python/pyLemmaCore.cpp View File

34
 
34
 
35
         // lifecycle
35
         // lifecycle
36
         RectilinearGrid.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
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGrid::DeSerialize),
38
+            "Construct object from yaml representation")
38
 
39
 
39
         // print
40
         // print
40
         .def("__repr__", &Lemma::RectilinearGrid::Print)
41
         .def("__repr__", &Lemma::RectilinearGrid::Print)
58
         .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z")
59
         .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z")
59
     ;
60
     ;
60
 
61
 
62
+    py::class_<Lemma::RectilinearGridReader, std::shared_ptr<Lemma::RectilinearGridReader> > RectilinearGridReader(m, "RectilinearGridReader");
63
+
64
+        // lifecycle
65
+        RectilinearGridReader.def(py::init(&Lemma::RectilinearGridReader::NewSP))
66
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGridReader::DeSerialize),
67
+            "Construct object from yaml representation")
68
+
69
+        // print
70
+        .def("__repr__", &Lemma::RectilinearGridReader::Print)
71
+        .def("Serialize", &Lemma::RectilinearGridReader::Print, "YAML representation of the class")
72
+
73
+        // accessors
74
+        .def("GetName", &Lemma::RectilinearGridReader::GetName, "Returns the name of the class")
75
+
76
+        // modifiers
77
+
78
+        //methods
79
+        .def("ReadASCIIGridFile", &Lemma::RectilinearGridReader::ReadASCIIGridFile, "Opens file specified by argument")
80
+
81
+        //methods
82
+        .def("GetGrid", &Lemma::RectilinearGridReader::GetGrid, "Returns the grid object")
83
+    ;
84
+
61
     py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> > ASCIIParser(m, "ASCIIParser");
85
     py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> > ASCIIParser(m, "ASCIIParser");
62
 
86
 
63
         // lifecycle
87
         // lifecycle
64
         ASCIIParser.def(py::init(&Lemma::ASCIIParser::NewSP))
88
         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")
89
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::ASCIIParser::DeSerialize),
90
+            "Construct object from yaml representation")
66
 
91
 
67
         // print
92
         // print
68
         .def("__repr__", &Lemma::ASCIIParser::Print)
93
         .def("__repr__", &Lemma::ASCIIParser::Print)
90
 
115
 
91
         // lifecycle
116
         // lifecycle
92
         .def(py::init(&Lemma::CubicSplineInterpolator::NewSP))
117
         .def(py::init(&Lemma::CubicSplineInterpolator::NewSP))
93
-        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::CubicSplineInterpolator::DeSerialize), "Construct object from yaml representation")
118
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::CubicSplineInterpolator::DeSerialize),
119
+            "Construct object from yaml representation")
94
 
120
 
95
         // print
121
         // print
96
         .def("__repr__", &Lemma::CubicSplineInterpolator::Print)
122
         .def("__repr__", &Lemma::CubicSplineInterpolator::Print)
103
 
129
 
104
         // modifiers
130
         // modifiers
105
         .def("SetKnots", &Lemma::CubicSplineInterpolator::SetKnots, "Sets the knots to use for interpolation")
131
         .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")
132
+        .def("ResetKnotOrdinate", &Lemma::CubicSplineInterpolator::ResetKnotOrdinate,
133
+            "Resets the knots to use for interpolation, when abscissa values haven't changed")
107
 
134
 
108
         // methods
135
         // methods
109
         .def("InterpolateOrderedSet", &Lemma::CubicSplineInterpolator::InterpolateOrderedSet, "Interpolate a monotonically increasing ordered set.")
136
         .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")
137
+        .def("Integrate", py::overload_cast<const Lemma::Real&, const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Integrate),
138
+                "Integrates between the arguments using cubic spline values.")
139
+        .def("IntegrateN", py::overload_cast<const Lemma::Real&, const Lemma::Real&, const int& >(&Lemma::CubicSplineInterpolator::Integrate),
140
+                "Integrates the spline from x0 to x1. Uses composite Simpson's rule and n is the number of segments")
141
+        .def("Interpolate", py::overload_cast<const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Interpolate),
142
+                "Interpolation at a single point, x is the interpolation abscissa point, returns the ordinate value at x")
143
+        .def("InterpolateI", py::overload_cast<const Lemma::Real&, int& >(&Lemma::CubicSplineInterpolator::Interpolate),
144
+                "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
 
145
 
115
     ;
146
     ;
116
 
147
 

Loading…
Cancel
Save