Your first spectrum¶
For amateurs - start here
You pointed your spectroscope at a bright star, ran your acquisition software, and
saved a FITS file. Now what? This page answers exactly that, with no prior coding
- just the spectro command. We will use Deneb as the example, but any star
works.
Deneb (α Cygni) is a perfect first target: very bright, high in the summer sky, and a hot supergiant whose spectrum shows the hydrogen Balmer lines clearly. By the end of this page you will have measured one of them.
What you need¶
- spectro-kernel installed - see Getting started.
- A FITS file from your session - call it
deneb.fits.
No spectrum of your own yet?
Generate a realistic Deneb-like one to follow along - a smooth continuum with hydrogen lines in absorption:
import numpy as np
from spectro_kernel.io import write_fits
from spectro_kernel.types import Spectrum1D
wave = np.linspace(4800, 6700, 3000)
flux = np.full(wave.size, 1000.0)
for centre, depth in [(6562.8, 380), (4861.3, 300), (4340.5, 220)]: # H-alpha, -beta, -gamma
flux -= depth * np.exp(-0.5 * ((wave - centre) / 6.0) ** 2)
flux += np.random.default_rng(7).normal(0, 12, wave.size)
write_fits(Spectrum1D(wave, flux, meta={"object": "Deneb"}), "deneb.fits")
Step 1 - does the file load?¶
If you see [OK], spectro-kernel understood your file - wavelength axis and all.
Step 2 - is my spectrum any good?¶
The single most useful number is the signal-to-noise ratio (SNR). A higher SNR means a cleaner spectrum.
Rough rule of thumb for amateurs: SNR above ~50 is good enough to measure lines; above
~100 is excellent. snr_der needs no special calibration - see why in
spectro describe snr_der.
Step 3 - flatten the continuum¶
Right now your flux is in raw counts. To see the lines clearly, divide out the smooth continuum so it sits at 1.0 and the lines become dips below it:
deneb_norm.fits is your normalised spectrum - the continuum is now flat at 1.0.
Step 4 - find the hydrogen lines¶
This is the satisfying part. Ask spectro-kernel to detect the lines and match them against the Balmer catalogue of hydrogen lines:
[OK] detect_lines
Detected 3 line(s), 3 matched to the balmer catalogue.
Metrics:
n_lines_detected = 3
n_lines_matched = 3
Three lines detected, all three identified as hydrogen. Your spectrograph really did record the hydrogen lines of a star ~2600 light-years away.
Step 5 - measure H-alpha¶
Pick the strongest line, H-alpha at 6562.8 Å, and fit it:
spectro run fit_gaussian_line --input deneb_norm.fits \
-p line_center_angstrom=6562.8 -p window_angstrom=40
[OK] fit_gaussian_line
Fitted absorption gaussian line at 6562.79 Å (FWHM 14.1 Å, R^2 0.992).
Metrics:
fwhm_angstrom = 14.12
r_squared = 0.992
You just measured a stellar absorption line: its exact position, its width (FWHM),
and how well a Gaussian describes it (R^2 near 1.0 means an excellent fit). That width
is real physics - it encodes the star's temperature, gravity and rotation.
The same thing, in Python¶
If you prefer a script, the five steps above are:
from spectro_kernel import WorkContext, run_algorithm
from spectro_kernel.io import read_fits
ctx = WorkContext(spectrum=read_fits("deneb.fits"))
run_algorithm("snr_der", ctx)
run_algorithm("normalize_polynomial", ctx, {"order": 3})
run_algorithm("detect_lines", ctx, {"catalog": "balmer"})
run_algorithm("fit_gaussian_line", ctx, {"line_center_angstrom": 6562.8, "window_angstrom": 40})
print("SNR :", round(ctx.metrics["snr_der"]))
print("lines found:", int(ctx.metrics["n_lines_matched"]))
print("H-alpha FWHM:", round(ctx.line_fits["6562.8"].fwhm_angstrom, 1), "Å")
What you achieved¶
In five commands you went from a raw FITS file to a measured stellar line - quality checked, continuum normalised, lines identified. That is a genuine scientific result.
Where to go next¶
- What else can I do? → Discover the catalogue - every operation available, and how to inspect each one.
- A fuller, guided analysis → Analyse a spectrum.
- Periodic targets (Be stars, eclipsing binaries) → the
lomb_scargleandphase_foldalgorithms in the catalogue.