Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A raw frame is not a picture of the sky
A telescope camera counts electrons in each pixel, but the count includes things that are not starlight. The electronics add a fixed offset. The warm detector produces electrons of its own. Some pixels are more sensitive than others, and the optics dim the corners. Cosmic rays leave bright streaks. Calibration removes each of these with special frames taken for the purpose, and stacking several exposures beats down the noise and rejects the streaks. The demo shows how the signal-to-noise ratio of a star grows with exposure time and which noise source dominates.
The same chain (bias, dark, flat, outlier rejection, stacking) reduces images from survey telescopes, space observatories, star trackers and Earth-observation cameras. Getting it wrong shows up as false variability, wrong fluxes and fake detections downstream.
- 1. A bias frame records…
- 2. A flat field corrects…
- 3. Stacking several exposures…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Detectors. Optical cameras use CCDs or, increasingly, CMOS sensors; infrared arrays (HgCdTe, as on JWST and Euclid’s NISP) are read non-destructively many times during an exposure (“up the ramp”), and the count rate is the slope of the ramp. Pixel values are in ADU; the gain converts them to electrons.
- Calibration frames. Bias (zero-second exposures, median-combined): the electronic offset and its pattern. Dark (shutter closed, same exposure time): thermal current and hot pixels. Flat (uniformly lit dome, twilight sky or night-sky frames, normalised to 1): pixel sensitivity, vignetting and dust shadows. Red bands may also need fringe frames.
- Calibrated image. (raw − bias − dark rate × t) / flat, plus a bad-pixel mask. Cosmic rays are rejected by comparing several exposures (sigma clipping) or, in a single frame, by their sharpness (L.A.Cosmic, van Dokkum 2001).
- Noise budget: the CCD equation. SNR = S / √(S + n_pix (sky + dark + read²)), all in electrons. Bright stars are source-limited, most survey targets sky-limited, short or narrow-band exposures read-noise-limited.
- After calibration. Astrometric solution (WCS) against Gaia, often with astrometry.net (Lang et al. 2010); photometric zero points against reference stars; resampling and co-addition (drizzle, Fruchter and Hook 2002; SWarp); catalogue extraction (G6-2).
- Pipelines and data. Astropy with ccdproc, photutils and reproject; the JWST calibration pipeline (stages 1 to 3: ramps to rates, calibrated exposures, combined products); the Rubin LSST Science Pipelines. Archives: MAST (HST, JWST, TESS), ESA’s archives (Gaia, Euclid), IRSA and NOIRLab’s Astro Data Lab.
- Surveys at scale. Rubin Observatory’s 8.4 m telescope with its 3.2-gigapixel camera produces about 20 TB per night; Euclid (launched 2023) is imaging a third of the sky in the optical and near-infrared from space.
- 1. Hot pixels are removed with…
- 2. Infrared arrays on JWST measure the count rate from…
- 3. A sky-limited observation's SNR grows as…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Reducing a night of images
Exercise 1.
- Master bias and master flat frames by median combination.
- The calibration formula.
- A sigma-clipped mean along a stack.
- The CCD equation.
Practice.
- Take enough calibration frames: noise in a master frame is added to every science frame; use tens of biases and flats with high counts (but well below saturation).
- Match conditions: darks at the same temperature and exposure time (or scale a dark rate); flats with the same filter and focus.
- Look at the data: display with a zscale or asinh stretch; inspect histograms of bias, dark and flat; check the flat for dust rings.
- Combine with rejection: sigma-clipped mean or median; align frames first with the WCS (reproject) for dithered data.
- Keep provenance in FITS headers: which masters, which software version, units (BUNIT) and the gain.
- For space data: start from the pipeline products (JWST _cal or _i2d files) and rerun stages only when you need different parameters.
import numpy as np
import ccdproc
from astropy.nddata import CCDData
bias = ccdproc.combine([CCDData.read(f, unit="adu") for f in bias_files], method="median")
flat = ccdproc.combine([ccdproc.subtract_bias(CCDData.read(f, unit="adu"), bias) for f in flat_files],
method="median", scale=lambda a: 1 / np.median(a))
sci = [ccdproc.flat_correct(ccdproc.subtract_bias(CCDData.read(f, unit="adu"), bias), flat) for f in sci_files]
stack = ccdproc.combine(sci, method="average", sigma_clip=True, sigma_clip_low_thresh=3, sigma_clip_high_thresh=3)
stack.write("stack.fits", overwrite=True)- 1. Why use many bias and flat frames?
- 2. A good display stretch for astronomical images:
- 3. Darks should match the science frames in…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Error propagation. With S electrons from the source spread over n_pix pixels, Poisson noise on source, sky and dark plus Gaussian read noise add in variance, which gives the CCD equation (Howell, Handbook of CCD Astronomy). Calibration frames add their own noise: a master bias from N frames contributes read²/N per pixel.
Multiplicative errors. The flat divides the image, so a flat that is 10% wrong in one corner makes every star there 10% wrong. Local sky subtraction cannot remove it. Bias and dark are additive: local sky subtraction removes most of a smooth error, but hot pixels inside an aperture do not cancel.
Combining estimators. For N frames of Gaussian noise the mean has the lowest variance, σ²/N. The median of many values has variance about (π/2) σ²/N, a noise penalty of √(π/2) ≈ 1.25 (slightly less for small N). The median is robust to a few outliers. A sigma-clipped mean keeps most of the efficiency of the mean and rejects cosmic rays, but too low a k clips good data and adds noise.
Up-the-ramp fitting. With non-destructive reads, the slope by least squares gives the rate; a cosmic ray is a jump between two reads and can be removed by fitting the segments on either side.
- 1. A median stack's noise relative to a mean of many frames:
- 2. Why can local sky subtraction not fix a bad flat?
- 3. A master bias from N frames adds…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How much does each calibration and stacking step matter for photometry?
History.
- W. Boyle and G. Smith invented the CCD in 1969; CCDs replaced photographic plates in astronomy during the 1980s.
- P. van Dokkum, “Cosmic-ray rejection by Laplacian edge detection” (2001).
- A. Fruchter and R. Hook, “Drizzle: a method for the linear reconstruction of undersampled images” (2002).
Exercise 2. A 96 × 96 detector, gain 1 e/ADU, read noise 5 e.
- Defects: bias of 500 ADU with a column pattern; dark current 0.02 e/s with 1% hot pixels at 3 e/s; a flat with 25% vignetting at the corners and 2% pixel-to-pixel variation.
- Scene: 25 stars (3000 to 60000 e) on a 100 e sky, PSF σ 1.5 px; nine 60-second exposures with 20 cosmic-ray hits each.
- Calibration frames: 15 biases, 9 darks and 15 flats.
- Measure: aperture photometry (radius 4 px, sky annulus 7 to 10 px) against the true fluxes, background noise, and pixels more than 6σ from the truth.
| product | flux rms error | worst star | background noise (e) | outlier pixels |
|---|---|---|---|---|
| one calibrated frame | 0.113 | 0.457 | 11.1 | 46 |
| mean of 9 | 0.071 | 0.238 | 4.00 | 370 |
| median of 9 | 0.0117 | 0.026 | 4.78 | 1 |
| sigma-clipped mean of 9 | 0.0107 | 0.024 | 4.35 | 0 |
| clipped mean, no flat | 0.095 | 0.173 | 6.08 | 1255 |
| clipped mean, no dark | 0.017 | 0.063 | 4.18 | 96 |
- Cosmic rays dominate single frames. A plain mean only dilutes them by nine, which still leaves 370 pixels above 6σ.
- Median versus clipped mean. Both remove the hits; the median’s noise is 1.20× the mean’s, and the clipped mean’s is 1.09×.
- The flat field matters most for photometry: without it, vignetting gives a 9.5% rms error (17% for the worst star).
- The dark matters for outliers: hot pixels survive stacking because they are in every frame.
- Seeds 1 and 2: clipped-mean error 0.020 and 0.013, median 0.024 and 0.012, no-flat 0.095 and 0.107, mean-stack outliers 362 and 351, median-to-mean noise 1.18 and 1.17. The no-dark error varied from 0.017 to 0.074, depending on whether hot pixels fall in apertures.
- Caveat: perfectly aligned frames and a Gaussian PSF; real stacks also need registration and PSF-aware weighting.
Telescope data in AI, robotics and aerospace
- Space telescopes: JWST, Euclid and Roman ship calibrated products from standard pipelines; machine-learning work usually starts from those, not from raw ramps.
- Rubin Observatory: the LSST Science Pipelines calibrate and co-add about 20 TB per night; the same steps feed its real-time alerts (G6-3).
- Star trackers and space situational awareness: onboard dark and flat correction and cosmic-ray rejection run before star identification and debris detection.
- Learning-based calibration: CNN cosmic-ray detectors such as deepCR (Zhang and Bloom 2020) replace hand-tuned rules for single exposures.
References
- S. Howell (2006). Handbook of CCD Astronomy, 2nd edition. Cambridge University Press.
- P. van Dokkum (2001). “Cosmic-ray rejection by Laplacian edge detection.” PASP 113.
- A. Fruchter and R. Hook (2002). “Drizzle: a method for the linear reconstruction of undersampled images.” PASP 114.
- D. Lang et al. (2010). “Astrometry.net: blind astrometric calibration of arbitrary astronomical images.” AJ 139.
- Astropy Collaboration (2022). “The Astropy Project: sustaining and growing a community-oriented open-source project and the latest major release (v5.0) of the core package.” ApJ 935.
- K. Zhang and J. Bloom (2020). “deepCR: cosmic ray rejection with deep learning.” ApJ 889.