optimize spectra calculation