Improved spectra generation script