Collapse#

Plugin Availability

The plugin will be visible when at least one compatible dataset is loaded.

Collapse a spectral cube along the spectral axis to create a 2D image.

Description#

The Collapse plugin reduces a 3D spectral cube to a 2D image by collapsing along the spectral (wavelength) axis using various reduction functions. This is useful for creating continuum images, line maps, or visualizing the integrated flux over a spectral region.

Key Features:

  • Collapse spectral cubes to 2D images

  • Multiple collapse functions (Sum, Mean, Median, Min, Max)

  • Spectral region selection via subsets

  • Automatic WCS propagation

  • Add results to any image viewer

Details#

Collapse Functions#

The plugin supports several collapse operations:

  • Sum: Total flux across spectral range (useful for line maps)

  • Mean: Average flux (useful for continuum imaging)

  • Median: Median flux (robust to outliers)

  • Min: Minimum flux value

  • Max: Maximum flux value

Spectral Region Selection#

You can collapse over:

  • Entire spectrum: Use all wavelengths in the cube

  • Spectral subset: Use a defined spectral region

When a spectral subset is selected, only wavelengths within that region are included in the collapse operation.

WCS Handling#

The plugin automatically extracts the 2D spatial WCS from the input cube and applies it to the output collapsed image. This preserves sky coordinates and enables proper overplotting with other datasets.

For GWCS (e.g., JWST data), the celestial component is extracted. For FITS WCS, the 2D spatial WCS is used.

Use Cases#

Continuum Imaging:

Collapse over a line-free spectral region using Mean or Median

Line Maps:

Collapse over an emission line using Sum (works best on continuum-subtracted data)

Quick-look Images:

Collapse entire cube using Mean to create a reference image

Noise Assessment:

Use Min or Max to identify outliers or artifacts

UI Access#

v0.1
Click toolbar icons to toggle different sidebars
Data Menu

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 Collapse icon in the plugin toolbar.

Workflow#

  1. Load data cube into Cubeviz

  2. Select dataset from Data dropdown

  3. Select collapse function from Function dropdown

  4. (Optional) Define spectral region:

    • Draw subset in spectrum viewer, OR

    • Select existing subset from Spectral region dropdown

  5. Choose output options:

    • Set output data label (auto-generated by default)

    • Select viewer to add result to

  6. Click Collapse to perform the operation

Results#

The collapsed 2D image is:

  • Added to the selected image viewer

  • Available in the data dropdown menus

  • Can be exported or used in other plugins

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['Collapse']

Basic Usage#

# Set parameters
plg.dataset = 'cube[FLUX]'
plg.function = 'Sum'

# Collapse entire cube
collapsed_image = plg.collapse(add_data=True)

Spectral Region#

# Collapse over spectral subset
plg.spectral_subset = 'Subset 1'
collapsed_image = plg.collapse(add_data=True)

Function Options#

# Try different functions
for func in ['Sum', 'Mean', 'Median', 'Min', 'Max']:
    plg.function = func
    plg.add_results.label = f'collapsed_{func.lower()}'
    plg.collapse(add_data=True)

Custom Output#

# Control where result is added
plg.add_results.label = 'continuum_image'
plg.add_results.viewer = 'flux-viewer'

collapsed_image = plg.collapse(add_data=True)

# Or get result without adding to app
collapsed_image = plg.collapse(add_data=False)

Direct Data Access#

# Get the collapsed data object
result = plg.collapse(add_data=False)

# Access flux array
flux_array = result.flux.value
flux_unit = result.flux.unit

# Save to file
plg.collapsed_flux.write('collapsed.fits')

API References#

Only the following attributes and methods are available through the

public plugin API:

For detailed API documentation, see Collapse.

Example Notebooks#

See Also#