Visualize Scaled Spectra and Median Profiles for Clustered IFU Data
Source:R/plot_cluster_spectra.R
plot_cluster_spectra.RdThis function creates a faceted plot that displays the individual pixel spectra (after scaling) and the corresponding median spectrum for each segmented cluster obtained from an IFU data cube. Each facet corresponds to a unique cluster, allowing for easy comparison of spectral profiles across different spatial regions.
Arguments
- cluster_result
A list produced by a segmentation function (e.g.
segment) containing at least the following elements:cluster_map: A matrix mapping each spatial pixel to a cluster.original_cube: The original data cube (typically a FITS object).axDat: Axis metadata (including wavelength information).
- scale_fn
A function that scales each individual spectrum (a numeric vector). The default is
median_scalewhich should be defined elsewhere in your package.- palette
Either a single viridis palette name or a vector of colors used to color the per-cluster median spectra.
Details
The function performs the following steps:
Extracts the spatial cluster map, original data cube, and wavelength information from
cluster_result.Converts the cube to a 2D matrix (assuming
cube_to_matrixis available).Creates a data frame mapping each valid spatial pixel to its cluster.
Extracts each pixel's spectrum and applies the scaling function
scale_fnto it.Computes the median spectrum for each cluster at every wavelength.
Constructs a faceted ggplot of the median spectrum for each cluster.