Skip to content

This is how you visualize cube_fitting data in Cubeviz (Jdaviz) #113

@pllim

Description

@pllim

Try with:

  • astropy 5.2 or later
  • jdaviz 3.1.2 or later
from astropy import units as u
from astropy.io import fits
from astropy.nddata import StdDevUncertainty
from astropy.wcs import WCS
from specutils import Spectrum1D

from jdaviz import Cubeviz

data_label = 'M58_SL1_cube'  # Also works with SL2
sci_filename = f'{data_label}.fits'
unc_filename = f'{data_label}_unc.fits'

pf_sci = fits.open(sci_filename)
pf_unc = fits.open(unc_filename)

# Image has SIP distortion that will break loading,
# so we have to delete them. See
# https://docs.astropy.org/en/stable/wcs/note_sip.html
sip_list = ('A_ORDER', 'A_0_2', 'A_0_3', 'A_1_1', 'A_1_2', 'A_2_0', 'A_2_1', 'A_3_0', 'A_DMAX',
            'B_ORDER', 'B_0_2', 'B_0_3', 'B_1_1', 'B_1_2', 'B_2_0', 'B_2_1', 'B_3_0', 'B_DMAX',
            'AP_ORDER', 'AP_0_1', 'AP_0_2', 'AP_0_3', 'AP_1_0', 'AP_1_1', 'AP_1_2', 'AP_2_0', 'AP_2_1', 'AP_3_0',
            'BP_ORDER', 'BP_0_1', 'BP_0_2', 'BP_0_3', 'BP_1_0', 'BP_1_1', 'BP_1_2', 'BP_2_0', 'BP_2_1', 'BP_3_0')

for key in sip_list:
    del pf_sci[0].header[key]

w = WCS(pf_sci[0].header, pf_sci)

# If this is not StdDevUncertainty, change to use the correct representation.
# We just assume this already aligns with the SCI data file.
unc = StdDevUncertainty(pf_unc[0].data)

flux = pf_sci[0].data * u.Unit(pf_sci[0].header['BUNIT'])
sp = Spectrum1D(flux=flux, wcs=w, uncertainty=unc, meta=dict(pf_sci[0].header))

cubeviz = Cubeviz()

cubeviz.show()

cubeviz.load_data(sp, data_label=data_label)

# When you are all done. Only do this at the end of the session.
pf_sci.close()
pf_unc.close()

SL1

Screenshot 2022-12-22 115416

SL2

Screenshot 2022-12-22 120107

cc @PatrickOgle

🐱

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions