WCS.dropaxis() does not update "NAXIS" keyword
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 74
Description
When working with `WCS.dropaxis()` I've encountered the following issue:
```python3
from astropy.io import fits
from astropy.wcs import WCS
# Define an example WCS reference header
header = fits.Header()
header['WCSAXES'] = 3
header['NAXIS'] = 3
header['NAXIS1'] = 100
header['NAXIS2'] = 100
header['NAXIS3'] = 3
header['CRPIX1'] = 100.5
header['CRPIX2'] = 100.5
header['CRPIX3'] = 0.5
header['CDELT1'] = -0.02
header['CDELT2'] = 0.02
header['CDELT3'] = 0.2
header['CTYPE1'] = 'RA---CAR'
header['CTYPE2'] = 'DEC--CAR'
header['CTYPE3'] = 'ENER-LOG'
header['CRVAL1'] = 0
header['CRVAL2'] = 0
header['CRVAL3'] = 1
wcs = WCS(header)
print(repr(wcs))
```
Returns:
```
WCS Keywords
Number of WCS axes: 3
CTYPE : 'RA---CAR' 'DEC--CAR' 'EN-LOG'
CRVAL : 0.0 0.0 1.0
CRPIX : 100.5 100.5 0.5
PC1_1 PC1_2 PC1_3 : 1.0 0.0 0.0
PC2_1 PC2_2 PC2_3 : 0.0 1.0 0.0
PC3_1 PC3_2 PC3_3 : 0.0 0.0 1.0
CDELT : -0.02 0.02 0.2
NAXIS : 100 100 3
```
If I now drop the third axis using `wcs.dropaxis()`:
```python3
wcs = wcs.dropaxis(2)
print(repr(wcs))
print(wcs._naxis)
```
The axis is dropped correctly, however it is still present in the `"NAXIS"` keyword of the `repr`:
```
WCS Keywords
Number of WCS axes: 2
CTYPE : 'RA---CAR' 'DEC--CAR'
CRVAL : 0.0 0.0
CRPIX : 100.5 100.5
PC1_1 PC1_2 : 1.0 0.0
PC2_1 PC2_2 : 0.0 1.0
CDELT : -0.02 0.02
NAXIS : 100 100 3
[100, 100, 3]
```
Contributor guide
Research direction
The issue names WCS.dropaxis(), repr(wcs), and wcs._naxis; start by running the supplied reproducer and tracing how dropaxis handles axis metadata. Add a regression test for dropping the third axis and verify that the displayed NAXIS matches the remaining dimensions and _naxis.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100