import numpy as np import pytest from ml_porosity.data.geometry import SurveyGeometry from ml_porosity.paths import f3_root SURVEY = f3_root() / ".survey" pytestmark = pytest.mark.skipif(not SURVEY.exists(), reason="thiếu F3 .survey") @pytest.fixture(scope="module") def geom(): return SurveyGeometry.from_survey(SURVEY) def test_parses_survey(geom): assert geom.il_range == (100, 750, 1) assert geom.xl_range == (300, 1250, 1) assert geom.epsg == 23031 assert len(geom.set_points) == 3 def test_set_points_forward_and_inverse(geom): for il, xl, x, y in geom.set_points: xp, yp = geom.bin_to_xy(il, xl) assert xp == pytest.approx(x, abs=0.01) assert yp == pytest.approx(y, abs=0.01) ilp, xlp = geom.xy_to_bin(x, y) assert ilp == pytest.approx(il, abs=1e-3) assert xlp == pytest.approx(xl, abs=1e-3) def test_bin_spacing_25m(geom): assert geom.bin_spacing() == pytest.approx((25.0, 25.0), abs=0.01) def test_round_trip_vectorised(geom): rng = np.random.default_rng(0) il = rng.uniform(100, 750, 100) xl = rng.uniform(300, 1250, 100) il2, xl2 = geom.xy_to_bin(*geom.bin_to_xy(il, xl)) np.testing.assert_allclose(il2, il, atol=1e-6) np.testing.assert_allclose(xl2, xl, atol=1e-6) @pytest.mark.parametrize( "name,xy,expected", [ # bảng IL/XL thật ở plan mục 1.2a ("F02-1", (606554, 6080126), (362, 336)), ("F03-2", (619101, 6089491), (722, 848)), ("F03-4", (623256, 6082586), (442, 1007)), ("F06-1", (607903, 6077213), (244, 387)), ], ) def test_well_bins_match_plan(geom, name, xy, expected): assert geom.nearest_bin(*xy) == expected assert geom.in_survey(*expected) @pytest.mark.parametrize( "legacy,xy,km", [ # vị trí luận văn dùng và độ lệch ở plan mục 1.2a ((418, 608), (606554, 6080126), 6.94), ((362, 821), (623256, 6082586), 5.05), ((283, 842), (607903, 6077213), 11.42), ], ) def test_legacy_offsets(geom, legacy, xy, km): x, y = geom.bin_to_xy(*legacy) assert np.hypot(x - xy[0], y - xy[1]) / 1000 == pytest.approx(km, abs=0.01)