Main Lemma Repository
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.

pyLemmaCore.cpp 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. py::class_<Lemma::RectilinearGrid, std::shared_ptr<Lemma::RectilinearGrid> > RectilinearGrid(m, "RectilinearGrid");
  26. // lifecycle
  27. RectilinearGrid.def(py::init(&Lemma::RectilinearGrid::NewSP))
  28. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGrid::DeSerialize),
  29. "Construct object from yaml representation")
  30. // print
  31. .def("__repr__", &Lemma::RectilinearGrid::Print)
  32. .def("Serialize", &Lemma::RectilinearGrid::Print, "YAML representation of the class")
  33. // accessors
  34. .def("GetName", &Lemma::RectilinearGrid::GetName, "Returns the name of the class")
  35. .def("GetNx", &Lemma::RectilinearGrid::GetNx, "Returns the number of cells in the x direction")
  36. .def("GetNy", &Lemma::RectilinearGrid::GetNy, "Returns the number of cells in the y direction")
  37. .def("GetNz", &Lemma::RectilinearGrid::GetNz, "Returns the number of cells in the z direction")
  38. .def("GetOx", &Lemma::RectilinearGrid::GetOx, "Returns the grid origin offset in the x direction")
  39. .def("GetOy", &Lemma::RectilinearGrid::GetOy, "Returns the grid origin offset in the y direction")
  40. .def("GetOz", &Lemma::RectilinearGrid::GetOz, "Returns the grid origin offset in the z direction")
  41. .def("GetDx", &Lemma::RectilinearGrid::GetDx, "Returns the grid spacing in the x direction")
  42. .def("GetDy", &Lemma::RectilinearGrid::GetDy, "Returns the grid spacing in the y direction")
  43. .def("GetDz", &Lemma::RectilinearGrid::GetDz, "Returns the grid spacing in the z direction")
  44. // modifiers
  45. .def("SetDimensions", &Lemma::RectilinearGrid::SetDimensions, "Sets the number of cells in x, y, and z")
  46. .def("SetOffset", &Lemma::RectilinearGrid::SetOffset, "Sets the origin offset in x, y, and z")
  47. .def("SetSpacing", &Lemma::RectilinearGrid::SetSpacing, "Sets the grid spacing in x, y, and z")
  48. ;
  49. py::class_<Lemma::RectilinearGridReader, std::shared_ptr<Lemma::RectilinearGridReader> > RectilinearGridReader(m, "RectilinearGridReader");
  50. // lifecycle
  51. RectilinearGridReader.def(py::init(&Lemma::RectilinearGridReader::NewSP))
  52. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::RectilinearGridReader::DeSerialize),
  53. "Construct object from yaml representation")
  54. // print
  55. .def("__repr__", &Lemma::RectilinearGridReader::Print)
  56. .def("Serialize", &Lemma::RectilinearGridReader::Print, "YAML representation of the class")
  57. // accessors
  58. .def("GetName", &Lemma::RectilinearGridReader::GetName, "Returns the name of the class")
  59. // modifiers
  60. //methods
  61. .def("ReadASCIIGridFile", &Lemma::RectilinearGridReader::ReadASCIIGridFile, "Opens file specified by argument")
  62. //methods
  63. .def("GetGrid", &Lemma::RectilinearGridReader::GetGrid, "Returns the grid object")
  64. ;
  65. py::class_<Lemma::ASCIIParser, std::shared_ptr<Lemma::ASCIIParser> > ASCIIParser(m, "ASCIIParser");
  66. // lifecycle
  67. ASCIIParser.def(py::init(&Lemma::ASCIIParser::NewSP))
  68. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::ASCIIParser::DeSerialize),
  69. "Construct object from yaml representation")
  70. // print
  71. .def("__repr__", &Lemma::ASCIIParser::Print)
  72. .def("Serialize", &Lemma::ASCIIParser::Print, "YAML representation of the class")
  73. // accessors
  74. .def("GetName", &Lemma::ASCIIParser::GetName, "Returns the name of the class")
  75. .def("GetFileLocation", &Lemma::ASCIIParser::GetFileLocation, "Returns the current file location")
  76. // modifiers
  77. .def("SetCommentString", &Lemma::ASCIIParser::SetCommentString, "Sets the comment string after which all text is ignored")
  78. .def("SetBufferSize", &Lemma::ASCIIParser::SetBufferSize, "Sets the buffer size")
  79. // methods
  80. .def("Open", &Lemma::ASCIIParser::Open, "Opens file specified by argument")
  81. .def("Close", &Lemma::ASCIIParser::Close, "Closes current file object")
  82. .def("ReadReals", &Lemma::ASCIIParser::ReadReals, "Returns vector of nr reals")
  83. .def("ReadInts", &Lemma::ASCIIParser::ReadInts, "Returns vector of ni ints")
  84. .def("ReadStrings", &Lemma::ASCIIParser::ReadStrings, "Returns vector of ns strings")
  85. .def("JumpToLocation", &Lemma::ASCIIParser::JumpToLocation, "File object jumps to specified location")
  86. ;
  87. py::class_<Lemma::CubicSplineInterpolator, std::shared_ptr<Lemma::CubicSplineInterpolator> >(m, "CubicSplineInterpolator")
  88. // lifecycle
  89. .def(py::init(&Lemma::CubicSplineInterpolator::NewSP))
  90. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::CubicSplineInterpolator::DeSerialize),
  91. "Construct object from yaml representation")
  92. // print
  93. .def("__repr__", &Lemma::CubicSplineInterpolator::Print)
  94. .def("Serialize", &Lemma::CubicSplineInterpolator::Print, "YAML representation of the class")
  95. // accessors
  96. .def("GetName", &Lemma::CubicSplineInterpolator::GetName, "Returns the name of the class")
  97. .def("GetKnotAbscissa", &Lemma::CubicSplineInterpolator::GetKnotAbscissa, "Returns the knot abscissa values")
  98. .def("GetKnotOrdinate", &Lemma::CubicSplineInterpolator::GetKnotOrdinate, "Returns the knot ordinate values")
  99. // modifiers
  100. .def("SetKnots", &Lemma::CubicSplineInterpolator::SetKnots, "Sets the knots to use for interpolation")
  101. .def("ResetKnotOrdinate", &Lemma::CubicSplineInterpolator::ResetKnotOrdinate,
  102. "Resets the knots to use for interpolation, when abscissa values haven't changed")
  103. // methods
  104. .def("InterpolateOrderedSet", &Lemma::CubicSplineInterpolator::InterpolateOrderedSet, "Interpolate a monotonically increasing ordered set.")
  105. .def("Integrate", py::overload_cast<const Lemma::Real&, const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Integrate),
  106. "Integrates between the arguments using cubic spline values.")
  107. .def("IntegrateN", py::overload_cast<const Lemma::Real&, const Lemma::Real&, const int& >(&Lemma::CubicSplineInterpolator::Integrate),
  108. "Integrates the spline from x0 to x1. Uses composite Simpson's rule and n is the number of segments")
  109. .def("Interpolate", py::overload_cast<const Lemma::Real& >(&Lemma::CubicSplineInterpolator::Interpolate),
  110. "Interpolation at a single point, x is the interpolation abscissa point, returns the ordinate value at x")
  111. .def("InterpolateI", py::overload_cast<const Lemma::Real&, int& >(&Lemma::CubicSplineInterpolator::Interpolate),
  112. "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")
  113. ;
  114. // ABC
  115. //py::class_<Lemma::EarthModel, std::shared_ptr<Lemma::EarthModel> >(m, "EarthModel")
  116. /*
  117. py::class_<Lemma::LayeredEarth, std::shared_ptr<Lemma::LayeredEarth> >(m, "LayeredEarth")
  118. // lifecycle
  119. .def(py::init(&Lemma::LayeredEarth::NewSP))
  120. //.def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::LayeredEarth::DeSerialize), "Construct object from yaml representation")
  121. // print
  122. .def("__repr__", &Lemma::LayeredEarth::Print)
  123. .def("Serialize", &Lemma::LayeredEarth::Print, "YAML representation of the class")
  124. ;
  125. */
  126. }