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.

Problem using WCS.pixel_to_world with WCS tab file

See original GitHub issue

Description

I am trying to use astropy to read a FITS file produced by the SSTRED pipeline from data taken at the Swedish 1-m Solar Telescope. The data can be read ok, but I have some trouble with the WCS object when trying to run operations such as pixel_to_world.

Expected behavior

When running w.pixel_to_world(), I expected to get an array with the world coordinates. Instead, I get an error.

Steps to Reproduce

Here is a minimal WCS header extracted from the actual object (original file is too large):

WCSAXES =                    5 / Number of coordinate axes
CRPIX1  =                  0.0 / Pixel coordinate of reference point
CRPIX2  =                  0.0 / Pixel coordinate of reference point
CRPIX3  =                  0.0 / Pixel coordinate of reference point
CRPIX4  =                  1.0 / Pixel coordinate of reference point
CRPIX5  =                  0.0 / Pixel coordinate of reference point
CDELT1  =                  1.0 / [arcsec] Coordinate increment at reference poin
CDELT2  =                  1.0 / [arcsec] Coordinate increment at reference poin
CDELT3  =                  1.0 / [nm] Coordinate increment at reference point
CDELT4  =                  1.0 / Coordinate increment at reference point
CDELT5  =                  1.0 / [s] Coordinate increment at reference point
CUNIT1  = 'arcsec'             / Units of coordinate increment and value
CUNIT2  = 'arcsec'             / Units of coordinate increment and value
CUNIT3  = 'nm'                 / Units of coordinate increment and value
CUNIT5  = 's'                  / Units of coordinate increment and value
CTYPE1  = 'HPLN-TAB'           / Coordinate type codeundefined projection
CTYPE2  = 'HPLT-TAB'           / Coordinate type codeundefined projection
CTYPE3  = 'WAVE-TAB'           / Vacuum wavelength
CTYPE4  = 'STOKES'             / Coordinate type code
CTYPE5  = 'UTC--TAB'           / Coordinate type code
CRVAL1  =                  0.0 / [arcsec] Coordinate value at reference point
CRVAL2  =                  0.0 / [arcsec] Coordinate value at reference point
CRVAL3  =                  0.0 / [nm] Coordinate value at reference point
CRVAL4  =                  1.0 / Coordinate value at reference point
CRVAL5  =                  0.0 / [s] Coordinate value at reference point
PV1_3   =                  1.0 / [deg] alias for LONPOLE (has precedence)
PV2_3   =                  2.0 /     projection parameter
PV3_3   =                  3.0 / Coordinate transformation parameter
PV5_3   =                  4.0 / Coordinate transformation parameter
PS1_0   = 'WCS-TAB '           / Coordinate transformation parameter
PS1_1   = 'HPLN+HPLT+WAVE+TIME' / Coordinate transformation parameter
PS1_2   = 'HPLN-INDEX'         / Coordinate transformation parameter
PS2_0   = 'WCS-TAB '           / Coordinate transformation parameter
PS2_1   = 'HPLN+HPLT+WAVE+TIME' / Coordinate transformation parameter
PS2_2   = 'HPLT-INDEX'         / Coordinate transformation parameter
PS3_0   = 'WCS-TAB '           / Coordinate transformation parameter
PS3_1   = 'HPLN+HPLT+WAVE+TIME' / Coordinate transformation parameter
PS5_0   = 'WCS-TAB '           / Coordinate transformation parameter
PS5_1   = 'HPLN+HPLT+WAVE+TIME' / Coordinate transformation parameter
LATPOLE =                 90.0 / [deg] Native latitude of celestial pole
CNAME1  = 'Spatial X'          / Axis name for labelling purposes
CNAME2  = 'Spatial Y'          / Axis name for labelling purposes
CNAME3  = 'Wavelength'         / Axis name for labelling purposes
CNAME5  = 'Time since DATEREF, increases with dim. 3 and 5' / Axis name for labe
CSYER1  =                 60.0 / [arcsec] Systematic error in coordinate
CSYER2  =                 60.0 / [arcsec] Systematic error in coordinate
TIMESYS = 'UTC'                / Time scale
DATEREF = '2021-06-22T00:00:00.000000' / ISO-8601 fiducial time
MJDREF  =              59387.0 / [d] MJD of fiducial time
DATE-OBS= '2021-06-22T16:10:31' / ISO-8601 time of observation
MJD-OBS =      59387.673969907 / [d] MJD of observation
DATE-BEG= '2021-06-22T16:10:33.61340' / ISO-8601 time at start of observation
MJD-BEG =      59387.674000155 / [d] MJD at start of observation
DATE-AVG= '2021-06-22T16:18:47.91310' / ISO-8601 time at midpoint of observation
MJD-AVG =      59387.679721216 / [d] MJD at midpoint of observation
DATE-END= '2021-06-22T16:27:36.28459' / ISO-8601 time at end of observation
MJD-END =      59387.685836627 / [d] MJD at end of observation
XPOSURE =             0.180015 / [s] Exposure (integration) time
OBSGEO-X=            5327403.0 / [m] observatory X-coordinate
OBSGEO-Y=           -1718726.0 / [m] observatory Y-coordinate
OBSGEO-Z=            3051730.0 / [m] observatory Z-coordinate

NOTE: with only this header the WCS will be missing the -TAB data.

If I put that into an WCS object called w, the first try is:

w.pixel_to_world(1, 1, 1, 1, 1)

This fails with an error:

NotImplementedError: SPECSYS= not yet supported

This seems to be an error with the original file, it is missing the SPECSYS keyword adding it manually, I can proceed a little longer:

w.wcs.specsys = 'TOPOCENT'
w.pixel_to_world(1, 1, 1, 1, 1)

Fails with:

ValueError: Unrecognized time CTYPE=UTC--TAB

I thought maybe the error was the double dash, so I did:

w.wcs.ctype[-1] = 'UTC-TAB'
w.pixel_to_world(1, 1, 1, 1, 1)

and then I get:

InconsistentAxisTypesError: ERROR 4 in wcs_types() at line 3074 of file cextern/wcslib/C/wcs.c:
Table parameters set for non-table axis type.

System Details

Linux-3.10.0-1127.19.1.el7.x86_64-x86_64-with-glibc2.10
Python 3.8.5 (default, Sep  4 2020, 07:30:14)
[GCC 7.3.0]
Numpy 1.20.2
astropy 4.3.1
Scipy 1.6.2
Matplotlib 3.4.1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mcaracommented, Aug 24, 2022

I also would like to add that currently time axis does not work well with -TAB due to a bug in WCSLIB. I am not sure what are all the consequences of the bug but selecting temporal axis using sub may not work as expected.

This was reported upstream a few months ago.

1reaction
Cadaircommented, Aug 24, 2022

it works 🥳

In [4]: w.pixel_to_world(0,0,0,0,0)
Out[4]: 
[<SkyCoord (Helioprojective: obstime=2021-08-04T09:56:50.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2021-08-04T09:56:50.000, rsun=695700.0 km): (lon, lat, radius) in (deg, deg, m)
     (0.00174495, 6.02251189, 1.51772714e+11)>): (Tx, Ty) in arcsec
     (244.35426644, 377.38281263)>,
 <SpectralCoord 
    (observer: <ITRS Coordinate (obstime=59430.4188856662, location=(0., 0., 0.) km): (x, y, z) in m
                   (5327403., -1718726., 3051730.)
                (v_x, v_y, v_z) in km / s
                   (0., 0., 0.)>
     target: <Helioprojective Coordinate (obstime=2021-08-04T09:56:50.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2021-08-04T09:56:50.000, rsun=695700.0 km): (lon, lat, radius) in (deg, deg, m)
                 (0.00174495, 6.02251189, 1.51772714e+11)>): (Tx, Ty, distance) in (arcsec, arcsec, kpc)
                 (0., 0., 1000.)
              (d_Tx, d_Ty, d_distance) in (arcsec / s, arcsec / s, km / s)
                 (0., 0., 0.)>
     observer to target (computed from above):
       radial_velocity=-11980.853083640337 km / s
       redshift=-0.03919626429118017)
   485.92380808 nm>,
 <Quantity 1.>,
 <Time object: scale='utc' format='mjd' value=59430.41848821678>]
Read more comments on GitHub >

github_iconTop Results From Across the Web

WCS pixel_to_world gives unexpected result #11808 - GitHub
Description A simple WCS transform using pixel_to_world appears to give the wrong answer transforming x,y to RA, Dec by about one CDELT.
Read more >
World Coordinate System (astropy.wcs)
World Coordinate Systems (WCSs) describe the geometric transformations between one set of coordinates and another. A common application is to map the pixels...
Read more >
World Coordinate System (astropy.wcs)
astropy.wcs contains utilities for managing World Coordinate System (WCS) transformations in FITS files. These transformations map the pixel locations in an ...
Read more >
WCSLIB: wcs.h File Reference
wcsperr () prints the error message(s) (if any) stored in a wcsprm struct, and the linprm, celprm, prjprm, spcprm, and tabprm structs that...
Read more >
WCSLIB 4.13.4: wcs.h File Reference - CFA Harvard
wcsperr () prints the error message(s) (if any) stored in a wcsprm struct, and the linprm, ... routines described in lin.h, log.h, cel.h,...
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