Skip to content

classify_template_chi2

Spectral classification by χ² against a Pickles-style template atlas.

Category Spectral classification
Backend scipy - implemented here on top of scipy primitives
Version 1.1.0
Reads ctx.spectrum (a Spectrum1D)
Writes extras.classification_report, metrics.best_chi2, metrics.best_coverage, metrics.ambiguous, metrics.teff_unstable

Common wavelength grid (default 3800–7500 Å at 2 Å step, matching pickles_atlas.canonical_grid()), running-median continuum normalisation (window 80 samples), unweighted χ² over the samples shared by observed + template. Templates with useable overlap < min_overlap are skipped. Confidence flags : ambiguous (χ²[1]/χ²[0] < 1.20) and teff_unstable (top-3 ΔT_eff > 500 K). Supply either atlas (an Atlas object, Python API) or atlas_dir (path to the Pickles .dat files, loaded with load_atlas_from_dir and cached per directory) ; atlas wins when both are given. The grid is always the atlas's own grid_aa : grid_lo / grid_hi / grid_step are accepted for backwards compatibility but currently UNUSED. Normalised templates are cached on Atlas.norm_cache (identical numbers, ~100× faster repeat calls). A descending observed wavelength axis is sorted before resampling.

Parameters

Parameter Default Required Description
atlas None - An Atlas instance (see classification.pickles_atlas.Atlas). Build with load_atlas_from_dir(path) or supply a custom {template_id → flux_on_grid} mapping plus meta. Python API only ; CLI/MCP callers use atlas_dir.
atlas_dir None - Directory holding the Pickles uk*.dat templates ; loaded with load_atlas_from_dir onto the canonical grid (cached). Ignored when atlas is given.
top_n 5 - Number of best-fit matches to report (≥ 1).
min_overlap 0.6 - Reject the run if observed-vs-grid overlap drops below this fraction.
continuum_window 80 - Running-median window (samples) for continuum normalisation.
grid_lo 3800.0 - Reserved (currently unused): the atlas's own grid_aa is used.
grid_hi 7500.0 - Reserved (currently unused): the atlas's own grid_aa is used.
grid_step 2.0 - Reserved (currently unused): the atlas's own grid_aa is used.

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("classify_template_chi2", ctx, {
    "atlas": None,
    "atlas_dir": None,
    "top_n": 5,
    "min_overlap": 0.6,
    "continuum_window": 80,
    "grid_lo": 3800.0,
    "grid_hi": 7500.0,
    "grid_step": 2.0
})
spectro run classify_template_chi2 --input spectrum.fits \
  --param atlas=none \
  --param atlas_dir=none \
  --param top_n=5 \
  --param min_overlap=0.6 \
  --param continuum_window=80 \
  --param grid_lo=3800.0 \
  --param grid_hi=7500.0 \
  --param grid_step=2.0
{
  "tool": "classify_template_chi2",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "atlas": null,
      "atlas_dir": null,
      "top_n": 5,
      "min_overlap": 0.6,
      "continuum_window": 80,
      "grid_lo": 3800.0,
      "grid_hi": 7500.0,
      "grid_step": 2.0
    }
  }
}

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

References

  • Pickles 1998, PASP 110, 863 — UVKLIB stellar template atlas.
  • Cappellari 2017, MNRAS 466, 798 — pPXF full-spectrum fitting.
  • Koleva et al. 2009, A&A 501, 1269 — ULySS.