Spaces:
Sleeping
Sleeping
File size: 3,883 Bytes
d4a8b05 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | #!/usr/bin/env python3
"""
Basic Calibration Example
This example demonstrates the core calibration workflow:
1. Read a step tablet scan
2. Analyze the density response
3. Generate a linearization curve
4. Export to QTR format
"""
import sys
from pathlib import Path
# Add parent directory to path for development
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from ptpd_calibration import (
StepTabletReader,
CurveGenerator,
CurveAnalyzer,
QTRExporter,
TabletType,
)
from ptpd_calibration.core.types import CurveType
def main():
# Configuration
scan_path = Path("step_tablet_scan.tiff") # Replace with your scan
output_path = Path("linearization_curve.txt")
# Paper and chemistry info
paper_type = "Arches Platine"
chemistry = "50% Pt / 50% Pd, 5 drops Na2"
print("=" * 60)
print("Pt/Pd Calibration - Basic Example")
print("=" * 60)
# Check if scan exists, otherwise use demo densities
if scan_path.exists():
print(f"\nReading step tablet from: {scan_path}")
# Initialize reader
reader = StepTabletReader(tablet_type=TabletType.STOUFFER_21)
# Read the scan
result = reader.read(scan_path)
print(f"\nExtraction Results:")
print(f" Patches detected: {result.extraction.num_patches}")
print(f" Dmin (paper base): {result.extraction.dmin:.3f}")
print(f" Dmax: {result.extraction.dmax:.3f}")
print(f" Density range: {result.extraction.density_range:.3f}")
print(f" Quality score: {result.extraction.overall_quality:.1%}")
if result.extraction.warnings:
print(f"\nWarnings:")
for warning in result.extraction.warnings:
print(f" - {warning}")
densities = result.extraction.get_densities()
else:
print(f"\nNo scan found at {scan_path}")
print("Using demo density values...")
# Demo densities (typical Pt/Pd response)
import numpy as np
steps = np.linspace(0, 1, 21)
densities = list(0.1 + 2.0 * (steps ** 0.85))
print(f"\nDemo Densities:")
print(f" Dmin: {min(densities):.3f}")
print(f" Dmax: {max(densities):.3f}")
print(f" Range: {max(densities) - min(densities):.3f}")
# Analyze the response
print("\n" + "-" * 60)
print("Density Analysis")
print("-" * 60)
analysis = CurveAnalyzer.analyze_linearity(densities)
print(f" Monotonic: {analysis.is_monotonic}")
print(f" Max linearity error: {analysis.max_error:.3f}")
print(f" RMS error: {analysis.rms_error:.3f}")
suggestions = CurveAnalyzer.suggest_adjustments(densities)
print("\nRecommendations:")
for suggestion in suggestions:
print(f" • {suggestion}")
# Generate curve
print("\n" + "-" * 60)
print("Generating Calibration Curve")
print("-" * 60)
generator = CurveGenerator()
curve = generator.generate(
densities,
curve_type=CurveType.LINEAR,
name=f"{paper_type} - Linear",
paper_type=paper_type,
chemistry=chemistry,
)
print(f" Curve name: {curve.name}")
print(f" Curve type: {curve.curve_type.value}")
print(f" Output points: {len(curve.output_values)}")
# Analyze the generated curve
curve_analysis = CurveAnalyzer.analyze_curve(curve)
print(f" Curve shape: {curve_analysis['shape']}")
print(f" Max deviation: {curve_analysis['max_deviation']:.3f}")
# Export
print("\n" + "-" * 60)
print("Exporting Curve")
print("-" * 60)
exporter = QTRExporter()
exporter.export(curve, output_path)
print(f" Exported to: {output_path}")
print(f" Format: QuadTone RIP")
print("\n" + "=" * 60)
print("Calibration complete!")
print("=" * 60)
return curve
if __name__ == "__main__":
main()
|