Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 5 additions & 3 deletions src/core/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ PYBIND11_MODULE(_num, m) {

PYBIND11_MODULE(_gather, m) {
py::class_<Gather>(m, "Gather")
.def(py::init<int, int, int, double>())
// .def(py::init<int, int, int, double>())
.def(py::init<int, int, int, double>(), 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);
}
38 changes: 32 additions & 6 deletions src/core/gather/gather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> 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);
Expand Down
4 changes: 3 additions & 1 deletion src/libseis/_gather.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Binary file added tests/fixtures/testTrace.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/libseis/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down