SpectralUnmix

SpectralUnmix is an R package for smooth non-negative spectral unmixing of hyperspectral datasets and astronomical IFU cubes.

The package fits a low-rank model that decomposes a spectral matrix into component spectra and spatial abundance maps while preserving non-negativity.

Model

The package solves

\[ X \approx A S \]

where X is a spaxel-by-wavelength matrix, A contains spatial abundances, and S contains component spectra.

Workflow

flowchart LR
  A["IFU cube<br/>nx × ny × nλ"] --> B["cube_to_matrix()"]
  B --> C["spaxel × wavelength matrix X"]
  C --> D["spectral_unmix()"]
  D --> E["A: abundance maps"]
  D --> F["S: component spectra"]
  D --> G["AS: reconstruction"]
  E --> H["component_map()"]
  F --> I["plot(type = 'spectra')"]
  G --> J["predict(type = 'cube') / fitted()"]

flowchart LR
  A["IFU cube<br/>nx × ny × nλ"] --> B["cube_to_matrix()"]
  B --> C["spaxel × wavelength matrix X"]
  C --> D["spectral_unmix()"]
  D --> E["A: abundance maps"]
  D --> F["S: component spectra"]
  D --> G["AS: reconstruction"]
  E --> H["component_map()"]
  F --> I["plot(type = 'spectra')"]
  G --> J["predict(type = 'cube') / fitted()"]

Interpretation

Each spaxel spectrum is modeled as a non-negative combination of a small number of latent spectral components. The abundances vary across the field, while the component spectra are shared across all spaxels.

Example output

The figure below shows the component spectra recovered from the bundled synthetic example used throughout the documentation.

Main functions

  • spectral_unmix() fits the model.
  • cube_to_matrix() and matrix_to_cube() reshape IFU cubes.
  • basis() and coef() provide NMF-style accessors.
  • fitted(), predict(), and residuals() provide standard model methods.
  • plot() and plot_reconstruction() provide quick diagnostics.

Installation

# install.packages("remotes")
remotes::install_github("RafaelSdeSouza/SpectralUnmix")

torch must be available in the local R installation.