- OCR: match the colleague's full-set Dataset Hub export to the DDRs by content (3,059/3,066 pages) and QC it against the HTML (CER 2.40%, exact 0.9181). - WITSML parser and formation tops: 21 DDR wellbores with time logs, 1,384 reports; WITSML 15/9-F-15 S is DDR 15/9-F-15. - Deterministic labels T1-T3 (configs/labels.yaml), 1,662 T4 questions with SQL, pandas and raw-XML answers in full agreement. - Trial label validation by three blind LLM raters (not an author or expert audit) and rater agreement script; draft protocol_v1 (not locked): split by well. - Literature notes and BibTeX; docs, report and run_m1.sh synchronised. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
40 lines
1.7 KiB
Python
40 lines
1.7 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
from volve_dia import audit
|
|
|
|
|
|
def test_allocate_minimum_then_sqrt_share():
|
|
a = audit.allocate({"big": 1600, "mid": 100, "tiny": 1}, 20, 2)
|
|
assert sum(a.values()) == 20 and a["tiny"] == 1 and a["mid"] >= 2 and a["big"] > a["mid"]
|
|
assert audit.allocate({"x": 3, "y": 3}, 10, 2) == {"x": 3, "y": 3} # never more than a stratum holds
|
|
with pytest.raises(ValueError):
|
|
audit.allocate({s: 10 for s in "abcdef"}, 5, 1)
|
|
|
|
|
|
def test_draw_weights_and_spread_over_wells():
|
|
f = pd.DataFrame({"act_id": range(400), "well": np.repeat(list("ABCD"), 100),
|
|
"zone": ["a"] * 100 + ["none"] * 300, "stratum": ["a/x"] * 100 + ["none/y"] * 300})
|
|
s = audit.draw(f, {"a": 8, "none": 8}, 2, seed=1)
|
|
assert len(s) == 16 and s["act_id"].is_unique
|
|
assert set(s.loc[s["zone"] == "none", "well"]) == {"B", "C", "D"} # spread over the wells of the stratum
|
|
assert s.groupby("stratum")["weight"].first().to_dict() == {"a/x": 12.5, "none/y": 37.5}
|
|
assert audit.draw(f, {"a": 8, "none": 8}, 2, seed=1)["act_id"].tolist() == s["act_id"].tolist()
|
|
|
|
|
|
def test_cohen_kappa():
|
|
a = pd.Series(list("yynnyn"))
|
|
assert audit.cohen_kappa(a, a) == pytest.approx(1.0)
|
|
b = pd.Series(list("ynynyn"))
|
|
po, pe = 4 / 6, 0.5 * 0.5 + 0.5 * 0.5
|
|
assert audit.cohen_kappa(a, b) == pytest.approx((po - pe) / (1 - pe))
|
|
w = pd.Series([1, 1, 1, 1, 1, 1.0])
|
|
assert audit.cohen_kappa(a, b, w) == pytest.approx(audit.cohen_kappa(a, b))
|
|
assert audit.cohen_kappa(pd.Series(["y", "y"]), pd.Series(["y", "y"])) is None # pe = 1
|
|
|
|
|
|
def test_zone():
|
|
z = audit.zone(pd.Series([True, False, False]), pd.Series([True, True, False]))
|
|
assert z.tolist() == ["a", "b_only", "none"]
|