Skip to main content

v1

GA calculation with fovea step v1.

Module

Submodules

Functions

task_fn

def task_fn(    datasource: BaseSource,    config: GACalculationWithFoveaConfig,    ga_predictions: CacheAccessor,    fovea_predictions: CacheAccessor,    filenames: list[str],    cache: CacheProtocol,    task_hash: str,    project_id: str | None = None,    run_id: str | None = None,)> GACalculationWithFoveaResult:

Compute GA metrics for each file and persist them to cache.

Runs in background mode: an in-memory result does not cross the phase boundary, so the per-file metrics are persisted 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.

Arguments

  • datasource: The datasource providing DICOM metadata (slice thickness, pixel spacing) for each file.
  • config: GA calculation with fovea configuration.
  • ga_predictions: Cache accessor for GA model inference results (background step ga_inference.cache).
  • fovea_predictions: Cache accessor for fovea model inference results (background step fovea_inference.cache).
  • filenames: List of file IDs to process.
  • cache: Cache instance to persist the GA metrics into.
  • task_hash: Partition key for the ga_calculation table (see GACalculation for the key's composition).
  • project_id: Provenance only — the project that triggered this run. NOT part of the cache key: rows are keyed by (task_hash, file_id).
  • run_id: Optional provenance run ID.

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

Classes

Config

class Config(**data: Any):

Config for the GA area / metrics calculation step (with fovea).

The segmentation lists and fovea_landmark_idx are required (supplied by the YAML template); the per-biomarker N-scan thresholds default to 0.5 so a template need not set them.

The N-scan thresholds are exposed as modeller variables, so a blank one arrives here as None. They tune detection for a criterion that is switched on elsewhere (n_scan_<label>_typical_width_micrometers on the criteria-matching step), so a blank cannot mean "no criterion" — there is no criterion here to suppress — and 0 is out of range. A blank therefore falls back to the 0.5 default rather than failing the whole run at config-parse time.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables

  • static fovea_landmark_idx : int
  • static ga_area_exclude_segmentations : list[str]
  • static ga_area_include_segmentations : list[str]
  • static model_config
  • static n_scan_diabetic_macular_edema_per_scan_threshold : float
  • static n_scan_diffuse_edema_per_scan_threshold : float
  • static n_scan_epiretinal_fibrosis_per_scan_threshold : float
  • static n_scan_intraretinal_cystoid_fluid_per_scan_threshold : float
  • static n_scan_subretinal_fluid_per_scan_threshold : float
  • static n_scan_subretinal_hyperreflective_material__shrm__per_scan_threshold : float

Result

class Result(**data: Any):

Result of a GA calculation with fovea task.

records_stored reports how many per-file GA rows were persisted to the ga_calculation cache table. The metrics themselves are not returned in-memory: this step runs in background mode, where an in-memory result does not cross the phase boundary, so a downstream step reads the rows via the <step_name>.cache accessor (or records in the same process).

records_stored means two different things depending on which path the task took: on the compute path it is the number of rows persisted by this invocation (len(records) in persist_ga_metrics); on the read-before-compute early return, where nothing was stale, it is instead the total row count of the step's own partition (own_accessor.count() in ga_calculation_with_fovea_task) — there being no new rows to report, the field falls back to describing what is already there.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Variables

  • static model_config
  • cache : CacheAccessor | None - Return the CacheAccessor for reading this result in a DAG pipeline.
  • records : pandas.core.frame.DataFrame - Retrieve this result's rows as a DataFrame.

    The DataFrame is fetched from the cache on each access — it is not stored in the result object, allowing lazy access to large datasets without materialising them in memory until needed.

    Returns: A pandas.DataFrame with one row per cached record.

    Raises: RuntimeError: If no accessor is attached (e.g. the result was serialised across a Prefect task boundary). In a DAG pipeline use <step_name>.cache instead.

Static methods


from_accessor

def from_accessor(    accessor: CacheAccessor, *, records_stored: int | None = None,)> Self:

Inherited from:

CacheBackedResult.from_accessor :

Build a result carrying accessor, in one call rather than two.

_accessor is a PrivateAttr, so it cannot be passed to the constructor and every producer would otherwise construct the result and then reach in to attach the accessor. That two-step is the shape this replaces.

Arguments

  • accessor: The CacheAccessor backing <step>.cache, scoped to the partition this result stands for.
  • records_stored: Rows this result stands for. Defaults to accessor.count() — the whole partition — which is what a step that persisted nothing this run reports. A step that wrote rows passes what it wrote; see the field's docstring for why the two are not interchangeable.

Returns An instance of the calling subclass, with the accessor attached.

Methods


model_post_init

def model_post_init(self: BaseModel, context: Any, /)> None:

Inherited from:

CacheBackedResult.model_post_init :

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that's what pydantic-core passes when calling it.

Arguments

  • self: The BaseModel instance.
  • context: The context.