Skip to content

embed_spectrum

Compute a fixed-length, L2-normalised embedding of a spectrum.

Category Embeddings
Backend scipy - implemented here on top of scipy primitives
Version 1.2.1
Reads ctx.spectrum (a Spectrum1D)
Writes embedding, extras.embedding_provenance, metrics.embedding_dim, metrics.embedding_norm

The actual maths lives in spectro_kernel.embeddings so a downstream service can batch-embed thousands of spectra without paying the per-call audit-trail overhead — but go through this algorithm if you want the ProcessingStep + content-hash record alongside the vector. Older strategy names ('pca', 'autoencoder') still work but emit a DeprecationWarning. Non-finite samples (NaN/inf) make the brick fail cleanly: the recipes act on the sample index, so bad pixels cannot be dropped — interpolate or mask them first.

Parameters

Parameter Default Required Description
dim 256 - Output vector length (positive integer).
strategy 'naive' - Embedding recipe: one of ('naive', 'dct', 'multiscale_dct'). Older names 'pca' and 'autoencoder' are accepted as aliases with a DeprecationWarning.
norm_method 'min_max' - Pre-embedding flux normalisation: one of ('none', 'min_max', 'z_score', 'continuum'). none skips normalisation (useful when the spectrum is already normalised by an upstream pipeline step).

Use it

from spectro_kernel import run_algorithm

output = run_algorithm("embed_spectrum", ctx, {
    "dim": 256,
    "strategy": "naive",
    "norm_method": "min_max"
})
spectro run embed_spectrum --input spectrum.fits \
  --param dim=256 \
  --param strategy=naive \
  --param norm_method=min_max
{
  "tool": "embed_spectrum",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "dim": 256,
      "strategy": "naive",
      "norm_method": "min_max"
    }
  }
}

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

References

  • Ahmed, Natarajan & Rao 1974, 'Discrete Cosine Transform', IEEE Trans. Computers, C-23, 90.
  • Bu et al. 2014, ApJS, 211, 28 — z-score standardisation for spectra.
  • Sharma et al. 2020, MNRAS, 491, 2280 — min-max rescaling of stellar spectra.
  • Sanchez-Saez et al. 2021, AJ, 162, 206 — spectral representations for anomaly detection.