Skip to content

combine_spectra_arithmetic

Add, subtract, multiply or divide ctx.spectrum by a reference.

Category Transforms
Backend numpy - implemented here on top of numpy primitives
Version 2.0.0
Reads ctx.spectrum (a Spectrum1D)
Writes spectrum

operation ∈ {add, sub, mul, div}. For 'div', samples where |reference| < min_denominator become NaN (clamp on near-zero responses). Pass-through outside the reference domain matches IRAF sarith and prevents wing zero-out. v2.0.0 — uncertainty propagation (independent errors, Bevington & Robinson §3.2) : add/sub σ = sqrt(σ_s² + σ_r²) ; mul/div σ = |result| · sqrt((σ_s/s)² + (σ_r/r)²) when the reference carries an uncertainty (σ_r resampled as sqrt(interp(σ_r²))), else σ = σ_s · |r| (mul) or σ_s / |r| (div). Outside the reference domain σ passes through with the flux ; NaN samples get a NaN σ ; a science spectrum without uncertainty stays without one. No covariance between science and reference is assumed (a response derived from the same night's standard is treated as independent).

Parameters

Parameter Default Required Description
operation 'div' - One of 'add', 'sub', 'mul', 'div'.
min_denominator 5e-05 - Division samples with |reference| below this become NaN. Ignored for non-div operations.
reference_path None - Path / URL of a FITS reference spectrum (loaded with read_fits).
reference_key 'reference_spectrum' - ctx.extras key holding a Spectrum1D reference.

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("combine_spectra_arithmetic", ctx, {
    "operation": "div",
    "min_denominator": 5e-05,
    "reference_path": None,
    "reference_key": "reference_spectrum"
})
spectro run combine_spectra_arithmetic --input spectrum.fits \
  --param operation=div \
  --param min_denominator=5e-05 \
  --param reference_path=none \
  --param reference_key=reference_spectrum
{
  "tool": "combine_spectra_arithmetic",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "operation": "div",
      "min_denominator": 5e-05,
      "reference_path": null,
      "reference_key": "reference_spectrum"
    }
  }
}

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 sarith heritage.
  • Astropy Collaboration (Robitaille et al.) 2013, A&A 558, A33 — the astropy units layer whose arithmetic conventions this brick follows ; specutils arithmetic (documentation) is the reference implementation of spectrum ± × ÷ spectrum.
  • Bevington & Robinson 2003, Data Reduction and Error Analysis for the Physical Sciences, 3rd ed., McGraw-Hill — §3.2, propagation of errors through sums, products and quotients.
  • clip_sigma - Remove outlier samples (cosmic rays, hot pixels) by iterative sigma clipping.
  • extract_region - Crop a spectrum to the wavelength window [wavelength_min, wavelength_max].
  • mask_range - Flag every sample inside a wavelength window as masked.