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

Spectrum1D WCS has wrong number of dimensions as an NDCube #1108

Open
gterreran opened this issue Nov 15, 2023 · 1 comment
Open

Spectrum1D WCS has wrong number of dimensions as an NDCube #1108

gterreran opened this issue Nov 15, 2023 · 1 comment

Comments

@gterreran
Copy link

As per title, it looks like that the dimensions of the WCS of Spectrum1D objects are not parsed correctly into the NDCube data class, as shown by the following snippet:

import numpy as np
import astropy.units as u
from specutils import Spectrum1D
from astropy.modeling import models

wl = np.linspace(4000,12000,128)*u.angstrom
flux_1 = models.BlackBody(temperature=5800*u.K)(wl)
flux_2 = models.BlackBody(temperature=4800*u.K)(wl)
flux_3 = models.BlackBody(temperature=6800*u.K)(wl)
flux = np.array([flux_1, flux_2, flux_3])*flux_1.unit

spec = Spectrum1D(spectral_axis=wl, flux=flux)
print(spec.wcs.pixel_n_dim)

which returns

1

while it should be 3.

@simontorres
Copy link
Contributor

Actually this behavior is correct, the spectral_axis which is wl is of dimension 1, in order to create the wcs instance the Spectrum1D class uses the function gwcs_from_array from utils/wcs_utils.py which is hard coded to create a 1D coordinate frame.

def gwcs_from_array(array):
    """
    Create a new WCS from provided tabular data. This defaults to being
    a GWCS object.
    """
    orig_array = u.Quantity(array)

    coord_frame = cf.CoordinateFrame(naxes=1,
                                     axes_type=('SPECTRAL',),
                                     axes_order=(0,))

I think there might be an option of getting the desired behavior by defining the flux as a NDCube instance in which case you also need to define the wcs by yourself.

Taking into consideration that this issue originated from the discussion regarding #1106 and that we are talking about Spectrum1D (emphasis on 1D) we should move forward with merging #1106 because the changes required to make the "NDCube.plot" method working are a lot more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants