Skip to main content

Guide: Feature Extraction

This step is the core of the AstroSpectro pipeline's "hybrid" approach (physics + ML). Instead of feeding the raw spectrum to a model, we extract physically relevant information that makes high classification performance possible.

This process is managed by two main classes: PeakDetector and FeatureEngineer.

Step 1: Line Detection and Measurement​

The PeakDetector module identifies local minima (absorption lines) and associates them with a list of known astrophysical lines.

  1. Detection with SciPy: The scipy.signal.find_peaks function is applied to the inverted flux to locate all peaks above a prominence threshold. This parameter, tuned interactively using our visualization tools, is crucial for keeping only significant lines.
  2. Matching with Known Lines: The detected peaks are compared with a dictionary of target lines (Hα, Hβ, CaII K&H, Mg_b, Na_D). The most prominent peak within a tolerance window is associated with the line.
  3. Returning Properties: The PeakDetector no longer returns only the position, but a dictionary containing a (wavelength, prominence) tuple for each detected line.
PeakDetector output example
matched_lines = {
"Hα": (6564.1, 0.281),
"Hβ": (4861.2, 0.485),
"CaII K": (3927.0, 2.344),
"CaII H": None, # Line not detected
"Mg_b": (5185.6, 0.996),
"Na_D": (5895.1, 0.528)
}

Step 2: Building the Feature Vector​

The line dictionary is then passed to FeatureEngineer, which transforms it into a rich numerical vector for the model. Our approach combines three feature families.

1. Physical Line Features​

For each detected line, we compute physical measurements that describe its shape and strength.

  • Strength (Prominence): The depth of the line, directly provided by PeakDetector.
  • Width (FWHM): The "Full Width at Half Maximum", computed with specutils on a smoothed (Savitzky-Golay) version of the line. It is an excellent indicator of luminosity class.

2. Ratio Features​

Ratios between features are often more discriminating than the features themselves.

  • Strength Ratios: We compute ratios between the prominences of different lines (e.g., CaII K / Hβ). These ratios are robust proxies for stellar temperature.
  • Color Index: We compute a simple color index (ratio of blue flux to red flux) from the spectrum continuum.

3. Observation metadata: not model inputs​

FITS headers also carry redshift, seeing and signal-to-noise ratios (snr_g, snr_r, snr_i). These describe the observation rather than the star, and they can correlate with spectral type through LAMOST's observing programmes. In the canonical spectro_only=True mode they are left out of the feature vector (see Physical Purity).

Result: the feature vector

Each spectrum is transformed into the canonical vector of 183 spectroscopic features: line shape and strength, ratios, band indices and continuum shape. The full list is in the Feature Catalogue, and the choice of features is discussed in Feature Engineering.