3D Spectral Extraction#
Plugin Availability
This plugin works with 3D spectral cubes.
The plugin will be visible when at least one 3D spectral cube dataset is loaded.
Extract 1D spectra from 3D spectral cubes.
Description#
The 3D Spectral Extraction plugin collapses the spatial dimensions of a spectral cube to produce a 1D spectrum. This is useful for extracting integrated spectra over spatial regions or collapsing entire cubes.
Key Features:
Extract 1D spectra from cubes
Multiple extraction functions (Sum, Mean, Min, Max)
Spatial region (aperture) support
Wavelength-dependent apertures (cone extraction)
Uncertainty propagation
Background spectrum extraction
Details#
Extraction Functions#
The plugin supports several collapse operations:
Sum: Total flux across spatial region (most common)
Mean: Average flux per pixel
Min: Minimum flux value
Max: Maximum flux value
Sum is typically used for total flux, while Mean gives flux per unit area.
Spatial Regions (Apertures)#
You can extract spectra from:
Entire cube: All spatial pixels (no aperture)
Spatial subset: Defined region of interest
Apertures can be circular, elliptical, rectangular, or any drawn subset.
Wavelength-Dependent Apertures#
For circular subsets with spatial axes in angular units, you can enable wavelength-dependent apertures to create a cone that scales with wavelength:
$text{radius}(lambda) = text{radius}_0 times (lambda / lambda_0)$
where $lambda_0$ is the reference wavelength (current slice by default). This is useful for matching PSF size variations with wavelength.
Aperture Masking Methods#
The plugin supports different aperture masking methods (see photutils aperture documentation):
Center: Use only pixels whose centers fall within the aperture
Exact: Calculate exact overlap between aperture and pixels (slower)
Subpixel: Subdivide pixels for approximate overlap calculation
Exact method provides most accurate results but is computationally expensive. For most cases, center or subpixel methods are sufficient.
Note: Exact masking with Min/Max functions is not supported.
Uncertainty Propagation#
When uncertainty data is available in the cube, uncertainties are automatically propagated to the extracted 1D spectrum following standard error propagation rules. For spatial sum, uncertainties add in quadrature. For mean, uncertainties are scaled appropriately.
Background Extraction#
An optional background spectrum can be extracted from a separate spatial region and scaled relative to the source aperture area. This is useful for background subtraction in subsequent analysis.
UI Access#
Control data and subset layer order and visibility for each viewer. Toggle layer visibility, reorder layers by dragging, and manage which data appears in the viewer.
dm = jd.viewers[viewer].data_menu
Opening the Plugin#
- Cubeviz:
Click the 3D Spectral Extraction icon in the plugin toolbar.
Workflow#
Load cube into Cubeviz
(Optional) Draw spatial region for aperture
Select dataset from Data dropdown
Select function from Function dropdown
Select aperture from Aperture dropdown (or use Entire Cube)
(Optional) For circular apertures:
Enable Wavelength dependent if desired
Click Adopt Current Slice to set reference wavelength
Select aperture masking method from Aperture masking method dropdown
Set output options:
Output data label
Viewer to add spectrum to
Click Extract to create 1D spectrum
Background Extraction#
To extract a background spectrum:
Define a background region (separate subset)
Select background region from Background dropdown
Click Extract Background button
The background spectrum is scaled by the aperture area ratio and can be subtracted from the source spectrum.
Results#
The extracted spectrum is:
Added to the spectrum viewer
Available in the data dropdown menus
Can be analyzed with spectroscopic plugins (line analysis, model fitting, etc.)
API Access#
Accessing the Plugin#
from jdaviz import Cubeviz
cubeviz = Cubeviz()
cubeviz.show()
cubeviz.load('cube.fits', format='3D Spectrum')
# Access plugin
plg = cubeviz.plugins['3D Spectral Extraction']
Basic Extraction#
# Extract from entire cube
plg.dataset = 'cube[FLUX]'
plg.function = 'Sum'
spectrum = plg.extract(add_data=True)
Aperture Extraction#
# Extract from spatial subset
plg.aperture = 'Subset 1'
plg.function = 'Sum'
spectrum = plg.extract(add_data=True)
Wavelength-Dependent Aperture#
# Enable cone extraction
plg.aperture = 'Subset 1' # Must be circular
plg.wavelength_dependent = True
plg.reference_wavelength = 5000 # Angstroms
spectrum = plg.extract(add_data=True)
Aperture Masking Method#
# Use exact masking for highest accuracy
plg.aperture_method = 'Exact'
spectrum = plg.extract(add_data=True)
Background Subtraction#
# Extract source spectrum
plg.aperture = 'Subset 1'
source_spec = plg.extract(add_data=True)
# Extract background spectrum
plg.background = 'Subset 2'
bg_spec = plg.extract_bg_spectrum(add_data=True)
# Background is auto-scaled by aperture area ratio
# Subtract in subsequent analysis
Custom Output#
# Control output
extraction.add_results.label = 'source_spectrum'
extraction.add_results.viewer = 'spectrum-viewer'
# Or get without adding
spectrum = extraction.extract(add_data=False)
# Access data
wavelength = spectrum.spectral_axis
flux = spectrum.flux
uncertainty = spectrum.uncertainty
Batch Extraction#
# Extract from multiple apertures
apertures = ['Subset 1', 'Subset 2', 'Subset 3']
for i, ap in enumerate(apertures, 1):
plg.aperture = ap
plg.add_results.label = f'spectrum_{i}'
plg.extract(add_data=True)
API References#
- See the 3D Spectral Extraction Plugin Documentation
for more details.
Only the following attributes and methods are available through the public plugin API:
show_live_previewWhether to show a live preview of the extracted spectrum.dataset(DatasetSelect) Dataset to use for spectral extraction.aperture(ApertureSubsetSelect): Subset to use for the spectral extraction, orEntire Cube.wavelength_dependent: Whether theapertureshould be considered wavelength-dependent. The cone is defined to intersectapertureatreference_spectral_value.reference_spectral_value: The wavelength that will be used to calculate the radius of the cone through the cube.background(ApertureSubsetSelect): Subset to use for background subtraction, orNone.bg_wavelength_dependent: Whether thebackgroundaperture should be considered wavelength-dependent (requireswavelength_dependentto also be set toTrue). The cone is defined to intersectbackgroundatreference_spectral_value.`bg_spec_per_spaxel:Whether to normalize the background per spaxel when calling
extract_bg_spectrum. Otherwise, the spectrum will be scaled by the ratio between the areas of the aperture and the background aperture. Only applicable iffunctionis ‘Sum’.
bg_spec_add_results(AddResults)aperture_method(SelectPluginComponent): Method to use for extracting spectrum (and background, if applicable).add_results(AddResults)
For detailed API documentation, see SpectralExtraction3D.
Example Notebooks#
CubevizExample.ipynb - Includes extraction examples
See Also#
3D Spectral Extraction - Detailed Cubeviz extraction documentation
Collapse - Create 2D images from cubes
Moment Maps - Alternative spectral integration method