Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pllim opened this issue Dec 22, 2022 · 1 comment
Open

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

pllim opened this issue Dec 22, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@pllim
Copy link
Contributor

pllim commented Dec 22, 2022

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

🐱

@pllim pllim added documentation Improvements or additions to documentation enhancement New feature or request labels Dec 22, 2022
@camipacifici
Copy link
Contributor

@PatrickOgle do you still need this? Can we close it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants