Skip to content

shine.validation.plots

Diagnostic plots for bias measurement.

Generates trace plots, marginal posterior histograms, pair plots, and (future) bias regression and coverage visualizations.

plots

Diagnostic plots for bias measurement using matplotlib and ArviZ.

plot_level0_diagnostics(idata, g1_true, g2_true, output_dir)

Generate Level 0 diagnostic plots, dispatching on inference method.

Reads inference_method from idata.posterior.attrs to select the appropriate plotting style: - NUTS: trace plots + histograms + pair plot - VI: histograms + pair plot (no trace since no chains) - MAP: bar at point estimate + truth line (2 panels: g1, g2)

Parameters:

Name Type Description Default
idata InferenceData

ArviZ InferenceData with posterior samples.

required
g1_true float

True g1 shear value.

required
g2_true float

True g2 shear value.

required
output_dir str

Directory to save plots.

required

Returns:

Type Description
List[Path]

List of saved plot file paths.

Source code in shine/validation/plots.py
def plot_level0_diagnostics(
    idata: az.InferenceData,
    g1_true: float,
    g2_true: float,
    output_dir: str,
) -> List[Path]:
    """Generate Level 0 diagnostic plots, dispatching on inference method.

    Reads ``inference_method`` from ``idata.posterior.attrs`` to select
    the appropriate plotting style:
    - NUTS: trace plots + histograms + pair plot
    - VI: histograms + pair plot (no trace since no chains)
    - MAP: bar at point estimate + truth line (2 panels: g1, g2)

    Args:
        idata: ArviZ InferenceData with posterior samples.
        g1_true: True g1 shear value.
        g2_true: True g2 shear value.
        output_dir: Directory to save plots.

    Returns:
        List of saved plot file paths.
    """
    method = idata.posterior.attrs.get("inference_method", "nuts")
    if method == "map":
        return _plot_map_diagnostics(idata, g1_true, g2_true, output_dir)
    elif method == "vi":
        return _plot_vi_diagnostics(idata, g1_true, g2_true, output_dir)
    else:
        return _plot_nuts_diagnostics(idata, g1_true, g2_true, output_dir)

plot_bias_vs_shear(g_true_values, g_est_means, g_est_stds, component, output_dir, m=None, c=None)

Plot estimated shear vs true shear with bias regression line.

Parameters:

Name Type Description Default
g_true_values ndarray

Array of true shear values.

required
g_est_means ndarray

Array of estimated shear means.

required
g_est_stds ndarray

Array of estimated shear standard deviations.

required
component str

Shear component name ("g1" or "g2").

required
output_dir str

Directory to save plot.

required
m Optional[float]

Multiplicative bias (for regression line).

None
c Optional[float]

Additive bias (for regression line).

None

Returns:

Type Description
Path

Path to saved plot.

Raises:

Type Description
NotImplementedError

This function is a stub for Level 1+.

Source code in shine/validation/plots.py
def plot_bias_vs_shear(
    g_true_values: np.ndarray,
    g_est_means: np.ndarray,
    g_est_stds: np.ndarray,
    component: str,
    output_dir: str,
    m: Optional[float] = None,
    c: Optional[float] = None,
) -> Path:
    """Plot estimated shear vs true shear with bias regression line.

    Args:
        g_true_values: Array of true shear values.
        g_est_means: Array of estimated shear means.
        g_est_stds: Array of estimated shear standard deviations.
        component: Shear component name ("g1" or "g2").
        output_dir: Directory to save plot.
        m: Multiplicative bias (for regression line).
        c: Additive bias (for regression line).

    Returns:
        Path to saved plot.

    Raises:
        NotImplementedError: This function is a stub for Level 1+.
    """
    raise NotImplementedError(
        "plot_bias_vs_shear() is planned for Level 1+."
    )

plot_coverage(alpha_levels, observed_coverage, output_dir)

Plot observed vs expected coverage.

Parameters:

Name Type Description Default
alpha_levels List[float]

Expected coverage levels.

required
observed_coverage List[float]

Observed coverage fractions.

required
output_dir str

Directory to save plot.

required

Returns:

Type Description
Path

Path to saved plot.

Raises:

Type Description
NotImplementedError

This function is a stub for Level 1+.

Source code in shine/validation/plots.py
def plot_coverage(
    alpha_levels: List[float],
    observed_coverage: List[float],
    output_dir: str,
) -> Path:
    """Plot observed vs expected coverage.

    Args:
        alpha_levels: Expected coverage levels.
        observed_coverage: Observed coverage fractions.
        output_dir: Directory to save plot.

    Returns:
        Path to saved plot.

    Raises:
        NotImplementedError: This function is a stub for Level 1+.
    """
    raise NotImplementedError(
        "plot_coverage() is planned for Level 1+."
    )

plot_sbc_histogram(ranks, param, output_dir)

Plot SBC rank histogram.

Parameters:

Name Type Description Default
ranks ndarray

Array of rank statistics.

required
param str

Parameter name.

required
output_dir str

Directory to save plot.

required

Returns:

Type Description
Path

Path to saved plot.

Raises:

Type Description
NotImplementedError

This function is a stub for Level 1+.

Source code in shine/validation/plots.py
def plot_sbc_histogram(
    ranks: np.ndarray,
    param: str,
    output_dir: str,
) -> Path:
    """Plot SBC rank histogram.

    Args:
        ranks: Array of rank statistics.
        param: Parameter name.
        output_dir: Directory to save plot.

    Returns:
        Path to saved plot.

    Raises:
        NotImplementedError: This function is a stub for Level 1+.
    """
    raise NotImplementedError(
        "plot_sbc_histogram() is planned for Level 1+."
    )