Starlink / ast

Starlink AST Library
GNU Lesser General Public License v3.0
12 stars 11 forks source link

AST does not support FITS-standard 2D look-up-table WCSes #26

Open gpdf opened 2 months ago

gpdf commented 2 months ago

The SPHEREx project is producing FITS-conformant (to the best of our knowledge) spectral WCSes for our Level 2 images (to be publicly released next year once we are on orbit) that use a two-dimensional table-lookup WCS, straight out of WCS paper III (see §6.1, https://www.aanda.org/articles/aa/full/2006/05/aa3818-05/aa3818-05.right.html#SECTION00070000000000000000) (also briefly referred to in the FITS 4.00 standard in Table 26 - algorithm code TAB).

This is provided as "alternative WCS" 'W', in addition to a straightforward spatial WCS as the default WCS.

Currently in our testing it appears to us that DS9, because of a limitation in the included AST library, cannot handle the spectral WCS.

AST fails with this error (where the first line of the message is specific to the DS9 context):

!! AST: Error in routine fits2TAB at line 3498 in file frame/fitsimage.C.
!  astRead(FitsChan): AST can currently only handle 1-dimensional coordinate look-up tables (the supplied table has 2 dimensions).
!  astRead(FitsChan): Cannot read a look-up table for a tabular WCS axis from column 'VALUES' of a FITS binary table.

There are two issues here:

  1. Of course we would like it if AST could be extended to handle this part of the FITS standard.
  2. But even if that's not immediately realistic, at least the way AST is invoked by DS9, this situation produces an error that apparently is preventing DS9 from making use even of the standard WCS(es) in the file. I think that's not the best way to handle situations in which AST knows that it's falling short of the standard. Could AST be changed, or the way DS9 invokes AST be changed, so that the unsupported-but-standard WCS 'W' in the file, which uses the -TAB algorithm code in a two-dimensional context, is simply ignored (with a warning) but the parsing of the rest of the WCS succeeds? The primary WCS and WCS 'A' in this file are both perfectly usable.

See also https://github.com/SAOImageDS9/SAOImageDS9/issues/201 .

dsberry commented 2 months ago

It would be relatively easy to modify AST so that alternative WCS axes that use unsupported features of FITS-WCS are ignored rather than causing the whole read operation to fail. However adding support for 2D lookup tables would be a much bigger job, which I probably couldn't offer to do.

dsberry commented 2 months ago

I've just pushed some commits that adds a new attribute called IgnoreBadAlt to the FitsChan class. If you set this to a non-zero value, unreadable alternate axes will be ignored.

gpdf commented 2 months ago

Excellent! I hope it'll be possible for this to get incorporated into DS9. We really appreciate the rapid response!

As far as the 2D lookup tables are concerned, I understand that it's a bigger task. I don't think we have the development effort required to tackle this ourselves before launch, but we'll take a look at it when we're in operations. We might need a few pointers on your architecture to get us started in the right spot.