Port over CUNIT handling from spectral-cube
- Dominant language
- Python
- Stars
- 204
- Forks
- 134
- Avg merge
- 12h 55m
- Merged PRs (30d)
- 1
Description
Due to astropy/astropy#3658 , you get the following behavior in `astropy` and `specutils`, which can be surprising to users expecting the `CUNITn` to be respected.
```python
from astropy.wcs import WCS
w = WCS({'WCSAXES': 3,
'CRPIX1': 21.299551407997, 'CRPIX2': 31.024649715622, 'CRPIX3': 1.0,
'CDELT1': -5.5555555555556e-05, 'CDELT2': 5.5555555555556e-05, 'CDELT3': 1.25,
'CUNIT1': 'deg', 'CUNIT2': 'deg', 'CUNIT3': 'Angstrom',
'CTYPE1': 'RA---TAN', 'CTYPE2': 'DEC--TAN', 'CTYPE3': 'AWAV',
'CRVAL1': 54.1925, 'CRVAL2': -35.99917, 'CRVAL3': 4749.931640624999,
'LONPOLE': 180.0, 'LATPOLE': -35.99917,
'CSYER1': 1.51033062781e-05, 'CSYER2': 5.76768648658e-06,
'MJDREF': 0.0, 'RADESYS': 'ICRS'})
print(w.wcs.cunit)
```
Get this:
```python
['deg', 'deg', 'm']
```
Want this:
```python
['deg', 'deg', 'Angstrom']
```
As a result, when this WCS is passed into `Spectrum1D`, you get this:
```python
import numpy as np
from astropy import units as u
from specutils import Spectrum1D
spec = Spectrum1D(flux=np.ones((10, 10, 10)) * u.nJy, wcs=w)
print(spec.spectral_axis.unit) # gets 'm' but want 'Angstrom'
```
In `spectral-cube`, [there are code to work around this](https://github.com/radio-astro-tools/spectral-cube/blob/master/spectral_cube/spectral_axis.py) but why was it not ported over here? If it was, I can't find it so would appreciate someone pointing me to it.
cc @keflavich
Contributor guide
Research direction
Start by reading spectral_cube/spectral_axis.py, then reproduce the WCS and Spectrum1D examples from the issue. Trace how WCS cunit is passed into Spectrum1D and verify the spectral axis retains Angstrom rather than becoming m; done means the shown CUNIT3 behavior is preserved for this case.
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
- 45/100