Untangling the physical components of galaxies using infrared spectra