Surface NMR forward modelling
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pyMerlin.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 "Merlin"
  21. namespace py = pybind11;
  22. PYBIND11_MODULE(Merlin, m) {
  23. py::add_ostream_redirect(m, "ostream_redirect");
  24. m.doc() = "Python binding of Lemma::Merlin, additional details can be found at https://lemmasoftware.org";
  25. py::class_<Lemma::KernelV0, std::shared_ptr<Lemma::KernelV0> > KernelV0(m, "KernelV0");
  26. // lifecycle
  27. KernelV0.def(py::init(&Lemma::KernelV0::NewSP))
  28. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::KernelV0::DeSerialize),
  29. "Construct object from yaml representation")
  30. // print
  31. .def("Serialize", &Lemma::KernelV0::Print, "YAML representation of the class")
  32. .def("__repr__", &Lemma::KernelV0::Print)
  33. // modifiers
  34. .def("PushCoil", &Lemma::KernelV0::PushCoil, "Adds a coil to the sNMR instrument")
  35. .def("SetLayeredEarthEM", &Lemma::KernelV0::SetLayeredEarthEM, "Sets the EM model used in kernel calculation")
  36. .def("SetIntegrationSize", &Lemma::KernelV0::SetIntegrationSize, "Sets the size of the volume to integrate the kernel")
  37. .def("SetIntegrationOrigin", &Lemma::KernelV0::SetIntegrationOrigin, "Sets the origin of the integration volume")
  38. .def("SetPulseCurrent", &Lemma::KernelV0::SetPulseCurrent, "Sets the current of the pulses")
  39. .def("SetTemperature", &Lemma::KernelV0::SetTemperature, "Sets the temperature, in K")
  40. .def("SetTolerance", &Lemma::KernelV0::SetTolerance, "Sets the tolerance used in octree splitting")
  41. .def("SetPulseDuration", &Lemma::KernelV0::SetPulseDuration, "Sets the duration of the pulse")
  42. .def("SetDepthLayerInteraces", &Lemma::KernelV0::SetDepthLayerInterfaces, "Sets the layer depth interfaces")
  43. // accessors
  44. .def("GetName", &Lemma::KernelV0::GetName, "Returns the name of the class")
  45. .def("GetSigmaModel", &Lemma::KernelV0::GetSigmaModel, "Returns the conductivity model")
  46. .def("GetKernel", &Lemma::KernelV0::GetKernel, "Returns the imaging kernel in matrix form")
  47. .def("GetTolerance", &Lemma::KernelV0::GetTolerance, "Returns the tolerance which was used to construct the kernel")
  48. .def("GetInterfaces", &Lemma::KernelV0::GetInterfaces, "Returns the layer interfaces")
  49. .def("GetPulseCurrent", &Lemma::KernelV0::GetPulseCurrent, "Returns the pulse current")
  50. .def("GetPulseDuration", &Lemma::KernelV0::GetPulseDuration, "Returns the length of the pulse moment")
  51. // operations
  52. .def("CalculateK0", &Lemma::KernelV0::CalculateK0, "Calculates an intial amplitude kernel")
  53. //.def("AlignWithAkvoDataset", &Lemma::KernelV0::AlignWithAkvoDataset, "Aligns the kernel parameters with a dataset")
  54. ;
  55. //
  56. // py::class_<Lemma::PolygonalWireAntenna, std::shared_ptr<Lemma::PolygonalWireAntenna> > PolygonalWireAntenna(m,
  57. // "PolygonalWireAntenna", KernelV0);
  58. //
  59. // // lifecycle
  60. // PolygonalWireAntenna.def(py::init(&Lemma::PolygonalWireAntenna::NewSP))
  61. // .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::PolygonalWireAntenna::DeSerialize),
  62. // "Construct object from yaml representation")
  63. //
  64. // // print
  65. // .def("__repr__", &Lemma::PolygonalWireAntenna::Print)
  66. // .def("Serialize", &Lemma::PolygonalWireAntenna::Print, "YAML representation of the class")
  67. //
  68. // // accessors
  69. // .def("GetName", &Lemma::PolygonalWireAntenna::GetName, "Returns the name of the class")
  70. //
  71. // // operations
  72. // .def("ApproximateWithElectricDipoles", &Lemma::PolygonalWireAntenna::ApproximateWithElectricDipoles,
  73. // "Approximates loop with series of electric dipoles around loop")
  74. //
  75. // // modifiers
  76. // .def("SetMinDipoleRatio", &Lemma::PolygonalWireAntenna::SetMinDipoleRatio,
  77. // "Sets the minimum dipole ratio use, smaller values increase precision")
  78. // .def("SetMinDipoleMoment", &Lemma::PolygonalWireAntenna::SetMinDipoleMoment,
  79. // "Sets the minimum dipole moment which will be used, smaller values increase precision and computational time")
  80. // .def("SetMaxDipoleMoment", &Lemma::PolygonalWireAntenna::SetMaxDipoleMoment,
  81. // "Sets the maximum dipole moment which will be used, smaller values increase precision and computational time")
  82. // ;
  83. //
  84. // py::class_<Lemma::DipoleSource, std::shared_ptr<Lemma::DipoleSource> > DipoleSource(m, "DipoleSource");
  85. //
  86. // // lifecycle
  87. // DipoleSource.def(py::init(&Lemma::DipoleSource::NewSP))
  88. // .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::DipoleSource::DeSerialize),
  89. // "Construct object from yaml representation")
  90. //
  91. // // print
  92. // .def("Serialize", &Lemma::DipoleSource::Print, "YAML representation of the class")
  93. // .def("__repr__", &Lemma::DipoleSource::Print)
  94. //
  95. // // accessors
  96. // .def("GetName", &Lemma::DipoleSource::GetName, "Returns the name of the class")
  97. // .def("GetNumberOfFrequencies", &Lemma::DipoleSource::GetNumberOfFrequencies,
  98. // "Returns the number of frequencies")
  99. // .def("GetFrequencies", &Lemma::DipoleSource::GetFrequencies, "Returns an array of frequencies")
  100. // .def("GetFrequency", &Lemma::DipoleSource::GetFrequency, "Returns the frequency of the argument index")
  101. // .def("GetAngularFrequency", &Lemma::DipoleSource::GetAngularFrequency,
  102. // "Returns the angular frequency of the argument index")
  103. // .def("GetPhase", &Lemma::DipoleSource::GetPhase, "Returns the phase of the dipole")
  104. // .def("GetMoment", &Lemma::DipoleSource::GetMoment, "Returns the moment of the dipole")
  105. // .def("GetLocation", py::overload_cast< >(&Lemma::DipoleSource::GetLocation), "Returns the location of the dipole")
  106. // .def("GetPolarisation", &Lemma::DipoleSource::GetPolarisation, "Returns the polarisation of the dipole")
  107. //
  108. // // modifiers
  109. // .def("SetLocation", py::overload_cast<const Lemma::Vector3r&> (&Lemma::DipoleSource::SetLocation),
  110. // "Sets the location of the dipole")
  111. // .def("SetPolarisation", py::overload_cast<const Lemma::Vector3r&> (&Lemma::DipoleSource::SetPolarisation),
  112. // "Sets the polarisation of the dipole")
  113. // .def("SetType", &Lemma::DipoleSource::SetType, "Sets the type")
  114. // .def("SetMoment", &Lemma::DipoleSource::SetMoment, "Sets the moment of the dipole")
  115. // .def("SetPhase", &Lemma::DipoleSource::SetPhase, "Sets the phase of the dipole")
  116. // .def("SetNumberOfFrequencies", &Lemma::DipoleSource::SetNumberOfFrequencies,
  117. // "Sets the number of frequencies to calculate for the dipole")
  118. // .def("SetFrequency", &Lemma::DipoleSource::SetFrequency,
  119. // "Sets a single frequency, first argument is index, second argument is frequency")
  120. // .def("SetFrequencies", &Lemma::DipoleSource::SetFrequencies,
  121. // "Sets all frequencies, argument is numpy array of frequencies")
  122. // ;
  123. //
  124. // py::class_<Lemma::LayeredEarthEM, std::shared_ptr<Lemma::LayeredEarthEM> >
  125. // LayeredEarthEM(m, "LayeredEarthEM");
  126. //
  127. // // lifecycle
  128. // LayeredEarthEM.def(py::init(&Lemma::LayeredEarthEM::NewSP))
  129. // .def_static("DeSerialize", py::overload_cast<const std::string&>
  130. // (&Lemma::LayeredEarthEM::DeSerialize),"Construct object from yaml representation")
  131. //
  132. // // print
  133. // .def("Serialize", &Lemma::LayeredEarthEM::Print, "YAML representation of the class")
  134. // .def("__repr__", &Lemma::LayeredEarthEM::Print)
  135. //
  136. // // accessors
  137. // .def("GetName", &Lemma::LayeredEarthEM::GetName, "Returns the name of the class")
  138. //
  139. // .def("GetLayerConductivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerConductivity),
  140. // "Returns the conductivity of all layers")
  141. // .def("GetLayerConductivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerConductivity),
  142. // "Returns the conductivity of the specified layer")
  143. //
  144. // .def("GetLayerSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerSusceptibility),
  145. // "Returns the susceptibility of all layers")
  146. // .def("GetLayerSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerSusceptibility),
  147. // "Returns the susceptibilty of the specified layer")
  148. // .def("GetLayerLowFreqSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerLowFreqSusceptibility),
  149. // "Returns the low frequqncy permitivity of all layers")
  150. // .def("GetLayerLowFreqSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerLowFreqSusceptibility),
  151. // "Returns the low frequency permitivity of the specified layer")
  152. // .def("GetLayerHighFreqSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerHighFreqSusceptibility),
  153. // "Returns the low frequency permitivity of all layers")
  154. // .def("GetLayerHighFreqSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerHighFreqSusceptibility),
  155. // "Returns the low frequency permitivity of the specified layer")
  156. // .def("GetLayerTauSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerTauSusceptibility),
  157. // "Returns the tau permitivity of all layers")
  158. // .def("GetLayerTauSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerTauSusceptibility),
  159. // "Returns the tau permitivity of the specified layer")
  160. // .def("GetLayerBreathSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerBreathSusceptibility),
  161. // "Returns the breth permitivity of all layers")
  162. // .def("GetLayerBreathSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerBreathSusceptibility),
  163. // "Returns the breath permitivity of the specified layer")
  164. //
  165. // .def("GetLayerPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerPermitivity),
  166. // "Returns the permitivity of all layers")
  167. // .def("GetLayerPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerPermitivity),
  168. // "Returns the permitivity of the specified layer")
  169. // .def("GetLayerLowFreqPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerLowFreqPermitivity),
  170. // "Returns the low frequqncy permitivity of all layers")
  171. // .def("GetLayerLowFreqPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerLowFreqPermitivity),
  172. // "Returns the low frequency permitivity of the specified layer")
  173. // .def("GetLayerHighFreqPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerHighFreqPermitivity),
  174. // "Returns the low frequency permitivity of all layers")
  175. // .def("GetLayerHighFreqPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerHighFreqPermitivity),
  176. // "Returns the low frequency permitivity of the specified layer")
  177. // .def("GetLayerTauPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerTauPermitivity),
  178. // "Returns the tau permitivity of all layers")
  179. // .def("GetLayerTauPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerTauPermitivity),
  180. // "Returns the tau permitivity of the specified layer")
  181. // .def("GetLayerBreathPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerBreathPermitivity),
  182. // "Returns the breth permitivity of all layers")
  183. // .def("GetLayerBreathPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerBreathPermitivity),
  184. // "Returns the breath permitivity of the specified layer")
  185. //
  186. //
  187. // // modifiers
  188. // .def("SetNumberOfLayers", &Lemma::LayeredEarthEM::SetNumberOfLayers,
  189. // "Sets the number of layers in the model")
  190. // .def("SetLayerConductivity", py::overload_cast< const Lemma::VectorXcr& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
  191. // "Sets the conductivity of the layers, the input is a complex array of conductivity")
  192. // .def("SetLayerConductivity1", py::overload_cast< const int&, const Lemma::Complex& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
  193. // "Sets the conductivity of a single layer, the first input is the layer index, and the secondinput is a complex conductivity")
  194. // .def("SetLayerThickness", &Lemma::LayeredEarthEM::SetLayerThickness,
  195. // "Sets the thickness of layers, excluding the air and bottom which are infinite")
  196. //
  197. // .def("SetLayerHighFreqSusceptibility", &Lemma::LayeredEarthEM::SetLayerHighFreqSusceptibility,
  198. // "Sets the high frequency susceptibility for Cole-COle model")
  199. // .def("SetLayerLowFreqSusceptibility", &Lemma::LayeredEarthEM::SetLayerLowFreqSusceptibility,
  200. // "Sets the low frequency susceptibility for Cole-COle model")
  201. // .def("SetLayerBreathSusceptibility", &Lemma::LayeredEarthEM::SetLayerBreathSusceptibility,
  202. // "Sets thesusceptibility breath for Cole-COle model")
  203. //
  204. // .def("SetLayerHighFreqPermitivity", &Lemma::LayeredEarthEM::SetLayerHighFreqPermitivity,
  205. // "Sets the high frequency permitivity for Cole-COle model")
  206. // .def("SetLayerLowFreqPermitivity", &Lemma::LayeredEarthEM::SetLayerLowFreqPermitivity,
  207. // "Sets the low frequency permitivity for Cole-COle model")
  208. // .def("SetLayerBreathPermitivity", &Lemma::LayeredEarthEM::SetLayerBreathPermitivity,
  209. // "Sets the permitivity breath for Cole-COle model")
  210. //
  211. //
  212. // // methods
  213. // .def("EvaluateColeColeModel", &Lemma::LayeredEarthEM::EvaluateColeColeModel,
  214. // "Calculates complex resistivity based on cole-cole parameters")
  215. // ;
  216. //
  217. // py::class_<Lemma::EMEarth1D, std::shared_ptr<Lemma::EMEarth1D> >
  218. // EMEarth1D(m, "EMEarth1D");
  219. //
  220. // // lifecycle
  221. // EMEarth1D.def(py::init(&Lemma::EMEarth1D::NewSP))
  222. // //.def_static("DeSerialize", py::overload_cast<const std::string&>
  223. // // (&Lemma::EMEarth1D::DeSerialize),"Construct object from yaml representation")
  224. //
  225. // // print
  226. // .def("Serialize", &Lemma::EMEarth1D::Print, "YAML representation of the class")
  227. // .def("__repr__", &Lemma::EMEarth1D::Print)
  228. //
  229. // // accessors
  230. // .def("GetName", &Lemma::EMEarth1D::GetName, "Returns the name of the class")
  231. // .def("GetFieldPoints", &Lemma::EMEarth1D::GetFieldPoints, "Returns the FieldPoint class")
  232. //
  233. // // modifiers
  234. // .def("AttachWireAntenna", &Lemma::EMEarth1D::AttachWireAntenna,
  235. // "Sets the wire antenna to use for calculations")
  236. // .def("AttachDipoleSOurce", &Lemma::EMEarth1D::AttachDipoleSource,
  237. // "Sets a DipoleSource to use for calculations")
  238. // .def("AttachFieldPoints", &Lemma::EMEarth1D::AttachFieldPoints,
  239. // "Sets the FieldPoints to use for calculations")
  240. // .def("AttachLayeredEarthEM", &Lemma::EMEarth1D::AttachLayeredEarthEM,
  241. // "Sets the LayeredEarthEM to use for calculations")
  242. //
  243. // .def("SetFieldToCalculate", &Lemma::EMEarth1D::SetFieldsToCalculate,
  244. // "Sets which fields to calculate")
  245. // .def("SetHankelTransformMethod", &Lemma::EMEarth1D::SetHankelTransformMethod,
  246. // "Sets which Hankel transform to use")
  247. // .def("SetTxRxMode", &Lemma::EMEarth1D::SetTxRxMode,
  248. // "Sets the TxRx mode flag")
  249. //
  250. // //methods
  251. // #ifdef KIHALEE_EM1D
  252. // .def("MakeCalc", &Lemma::EMEarth1D::MakeCalc, "Calls KiHa Lee's EM1D FORTRAN77 code")
  253. // #endif
  254. //
  255. // .def("MakeCalc3", &Lemma::EMEarth1D::MakeCalc3, "Native Lemma EM calculation")
  256. // .def("CalculateWireAntennaFields", &Lemma::EMEarth1D::CalculateWireAntennaFields,
  257. // "Native Lemma calculation of a wire antenna")
  258. // ;
  259. //
  260. // py::class_<Lemma::FieldPoints, std::shared_ptr<Lemma::FieldPoints> >
  261. // FieldPoints(m, "FieldPoints");
  262. //
  263. // // lifecycle
  264. // FieldPoints.def(py::init(&Lemma::FieldPoints::NewSP))
  265. // .def_static("DeSerialize", py::overload_cast<const std::string&>
  266. // (&Lemma::FieldPoints::DeSerialize),"Construct object from yaml representation")
  267. //
  268. // // print
  269. // .def("Serialize", &Lemma::FieldPoints::Print, "YAML representation of the class")
  270. // .def("__repr__", &Lemma::FieldPoints::Print)
  271. //
  272. // // modifiers
  273. // .def("SetNumberOfPoints", &Lemma::FieldPoints::SetNumberOfPoints,
  274. // "Sets the number of locations to make calculations on.")
  275. // .def("SetLocation", py::overload_cast< const int&, const Lemma::Vector3r& >
  276. // (&Lemma::FieldPoints::SetLocation), "Sets the location of the index-specified point." )
  277. // .def("SetLocation", py::overload_cast< const int&,
  278. // const Lemma::Real&, const Lemma::Real&, const Lemma::Real& >
  279. // (&Lemma::FieldPoints::SetLocation),
  280. // "Sets the location of the index-specified point with the three coordinates")
  281. //
  282. // // accessors
  283. // .def("GetNumberOfPoints", &Lemma::FieldPoints::GetNumberOfPoints,
  284. // "Returns the number of locations to make calculations on.")
  285. // .def("GetLocations", &Lemma::FieldPoints::GetLocations,
  286. // "Returns the locations which calculations are made on.")
  287. // .def("GetLocationsMat", &Lemma::FieldPoints::GetLocationsMat,
  288. // "Returns a matrix of the locations which calculations are made on.")
  289. // .def("GetLocation", &Lemma::FieldPoints::GetLocation,
  290. // "Returns the location of the specified index.")
  291. // .def("GetLocationX", &Lemma::FieldPoints::GetLocationX,
  292. // "Returns the northing (x) location of the specified index.")
  293. // .def("GetLocationY", &Lemma::FieldPoints::GetLocationY,
  294. // "Returns the easting (y) location of the specified index.")
  295. // .def("GetLocationZ", &Lemma::FieldPoints::GetLocationZ,
  296. // "Returns the altitude/depth (z) location of the specified index.")
  297. // .def("GetEfield", py::overload_cast< > (&Lemma::FieldPoints::GetEfield),
  298. // "Returns the electric field for all frequencies.")
  299. // .def("GetEfield", py::overload_cast< const int& > (&Lemma::FieldPoints::GetEfield),
  300. // "Returns the electric field for the specified frequency index.")
  301. // .def("GetEfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetEfield),
  302. // "Returns the electric field for the specified frequency and location index.")
  303. // .def("GetEfieldMat", &Lemma::FieldPoints::GetEfieldMat,
  304. // "Returns the electric field for the specified frequency.")
  305. // .def("GetHfield", py::overload_cast< > (&Lemma::FieldPoints::GetHfield),
  306. // "Returns the H field for all frequencies.")
  307. // .def("GetHfield", py::overload_cast< const int& > (&Lemma::FieldPoints::GetHfield),
  308. // "Returns the H field for the specified frequency index.")
  309. // .def("GetHfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetHfield),
  310. // "Returns the H field for the specified frequency and location index.")
  311. // //.def("GetBfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetBfield),
  312. // // "Returns the magnetic (B) field for the specified frequency and location index.")
  313. // .def("GetHfieldMat", &Lemma::FieldPoints::GetHfieldMat,
  314. // "Returns the H field for the specified frequency.")
  315. // .def("GetMask", &Lemma::FieldPoints::MaskPoint, "Return the mask boolean value for the specified index")
  316. //
  317. // // methods
  318. // .def("ClearFields", &Lemma::FieldPoints::ClearFields, "Clears calculated fields")
  319. // .def("MaskPoint", &Lemma::FieldPoints::MaskPoint, "Masks the index resulting in no calculation")
  320. // .def("UnMaskPoint", &Lemma::FieldPoints::UnMaskPoint, "Unmasks the index resulting in a calculation")
  321. //
  322. // ;
  323. }