flat_normalize_response¶
Flat-field a 2-D spectral frame with a flat normalised along the dispersion.
| Category | Preprocessing (2-D image) |
| Backend | scipy - implemented here on top of scipy primitives |
| Version | 1.0.0 |
| Reads | ctx.image (an ImageFrame) |
| Writes | image, metrics.applied, metrics.science_pedestal_adu, metrics.lit_col_lo, metrics.lit_col_hi, metrics.lit_rows, metrics.corrected_fraction, metrics.pixel_response_std, metrics.illumination_p5, metrics.illumination_p95 |
N(y, x) = (flat − pedestal) / S(x), S the lamp spectrum (median of the lit rows, median-filtered over smooth_px columns then Gaussian-smoothed with σ = smooth_px / 6), scaled to median 1 over the lit area ; the flat's pedestal is the master bias at bias_key when present, else the median of its darkest 5 % of columns. Pixels outside the lit area, or whose response falls outside [min_response, max_response], get N = 1 and are left untouched. The science frame is corrected as (image − p) / N + p : with pedestal_mode = 'dark_margin' and no master bias on the context, p is the sigma-clipped mean (clip_sigma) of the science pixels in the columns the lamp never reaches on pedestal_side of the lit span (at least min_pedestal_columns of them), so a pedestal still in the frame is not multiplied by the flat pattern and a later margin-pedestal subtraction still finds it ; otherwise p = 0. Metrics: applied, science_pedestal_adu, lit_col_lo / lit_col_hi (first lit column and last lit column + 1, −1 when none), lit_rows, corrected_fraction, pixel_response_std (scatter of N over a 15-column running mean, the pixel-to-pixel part), illumination_p5 / illumination_p95 (5th and 95th percentiles of the row medians of N over the lit columns, the slit-illumination part ; a row with one unusable lit pixel has no median and the percentiles fall back to 1.0 when no row survives). Header FLATCOR = True. Companion: flat_normalize divides by the flat over one global median and keeps the lamp shape ; use it for imaging-like flats, this brick for spectroscopic ones.
Parameters¶
| Parameter | Default | Required | Description |
|---|---|---|---|
flat_key |
'master_flat' |
- | ctx.extras key of the raw master flat (ImageFrame). |
bias_key |
'master_bias' |
- | ctx.extras key of the master bias subtracted from the flat ; absent, the flat's darkest columns give its pedestal. |
smooth_px |
51 |
- | Running-median window (columns) of the lamp spectrum ; larger keeps more column-to-column response in N. At least 3. |
min_signal_fraction |
0.25 |
- | Columns (and rows) where the lamp is below this fraction of its peak are not corrected. |
min_response |
0.2 |
- | Pixels whose normalised response is below this are not corrected. |
max_response |
5.0 |
- | Pixels whose normalised response is above this are not corrected. |
pedestal_mode |
'none' |
- | 'none': divide the frame as it is ; 'dark_margin': hold the science pedestal out of the division, measured on the unlit columns (only when no master bias is on the context). |
pedestal_side |
'both' |
- | Which unlit columns measure the science pedestal: 'low' (below the lit span), 'high' (above it) or 'both'. |
min_pedestal_columns |
10 |
- | Fewer unlit columns than this and the pedestal stays 0. |
clip_sigma |
4.0 |
- | Sigma of the clipped mean that measures the science pedestal. |
Use it¶
from spectro_kernel import run_algorithm
output = run_algorithm("flat_normalize_response", ctx, {
"flat_key": "master_flat",
"bias_key": "master_bias",
"smooth_px": 51,
"min_signal_fraction": 0.25,
"min_response": 0.2,
"max_response": 5.0,
"pedestal_mode": "none",
"pedestal_side": "both",
"min_pedestal_columns": 10,
"clip_sigma": 4.0
})
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.
{
"tool": "flat_normalize_response",
"arguments": {
"session_id": "<session_id>",
"params": {
"flat_key": "master_flat",
"bias_key": "master_bias",
"smooth_px": 51,
"min_signal_fraction": 0.25,
"min_response": 0.2,
"max_response": 5.0,
"pedestal_mode": "none",
"pedestal_side": "both",
"min_pedestal_columns": 10,
"clip_sigma": 4.0
}
}
}
Every algorithm is an MCP tool of the same name; describe_algorithm returns
this page's metadata as JSON.
References¶
- Massey, Valdes & Barnes 1992 — A User's Guide to Reducing Slit Spectra with IRAF, NOAO (the
responsenormalisation of spectroscopic flats). - Howell 2006 — Handbook of CCD Astronomy, 2nd ed., ch. 4 (bias out before the flat division).
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_smile_xcorr- Straighten the spectral lines ofctx.imagefrom the frame's own lines.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- Subtract the master bias, a constant level, or the pedestal of the frame's margin.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.subtract_sky_2d- Subtract a per-column sky model fitted from off-trace rows ofctx.image.