question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WCS.dropaxis() does not update "NAXIS" keyword

See original GitHub issue

When working with WCS.dropaxis() I’ve encountered the following issue:

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():

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]

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pllimcommented, Aug 15, 2022

I don’t think we have any planned 4.x releases no more, so it is okay if you cannot test on 4.x. Thanks!

1reaction
cmarmocommented, Aug 14, 2022

Hello, I have checked the snippet of code with the development version

import astropy
from astropy.io import fits
from astropy.wcs import WCS

print(astropy.__version__)

# 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("\nRepr wcs:\n", repr(wcs))

wcs = wcs.dropaxis(2)
print("\nRepr wcs:\n", repr(wcs))
print("\nwcs._naxis:\n", wcs._naxis)

And the output is

5.2.dev341+gf4615bfaf

Repr wcs:
 WCS Keywords

Number of WCS axes: 3
CTYPE : 'RA---CAR'  'DEC--CAR'  'ENER-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

Repr wcs:
 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

wcs._naxis:
 [100, 100]

It looks to me that the problem is now solved, but I don’t know the code enough to understand when and where this was fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WCS — Astropy v5.2
Extracts specific coordinate axes using sub() . If a header is provided, and naxis is not None , naxis will be passed to...
Read more >
WCS — Astropy v1.0.4
Extracts specific coordinate axes using sub(). If a header is provided, and naxis is not None, naxis will be passed to sub() in...
Read more >
STWCS Documentation - Read the Docs
This package provides support for WCS based distortion models and ... Normally all_world2pix() may not achieve the required accuracy if ...
Read more >
WCS object trouble in changing coordinates with astropy 4.0
My code was working before I have update both python (now python 3.7.1) and ... wcs WCS Keywords Number of WCS axes: 4...
Read more >
2. Reading IRIS files — A low-level guide to IRIS with Python
The IRIS level 2 FITS files are the standard science data product, and can be ... We do wcs.dropaxis(-1) because we do not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found