Skip to main content

pdf_render

PDF report rendering for the pdf_report step.

Contains all ReportLab-based PDF generation logic, including the slider visualisation previously in bitfount.visualisation.

Module

Functions

generate_pdf

def generate_pdf(    file_name: str | os.PathLike[str],    report_info: RecordInfo,    scans: ScanData | list[ScanData],    metrics: GAMetricsLike | list[GAMetricsLike],    task_id: str,    total_ga_area_lower_bound: float = 2.5,    total_ga_area_upper_bound: float = 17.5,)> None:

Generate and save a GA OCT PDF report.

Arguments

  • file_name: Destination path for the PDF.
  • report_info: Patient/record header information.
  • scans: One or more scans to include in the report.
  • metrics: GA metrics corresponding to each scan.
  • task_id: Task run ID (used to generate a Hub hyperlink).
  • total_ga_area_lower_bound: Lower bound for the GA area slider.
  • total_ga_area_upper_bound: Upper bound for the GA area slider.

generate_slider

def generate_slider(    ga_metric: float,    filename: str | os.PathLike[str] | None = None,    total_ga_area_lower_bound: float = 2.5,    total_ga_area_upper_bound: float = 17.5,)> None:

Generate a slider PNG visualisation for the given GA metric value.

Arguments

  • ga_metric: The value of the GA metric.
  • filename: Path to save the slider PNG. Defaults to slider.png in the assets directory.
  • total_ga_area_lower_bound: Lower bound of the GA area range.
  • total_ga_area_upper_bound: Upper bound of the GA area range.

Classes

GAMetricsLike

class GAMetricsLike(*args, **kwargs):

Structural protocol for GA metrics objects accepted by the renderer.

This decouples the renderer from any specific GAMetrics class, allowing both bitfount.steps.types.GAMetrics and the legacy bitfount.federated.algorithms.ophthalmology.ophth_algo_types.GAMetrics to be passed without a type error.

Variables

  • static num_bscans_with_ga : int
  • static total_ga_area : float

RecordInfo

class RecordInfo(    text_fields: list[tuple[str, str]], heading: str | None = 'GA OCT REPORT',):

Patient/scan information for the report.

Arguments

  • text_fields: A list of (heading, value) tuples for the PDF header table.
  • heading: The heading for the PDF. Defaults to None.

Variables

  • static heading : str | None
  • static text_fields : list[tuple[str, str]]

ReportRenderer

class ReportRenderer(    record_info: RecordInfo,    scan: ScanData | list[ScanData],    metrics: GAMetricsLike | list[GAMetricsLike],    task_id: str,    total_ga_area_lower_bound: float = 2.5,    total_ga_area_upper_bound: float = 17.5,    **kwargs: Any,):

Generate a PDF report from scan data and GA metrics using ReportLab.

Arguments

  • record_info: Patient/scan header information for the report.
  • scan: A single scan or list of scans to include.
  • metrics: GA metrics corresponding to each scan.
  • task_id: The task run ID (used to generate a Hub hyperlink).
  • total_ga_area_lower_bound: Lower bound for the GA area slider.
  • total_ga_area_upper_bound: Upper bound for the GA area slider.

Methods


generate

def generate(self)> None:

Render all pages onto the current canvas.

Call output() rather than this directly.

output

def output(self, filename: str | os.PathLike[str])> None:

Render the report and save it to filename.

Arguments

  • filename: Destination path for the PDF file.

ScanData

class ScanData(    bscan_image: str | os.PathLike[str] | PILImage,    bscan_idx: int,    bscan_total: int,    bscan_w_mask: str | os.PathLike[str] | PILImage,    legend2color: dict[str, tuple[int, int, int]],    laterality: str | None = None,):

Scan data for a single PDF report page.

Arguments

  • bscan_image: The raw B-scan image (path or PIL Image).
  • bscan_idx: Zero-based index of this B-scan within the volume.
  • bscan_total: Total number of B-scans in the volume.
  • bscan_w_mask: B-scan with segmentation mask overlay (path or PIL Image).
  • legend2color: Mapping of legend label to RGB colour tuple.
  • laterality: Eye laterality string (e.g. "left", "right"), optional.

Variables

  • static bscan_idx : int
  • static bscan_image : str | os.PathLike[str] | PIL.Image.Image
  • static bscan_total : int
  • static bscan_w_mask : str | os.PathLike[str] | PIL.Image.Image
  • static laterality : str | None
  • static legend2color : dict[str, tuple[int, int, int]]