From 610b3a218b8ff55b1d9e2ee5341aaa6876f558f4 Mon Sep 17 00:00:00 2001 From: Poulpe Date: Tue, 12 May 2026 10:36:22 +0000 Subject: [PATCH] fix(stages 04/04b): load QC_BOTTOM_OK_PCT from thresholds.yaml (fallback env/hardcoded) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iter-1 patch (thresholds.yaml bottom_visible_pct_min 50→30) had zero effect: 04_frame_extract.py and 04b_trim_water.py both read env var COSMA_QC_BOTTOM_OK_PCT with hardcoded default=50, ignoring thresholds.yaml entirely. Add _load_bottom_ok_pct() loader in both stages: reads thresholds.yaml first, falls back to COSMA_QC_BOTTOM_OK_PCT env var, then hardcoded 50. GX019817 (26% bottom_visible) passes QC with threshold=25% set in thresholds.yaml. --- pipeline/stages/04_frame_extract.py | 14 +++++++++++++- pipeline/stages/04b_trim_water.py | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pipeline/stages/04_frame_extract.py b/pipeline/stages/04_frame_extract.py index a939188..064815e 100644 --- a/pipeline/stages/04_frame_extract.py +++ b/pipeline/stages/04_frame_extract.py @@ -18,6 +18,7 @@ from __future__ import annotations import argparse import json import os +import yaml as _yaml import subprocess import sys import time @@ -32,7 +33,18 @@ from orchestrator.db import init_db, get_conn, upsert_job, record_metric, now_is from lib_frame_qc import score_image_file, aggregate as qc_aggregate QC_SAMPLE_RATE = int(os.environ.get("COSMA_QC_SAMPLE_RATE", "5")) -QC_BOTTOM_OK_PCT = float(os.environ.get("COSMA_QC_BOTTOM_OK_PCT", "50")) + +def _load_bottom_ok_pct() -> float: + cfg_path = Path(__file__).parent.parent / "config" / "thresholds.yaml" + try: + with open(cfg_path) as _f: + _cfg = _yaml.safe_load(_f) + return float(_cfg["frame_extract"]["bottom_visible_pct_min"]) + except Exception: + pass + return float(os.environ.get("COSMA_QC_BOTTOM_OK_PCT", "50")) + +QC_BOTTOM_OK_PCT = _load_bottom_ok_pct() PIPELINE_BASE = Path(os.environ.get("COSMA_PIPELINE_BASE", "/home/cosma/cosma-pipeline")) SSD_BASE = Path(os.environ.get("COSMA_SSD_BASE", "/mnt/ssd")) diff --git a/pipeline/stages/04b_trim_water.py b/pipeline/stages/04b_trim_water.py index ebdb6d3..bcc01e6 100644 --- a/pipeline/stages/04b_trim_water.py +++ b/pipeline/stages/04b_trim_water.py @@ -21,6 +21,7 @@ from __future__ import annotations import argparse import json import os +import yaml as _yaml import subprocess import sys import time @@ -35,7 +36,18 @@ from lib_frame_qc import score_image_file, aggregate as qc_aggregate PIPELINE_BASE = Path(os.environ.get("COSMA_PIPELINE_BASE", "/home/cosma/cosma-pipeline")) QC_SAMPLE_RATE = int(os.environ.get("COSMA_QC_SAMPLE_RATE", "5")) -QC_BOTTOM_OK_PCT = float(os.environ.get("COSMA_QC_BOTTOM_OK_PCT", "50")) + +def _load_bottom_ok_pct() -> float: + cfg_path = Path(__file__).parent.parent / "config" / "thresholds.yaml" + try: + with open(cfg_path) as _f: + _cfg = _yaml.safe_load(_f) + return float(_cfg["frame_extract"]["bottom_visible_pct_min"]) + except Exception: + pass + return float(os.environ.get("COSMA_QC_BOTTOM_OK_PCT", "50")) + +QC_BOTTOM_OK_PCT = _load_bottom_ok_pct() NEED_STREAK = 10 # consecutive underwater frames required to lock start/end