Skip to main content

v2

CST/CRT calculation step v2 — CST/CRT plus EZ integrity at the fovea.

Adds the ellipsoid-zone measurement a trial's inclusion criterion needs: the widest contiguous span of the fovea-reference B-scan whose EZ-to-RPE separation exceeds a configured threshold. See v2.task for why cst_calculation hosts it and what the version bump costs, and v2.config for the assumptions the measurement makes.

Module

Submodules

Functions

task_fn

def task_fn(    datasource: BaseSource,    config: CSTCalculationConfigV2,    layer_predictions: CacheAccessor,    center_predictions: CacheAccessor,    filenames: list[str],    cache: CacheProtocol,    task_hash: str,    project_id: str | None = None,    run_id: str | None = None,)> CSTCalculationResult:

Compute CST/CRT metrics for each file and persist them to cache.

Arguments

  • datasource: The datasource providing DICOM metadata (slice thickness, pixel spacing row/column) for each file.
  • config: CST calculation configuration, including the EZ-integrity layer pair and threshold.
  • layer_predictions: Cache accessor for retinal-layers model inference results (background step retinal_layers_inference.cache).
  • center_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 CST metrics into.
  • task_hash: Partition key for the cst_calculation table; a config change lands in a fresh partition.
  • 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 CSTCalculationResult carrying the number of rows persisted and a CacheAccessor scoped to this task_hash (cst_calculation.cache).

Classes

Config

class Config(**data: Any):

CST/CRT config, plus the EZ-integrity measurement.

The EZ block is inert unless ez_attenuation_threshold_um is set, which is what makes the step safe to wire into a template before a trial has agreed its threshold: every ez_* column is then empty rather than wrong.

Two assumptions are being made literally, and are recorded here so they are auditable if a cohort looks wrong rather than being rediscovered:

  1. A 50 µm gate sits close to normal anatomy. Healthy EZ-to-RPE separation is on the order of a few tens of micrometres, so the measurement convention matters more than it would for a threshold with margin.
  2. dedupe_layer_points biases the separation upward. Where a polyline is multivalued at one X, the inner boundary keeps the shallowest Y and the outer the deepest, which is the largest separation available. That convention was chosen for ILM-to-RPE, where it means "full retinal thickness"; here it biases towards calling tissue intact. It is left unchanged so CST and GCC are unaffected.

Attributes

  • ez_inner_layer_name: Inner layer of the EZ pair.
  • ez_outer_layer_name: Outer layer of the EZ pair. Bruch's membrane is in RetinalLayer but absent from the layers model's real output, so EZ-to-BM is not obtainable today.
  • ez_attenuation_threshold_um: Separation above which the EZ counts as intact. None switches the measurement off.

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 ez_attenuation_threshold_um : float | None
  • static ez_inner_layer_name : str
  • static ez_outer_layer_name : str
  • static model_config

Result

class Result(**data: Any):

Result of a CST/CRT calculation task.

records_stored reports how many per-file CST/CRT rows were persisted to the cst_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_cst_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 cst_calculation_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.