linumpy.metrics#
Metrics module for collecting and saving quality metrics from pipeline steps.
This module provides utilities for recording, saving, and aggregating metrics from various processing steps in the 3D reconstruction pipeline.
- Usage:
# Use step-specific collectors (recommended) from linumpy.metrics import collect_pairwise_registration_metrics
Submodules#
Attributes#
Classes#
Custom JSON encoder to handle numpy types. |
|
Class for collecting and managing metrics from pipeline steps. |
Functions#
|
Collect metrics for intensity normalization step. |
|
Collect metrics for XY transform estimation step. |
|
Collect metrics for pairwise registration step. |
|
Collect metrics for interface cropping step. |
|
Collect metrics for PSF compensation step. |
|
Collect metrics for slice stacking step. |
|
Collect metrics for 3D tile stitching step. |
|
Load metrics from a JSON file. |
|
Aggregate all metrics files from a directory. |
|
Compute summary statistics for a list of metrics from the same step. |
Package Contents#
- class linumpy.metrics.MetricsEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#
Bases:
json.JSONEncoderCustom JSON encoder to handle numpy types.
- class linumpy.metrics.PipelineMetrics(step_name, output_dir=None)[source]#
Class for collecting and managing metrics from pipeline steps.
Each step can record multiple metrics with associated quality indicators. Metrics are saved as JSON files for later aggregation and report generation.
- add_metric(name, value, unit=None, threshold_name=None, custom_thresholds=None, description=None)[source]#
Add a metric with optional quality assessment.
- Parameters:
name (str) – Name of the metric.
value (Any) – Value of the metric.
unit (str, optional) – Unit of measurement.
threshold_name (str, optional) – Name of threshold to use from DEFAULT_THRESHOLDS.
custom_thresholds (dict, optional) – Custom thresholds {‘warning’: val, ‘error’: val, ‘higher_is_better’: bool}
description (str, optional) – Human-readable description of the metric.
- Return type:
None
- get_overall_status()[source]#
Get overall status based on all metrics.
- Returns:
‘error’, ‘warning’, or ‘ok’
- Return type:
- to_dict()[source]#
Convert metrics to dictionary format.
- Returns:
Dictionary containing all metrics and metadata.
- Return type:
- linumpy.metrics.collect_normalization_metrics(vol_normalized, agarose_mask, otsu_threshold, background_thresholds, output_path, input_path=None, params=None)[source]#
Collect metrics for intensity normalization step.
- Parameters:
vol_normalized (np.ndarray) – The normalized volume.
agarose_mask (np.ndarray) – The agarose mask used.
otsu_threshold (float) – Otsu threshold computed.
background_thresholds (np.ndarray) – Background thresholds per slice.
output_path (str or Path) – Path to the output file.
input_path (str, optional) – Path to the input image.
params (dict, optional) – Dictionary of parameters used.
- Returns:
Metrics object (already saved).
- Return type:
- linumpy.metrics.collect_xy_transform_metrics(transform, tile_pairs_used, tile_shape, residuals, output_path, input_paths=None, params=None, n_tiles_x=None, n_tiles_y=None)[source]#
Collect metrics for XY transform estimation step.
- Parameters:
transform (np.ndarray) – The estimated 2x2 transform matrix.
tile_pairs_used (int) – Number of tile pairs used for estimation.
tile_shape (tuple) – Tile shape (rows, cols).
residuals (np.ndarray) – Residuals from least squares fit.
output_path (str or Path) – Path to the output transform file.
input_paths (list, optional) – List of input image paths.
params (dict, optional) – Dictionary of parameters used.
n_tiles_x (int, optional) – Number of tiles in the X (column) direction.
n_tiles_y (int, optional) – Number of tiles in the Y (row) direction.
- Returns:
Metrics object (already saved).
- Return type:
- linumpy.metrics.collect_pairwise_registration_metrics(registration_error, tx, ty, rotation_deg, best_z_index, expected_z_index, output_path, fixed_path=None, moving_path=None, params=None, z_correlation=0.0)[source]#
Collect metrics for pairwise registration step.
- Parameters:
registration_error (float) – Registration error value.
tx (float) – Translation in X and Y.
ty (float) – Translation in X and Y.
rotation_deg (float) – Rotation in degrees.
best_z_index (int) – Best matching z-index.
expected_z_index (int) – Expected z-index based on slice interval.
output_path (str or Path) – Path to the output directory.
fixed_path (str, optional) – Paths to fixed and moving volumes.
moving_path (str, optional) – Paths to fixed and moving volumes.
params (dict, optional) – Dictionary of parameters used.
z_correlation (float, optional) – Normalized cross-correlation score from Z-matching (0-1). Higher values indicate a reliable Z-match between the two slices.
- Returns:
Metrics object (already saved).
- Return type:
- linumpy.metrics.collect_interface_crop_metrics(detected_interface, crop_depth_px, start_idx, end_idx, input_shape, output_shape, resolution_um, output_path, input_path=None, padding_needed=False)[source]#
Collect metrics for interface cropping step.
- Parameters:
detected_interface (int) – Detected interface depth in voxels.
crop_depth_px (int) – Cropping depth in voxels.
start_idx (int) – Start and end indices for cropping.
end_idx (int) – Start and end indices for cropping.
input_shape (tuple) – Input and output volume shapes.
output_shape (tuple) – Input and output volume shapes.
resolution_um (float) – Resolution in microns.
output_path (str or Path) – Path to the output file.
input_path (str, optional) – Path to the input file.
padding_needed (bool) – Whether padding was required.
- Returns:
Metrics object (already saved).
- Return type:
- linumpy.metrics.collect_psf_compensation_metrics(psf, agarose_coverage, output_path, input_path=None, fit_gaussian=False)[source]#
Collect metrics for PSF compensation step.
- Parameters:
- Returns:
Metrics object (already saved).
- Return type:
- linumpy.metrics.collect_stack_metrics(output_shape, z_offsets, num_slices, resolution, output_path, blend_enabled=False, normalize_enabled=False)[source]#
Collect metrics for slice stacking step.
- Parameters:
output_shape (tuple) – Final output shape.
z_offsets (np.ndarray) – Z-offsets between consecutive slices.
num_slices (int) – Number of slices stacked.
resolution (list) – Output resolution.
output_path (str or Path) – Path to the output file.
blend_enabled (bool) – Whether blending was enabled.
normalize_enabled (bool) – Whether normalization was enabled.
- Returns:
Metrics object (already saved).
- Return type:
- linumpy.metrics.collect_stitch_3d_metrics(input_shape, output_shape, num_tiles, resolution, output_path, input_path=None, blending_method='diffusion')[source]#
Collect metrics for 3D tile stitching step.
- Parameters:
input_shape (tuple) – Input mosaic grid shape.
output_shape (tuple) – Output stitched volume shape.
num_tiles (int) – Number of tiles stitched.
resolution (list) – Output resolution.
output_path (str or Path) – Path to the output file.
input_path (str, optional) – Path to the input file.
blending_method (str) – Blending method used.
- Returns:
Metrics object (already saved).
- Return type: