subtract_sky_2d¶
Subtract a per-column sky model fitted from off-trace rows of ctx.image.
| Category | Preprocessing (2-D image) |
| Backend | numpy - implemented here on top of numpy primitives |
| Version | 1.0.1 |
| Reads | ctx.image (an ImageFrame) |
| Writes | image, metrics.sky_median |
Sky regions are taken on either side of the trace and far enough away to be clean of stellar flux. The fit defaults to a degree-1 polynomial (linear gradient across the slit), which handles tilted sky and twilight gradients without over-fitting. v1.0.1: all columns are fitted in one vectorised least-squares call (numpy.polyfit on the 2-D sky block) — identical numbers, ~60× faster on a 200×2048 frame.
Parameters¶
| Parameter | Default | Required | Description |
|---|---|---|---|
trace_row |
None |
yes | Approximate y-pixel of the spectral trace. |
trace_half_width |
8 |
- | Half-width (rows) of the protected aperture around the trace. |
sky_offset |
4 |
- | Number of rows between trace edge and sky window start. |
sky_half_width |
10 |
- | Half-width (rows) of each sky window. |
poly_order |
1 |
- | Polynomial degree for the per-column cross-slit sky fit (0 = constant). |
Use it¶
The CLI loads a single 1-D spectrum with --input; this algorithm needs
ctx.image (an ImageFrame). Run it from Python or as a step of a pipeline preset.
References¶
- Horne 1986, PASP 98, 609 — §2 (standard extraction): sky estimated at each wavelength by a low-order polynomial fit across the spatial direction to the pixels outside the object aperture.
- Tody 1986, Proc. SPIE 627, 733 — IRAF apall background fitting (per-column polynomial in the background windows).
Related algorithms¶
correct_slant_affine- Make monochromatic lines parallel to the rows by a horizontal shear.correct_smile_polynomial- Undo smile curvature via the Schroeder even-order expansion.correct_tilt_affine- Re-align the slit with the detector columns by a vertical shear.dark_subtract- Subtract a master dark fromctx.image.denoise_gaussian_2d- Separable isotropic Gaussian smoothing ofctx.image.denoise_median_2d- Square median filter overctx.image, optionally banded by rows.flat_normalize- Dividectx.imageby a master flat normalised to unity.flat_normalize_easyspec- Flat-field correct a science frame viacleaning.flatten.outlier_rejection_mad_adaptive- Replace pixels whose deviation from a local median exceedsthreshold·MAD.subtract_bias_easyspec- Subtract a master bias from a single science frame viacleaning.debias.subtract_dark_easyspec- Subtract a master dark from a science frame viacleaning.sub_dark.