library(SpectralUnmix)Getting Started
Simulated example
demo <- simulate_ifu_cube(nx = 16, ny = 16, n_wave = 100)
fit <- spectral_unmix(
demo$matrix,
k = 3,
lambda_smooth = 0.02,
niter = 300,
lr = 0.03
)Standard interface
print(fit)
summary(fit)
basis(fit)
coef(fit)Plots
plot(fit, type = "spectra", wavelength = demo$wavelength)
plot(fit, type = "maps", nx = demo$nx, ny = demo$ny)
plot(fit, type = "loss")
plot_reconstruction(fit, demo$matrix, n = 4, wavelength = demo$wavelength)Example figures
Component spectra:

Component maps:

Observed versus reconstructed spectra:

What the outputs mean
fit$spatialcontains one abundance weight per spaxel and per component.fit$spectracontains the recovered component spectra.fit$reconstructionis the model approximationA %*% S.fitted(fit, nx, ny)andpredict(fit, type = "cube", nx, ny)reshape that reconstruction back into a cube.residuals(fit, x = ...)returns data minus reconstruction.
Real library example
real_demo <- coelho_demo_spectra()
dim(real_demo$matrix)[1] 4 2250
real_demo$metadata id file teff logg feh
1 cool_giant t03000_g-0.5_p00p00_sed.fits 3000 -0.5 0.0
2 solar_dwarf t05750_g+4.5_p00p04_sed.fits 5750 4.5 0.0
3 a_star t09000_g+4.5_p00p00_sed.fits 9000 4.5 0.0
4 hot_star t18000_g+4.5_p02p00_sed.fits 18000 4.5 0.2
fit_real <- spectral_unmix(
real_demo$matrix,
k = 3,
lambda_smooth = 0.001,
niter = 400,
lr = 0.03
)
plot(fit_real, type = "spectra", wavelength = real_demo$wavelength)
plot_reconstruction(
fit_real,
real_demo$matrix,
n = 4,
wavelength = real_demo$wavelength
)Static reconstruction view for the Coelho demo sample:

Stellar library compression
stellar_lib <- coelho_stellar_subset()
dim(stellar_lib$matrix)[1] 100 2250
table(stellar_lib$metadata$type)
a_f_star cool_dwarf cool_giant hot_star solar_like
20 20 20 20 20
fit_lib <- spectral_unmix(
stellar_lib$matrix,
k = 5,
lambda_smooth = 0.001,
niter = 500,
lr = 0.03
)
plot(fit_lib, type = "spectra", wavelength = stellar_lib$wavelength)
plot_reconstruction(
fit_lib,
stellar_lib$matrix,
n = 6,
wavelength = stellar_lib$wavelength
)