Skip to content

wavelength_calibrate_polynomial

Fit a polynomial to (pixel → wavelength) pairs, or apply known coefficients.

Category Wavelength calibration
Backend numpy - implemented here on top of numpy primitives
Version 1.1.0
Reads ctx.spectrum (a Spectrum1D)
Writes spectrum, metrics.calibration_rms_angstrom, metrics.applied, metrics.wavelength_min_angstrom, metrics.wavelength_max_angstrom, metrics.dispersion_angstrom_per_px

The polynomial is fitted with numpy.polynomial.Polynomial.fit, which handles the domain mapping so high orders stay well-conditioned. pixel_positions are 0-based indices on the current ctx.spectrum.wavelength axis (see the class docstring). v1.1.0 — apply mode: with coefficients the brick evaluates the given polynomial instead of fitting one ; coefficients_order says whether the list is lowest-degree first (numpy.polynomial convention, the default) or highest-degree first (numpy.polyval convention), pixel_offset is added to the pixel axis before the evaluation (absolute detector columns). The new axis must be strictly increasing, otherwise the brick fails and points at the coefficient order. Apply mode writes meta['wavelength_calibration'] = {method: 'polynomial_coefficients', coefficients, coefficients_order, pixel_offset}, wavelength_calibrated = True and needs_wavelength_calibration = False, and reports applied, wavelength_min_angstrom, wavelength_max_angstrom and dispersion_angstrom_per_px (no calibration_rms_angstrom: nothing was fitted). It does not resample: chain resample_linear for a uniform grid. The fit path (coefficients absent) is byte-identical to 1.0.1.

Parameters

Parameter Default Required Description
pixel_positions None - List of 0-based pixel indices identified in the arc spectrum (same frame as ctx.spectrum.wavelength; first sample = 0).
wavelengths_angstrom None - Rest wavelengths corresponding to those pixels (Å).
order 3 - Polynomial degree (fit mode).
coefficients None - Known polynomial coefficients λ(x) in Å (apply mode, no fit); at least two. Leave null to fit pixel_positions / wavelengths_angstrom.
coefficients_order 'lowest_first' - 'lowest_first' (c0 + c1·x + c2·x² …, numpy.polynomial convention) or 'highest_first' (numpy.polyval convention).
pixel_offset 0 - Added to the pixel axis before evaluating the coefficients: the detector column of the spectrum's first sample when the solution is expressed in absolute columns (apply mode only).

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("wavelength_calibrate_polynomial", ctx, {
    "pixel_positions": None,
    "wavelengths_angstrom": None,
    "order": 3,
    "coefficients": None,
    "coefficients_order": "lowest_first",
    "pixel_offset": 0
})
spectro run wavelength_calibrate_polynomial --input spectrum.fits \
  --param pixel_positions=none \
  --param wavelengths_angstrom=none \
  --param order=3 \
  --param coefficients=none \
  --param coefficients_order=lowest_first \
  --param pixel_offset=0
{
  "tool": "wavelength_calibrate_polynomial",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "pixel_positions": null,
      "wavelengths_angstrom": null,
      "order": 3,
      "coefficients": null,
      "coefficients_order": "lowest_first",
      "pixel_offset": 0
    }
  }
}

Every algorithm is an MCP tool of the same name; describe_algorithm returns this page's metadata as JSON.

References

  • Tody 1986, Proc. SPIE 627, 733 — IRAF identify: polynomial dispersion solution fitted through identified arc lines.
  • Tody 1993, ASP Conf. Ser. 52, 173 — IRAF in the Nineties (identify / dispcor dispersion functions).
  • Massey & Hanson 2013, Astronomical Spectroscopy, in Planets, Stars and Stellar Systems vol. 2, Springer, DOI 10.1007/978-94-007-5618-2_2 (arXiv:1010.5270) — dispersion solutions as low-order polynomials of the detector column.