scan_metrics
Criteria on the measurements of a scan's analysis.
The flat config bounds on scan metrics: GA area and lesion counts, drusen,
CNV and wet AMD probability, CST/GCC/fluid, EZ loss, distance from the fovea
and the n-scan biomarkers. In make_count_guarded_filter, a lesion count of
zero settles a lesion bound that has no measurement. _scan_unknown_reason
says why a scan bound could not be decided.
Module
Functions
configured_scan_range_columns
def configured_scan_range_columns(config: CriteriaMatchConfig) ‑> set[str]:Columns whose scan-metric range filter this config actually emits.
A column appears iff at least one of its bounds is set. Used to warn when a range field is configured but the calc step that produces its column is not wired, so the criterion would otherwise silently mark every patient ineligible with no diagnostic (unlike the GA path, which warns).
Arguments
config: The criteria-matching config carrying the range bounds.
Returns The set of target column names with at least one bound set.
make_count_guarded_filter
def make_count_guarded_filter( *, value_column: str, count_column: str, passes: Callable[[float], bool], zero_count_passes: bool, zero_count_context: str, failed_context: Callable[[float], str] | None = None, reference_type_column: str | None = None,) ‑> Callable[[pd.Series[Any]], MethodOutcome]:Build a numeric criterion that a count of zero settles on its own.
A lesion measurement is null in two situations a plain comparison cannot
tell apart: the region held no lesions, or nothing measured it. The first
settles the criterion — with no GA at all none of it reaches the fovea, and
with no drusen in the ROI none is wider than T — while the second is a
genuine unknown. The count column separates them: zero is a measured
absence, null is an unmeasured region (every roi_ column is null rather
than zero where no landmark gave a region).
The measured value is reported whenever there is one, so the evidence still
carries the number even though the verdict came from a predicate. A verdict
the count settled is marked definitive, so it is not reported as an
unmeasured row on the strength of the null it deliberately read past.
Arguments
value_column: The measurement the criterion is about.count_column: Lesion count over the same region as value_column.passes: Predicate on the measured value;Trueis PASS.zero_count_passes: The verdict when count_column reads zero.zero_count_context: Context to report for that verdict.failed_context: Context for a measured value that fails passes, orNoneto report the filter's static failure message instead.reference_type_column: Column recording how the fovea landmark behind a fovea-centred region was found, orNonefor a region that does not depend on one. A null value on a row whose reference isFOVEA_REFERENCE_NOT_DETECTED(the fovea model ran on the scan and located no fovea) is reported as unknown because the fovea was not located. Any other null keeps the default unknown reason; that includesFOVEA_REFERENCE_UNAVAILABLE, where no fovea model output was read, so nothing is known about the fovea. The row does not say whether the producing step configured a region at all, so a scan with no fovea detected AND no region configured is still given the fovea reason, which is true but not the whole story.
Returns
A row predicate returning a MethodOutcome.
make_drusen_inclusion_filter
def make_drusen_inclusion_filter( *, drusen_threshold: float, hard_drusen_column: str, soft_drusen_column: str, confluent_drusen_column: str,) ‑> Callable[[pd.Series[Any]], tuple[bool | None, str | None]]:Build the combined drusen-inclusion filter.
Passes when hard-, soft-, or confluent-drusen probability is at or above
(>=) drusen_threshold on the scan. Each signal is guarded on its value
being present (non-NaN). When all three probabilities are absent/NaN the
result is UNKNOWN (None); when at least one is present but none reach the
threshold the result is FAIL.
Arguments
drusen_threshold:>=threshold applied to each drusen probability.hard_drusen_column: Max hard-drusen probability column name.soft_drusen_column: Max soft-drusen probability column name.confluent_drusen_column: Max confluent-drusen probability column name.
Returns
A row predicate returning (state, context) where state is
True/False/None (PASS/FAIL/UNKNOWN).
make_n_scan_biomarker_filter
def make_n_scan_biomarker_filter( *, biomarker_display_name: str, typical_width_micrometers: float, run_length_column: str, slice_thickness_column: str,) ‑> Callable[[pd.Series[Any]], tuple[bool | None, str | None]]:Build the N-scan consecutive-run biomarker exclusion filter.
A scan is ineligible (FAIL) when the biomarker's longest consecutive-B-scan
run reaches ceil(typical_width_micrometers / slice_thickness_micrometers)
(default run threshold 1 when the width is 0).
The run-length check runs FIRST, because the two missing-data causes
correlate: an absent Slice Thickness is itself a missing_data:* reason
for the GA metrics, so testing thickness first would PASS a scan that has no
run-length metric at all — reporting it eligible on this criterion while the
degraded path simultaneously reports every GA metric unknown.
The two missing-data branches then diverge deliberately:
- A missing/zero/NaN slice thickness PASSES: without a thickness the run
cannot be converted to a width, so the criterion is unevaluable and does
not exclude on this basis. An absent
Slice Thicknesscolumn behaves identically to a NaN value, because the column is not inrequired_columns: listing it there would letbuild_eligibility_filtersclaim it as a typed-field column and silently drop a user's genericcolumn_criteriaon it. - A missing/NaN run-length value returns UNKNOWN, NOT PASS: the biomarker
was never measured, so no verdict is available. UNKNOWN has to be
explicit here because
convert_metrics_to_dfreindexes a missing expected column into existence as NaN, which defeatsMethodFilter's own missing-column UNKNOWN guard; returning PASS would report every scan of a no-GA-data patient as eligible on this criterion.
Arguments
biomarker_display_name: Human-readable biomarker name, used verbatim in the user-facing context and failure messages (e.g. "Subretinal Hyperreflective Material (SHRM)"). Never the raw internal label.typical_width_micrometers: The lesion width driving the scan-count threshold, in micrometers.run_length_column: Column holding the biomarker's longest consecutive run (n_scan_run_<label>).slice_thickness_column: Column holding the per-scan slice thickness (mm).
Returns
A row predicate returning (state, context) where state is
True (PASS), False (FAIL), or None (UNKNOWN, missing run-length
data only).
scan_metric_filters_after_age
def scan_metric_filters_after_age( config: CriteriaMatchConfig, ctx: FilterBuildContext,) ‑> list[ColumnFilter | MethodFilter]:Build the fovea-distance filters, which come after the age filters.
Arguments
config: The criteria-matching config.ctx: What the filter builders share; unused here.
Returns One filter for each of these fields that the config sets.
scan_metric_filters_after_code_lists
def scan_metric_filters_after_code_lists( config: CriteriaMatchConfig, ctx: FilterBuildContext,) ‑> list[ColumnFilter | MethodFilter]:Build the drusen-inclusion and n-scan filters, after the code lists.
Arguments
config: The criteria-matching config.ctx: What the filter builders share; unused here.
Returns One filter for each of these fields that the config sets.
scan_metric_filters_before_age
def scan_metric_filters_before_age( config: CriteriaMatchConfig, ctx: FilterBuildContext,) ‑> list[ColumnFilter | MethodFilter]:Build the scan-metric filters that come before the age filters.
GA area, the drusen widths, largest GA lesion, CNV, the biomarker
thresholds, wet AMD, the CST/GCC/fluid ranges and EZ. The scan metrics are
split into three builders only to keep the order the filters have always
had; see assembly._FLAT_FIELD_BUILDERS.
Arguments
config: The criteria-matching config.ctx: What the filter builders share; unused here.
Returns One filter for each of these fields that the config sets.