3d_model / tests /test_inference_sigma_calibration_table.py
Azan
Clean deployment build (Squashed)
7a87926
import json
from pathlib import Path
import numpy as np
import pytest
from ylff.services.inference_pipeline import _apply_sigma_calibration_from_json
pytestmark = pytest.mark.spec
def test_inference_can_apply_versioned_per_regime_affine_table(tmp_path: Path):
sigma = np.array([[1.0, 2.0]], dtype=np.float32)
table = {
"schema_version": "1.0",
"calibration_version": "vtest",
"method": "per_regime_affine",
"params": {"per_regime": {"indoor_constrained": {"a": 2.0, "b": 1.0}}},
"split": {},
"notes": {},
}
p = tmp_path / "calib.json"
p.write_text(json.dumps(table))
out, meta = _apply_sigma_calibration_from_json(
sigma, str(p), operating_regime="indoor_constrained"
)
assert np.allclose(out, sigma * 2.0 + 1.0)
assert meta.get("calibration_version") == "vtest"
def test_inference_accepts_legacy_affine_json(tmp_path: Path):
sigma = np.array([1.0, 2.0], dtype=np.float32)
p = tmp_path / "calib.json"
p.write_text(json.dumps({"a": 3.0, "b": 0.5}))
out, meta = _apply_sigma_calibration_from_json(sigma, str(p))
assert np.allclose(out, sigma * 3.0 + 0.5)
assert meta.get("applied") == "affine"