glue-viz / glue-astronomy

Plugin to add astronomy-specific functionality to glue
https://glue-astronomy.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
11 stars 12 forks source link

How to use PaddedSpectrumWCS on 3D cube? #75

Open pllim opened 1 year ago

pllim commented 1 year ago

I have a 3D WCS but all I care about is to translate the spatial WCS (i.e., given a SkyCoord, I want X and Y pixel positions). I don't care about the spectral axis. In Cubeviz, the translator encodes the WCS as PaddedSpectrumWCS but I cannot figure out how to use it to grab just the spatial WCS object. I want to pass this spatial WCS to the to_pixel method in a regions shape.

This is as far as I got:

from astropy.wcs import WCS
from specutils import Spectrum1D

from glue_astronomy.translators.spectrum1d import PaddedSpectrumWCS

flux = np.arange(16).reshape((2, 2, 4)) * u.Jy
wcs_dict = {"CTYPE1": "RA---TAN", "CTYPE2": "DEC--TAN", "CTYPE3": "WAVE",
            "CRVAL1": 205, "CRVAL2": 27, "CRVAL3": 1,
            "CDELT1": -0.0001, "CDELT2": 0.0001, "CDELT3": 8e-11,
            "CRPIX1": 0, "CRPIX2": 0, "CRPIX3": 0}
w = WCS(wcs_dict)

sp = Spectrum1D(flux=flux, wcs=w)

coords = PaddedSpectrumWCS(sp.wcs, sp.flux.ndim)

What should I do after this? Any ideas, @astrofrog or @dhomeier ?

dhomeier commented 1 year ago

Is this issue still open? If I understand right, you'd need the original w.celestial or sp.wcs.celestial to pass to shape.to_pixel(wcs), but all you have is the coords after transformation to PaddedSpectrumWCS)?

pllim commented 1 year ago

I ended up storing the original WCS somewhere hacky and not use PaddedSpectrumWCS at all. So this is still a problem. Would be nice if we can get rid of this altogether and use something more conventional.