Kaynağa Gözat

python wrapper progress

master
Trevor Irons 5 yıl önce
ebeveyn
işleme
6ddbd0a5c6

+ 9
- 1
Modules/FDEM1D/include/LayeredEarthEM.h Dosyayı Görüntüle

@@ -62,6 +62,14 @@ namespace Lemma {
62 62
              */
63 63
             static std::shared_ptr< LayeredEarthEM > DeSerialize(const YAML::Node& node);
64 64
 
65
+            /**
66
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
67
+             *   used in Python wrapping
68
+             */
69
+            static std::shared_ptr< LayeredEarthEM > DeSerialize( const std::string& node ) {
70
+                return LayeredEarthEM::DeSerialize(YAML::Load(node));
71
+            }
72
+
65 73
             /** @return a deep copy
66 74
              */
67 75
 			std::shared_ptr<LayeredEarthEM> Clone();
@@ -94,7 +102,7 @@ namespace Lemma {
94 102
              *  @param[in] sigma is  the conducivity of the layer
95 103
              *  @param[in] ilay is  the layer index
96 104
              */
97
-            void SetLayerConductivity(const int& ilay, const Complex &sigma);
105
+            void SetLayerConductivity(const int& ilay, const Complex& sigma);
98 106
 
99 107
             /* Sets Complex resitivity of the layers
100 108
              *  @param[in] ohm is a vector of the resistivity of the layers

+ 31
- 18
Modules/FDEM1D/python/pyFDEM1D.cpp Dosyayı Görüntüle

@@ -35,7 +35,8 @@ PYBIND11_MODULE(FDEM1D, m) {
35 35
 
36 36
         // lifecycle
37 37
         WireAntenna.def(py::init(&Lemma::WireAntenna::NewSP))
38
-        .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),
39
+            "Construct object from yaml representation")
39 40
 
40 41
         // print
41 42
         .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
@@ -43,7 +44,8 @@ PYBIND11_MODULE(FDEM1D, m) {
43 44
 
44 45
         // modifiers
45 46
         .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")
47
+        .def("SetPoint", py::overload_cast<const int&, const Lemma::Real&, const Lemma::Real&, const Lemma::Real&>(&Lemma::WireAntenna::SetPoint),
48
+            "Sets a point in the antenna")
47 49
         .def("SetPoint", py::overload_cast<const int&, const Lemma::Vector3r&>(&Lemma::WireAntenna::SetPoint),
48 50
             "Sets a point in the antenna")
49 51
         .def("SetNumberOfTurns", &Lemma::WireAntenna::SetNumberOfTurns, "Sets the number of turns of the antenna")
@@ -127,26 +129,37 @@ PYBIND11_MODULE(FDEM1D, m) {
127 129
         .def("SetFrequencies", &Lemma::DipoleSource::SetFrequencies,
128 130
             "Sets all frequencies, argument is numpy array of frequencies")
129 131
         ;
130
-}
131
-
132 132
 
133
-/*
134
-BOOST_PYTHON_MODULE(pyLemmaCore)
135
-{
136
-    Py_Initialize();
137
-    np::initialize();
133
+    py::class_<Lemma::LayeredEarthEM, std::shared_ptr<Lemma::LayeredEarthEM> > LayeredEarthEM(m, "LayeredEarthEM");
138 134
 
139
- 	bp::class_<Lemma::PolygonalWireAntenna, boost::noncopyable> ("PolygonalWireAntenna", boost::python::no_init)
135
+        // lifecycle
136
+        LayeredEarthEM.def(py::init(&Lemma::LayeredEarthEM::NewSP))
137
+        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::LayeredEarthEM::DeSerialize),
138
+            "Construct object from yaml representation")
140 139
 
141 140
         // print
142
-        .def(boost::python::self_ns::str(bp::self))
141
+        .def("Serialize", &Lemma::LayeredEarthEM::Print, "YAML representation of the class")
142
+        .def("__repr__", &Lemma::LayeredEarthEM::Print)
143 143
 
144
-        // Lifecycle
145
-        .def("__init__", boost::python::make_constructor(&Lemma::PolygonalWireAntenna::NewSP))
146
-        //.def("Serialize", &Lemma::PolygonalWireAntenna::Serialize)
147
-        //.def("DeSerialize", &Lemma::PolygonalWireAntenna::DeSerialize)
144
+        // accessors
145
+        .def("GetName", &Lemma::LayeredEarthEM::GetName, "Returns the name of the class")
146
+
147
+        // modifiers
148
+        .def("SetNumberOfLayers", &Lemma::LayeredEarthEM::SetNumberOfLayers, "Sets the number of layers in the model")
149
+        .def("SetLayerConductivity", py::overload_cast< const Lemma::VectorXcr& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
150
+            "Sets the conductivity of the layers, the input is a complex array of conductivity")
151
+        .def("SetLayerConductivity1", py::overload_cast< const int&, const Lemma::Complex& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
152
+            "Sets the conductivity of a single layer, the first input is the layer index, and the secondinput is a complex conductivity")
153
+        .def("SetLayerThickness", &Lemma::LayeredEarthEM::SetLayerThickness,
154
+            "Sets the thickness of layers, excluding the air and bottom which are infinite")
155
+
156
+        // methods
157
+        .def("EvaluateColeColeModel", &Lemma::LayeredEarthEM::EvaluateColeColeModel,
158
+            "Calculates complex resistivity based on cole-cole parameters")
159
+
160
+
161
+        ;
148 162
 
149
-        // Accessors
150
-    ;
151 163
 }
152
-*/
164
+
165
+

Loading…
İptal
Kaydet