diff --git a/pyproject.toml b/pyproject.toml index e26d86e..00836d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ cache-keys = [ [tool.scikit-build] wheel.expand-macos-universal-tags = true minimum-version = "build-system.requires" -build-dir = "build/" +build-dir = "build/{wheel_tag}" [tool.pytest.ini_options] diff --git a/src/core/bindings.cpp b/src/core/bindings.cpp index 5f685c6..2886e56 100644 --- a/src/core/bindings.cpp +++ b/src/core/bindings.cpp @@ -39,12 +39,14 @@ PYBIND11_MODULE(_num, m) { PYBIND11_MODULE(_gather, m) { py::class_(m, "Gather") - .def(py::init()) + // .def(py::init()) + .def(py::init(), py::arg("id"), py::arg("nt"), + py::arg("nx"), py::arg("dt")) .def_readwrite("id", &Gather::id) - .def_readwrite("dt", &Gather::dt) .def_readwrite("nt", &Gather::nt) .def_readwrite("nx", &Gather::nx) + .def_readwrite("dt", &Gather::dt) .def_readonly("data", &Gather::data) - .def("__str__", &Gather::display) + .def("__str__", &Gather::str) .def("from_bin_file", &Gather::from_bin_file); } diff --git a/src/core/gather/gather.hpp b/src/core/gather/gather.hpp index 6c179f0..52fb0d7 100644 --- a/src/core/gather/gather.hpp +++ b/src/core/gather/gather.hpp @@ -12,19 +12,45 @@ class Gather { public: - int id; - int nt; - int nx; - double dt; + int id{}; + int nt{}; + int nx{}; + double dt{}; std::vector data; + Gather() = default; + Gather(const int id, const int nt, const int nx, const double dt) - : id(id), nt(nt), nx(nx), dt(dt), data() {} + : id{id}, nt{nt}, nx{nx}, dt{dt} { + data.resize(nt * nx); + } - [[nodiscard]] std::string display() const { + /** + * @brief a helper function used for Python __str__ method. + */ + [[nodiscard]] std::string str() const { return "Gather id: " + std::to_string(id); } + /** + * @brief overload the output stream operator for Gather. + */ + friend std::ostream &operator<<(std::ostream &os, const Gather &gather) { + os << "Gather id: " << gather.id << std::endl; + return os; + } + + /** + * @brief Read a binary file and create a Gather object. + * + * This function takes a file path (string), the number of time samples (nt), + * and the number of traces (nx) to read from the binary file. + * + * @param path the path to the binary file. + * @param nt the number of time samples per trace. + * @param nx the number of traces per gather. + * @return Gather object populated with data from the file. + */ static Gather from_bin_file(const std::string &path, int nt, int nx, double dt = 0.0) { std::ifstream file(path, std::ios::binary); diff --git a/src/libseis/_gather.pyi b/src/libseis/_gather.pyi index 839be4c..972f1eb 100644 --- a/src/libseis/_gather.pyi +++ b/src/libseis/_gather.pyi @@ -11,7 +11,9 @@ class Gather: dt: float data: list[float] - def __init__(self, id: int = 0, nt: int = 0, nx: int = 0) -> Self: ... + def __init__( + self, id: int = 0, nt: int = 0, nx: int = 0, dt: float = 0 + ) -> Self: ... @staticmethod def from_bin_file( filename: str, diff --git a/tests/fixtures/testTrace.bin b/tests/fixtures/testTrace.bin new file mode 100644 index 0000000..a5bbb2c Binary files /dev/null and b/tests/fixtures/testTrace.bin differ diff --git a/tests/libseis/test_gather.py b/tests/libseis/test_gather.py index 0684690..b994cac 100644 --- a/tests/libseis/test_gather.py +++ b/tests/libseis/test_gather.py @@ -9,7 +9,7 @@ class TestSeismicGather: @pytest.fixture def gather(self): """Fixture to create a Gather instance.""" - return Gather() + return Gather(id=1, nt=2, nx=3, dt=4.0) def test_gather_init(self, gather): """Test the Gather class base constructor."""