A principal components algorithm for spectra normalisation