import numpy as np import pytest import segyio from ml_porosity.data.geometry import SurveyGeometry from ml_porosity.data.seismic_io import SeismicCube from ml_porosity.paths import f3_root, f3_segy pytestmark = [ pytest.mark.data, pytest.mark.skipif(not f3_segy().exists(), reason="missing F3_entire.segy"), ] @pytest.fixture(scope="module") def cube(): with SeismicCube() as c: yield c def test_axes(cube): assert (cube.ilines[0], cube.ilines[-1], len(cube.ilines)) == (100, 750, 651) assert (cube.xlines[0], cube.xlines[-1], len(cube.xlines)) == (300, 1250, 951) # DelayRecordingTime = 4 ms: the first sample is at 4 ms, not 0 assert cube.times_ms[0] == 4.0 and cube.dt_ms == 4.0 and len(cube.times_ms) == 462 @pytest.mark.parametrize("il,xl", [(100, 300), (244, 387), (722, 848), (750, 1250)]) def test_trace_index_matches_headers(cube, il, xl): idx = cube._index(il, xl) h = cube._f.header[idx] assert (h[segyio.TraceField.INLINE_3D], h[segyio.TraceField.CROSSLINE_3D]) == (il, xl) # Header coordinates (scalar −100) match the .survey transform geom = SurveyGeometry.from_survey(f3_root()) x, y = geom.bin_to_xy(il, xl) assert h[segyio.TraceField.CDP_X] / 100 == pytest.approx(x, abs=0.5) assert h[segyio.TraceField.CDP_Y] / 100 == pytest.approx(y, abs=0.5) def test_patch(cube): p = cube.patch(244, 387, 1) assert p.shape == (9, 462) np.testing.assert_array_equal(p[4], cube.trace(244, 387)) np.testing.assert_array_equal(p[0], cube.trace(243, 386)) with pytest.raises(KeyError): cube.patch(100, 300, 1)