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 adds third axis even though WCSAXES = 2

See original GitHub issue

I’ve been trying to use astropy.wcs.WCS to preserve WCS information when constructing some data cubes, and getting an extra axis when I try to use the WCS information. I only have a defined WCS for two of the three axes (because of #5462), and want to just use the same WCS for all the planes in the cube.

When I initialize the WCS, though:

>>> mywcs = wcs.WCS(hdulist['BLENDED'].header)
>>> mywcs

WCS Keywords

Number of WCS axes: 3
CTYPE : 'RA---TAN'  'DEC--TAN'  ''  
CRVAL : 150.11632130000001  2.2009730969999999  0.0  
CRPIX : -265.5  -234.5  0.0  
PC1_1 PC1_2 PC1_3  : -6.6666679999999995e-05  0.0  0.0  
PC2_1 PC2_2 PC2_3  : 0.0  6.6666679999999995e-05  0.0  
PC3_1 PC3_2 PC3_3  : 0.0  0.0  1.0  
CDELT : 1.0  1.0  1.0  
NAXIS    : 83 94

>>> mywcs.all_pix2world([[1, 2]], 0)
ValueError: When providing two arguments, the array must be of shape (N, 3)

The process, roughly speaking, is to cut the same WxH pixel region out of N 2D images taken in different filters and resampled to the same pixel grid, then construct a (N, H, W) (or (W, H, N) in FITS axis ordering) data cube where each plane is a different filter.

Here’s the header of one extension in the file I created:

XTENSION= 'IMAGE   '           / Image extension                                
BITPIX  =                  -64 / array data type                                
NAXIS   =                    3 / number of array dimensions                     
NAXIS1  =                   83                                                  
NAXIS2  =                   94                                                  
NAXIS3  =                    6                                                  
PCOUNT  =                    0 / number of parameters                           
GCOUNT  =                    1 / number of groups                               
WCSAXES =                    2 / Number of coordinate axes                      
CRPIX1  =               -265.5 / Pixel coordinate of reference point            
CRPIX2  =               -234.5 / Pixel coordinate of reference point            
PC1_1   =        -6.666668E-05 / Coordinate transformation matrix element       
PC2_2   =         6.666668E-05 / Coordinate transformation matrix element       
CDELT1  =                  1.0 / [deg] Coordinate increment at reference point  
CDELT2  =                  1.0 / [deg] Coordinate increment at reference point  
CUNIT1  = 'deg'                / Units of coordinate increment and value        
CUNIT2  = 'deg'                / Units of coordinate increment and value        
CTYPE1  = 'RA---TAN'           / Right ascension, gnomonic projection           
CTYPE2  = 'DEC--TAN'           / Declination, gnomonic projection               
CRVAL1  =          150.1163213 / [deg] Coordinate value at reference point      
CRVAL2  =          2.200973097 / [deg] Coordinate value at reference point      
LONPOLE =                180.0 / [deg] Native longitude of celestial pole       
LATPOLE =          2.200973097 / [deg] Native latitude of celestial pole        
RADESYS = 'FK5'                / Equatorial coordinate system                   
EQUINOX =               2000.0 / [yr] Equinox of equatorial coordinates         
MJD-OBS =              55924.0 / [d] MJD of observation matching DATE-OBS       
DATE-OBS= '2011-12-29'         / ISO-8601 observation date matching MJD-OBS     
EXTNAME = 'BLENDED '                                                            
FWHMAS  =                  0.7 / Kernel FWHM in arcseconds   

Here’s the wcslint output:

$ wcslint COSMOS_150.06694880+2.2103795_at_0.70_arcsec.fits
HDU 1 (BLENDED):
  WCS key ' ':
    No issues.

HDU 2 (TRUTH):
  WCS key ' ':
    No issues.

HDU 3 (BANDS):
  WCS key ' ':
    No issues.

HDU 4 (CATALOG):
  WCS key ' ':
    No issues.

HDU 5 (SEGMAP):
  WCS key ' ':
    No issues.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
josePhoenixcommented, Jun 2, 2017

Thanks! I also found a workaround by supplying naxis=2 when initializing the WCS from the header (i.e. wcs.WCS(hdulist['BLENDED'].header, naxis=2)).

1reaction
josePhoenixcommented, Jun 2, 2017

Sure. Works for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Initializing axes with world coordinates — Astropy v5.2
To make a plot using WCSAxes , we first read in the data using astropy.io.fits and parse the WCS information. In this example,...
Read more >
Always display entire tick labels on wcs axes - Stack Overflow
As another has said, this behaviour is expected and built in to Astropy via the TickLabels class function simplify_labels (see Astropy ...
Read more >
Slicing Multidimensional Data — Astropy v3.2.dev994
WCSAxes can ultimately only plot two-dimensional data. If we have an n-dimensional dataset, we have to select which dimensions to use for the...
Read more >
WCS — Astropy v1.0.4
A copy of the current WCS with only the celestial axes included ... 2 arguments: An N x naxis array of coordinates, and...
Read more >
FITS-WCS Coverage - Starlink
F.2 Paper II - Celestial Coordinates F.3 Paper III - Spectral ... Set to the number of axes in the WCS Frame -...
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