Skip to content

czitools.hcs_check #

Command-line inspector for CZI HCS metadata and stored dimensions.

Functions:

main #

main() -> int

Run the CZI HCS inspector.

Returns:

  • int ( int ) –

    Process exit code.

Source code in czitools/hcs_check.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def main() -> int:
    """Run the CZI HCS inspector.

    Returns:
        int: Process exit code.
    """
    args = _create_parser().parse_args()
    filepath = args.filepath_flag if args.filepath_flag else args.filepath
    if filepath is None:
        console.print(
            "[bold red]Error:[/bold red] filepath is required. " "Use -f, --filepath, or a positional path.",
            file=sys.stderr,
        )
        return 1
    if not filepath.exists():
        console.print(f"[bold red]Error:[/bold red] File not found: {filepath}", file=sys.stderr)
        return 1

    try:
        metadata = CziMetadata(
            filepath,
            filter_hcs_to_stored_scenes=not args.show_declared,
        )
        console.print(
            Panel(
                f"[bold]File:[/bold] {filepath}",
                border_style="green",
                style="bold green",
                title="CZI - HCS Inspector",
            )
        )
        print_subblock_dimensions(metadata)
        print_hcs_plate_info(metadata, show_well_table=not args.no_well_table)
        print_sample_metadata(metadata, args.well)
        print_well_fields(metadata, args.well)
        console.print(
            Panel(
                "[bold green]Analysis complete.[/bold green]",
                border_style="green",
                style="dim green",
            )
        )
        return 0
    except Exception as error:
        console.print(
            Panel(
                f"[bold red]{error}[/bold red]",
                title="[bold red]Error Processing File[/bold red]",
                border_style="red",
                style="red",
            )
        )
        return 1

print_subblock_dimensions #

print_subblock_dimensions(metadata: CziMetadata) -> None

Display full-resolution dimension sizes and bounds from stored subblocks.

Parameters:

  • metadata #

    (CziMetadata) –

    CZI metadata containing physical dimensions.

Source code in czitools/hcs_check.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def print_subblock_dimensions(metadata: CziMetadata) -> None:
    """Display full-resolution dimension sizes and bounds from stored subblocks.

    Args:
        metadata (CziMetadata): CZI metadata containing physical dimensions.
    """
    image = metadata.image
    if image is None:
        console.print("[yellow]No subblock-derived dimensions available.[/yellow]")
        return

    dimensions = (
        ("S", "Scene", image.SizeS),
        ("T", "Time", image.SizeT),
        ("C", "Channel", image.SizeC),
        ("Z", "Z-slice", image.SizeZ),
        ("Y", "Height (all-scenes bbox)", image.SizeY),
        ("X", "Width (all-scenes bbox)", image.SizeX),
        ("M", "Mosaic", image.SizeM),
        ("R", "Rotation", image.SizeR),
        ("I", "Illumination", image.SizeI),
        ("H", "Phase", image.SizeH),
        ("V", "View", image.SizeV),
        ("B", "Block", image.SizeB),
    )

    table = Table(title="Full-Resolution Subblock Dimensions", style="cyan")
    table.add_column("Dimension", style="bright_cyan", justify="center")
    table.add_column("Meaning")
    table.add_column("Size", style="yellow", justify="right")
    table.add_column("Start", style="green", justify="right")
    table.add_column("End (exclusive)", style="green", justify="right")
    table.add_column("Bounds", style="bright_magenta")
    table.add_column("Valid indices", style="bright_blue")

    for dimension, meaning, size in dimensions:
        valid_indices = image.dimension_indices.get(dimension, ())
        bounds_value = image.dimension_bounds.get(dimension)
        if bounds_value is not None:
            start, end = bounds_value
            bounds = f"[{start}, {end})"
        elif valid_indices:
            start = min(valid_indices)
            end = max(valid_indices) + 1
            bounds = f"[{start}, {end})"
        else:
            start = None
            end = None
            bounds = "[dim]not available[/dim]"

        table.add_row(
            dimension,
            meaning,
            str(size) if size is not None else "[dim]not present[/dim]",
            str(start) if start is not None else "[dim]-[/dim]",
            str(end) if end is not None else "[dim]-[/dim]",
            bounds,
            _format_valid_indices(valid_indices),
        )

    scene_y = image.SizeY_scene if image.SizeY_scene is not None else "not available"
    scene_x = image.SizeX_scene if image.SizeX_scene is not None else "not available"
    table.caption = f"First stored scene: Y={scene_y} px, X={scene_x} px"
    console.print(table)