Challenge: Linear Regression

When assigning redshifts to galaxies with an observed spectrum, one typically fits model spectra for the local spectrum of a galaxy to the observed one while accounting for the redshift of the wavelengths. In this challenge, we first want to try to fit a local spectrum with templates using a linear regression and least-squares before trying to estimate the redshift of a redshifted spectrum.

Challenge 1: Extract templates

In the repository you can find a fits-file containing the model spectra, templates, we want to use to fit the observed spectrum later. You'll also find a python script that shows you how to work with the template. Extract and plot the unsmoothed template with all components included.

Challenge 2: Fitting template amplitudes

Formulate and solve the least squares problem of finding the best fit amplitudes of the templates from challenge 1 when fitting them to the data of a local (i.e. redshift zero) spectrum in \(\verb|localspectrum.txt|\). Implement your own linear least squares solver and compare it to numpy's implementation. Which one fits the data better?

Challenge 3: Fitting for the redshift

\(\verb|redshiftedspectrum.txt|\) contains a redshifted spectrum. Fitting both redshift and template amplitudes is no longer a linear problem. Find the redshift by solving the linear problem of challenge 2 on a grid of redshifts between 0 and 1.