astropy / astropy/specutils

Spectrum1D is not able to take 2D WCS for 2D dataset

Open
#857 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
204
Forks
134
Avg merge
12h 55m
Merged PRs (30d)
1

Description

I am trying to provide a 2D WCS to the Spectrum1D class but this does not work:

```python
import numpy as np
from astropy.wcs import WCS
from astropy import units as u
from specutils import Spectrum1D

wcs = WCS(naxis=2)
wcs.wcs.ctype = ['SPATIAL', 'FREQ']
wcs.wcs.set()

flux = np.ones((10, 15)) * u.Unit('Jy')

spec2d = Spectrum1D(flux, wcs=wcs)
```

The error is:

```
Traceback (most recent call last):
File "test.py", line 14, in
spec2d = Spectrum1D(flux, wcs=wcs)
File "/Users/tom/python/dev/lib/python3.8/site-packages/specutils/spectra/spectrum1d.py", line 252, in __init__
spec_axis = self.wcs.pixel_to_world(np.arange(self.flux.shape[-1]))
File "/Users/tom/python/dev/lib/python3.8/site-packages/astropy/wcs/wcsapi/high_level_api.py", line 239, in pixel_to_world
world = self.low_level_wcs.pixel_to_world_values(*pixel_arrays)
File "/Users/tom/python/dev/lib/python3.8/site-packages/astropy/wcs/wcsapi/fitswcs.py", line 322, in pixel_to_world_values
world = self.all_pix2world(*pixel_arrays, 0)
File "/Users/tom/python/dev/lib/python3.8/site-packages/astropy/wcs/wcs.py", line 1347, in all_pix2world
return self._array_converter(
File "/Users/tom/python/dev/lib/python3.8/site-packages/astropy/wcs/wcs.py", line 1323, in _array_converter
return _return_list_of_arrays([xy], origin)
File "/Users/tom/python/dev/lib/python3.8/site-packages/astropy/wcs/wcs.py", line 1291, in _return_list_of_arrays
output = func(xy, origin)
ValueError: Wrong number of dimensions in input array. Expected 2.
```

This is despite the axes being completely separable in the WCS. Based on discussions with @eteq I would have thought this would be supported?

Contributor guide

Open the contributing guide

Research direction

Start in specutils/spectra/spectrum1d.py at the Spectrum1D constructor, around the pixel_to_world call shown in the traceback, and reproduce the provided 2D WCS example. Determine how separable 2D WCS axes should be handled; done means the example constructs Spectrum1D without the wrong-dimensions error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.