WCS: Number of world inputs (1) does not match expected (2)

New user here, but i am having trouble debugging something that I’ve reproduced on two different fits files.

Initially, i was working with TESS data (which comes as a stack of like 1000s of postage stamp masks), and when converting from world to pixel coordinates I got the following error:

ValueError: Number of world inputs (1) does not match expected (2)

Ok, so I figured I would try the exact same process on some more vanilla .fits files, so I grabbed some from our local telescope and got the same error. Basically what I’m doing is the folliowing (not MWE, just relevent code, since I assume I’m doing something more stupid):


hdu = fits.open(filename)
headers=hdu[0].header
wcs = WCS(headers)
wcs

WCS Keywords

Number of WCS axes: 2
CTYPE : '' '' 
CRVAL : 0.0 0.0 
CRPIX : 0.0 0.0 
PC1_1 PC1_2  : 1.0 0.0 
PC2_1 PC2_2  : 0.0 1.0 
CDELT : 1.0 1.0 
NAXIS : 3072  2048
positions = SkyCoord(l=102.53*u.deg,b=14.94*u.deg,frame='galactic')
aperture = SkyCircularAperture(positions, r=4.0 * u.arcsec)
aperture
<SkyCircularAperture(<SkyCoord (Galactic): (l, b) in deg
    (102.53, 14.94)>, r=4.0 arcsec)>
wcs.world_to_pixel(aperture)
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_95490/3490634320.py in <module>
----> 1 wcs.world_to_pixel(aperture)

~/.local/lib/python3.10/site-packages/astropy/wcs/wcsapi/high_level_api.py in world_to_pixel(self, *world_objects)
    314 
    315     def world_to_pixel(self, *world_objects):
--> 316         world_values = high_level_objects_to_values(
    317             *world_objects, low_level_wcs=self.low_level_wcs
    318         )

~/.local/lib/python3.10/site-packages/astropy/wcs/wcsapi/high_level_api.py in high_level_objects_to_values(low_level_wcs, *world_objects)
    152     # Check that the number of classes matches the number of inputs
    153     if len(world_objects) != len(classes):
--> 154         raise ValueError(
    155             f"Number of world inputs ({len(world_objects)}) does not match expected"
    156             f" ({len(classes)})"

ValueError: Number of world inputs (1) does not match expected (2)

anyone have any thoughts? I assume it’s something to do with the specific way i’m using the WCS routines, or defining the sky positions, since it happened on two very different files in very different contexts.

EDIT: Making progress. The problem is that I don’t understand the TESS WCS info, and the problem with my file is that it didn’t HAVE WCS info yet! But TESS does:

hdulist[1].header
WCAX6   =                    2 / number of WCS axes                             
1CTYP6  = 'RA---TAN'           / right ascension coordinate type                
2CTYP6  = 'DEC--TAN'           / declination coordinate type                    
1CRPX6  =      25.316596610765 / [pixel] reference pixel along image axis 1     
2CRPX6  =      25.495726787953 / [pixel] reference pixel along image axis 2     
1CRVL6  =      311.45745845466 / [deg] right ascension at reference pixel       
2CRVL6  =      67.452116488302 / [deg] declination at reference pixel           
1CUNI6  = 'deg     '           / physical unit in column dimension              
2CUNI6  = 'deg     '           / physical unit in row dimension                 
1CDLT6  =                  1.0 / [deg] pixel scale in RA dimension              
2CDLT6  =                  1.0 / [deg] pixel scale in DEC dimension

So…how do I get AstroPy to recognize this WCS?

lightkurve has some translation logic for creating the WCS from a TPF file, maybe this will help (the header format does look quite nonstandard!) :face_with_diagonal_mouth: