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

WCS and class for 2d spectra in MOSViz #804

Closed
astrofrog-conda-forge opened this issue Aug 25, 2021 · 3 comments
Closed

WCS and class for 2d spectra in MOSViz #804

astrofrog-conda-forge opened this issue Aug 25, 2021 · 3 comments
Labels
bug Something isn't working mosviz

Comments

@astrofrog-conda-forge
Copy link

astrofrog-conda-forge commented Aug 25, 2021

I am opening an issue about this rather than a PR since there are already several PRs overlapping with this - also oops I opened this from the wrong account, but it doesn't matter 🤦

I just wanted to open a summary of where I think we need to go with 2D spectra and the possibility of having a new kind of viewer. Following some investigation, I realized that the issues that people have with the current 2D spectrum viewer is due to the fact that 2D spectra are (incorrectly) represented as SpectralCube. Here is an example of a MOSViz parser where a dimension is added to the data as well as an extra WCS dimension:

# Information that needs to be added to the header in order to load
# WCS information into SpectralCube.
# TODO: Use gwcs instead to avoid hardcoding information for 3rd wcs axis
new_data = np.expand_dims(data, axis=1)
header['NAXIS'] = 3
header['NAXIS3'] = 1
header['BUNIT'] = 'dN/s'
header['CUNIT3'] = 'um'
header['WCSAXES'] = 3
header['CRPIX3'] = 0.0
header['CDELT3'] = 1E-06
header['CUNIT3'] = 'm'
header['CTYPE3'] = 'WAVE'
header['CRVAL3'] = 0.0

This code means that the axis dropdown in the image viewer shows RA, Dec, and Wavelength. However, these datasets are inherently 2D and we should not be using SpectralCube to store them.

The best way to represent these datasets from a visualization perspective is as 2D arrays with 2D WCS where one WCS dimension is the spectral dimension and the other is a positional offset - whether in arcseconds or pixels. I think the most suitable class for this is the Spectrum1D class (provided it can contain a 2D WCS).

Initially, I think it would be easiest to treat the extra dimension's WCS as being simply an identity transform so that the offset is in pixels, but in future we could always consider switching to representing an offset in e.g. arcseconds along that dimension (but this will require the information to be available in the files). For the above example in the MOSViz parsers, the WCS would be constructed using e.g.:

from astropy.wcs import WCS
wcs = WCS(naxis=2)
wcs.ctype = 'WAVE', 'OFFSET'
wcs.cunit = 'um', ''
wcs.crval = 0, 0
wcs.crpix = 0, 0
wcs.cdelt = 1e-6, 1

The above assumes that the first world coordinate (second dimension in Numpy array) is the spectral one but of course this can be swapped as appropriate. The spectral values are dummy values as in the current MOSViz parsers, but in future once we want to extract the proper spectral WCS, we can use WCS.sub in the case of FITS WCS to split out the spectral component and add a new positional component (unless the 2D spectra contain a valid 2D WCS in the first place in which case we won't need to customize anything in the parser).

So in the short term, while we still use dummy WCSes, I think the plan should be to change from SpectralCube to Spectrum1D for 2D spectra, and use a WCS similar to the above. With this in place, the image viewer will then only show two attributes in the dropdowns - wavelength and offset, so there should be no need to make a custom viewer. In future, we can then plan to read in the real spectral WCS component as well as optionally make the offset be in e.g. arcseconds.

Related PRs:

(Side note: I know it is conceptually possible to represent 2D spectra as 2D arrays with 3D WCS but the WCS is a bit trickier to set up correctly and it can be a bit confusing for users)

EDIT: Also see #811

@pllim
Copy link
Contributor

pllim commented Aug 25, 2021

You know it is serious when you see Tom post from his conda-forge account! 😹

@astrofrog
Copy link
Collaborator

Or maybe Tom is sleep deprived 😴

@rosteen
Copy link
Collaborator

rosteen commented Sep 30, 2021

Can this be closed now that the linked PRs were merged?

@pllim pllim closed this as completed Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mosviz
Projects
None yet
Development

No branches or pull requests

4 participants