v3
CST/CRT calculation step v3 — EZ integrity read from the band edges.
Same config, result and table as v2. What changes is how the EZ measurement
reads the EZ and RPE boundaries: the EZ band's top edge and the RPE band's
bottom edge at every A-scan, whatever vertex the model started each polygon
from. See v3.task for the defect this fixes and what the version bump costs.
Module
Submodules
- bitfount.steps.cst_calculation.v3.task - Prefect task for the CST/CRT calculation step (v3).
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.
The EZ pair is read as band edges. See run_cst_calculation for the
arguments.
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:
- 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.
dedupe_layer_pointsbiases 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 inRetinalLayerbut 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.Noneswitches the measurement off.analysis_region: En-face region the EZ spans and measured width are restricted to, on the reference B-scan.Nonemeasures the whole B-scan. CST/CRT is unaffected.
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.
Ancestors
Variables
- static
model_config
- static
records_stored : int
cache : CacheAccessor | None- Return theCacheAccessorfor 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.DataFramewith 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>.cacheinstead.
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: TheCacheAccessorbacking<step>.cache, scoped to the partition this result stands for.records_stored: Rows this result stands for. Defaults toaccessor.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.