Coverage for cosmolayer/store/reporting.py: 94%
17 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-26 00:09 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-26 00:09 +0000
1"""Console reporting helpers for the ``cosmolayer.store`` CLI."""
3from typing import Any
5import numpy as np
6from numpy.typing import NDArray
9def print_stats(
10 title: str,
11 properties: NDArray[np.number[Any]],
12 quantiles: tuple[float, ...] = (0.01, 0.1, 0.5, 0.9, 0.99),
13 value_format: str = ".6f",
14) -> None:
15 """Print min, max, mean, and quantiles of a property as a table.
17 Parameters
18 ----------
19 title : str
20 Column header identifying the property.
21 properties : np.ndarray
22 Numeric values to summarize.
23 quantiles : tuple[float, ...], optional
24 Quantiles in ``[0, 1]`` to report, by default
25 ``(0.01, 0.1, 0.5, 0.9, 0.99)``.
26 value_format : str, optional
27 Format spec for the reported values, by default ``".6f"``. Use
28 an exponential format such as ``".3e"`` when values would
29 otherwise print as zeros.
30 """
31 print(f"\n{'Statistic':<10} | {title:>20}")
32 print("-" * 33)
33 print(f"{'Count':<10} | {len(properties):>20}")
34 print(f"{'Min':<10} | {np.min(properties):>20{value_format}}")
35 for q in sorted(quantiles):
36 q_percent = q * 100
37 if int(q_percent) == q_percent:
38 qtext = f"{q_percent:.0f}%"
39 else:
40 qtext = f"{q_percent:.1f}%"
41 print(f"{qtext:<10} | {np.quantile(properties, q):>20{value_format}}")
42 print(f"{'Max':<10} | {np.max(properties):>20{value_format}}")
43 print(f"{'Mean':<10} | {properties.mean():>20{value_format}}")
44 print()