Compressed sensing for spectroscopy and polarimetry