Skip to main content

task

Prefect task for the generic en-face lesion calculation step.

Calls compute_lesion_metrics_for_scan from steps.lesion_calculation.functions to measure every configured mask group — area, volume, per-lesion detail, and fovea-relative geometry — for each scan from pathology model predictions and, when wired, fovea model predictions.

Runs in background mode: an in-memory result does not cross the phase boundary, so the per-file metrics are persisted to the lesion_calculation cache table (keyed by (task_hash, file_id), project_id provenance-only) and a downstream step reads them via the lesion_calculation.cache accessor.

Module

Functions

lesion_calculation_task

def lesion_calculation_task(    datasource: BaseSource,    config: LesionCalculationConfig,    pathology_predictions: CacheAccessor,    filenames: list[str],    cache: CacheProtocol,    task_hash: str,    fovea_predictions: CacheAccessor | None = None,    project_id: str | None = None,    run_id: str | None = None,)> LesionCalculationResult:

Compute per-group lesion metrics for each file and persist them to cache.

Arguments

  • datasource: The datasource providing DICOM metadata (slice thickness, pixel spacing) for each file.
  • config: Lesion calculation configuration, naming the groups to measure, the ROI radius, and the per-group lesion cap.
  • pathology_predictions: Cache accessor for pathology model inference results (background step ga_inference.cache).
  • filenames: List of file IDs to process.
  • cache: Cache instance to persist the lesion metrics into.
  • task_hash: Partition key for the lesion_calculation table; a config change lands in a fresh partition.
  • fovea_predictions: Optional cache accessor for fovea model inference results (background step fovea_inference.cache). None is a supported state, not an error: a template without a fovea step still gets areas, volumes and lesion sizes, just no fovea-relative fields.
  • project_id: Provenance only — the project that triggered this run. NOT part of the cache key: rows are keyed by (task_hash, file_id) so two projects on the same datasource share them.
  • run_id: Optional provenance run ID.

Returns LesionCalculationResult carrying the number of rows persisted and a CacheAccessor scoped to this task_hash (lesion_calculation.cache).

Raises

  • KeyError: If the predictions frame lacks the file_id column the merge aligns on — a programming error, not a data condition.