radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
95 stars 62 forks source link

Add support for HighLevelWCS in reproject #777

Open keflavich opened 2 years ago

keflavich commented 2 years ago

spectral-cube's reprojection only works with FITS WCS objects at the moment

from ndcube.wcs.wrappers import ResampledLowLevelWCS
from spectral_cube import SpectralCube
import reproject
from astropy.wcs.wcsapi import HighLevelWCSWrapper

# read whatever random cube I have laying around
cube = SpectralCube.read('G000.00+00.00_H2CO_2pol.fits')[:25,:20,:21]
ww = ResampledLowLevelWCS(cube.wcs, [2,2,1])
hw = HighLevelWCSWrapper(ww)

cube.reproject(hw)

yields

Traceback (most recent call last):
  File "<ipython-input-39-7934036dabd6>", line 1, in <module>
    cube.reproject(HighLevelWCSWrapper(ww))
  File "/home/adam/repos/spectral-cube/spectral_cube/utils.py", line 49, in wrapper
    return function(self, *args, **kwargs)
  File "/home/adam/repos/spectral-cube/spectral_cube/spectral_cube.py", line 2610, in reproject
    newwcs = wcs.WCS(header)
  File "/home/adam/repos/astropy/astropy/wcs/wcs.py", line 416, in __init__
    for dict_key in orig_header.keys():
AttributeError: 'HighLevelWCSWrapper' object has no attribute 'keys'

We should support APE14 HighLevelWCS objects.

The reason reproject takes a header right now is the need to specify an output grid. However, HighLevelWCS's are supposed to have array_shapes defined.