The universe is a symphony of light, but to the naked eye, it often looks like a static painting. Stars are points; galaxies are fuzzy patches. But hidden within that light is a rich, dynamic story—a cosmic fingerprint that tells us exactly what an object is made of, how hot it is, and—most importantly—how fast it is moving away from us.
This is the power of spectroscopy, the astronomer’s most indispensable tool. By breaking light into its constituent wavelengths, we transform a single beam of photons into a detailed dataset. In this guide, we’ll explore the theoretical foundations of spectral analysis, the physics of redshift, and how to build a Python "Stellar Speedometer" to calculate the expansion of the universe from your own computer.
The Cosmic Fingerprint: Emission and Absorption
At its core, spectroscopy relies on quantum mechanics. Electrons orbiting an atom can only exist at specific energy levels. When an electron jumps between these levels, it must absorb or emit a photon with energy exactly equal to the difference between those levels.
Because energy is related to wavelength (












