Files
ML-Porosity/tests/test_geometry.py
lamlvh cee2ff0859 P2 diagnosis on dev, P3 dev experiments, lock protocol_p3
- P2: SMC tie posterior (numpy + torch), RML/soft-DTW losses, bank training,
  D2 synthetic generator, scripts 09-13, protocol_p2 (locked) and its outcome
  (G-B failed; H1 not rejected, H3 rejected, H4 not rejected).
- Diagnosis on dev realizations 900/901 only (scripts 14-17, run_p3_dev.sh):
  posterior screen, SMC stability (P = 1024, K = 1), sigma_a misspecification
  stress and training, H3 with the SMC posterior, F3 placement on sigma_post.
- protocol_p3: H2 split into H2a (posterior-mean labels vs point ties) and
  H2b (RML vs posterior mean as a function of sigma_post); H3 descriptive only;
  sigma_a arm; new D2 config d2_synth_p3.yaml; main grid on realizations 8-15.
  Locked by configs/protocol_p3.sha256 and tag protocol-p3.
- runlog: per-run logs and runtime index (logs/index.csv).
- Docs: plan §12 items 10-11, theory, technical overview, report; wording
  aligned with Gunning & Glinsky (2006): the tie posterior is not claimed as new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 06:03:33 +00:00

71 lines
2.1 KiB
Python

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="missing 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",
[ # true IL/XL table in plan §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",
[ # locations used in the thesis and their offsets, plan §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)