Browse Source

EMEarth1D functional in pyLemma

master
Trevor Irons 4 years ago
parent
commit
7c978773e8

+ 7
- 6
Modules/FDEM1D/include/EMEarth1D.h View File

@@ -89,6 +89,7 @@ namespace Lemma {
89 89
              */
90 90
             YAML::Node Serialize() const;
91 91
 
92
+            // TODO, add this
92 93
             //static EMEarth1D* DeSerialize(const YAML::Node& node);
93 94
 
94 95
             // ====================  OPERATORS     ===========================
@@ -110,23 +111,23 @@ namespace Lemma {
110 111
             // ====================  ACCESS        ===========================
111 112
 
112 113
             /** Attaches an antennae */
113
-            void AttachWireAntenna( std::shared_ptr<WireAntenna> antennae);
114
+            void AttachWireAntenna( std::shared_ptr<WireAntenna> antennae );
114 115
 
115 116
             /** Attaches a dipole for calculation */
116
-            void AttachDipoleSource( std::shared_ptr<DipoleSource> dipole);
117
+            void AttachDipoleSource( std::shared_ptr<DipoleSource> dipole );
117 118
 
118 119
             /** Attaches a layered earth model for calculation */
119
-            void AttachLayeredEarthEM( std::shared_ptr<LayeredEarthEM> Earth);
120
+            void AttachLayeredEarthEM( std::shared_ptr<LayeredEarthEM> Earth );
120 121
 
121 122
             /** Attaches a set of receiver points for calculation */
122
-            void AttachFieldPoints( std::shared_ptr<FieldPoints> Receivers);
123
+            void AttachFieldPoints( std::shared_ptr<FieldPoints> Receivers );
123 124
 
124 125
             /** Sets the fields that are calcultated, E,H or BOTH */
125
-            void SetFieldsToCalculate(const FIELDCALCULATIONS &calc);
126
+            void SetFieldsToCalculate( const FIELDCALCULATIONS &calc );
126 127
 
127 128
             /** Sets the method to use to evaluate the Hankel integral,
128 129
              */
129
-            void SetHankelTransformMethod(const HANKELTRANSFORMTYPE &type);
130
+            void SetHankelTransformMethod( const HANKELTRANSFORMTYPE &type );
130 131
 
131 132
             /**
132 133
              *   Accesor for field points

+ 24
- 16
Modules/FDEM1D/include/FieldPoints.h View File

@@ -92,6 +92,14 @@ namespace Lemma {
92 92
              */
93 93
             static std::shared_ptr<FieldPoints> DeSerialize(const YAML::Node& node);
94 94
 
95
+            /**
96
+             *   Constructs an object from a string representation of a YAML::Node. This is primarily
97
+             *   used in Python wrapping
98
+             */
99
+            static std::shared_ptr<FieldPoints> DeSerialize( const std::string& node ) {
100
+                return FieldPoints::DeSerialize(YAML::Load(node));
101
+            }
102
+
95 103
             // ====================  OPERATORS     ===========================
96 104
 
97 105
             // ====================  OPERATIONS    ===========================
@@ -116,11 +124,8 @@ namespace Lemma {
116 124
             /// Returns the number of receiverpoints.
117 125
             int GetNumberOfPoints();
118 126
 
119
-            /// Returns all the receiver locations as a 3 X matrix
120
-            Vector3Xr GetLocations();
121
-
122
-            /// Returns all the receiver locations as a general matrix, useful for python wrapper
123
-            MatrixXr GetLocationsMat();
127
+            /// Returns all of the computed E fields. Every frequency
128
+            std::vector<Vector3Xcr> GetEfield( );
124 129
 
125 130
             /// Returns the E field for all locations
126 131
             /// nfreq is the freqency desired
@@ -130,23 +135,20 @@ namespace Lemma {
130 135
             /// nfreq is the freqency desired, cast to general dynamic matrix, for python interoperability
131 136
             MatrixXcr GetEfieldMat(const int &nfreq);
132 137
 
133
-            /// Returns the H field for all locations
134
-            /// nfreq is the freqency desired, cast to general dynamic matrix, for python interoperability
135
-            MatrixXcr GetHfieldMat(const int &nfreq);
136
-
137
-            /// Returns the H field for all locations
138
+            /// Returns the E field of a single receiver as an Eigen Vector
138 139
             /// nfreq is the freqency desired
139
-            Vector3Xcr GetHfield(const int &nfreq);
140
+            Vector3cr GetEfield(const int &nfreq, const int& loc);
140 141
 
141 142
             /// Returns all of the computed H fields. Every frequency
142 143
             std::vector<Vector3Xcr> GetHfield( );
143 144
 
144
-            /// Returns all of the computed E fields. Every frequency
145
-            std::vector<Vector3Xcr> GetEfield( );
146
-
147
-            /// Returns the E field of a single receiver as an Eigen Vector
145
+            /// Returns the H field for all locations
148 146
             /// nfreq is the freqency desired
149
-            Vector3cr GetEfield(const int &nfreq, const int& loc);
147
+            Vector3Xcr GetHfield(const int &nfreq);
148
+
149
+            /// Returns the H field for all locations
150
+            /// nfreq is the freqency desired, cast to general dynamic matrix, for python interoperability
151
+            MatrixXcr GetHfieldMat(const int &nfreq);
150 152
 
151 153
             /// Returns the H field of a single receiver as an Eigen Vector
152 154
             /// nfreq is the freqency desired
@@ -177,6 +179,12 @@ namespace Lemma {
177 179
                 const VectorXr& Freqs);
178 180
             #endif
179 181
 
182
+            /// Returns all the receiver locations as a 3 X matrix
183
+            Vector3Xr GetLocations();
184
+
185
+            /// Returns all the receiver locations as a general matrix, useful for python wrapper
186
+            MatrixXr GetLocationsMat();
187
+
180 188
             /// Returns the location of a single receiver as an Eigen Vector
181 189
             Vector3r GetLocation(const int& loc);
182 190
 

+ 112
- 5
Modules/FDEM1D/python/pyFDEM1D.cpp View File

@@ -43,7 +43,8 @@ PYBIND11_MODULE(FDEM1D, m) {
43 43
         .def("__repr__", &Lemma::WireAntenna::Print)
44 44
 
45 45
         // modifiers
46
-        .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints, "Sets the number of points comprising the antenna")
46
+        .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints,
47
+            "Sets the number of points comprising the antenna")
47 48
         .def("SetPoint", py::overload_cast<const int&, const Lemma::Real&, const Lemma::Real&, const Lemma::Real&>(&Lemma::WireAntenna::SetPoint),
48 49
             "Sets a point in the antenna")
49 50
         .def("SetPoint", py::overload_cast<const int&, const Lemma::Vector3r&>(&Lemma::WireAntenna::SetPoint),
@@ -131,12 +132,13 @@ PYBIND11_MODULE(FDEM1D, m) {
131 132
             "Sets all frequencies, argument is numpy array of frequencies")
132 133
         ;
133 134
 
134
-    py::class_<Lemma::LayeredEarthEM, std::shared_ptr<Lemma::LayeredEarthEM> > LayeredEarthEM(m, "LayeredEarthEM");
135
+    py::class_<Lemma::LayeredEarthEM, std::shared_ptr<Lemma::LayeredEarthEM> >
136
+        LayeredEarthEM(m, "LayeredEarthEM");
135 137
 
136 138
         // lifecycle
137 139
         LayeredEarthEM.def(py::init(&Lemma::LayeredEarthEM::NewSP))
138
-        .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::LayeredEarthEM::DeSerialize),
139
-            "Construct object from yaml representation")
140
+        .def_static("DeSerialize", py::overload_cast<const std::string&>
141
+            (&Lemma::LayeredEarthEM::DeSerialize),"Construct object from yaml representation")
140 142
 
141 143
         // print
142 144
         .def("Serialize", &Lemma::LayeredEarthEM::Print, "YAML representation of the class")
@@ -194,7 +196,8 @@ PYBIND11_MODULE(FDEM1D, m) {
194 196
 
195 197
 
196 198
         // modifiers
197
-        .def("SetNumberOfLayers", &Lemma::LayeredEarthEM::SetNumberOfLayers, "Sets the number of layers in the model")
199
+        .def("SetNumberOfLayers", &Lemma::LayeredEarthEM::SetNumberOfLayers,
200
+            "Sets the number of layers in the model")
198 201
         .def("SetLayerConductivity", py::overload_cast< const Lemma::VectorXcr& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
199 202
             "Sets the conductivity of the layers, the input is a complex array of conductivity")
200 203
         .def("SetLayerConductivity1", py::overload_cast< const int&, const Lemma::Complex& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
@@ -220,10 +223,114 @@ PYBIND11_MODULE(FDEM1D, m) {
220 223
         // methods
221 224
         .def("EvaluateColeColeModel", &Lemma::LayeredEarthEM::EvaluateColeColeModel,
222 225
             "Calculates complex resistivity based on cole-cole parameters")
226
+        ;
227
+
228
+    py::class_<Lemma::EMEarth1D, std::shared_ptr<Lemma::EMEarth1D> >
229
+        EMEarth1D(m, "EMEarth1D");
223 230
 
231
+        // lifecycle
232
+        EMEarth1D.def(py::init(&Lemma::EMEarth1D::NewSP))
233
+        //.def_static("DeSerialize", py::overload_cast<const std::string&>
234
+        //    (&Lemma::EMEarth1D::DeSerialize),"Construct object from yaml representation")
235
+
236
+        // print
237
+        .def("Serialize", &Lemma::EMEarth1D::Print, "YAML representation of the class")
238
+        .def("__repr__", &Lemma::EMEarth1D::Print)
224 239
 
240
+        // accessors
241
+        .def("GetName", &Lemma::EMEarth1D::GetName, "Returns the name of the class")
242
+        .def("GetFieldPoints", &Lemma::EMEarth1D::GetFieldPoints, "Returns the FieldPoint class")
243
+
244
+        // modifiers
245
+        .def("AttachWireAntenna", &Lemma::EMEarth1D::AttachWireAntenna,
246
+            "Sets the wire antenna to use for calculations")
247
+        .def("AttachDipoleSOurce", &Lemma::EMEarth1D::AttachDipoleSource,
248
+            "Sets a DipoleSource to use for calculations")
249
+        .def("AttachFieldPoints", &Lemma::EMEarth1D::AttachFieldPoints,
250
+            "Sets the FieldPoints to use for calculations")
251
+        .def("AttachLayeredEarthEM", &Lemma::EMEarth1D::AttachLayeredEarthEM,
252
+            "Sets the LayeredEarthEM to use for calculations")
253
+
254
+        .def("SetFieldToCalculate", &Lemma::EMEarth1D::SetFieldsToCalculate,
255
+            "Sets which fields to calculate")
256
+        .def("SetHankelTransformMethod", &Lemma::EMEarth1D::SetHankelTransformMethod,
257
+            "Sets which Hankel transform to use")
258
+        .def("SetTxRxMode", &Lemma::EMEarth1D::SetTxRxMode,
259
+            "Sets the TxRx mode flag")
260
+
261
+        //methods
262
+#ifdef KIHALEE_EM1D
263
+        .def("MakeCalc", &Lemma::EMEarth1D::MakeCalc, "Calls KiHa Lee's EM1D FORTRAN77 code")
264
+#endif
265
+
266
+        .def("MakeCalc3", &Lemma::EMEarth1D::MakeCalc3, "Native Lemma EM calculation")
267
+        .def("CalculateWireAntennaFields", &Lemma::EMEarth1D::CalculateWireAntennaFields,
268
+            "Native Lemma calculation of a wire antenna")
225 269
         ;
226 270
 
271
+    py::class_<Lemma::FieldPoints, std::shared_ptr<Lemma::FieldPoints> >
272
+        FieldPoints(m, "FieldPoints");
273
+
274
+        // lifecycle
275
+        FieldPoints.def(py::init(&Lemma::FieldPoints::NewSP))
276
+        .def_static("DeSerialize", py::overload_cast<const std::string&>
277
+            (&Lemma::FieldPoints::DeSerialize),"Construct object from yaml representation")
278
+
279
+        // print
280
+        .def("Serialize", &Lemma::FieldPoints::Print, "YAML representation of the class")
281
+        .def("__repr__", &Lemma::FieldPoints::Print)
282
+
283
+        // modifiers
284
+        .def("SetNumberOfPoints", &Lemma::FieldPoints::SetNumberOfPoints,
285
+            "Sets the number of locations to make calculations on.")
286
+        .def("SetLocation", py::overload_cast< const int&, const Lemma::Vector3r& >
287
+            (&Lemma::FieldPoints::SetLocation), "Sets the location of the index-specified point." )
288
+        .def("SetLocation", py::overload_cast< const int&,
289
+                    const Lemma::Real&, const Lemma::Real&, const Lemma::Real& >
290
+            (&Lemma::FieldPoints::SetLocation),
291
+            "Sets the location of the index-specified point with the three coordinates")
292
+
293
+        // accessors
294
+        .def("GetNumberOfPoints", &Lemma::FieldPoints::GetNumberOfPoints,
295
+            "Returns the number of locations to make calculations on.")
296
+        .def("GetLocations", &Lemma::FieldPoints::GetLocations,
297
+            "Returns the locations which calculations are made on.")
298
+        .def("GetLocationsMat", &Lemma::FieldPoints::GetLocationsMat,
299
+            "Returns a matrix of the locations which calculations are made on.")
300
+        .def("GetLocation", &Lemma::FieldPoints::GetLocation,
301
+            "Returns the location of the specified index.")
302
+        .def("GetLocationX", &Lemma::FieldPoints::GetLocationX,
303
+            "Returns the northing (x) location of the specified index.")
304
+        .def("GetLocationY", &Lemma::FieldPoints::GetLocationY,
305
+            "Returns the easting (y) location of the specified index.")
306
+        .def("GetLocationZ", &Lemma::FieldPoints::GetLocationZ,
307
+            "Returns the altitude/depth (z) location of the specified index.")
308
+        .def("GetEfield", py::overload_cast<  > (&Lemma::FieldPoints::GetEfield),
309
+            "Returns the electric field for all frequencies.")
310
+        .def("GetEfield", py::overload_cast< const int& > (&Lemma::FieldPoints::GetEfield),
311
+            "Returns the electric field for the specified frequency index.")
312
+        .def("GetEfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetEfield),
313
+            "Returns the electric field for the specified frequency and location index.")
314
+        .def("GetEfieldMat", &Lemma::FieldPoints::GetEfieldMat,
315
+            "Returns the electric field for the specified frequency.")
316
+        .def("GetHfield", py::overload_cast<  > (&Lemma::FieldPoints::GetHfield),
317
+            "Returns the H field for all frequencies.")
318
+        .def("GetHfield", py::overload_cast< const int& > (&Lemma::FieldPoints::GetHfield),
319
+            "Returns the H field for the specified frequency index.")
320
+        .def("GetHfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetHfield),
321
+            "Returns the H field for the specified frequency and location index.")
322
+        //.def("GetBfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetBfield),
323
+        //    "Returns the magnetic (B) field for the specified frequency and location index.")
324
+        .def("GetHfieldMat", &Lemma::FieldPoints::GetHfieldMat,
325
+            "Returns the H field for the specified frequency.")
326
+        .def("GetMask", &Lemma::FieldPoints::MaskPoint, "Return the mask boolean value for the specified index")
327
+
328
+        // methods
329
+        .def("ClearFields", &Lemma::FieldPoints::ClearFields, "Clears calculated fields")
330
+        .def("MaskPoint", &Lemma::FieldPoints::MaskPoint, "Masks the index resulting in no calculation")
331
+        .def("UnMaskPoint", &Lemma::FieldPoints::UnMaskPoint, "Unmasks the index resulting in a calculation")
332
+
333
+        ;
227 334
 }
228 335
 
229 336
 

Loading…
Cancel
Save