Optimal Extraction Algorithm
Overview
Optimal extraction (Horne 1986) maximizes signal-to-noise ratio by weighting spatial pixels according to the spatial profile and inverse variance. This outperforms simple aperture summation, especially for faint sources.
Method: Horne 1986 Algorithm
The optimal extraction algorithm computes extracted flux as:
where:
\(D(y, \\lambda)\) = 2D sky-subtracted data
\(P(y)\) = normalized spatial profile
\(V(y, \\lambda)\) = variance (read noise + Poisson)
\(y\) = spatial coordinate
\(\\lambda\) = wavelength coordinate
Algorithm Steps
Fit Spatial Profile
Fit Gaussian (or Moffat) to spatial cross-section:
\[\begin{split}P(y) = A \\exp\\left(-\\frac{(y - y_0)^2}{2\\sigma^2}\\right)\end{split}\]Compute Variance
Propagate noise from read noise and Poisson statistics:
\[\begin{split}V(y, \\lambda) = (\\text{readnoise})^2 + \\text{gain} \\cdot D(y, \\lambda)\end{split}\]Weighted Extraction
Apply profile weights normalized by variance
Cosmic Ray Masking
Pixels flagged as cosmic rays get zero weight
Advantages Over Aperture Extraction
Signal-to-Noise Improvement:
Typical gain: 10-30% for point sources
Greater improvement for faint sources
Down-weights noisy edge pixels
Optimal Use of Data:
All pixels in aperture contribute
Weights match actual spatial profile
Robust to seeing variations
Comparison: Optimal vs Boxcar
Aspect |
Optimal Extraction |
Boxcar (Aperture Sum) |
|---|---|---|
SNR |
Higher (weighted by profile) |
Lower (equal weights) |
Implementation |
Complex (profile fitting) |
Simple (sum pixels) |
Robustness |
Sensitive to profile errors |
Robust, less optimal |
Speed |
Slower (~2×) |
Faster |
Best for |
Faint sources, precision |
Bright sources, quick-look |
When to Use Boxcar Instead
Boxcar extraction preferred when:
Very bright sources (SNR > 50)
Poor spatial profile fit (extended/irregular)
Quick-look / exploratory analysis
Profile varies significantly along spectrum
Configure in YAML:
extraction:
method: boxcar # or 'optimal'
aperture_width: 10
Spatial Profile Fitting
Gaussian Profile:
Best for: Point sources, good seeing
Parameters: amplitude, center, width
Moffat Profile:
Best for: Extended wings, poor seeing
Parameters: amplitude, center, width, power
Empirical Profile:
Use actual data profile without parametric fit
Robust when profile shape unknown
Fallback if Gaussian/Moffat fail
Variance Propagation
Total variance combines read noise and Poisson noise:
where:
\(\\sigma_{read}\) = read noise (electrons)
\(g\) = gain (e⁻/ADU)
\(D\) = data (ADU)
Uncertainty in extracted flux:
Parameters
- aperture_width: 10 pixels
Width of extraction region around trace center
- profile_type: ‘Gaussian’
Spatial profile model (‘Gaussian’, ‘Moffat’, ‘empirical’)
- method: ‘optimal’
Extraction method (‘optimal’, ‘boxcar’)
Performance
Typical Metrics:
SNR improvement: 15-25% over boxcar
Extraction time: 1-3 seconds per trace
Profile fit χ²: <2.0 for good data
Failure Modes:
Poor profile fit (χ² > 10):
Use empirical profile
Or fall back to boxcar
Negative flux values:
Sky over-subtracted
Increase sky_buffer parameter
References
Horne, K. 1986, PASP, 98, 609 - “An Optimal Extraction Algorithm for CCD Spectroscopy”
Marsh, T. R. 1989, PASP, 101, 1032 - “The Extraction of Highly Distorted Spectra”
See Also
Extraction Module - API reference
Configuration Reference - Extraction parameters
Trace Detection Algorithm - Trace detection