Skip to main content

functions

Cache-persistence helpers for the ga_calculation_without_fovea step (v1).

Extracted from ga_calculation_without_fovea_task to keep the cache-write orchestration (building the ga_calculation_without_fovea.cache accessor and upserting the per-file rows) apart from the task body, mirroring the sibling ga_calculation_with_fovea step.

Persistence is conditional: the task keeps returning the in-memory metrics map for same-phase consumers AND — when a cache is supplied (the background / cross-phase case) — persists the per-file rows here so a later interactive step can read them via the ga_calculation_without_fovea.cache accessor.

Module

Functions

build_ga_accessor

def build_ga_accessor(    cache: CacheProtocol,    task_hash: str,    config: GACalculationWithoutFoveaConfig,    *filter_fields: str,)> CacheAccessor:

Build the CacheAccessor for this step's cache 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's cache_filter_fields — empty for this step, whose rows are keyed by task_hash alone.

Returns A CacheAccessor scoped to this task_hash.

ga_metrics_json

def ga_metrics_json(metrics: GAMetrics)> dict[str, typing.Any]:

Flatten a GAMetrics 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 / drusen / segmentation-area / n_scan_run_<label> columns from the cache exactly as the in-memory path does. 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: GACalculationWithoutFoveaConfig,    output: dict[str, GAMetrics | str | None],    *,    project_id: str | None = None,    run_id: str | None = None,    filter_fields: tuple[str, ...] = (),)> GACalculationWithoutFoveaResult:

Upsert per-file GA rows and return the cache-backed result.

Arguments

  • cache: The cache backend to persist into.
  • task_hash: Partition key for the ga_calculation_without_fovea table.
  • config: The step config (passed through to the accessor).
  • output: Per-file result map — a GAMetrics (success), a reason str (missing_data:* / calculation_error:*), or None (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's cache_filter_fields, forwarded to the accessor.

Returns GACalculationWithoutFoveaResult carrying the row count and a scoped accessor.