functions
Cache-persistence helpers for the ga_calculation_with_fovea step (v1).
Extracted from ga_calculation_with_fovea_task to keep the cache-write
orchestration (building the ga_calculation.cache accessor and upserting the
per-file rows) apart from the task body, mirroring the sibling thickness steps
(cst_calculation / gcc_calculation).
This step runs in background mode and is cache-backed: it persists per-file GA
metrics to the ga_calculation cache table (keyed by (task_hash, file_id),
project_id provenance-only) and a downstream step reads them via the
ga_calculation.cache accessor.
Module
Functions
build_ga_accessor
def build_ga_accessor( cache: CacheProtocol, task_hash: str, config: GACalculationWithFoveaConfig, *filter_fields: str,) ‑> CacheAccessor:Build the CacheAccessor for this step's ga_calculation partition.
Arguments
cache: The cache backend.task_hash: The step's partition key.config: The step config (source of any config-derived equality filters).*filter_fields: The step'scache_filter_fields— empty for this step, whose rows are keyed bytask_hashalone.
Returns
A CacheAccessor scoped to this task_hash.
ga_metrics_json
def ga_metrics_json(metrics: GAMetricsWithFovea) ‑> dict[str, typing.Any]:Flatten a GAMetricsWithFovea for the schemaless metrics_json blob.
Keeps the scalar fields plus the segmentation_areas,
max_pathology_probabilities, and n_scan_run_lengths mappings so a
downstream reader can derive the per-pathology max_*_probability,
drusen / segmentation-area, and n_scan_run_<label> columns from the cache
exactly as the in-memory path did. Only raw_pathology_probabilities (a
per-bscan NumPy-array mapping) is dropped: it is large, model-internal, and
never surfaced downstream.
Arguments
metrics: The per-file GA metrics to serialise.
Returns
A JSON-serialisable dict (subject to json_safe on write).
persist_ga_metrics
def persist_ga_metrics( cache: CacheProtocol, task_hash: str, config: GACalculationWithFoveaConfig, output: dict[str, GAMetricsWithFovea | str | None], *, project_id: str | None = None, run_id: str | None = None, filter_fields: tuple[str, ...] = (),) ‑> GACalculationWithFoveaResult:Upsert per-file GA rows and return the cache-backed result.
Arguments
cache: The cache backend to persist into.task_hash: Partition key for thega_calculationtable.config: The step config (passed through to the accessor).output: Per-file result map — aGAMetricsWithFovea(success), a reasonstr(missing_data:*/calculation_error:*), orNone(the metric could not be computed for the file).project_id: Provenance only — not part of the cache key.run_id: Optional provenance run ID.filter_fields: The step'scache_filter_fields, forwarded to the accessor.
Returns
GACalculationWithFoveaResult carrying the row count and a scoped
accessor.