Main Lemma Repository
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

pyLemmaCore.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 22/04/19 14:06:32
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@utah.edu
  14. * @copyright Copyright (c) 2019, University of Utah
  15. * @copyright Copyright (c) 2019, Lemma Software, LLC
  16. */
  17. #include <pybind11/pybind11.h>
  18. #include <pybind11/iostream.h>
  19. #include <pybind11/eigen.h>
  20. #include "LemmaCore"
  21. namespace py = pybind11;
  22. PYBIND11_MODULE(LemmaCore, m) {
  23. py::add_ostream_redirect(m, "ostream_redirect");
  24. m.doc() = "Python binding of LemmaCore, additional details can be found at https://lemmasoftware.org";
  25. //////////////////
  26. // Enumerations //
  27. //////////////////
  28. py::enum_<Lemma::MAGUNITS>(m, "MAGUNITS")
  29. .value("TESLA", Lemma::TESLA)
  30. .value("NANOTESLA", Lemma::NANOTESLA)
  31. .value("GAUSS", Lemma::GAUSS)
  32. .export_values();
  33. py::enum_<Lemma::TEMPUNITS>(m, "TEMPUNITS")
  34. .value("CELCIUS", Lemma::CELCIUS)
  35. .value("KELVIN", Lemma::KELVIN)
  36. .export_values();
  37. py::enum_<Lemma::TIMEUNITS>(m, "TIMEUNITS")
  38. .value("SEC", Lemma::SEC)
  39. .value("MILLISEC", Lemma::MILLISEC)
  40. .value("MICROSEC", Lemma::MICROSEC)
  41. .value("NANOSEC", Lemma::NANOSEC)
  42. .value("PICOSEC", Lemma::PICOSEC)
  43. .export_values();
  44. py::enum_<Lemma::FREQUENCYUNITS>(m, "FREQUENCYUNITS")
  45. .value("HZ", Lemma::HZ)
  46. .value("KHZ", Lemma::KHZ)
  47. .value("MHZ", Lemma::MHZ)
  48. .value("GHZ", Lemma::GHZ)
  49. .export_values();
  50. py::enum_<Lemma::FEMCOILORIENTATION>(m, "FEMCOILORIENTATION")
  51. .value("COAXIAL", Lemma::COAXIAL)
  52. .value("COPLANAR", Lemma::COPLANAR)
  53. .export_values();
  54. py::enum_<Lemma::DIPOLESOURCETYPE>(m, "DIPOLESOURCETYPE")
  55. .value("NOSOURCETYPE", Lemma::NOSOURCETYPE)
  56. .value("GROUNDEDELECTRICDIPOLE", Lemma::GROUNDEDELECTRICDIPOLE )
  57. .value("UNGROUNDEDELECTRICDIPOLE", Lemma::UNGROUNDEDELECTRICDIPOLE )
  58. .value("MAGNETICDIPOLE", Lemma::MAGNETICDIPOLE )
  59. .export_values();
  60. py::enum_<Lemma::HANKELTRANSFORMTYPE>(m, "HANKELTRANSFORMTYPE")
  61. .value("ANDERSON801", Lemma::ANDERSON801)
  62. .value("CHAVE", Lemma::CHAVE)
  63. .value("FHTKEY201", Lemma::FHTKEY201)
  64. .value("FHTKEY101", Lemma::FHTKEY101)
  65. .value("FHTKEY51", Lemma::FHTKEY51)
  66. .value("QWEKEY", Lemma::QWEKEY)
  67. .value("FHTKONG61", Lemma::FHTKONG61)
  68. .value("FHTKONG121", Lemma::FHTKONG121)
  69. .value("FHTKONG241", Lemma::FHTKONG241)
  70. .value("IRONS", Lemma::IRONS)
  71. .export_values();
  72. py::enum_<Lemma::FIELDCALCULATIONS>(m, "FIELDCALCULATIONS")
  73. .value("E", Lemma::E)
  74. .value("H", Lemma::H)
  75. .value("BOTH", Lemma::BOTH)
  76. .export_values();
  77. //what the what? This won't compile on gcc?? Maybe because not all caps?
  78. /*
  79. py::enum_<Lemma::DipoleSourcePolarity>(m "DipoleSourcePolarity")
  80. .value("NEGATIVE", Lemma::NEGATIVE)
  81. .value("POSITIVE", Lemma::POSITIVE)
  82. .export_values();
  83. py::enum_<Lemma::DipoleSourcePolarisation>(m "DipoleSourcePolarisation")
  84. .value("NOPOLARISATION", Lemma::NOPOLARISATION)
  85. .value("XPOLARISATION", Lemma::XPOLARISATION)
  86. .value("YPOLARISATION", Lemma::YPOLARISATION)
  87. .value("ZPOLARISATION", Lemma::ZPOLARISATION)
  88. .export_values();
  89. */
  90. ///////////////////////
  91. // LemmaCore Classes //
  92. ///////////////////////
  93. py::class_<Lemma::RectilinearGrid, std::shared_ptr<Lemma::RectilinearGrid> > RectilinearGrid(m, "RectilinearGrid");
  94. // lifecycle
  95. RectilinearGrid.def(py::init(&Lemma::RectilinearGrid::NewSP))
  96. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGrid::DeSerialize),
  97. "Construct object from yaml representation")
  98. // print
  99. .def("__repr__", &Lemma::RectilinearGrid::Print)
  100. .def("Serialize", &Lemma::RectilinearGrid::Print, "YAML representation of the class")
  101. // accessors
  102. .def("GetName", &Lemma::RectilinearGrid::GetName, "Returns the name of the class")
  103. .def("GetNx", &Lemma::RectilinearGrid::GetNx, "Returns the number of cells in the x direction")
  104. .def("GetNy", &Lemma::RectilinearGrid::GetNy, "Returns the number of cells in the y direction")
  105. .def("GetNz", &Lemma::RectilinearGrid::GetNz, "Returns the number of cells in the z direction")
  106. .def("GetOx", &Lemma::RectilinearGrid::GetOx, "Returns the grid origin offset in the x direction")
  107. .def("GetOy", &Lemma::RectilinearGrid::GetOy, "Returns the grid origin offset in the y direction")
  108. .def("GetOz", &Lemma::RectilinearGrid::GetOz, "Returns the grid origin offset in the z direction")
  109. .def("GetDx", &Lemma::RectilinearGrid::GetDx, "Returns the grid spacing in the x direction")
  110. .def("GetDy", &Lemma::RectilinearGrid::GetDy, "Returns the grid spacing in the y direction")
  111. .def("GetDz", &Lemma::RectilinearGrid::GetDz, "Returns the grid spacing in the z direction")
  112. // modifiers
  113. .def("SetDimensions", &Lemma::RectilinearGrid::SetDimensions, "Sets the number of cells in x, y, and z")
  114. .def("SetOffset", &Lemma::RectilinearGrid::SetOffset, "Sets the origin offset in x, y, and z")
  115. .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z")
  116. ;
  117. py::class_<Lemma::RectilinearGridReader, std::shared_ptr<Lemma::RectilinearGridReader> > RectilinearGridReader(m, "RectilinearGridReader");
  118. // lifecycle
  119. RectilinearGridReader.def(py::init(&Lemma::RectilinearGridReader::NewSP))
  120. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGridReader::DeSerialize),
  121. "Construct object from yaml representation")
  122. // print
  123. .def("__repr__", &Lemma::RectilinearGridReader::Print)
  124. .def("Serialize", &Lemma::RectilinearGridReader::Print, "YAML representation of the class")
  125. // accessors
  126. .def("GetName", &Lemma::RectilinearGridReader::GetName, "Returns the name of the class")
  127. // modifiers
  128. //methods
  129. .def("ReadASCIIGridFile", &Lemma::RectilinearGridReader::ReadASCIIGridFile, "Opens file specified by argument")
  130. //methods
  131. .def("GetGrid", &Lemma::RectilinearGridReader::GetGrid, "Returns the grid object")
  132. ;
  133. py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> > ASCIIParser(m, "ASCIIParser");
  134. // lifecycle
  135. ASCIIParser.def(py::init(&Lemma::ASCIIParser::NewSP))
  136. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::ASCIIParser::DeSerialize),
  137. "Construct object from yaml representation")
  138. // print
  139. .def("__repr__", &Lemma::ASCIIParser::Print)
  140. .def("Serialize", &Lemma::ASCIIParser::Print, "YAML representation of the class")
  141. // accessors
  142. .def("GetName", &Lemma::ASCIIParser::GetName, "Returns the name of the class")
  143. .def("GetFileLocation", &Lemma::ASCIIParser::GetFileLocation, "Returns the current file location")
  144. // modifiers
  145. .def("SetCommentString", &Lemma::ASCIIParser::SetCommentString, "Sets the comment string after which all text is ignored")
  146. .def("SetBufferSize", &Lemma::ASCIIParser::SetBufferSize, "Sets the buffer size")
  147. // methods
  148. .def("Open", &Lemma::ASCIIParser::Open, "Opens file specified by argument")
  149. .def("Close", &Lemma::ASCIIParser::Close, "Closes current file object")
  150. .def("ReadReals", &Lemma::ASCIIParser::ReadReals, "Returns vector of nr reals")
  151. .def("ReadInts", &Lemma::ASCIIParser::ReadInts, "Returns vector of ni ints")
  152. .def("ReadStrings", &Lemma::ASCIIParser::ReadStrings, "Returns vector of ns strings")
  153. .def("JumpToLocation", &Lemma::ASCIIParser::JumpToLocation, "File object jumps to specified location")
  154. ;
  155. py::class_<Lemma::CubicSplineInterpolator, std::shared_ptr<Lemma::CubicSplineInterpolator> >(m, "CubicSplineInterpolator")
  156. // lifecycle
  157. .def(py::init(&Lemma::CubicSplineInterpolator::NewSP))
  158. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::CubicSplineInterpolator::DeSerialize),
  159. "Construct object from yaml representation")
  160. // print
  161. .def("__repr__", &Lemma::CubicSplineInterpolator::Print)
  162. .def("Serialize", &Lemma::CubicSplineInterpolator::Print, "YAML representation of the class")
  163. // accessors
  164. .def("GetName", &Lemma::CubicSplineInterpolator::GetName, "Returns the name of the class")
  165. .def("GetKnotAbscissa", &Lemma::CubicSplineInterpolator::GetKnotAbscissa, "Returns the knot abscissa values")
  166. .def("GetKnotOrdinate", &Lemma::CubicSplineInterpolator::GetKnotOrdinate, "Returns the knot ordinate values")
  167. // modifiers
  168. .def("SetKnots", &Lemma::CubicSplineInterpolator::SetKnots, "Sets the knots to use for interpolation")
  169. .def("ResetKnotOrdinate", &Lemma::CubicSplineInterpolator::ResetKnotOrdinate,
  170. "Resets the knots to use for interpolation, when abscissa values haven't changed")
  171. // methods
  172. .def("InterpolateOrderedSet", &Lemma::CubicSplineInterpolator::InterpolateOrderedSet, "Interpolate a monotonically increasing ordered set.")
  173. .def("Integrate", py::overload_cast<const Lemma::Real&, const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Integrate),
  174. "Integrates between the arguments using cubic spline values.")
  175. .def("IntegrateN", py::overload_cast<const Lemma::Real&, const Lemma::Real&, const int& >(&Lemma::CubicSplineInterpolator::Integrate),
  176. "Integrates the spline from x0 to x1. Uses composite Simpson's rule and n is the number of segments")
  177. .def("Interpolate", py::overload_cast<const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Interpolate),
  178. "Interpolation at a single point, x is the interpolation abscissa point, returns the ordinate value at x")
  179. .def("InterpolateI", py::overload_cast<const Lemma::Real&, int& >(&Lemma::CubicSplineInterpolator::Interpolate),
  180. "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")
  181. ;
  182. // ABC
  183. py::class_<Lemma::EarthModel, std::shared_ptr<Lemma::EarthModel> > abcEarthModel (m, "EarthModel");
  184. // Modifiers
  185. abcEarthModel.def("SetMagneticFieldIncDecMag", &Lemma::EarthModel::SetMagneticFieldIncDecMag, "Sets the inducing field" );
  186. abcEarthModel.def("SetMagneticFieldComponents", &Lemma::EarthModel::SetMagneticFieldComponents, "Sets the inducing field" );
  187. // Accessors
  188. abcEarthModel.def("GetMagneticField", &Lemma::EarthModel::GetMagneticField, "returns the inducing field in Tesla" );
  189. abcEarthModel.def("GetMagneticFieldInGauss", &Lemma::EarthModel::GetMagneticFieldInGauss, "returns the inducing field in Gauss" );
  190. abcEarthModel.def("GetMagneticFieldUnitVector", &Lemma::EarthModel::GetMagneticFieldUnitVector, "returns the inducing field unit vector" );
  191. abcEarthModel.def("GetMagneticFieldMagnitude", &Lemma::EarthModel::GetMagneticFieldMagnitude, "returns the magnitude of the inducing field" );
  192. abcEarthModel.def("GetMagneticFieldMagnitudeInGauss", &Lemma::EarthModel::GetMagneticFieldMagnitudeInGauss, "returns the magnitude of the inducing field" );
  193. /*
  194. py::class_<Lemma::LayeredEarth, std::shared_ptr<Lemma::LayeredEarth> >(m, "LayeredEarth")
  195. // lifecycle
  196. .def(py::init(&Lemma::LayeredEarth::NewSP))
  197. //.def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::LayeredEarth::DeSerialize), "Construct object from yaml representation")
  198. // print
  199. .def("__repr__", &Lemma::LayeredEarth::Print)
  200. .def("Serialize", &Lemma::LayeredEarth::Print, "YAML representation of the class")
  201. ;
  202. */
  203. }