Skip to content

Lookup-table WCS for irregular spectral sampling doesn't look up #5462

Description

@josePhoenix

Bearing in mind this may be a) not implemented or b) user error, I seem to be having difficulties expressing the -TAB coordinate type. I have a (4096, 4096, 19) (in FITS axes order) datacube with 19 planes representing simulated observations through different filters.

I want to assign a bogus WCS so that I can visualize angular dimensions on each plane in ds9 or similar. It occurred to me that the third dimension actually is wavelength, and I think I can represent it in FITS WCS using a lookup table. However, when I try to do mywcs.all_pix2world I get unexpected behavior that might even be uninitialized memory (i.e. calling the same function twice gives two different results for the wavelength axis).

I call mywcs.all_pix2world([[2048, 2048, i],], 0) where i is in [0, 19). The first two dimensions come out as I expect (that is, 0, 0) but the last is usually 0 and sometimes a very small float value (like 1e-322):

>>> mywcs.all_pix2world([[2048, 2048, 2],], 0)
array([[  5.55555555e-005,   5.55555556e-005,   1.58101007e-322]])

Here's my WCS header:

WCSAXES =                    3 / Number of coordinate axes                      
CRPIX1  =               2048.0 / Pixel coordinate of reference point            
CRPIX2  =               2048.0 / Pixel coordinate of reference point            
CRPIX3  =                  0.0 / Pixel coordinate of reference point            
CDELT1  =  5.5555555555556E-05 / [deg] Coordinate increment at reference point  
CDELT2  =  5.5555555555556E-05 / [deg] Coordinate increment at reference point  
CDELT3  =                  1.0 / [m] Coordinate increment at reference point    
CUNIT1  = 'deg'                / Units of coordinate increment and value        
CUNIT2  = 'deg'                / Units of coordinate increment and value        
CUNIT3  = 'm'                  / Units of coordinate increment and value        
CTYPE1  = 'RA---TAN'           / Right ascension, gnomonic projection           
CTYPE2  = 'DEC--TAN'           / Declination, gnomonic projection               
CTYPE3  = 'WAVE-TAB'           / Vacuum wavelength                              
CRVAL1  =                  0.0 / [deg] Coordinate value at reference point      
CRVAL2  =                  0.0 / [deg] Coordinate value at reference point      
CRVAL3  =                  0.0 / [m] Coordinate value at reference point        
PS3_0   = 'FILTERS'            / Coordinate transformation parameter            
PS3_1   = 'lambda_eff'         / Coordinate transformation parameter            
LONPOLE =                180.0 / [deg] Native longitude of celestial pole       
LATPOLE =                  0.0 / [deg] Native latitude of celestial pole        
RADESYS = 'ICRS'               / Equatorial coordinate system

Here's the code to build it up:

mywcs = wcs.WCS(fobj=hdulist, naxis=3)
pixel_scale = 0.2
mywcs.wcs.ctype = ['RA---TAN', 'DEC--TAN', 'WAVE-TAB']
mywcs.wcs.cunit = ['deg', 'deg', 'm']
mywcs.wcs.cdelt = [
    pixel_scale / 60 / 60, 
    pixel_scale / 60 / 60,
    1
]
mywcs.wcs.crpix = [2048, 2048, 0]
mywcs.wcs.crval = [0, 0, 0]
mywcs.wcs.set_ps([(3, 0, 'FILTERS'),
                  (3, 1, 'lambda_eff')])
mywcs.to_header()

Here's the header of the extension FILTERS:

XTENSION= 'BINTABLE'           / binary table extension                         
BITPIX  =                    8 / 8-bit bytes                                    
NAXIS   =                    2 / 2-dimensional binary table                     
NAXIS1  =                   86 / width of table in bytes                        
NAXIS2  =                   19 / number of rows in table                        
PCOUNT  =                    0 / size of special data area                      
GCOUNT  =                    1 / one data group (required keyword)              
TFIELDS =                    8 / number of fields in each row                   
EXTNAME = 'FILTERS '           / name of this binary table extension            
TTYPE1  = 'filter  '           / label for field                                
TFORM1  = '30A     '           / format of field                                
TUNIT1  = 'Filter name'                                                         
TTYPE2  = 'lambda_eff'         / label for field                                
TFORM2  = 'D       '           / format of field                                
TUNIT2  = 'm       '                                                            
TTYPE3  = 'ewidth_lambda'      / label for field                                
TFORM3  = 'D       '           / format of field                                
TUNIT3  = 'm       '                                                            
TTYPE4  = 'ewidth_nu'          / label for field                                
TFORM4  = 'D       '           / format of field                                
TUNIT4  = 'Hz      '                                                            
TTYPE5  = 'L_lambda_eff0'      / label for field                                
TFORM5  = 'D       '           / format of field                                
TUNIT5  = 'W/m     '                                                            
TTYPE6  = 'AB_mag0 '           / label for field                                
TFORM6  = 'D       '           / format of field                                
TTYPE7  = 'L_lambda_eff_nonscatter0' / label for field                          
TFORM7  = 'D       '           / format of field                                
TUNIT7  = 'W/m     '                                                            
TTYPE8  = 'AB_mag_nonscatter0' / label for field                                
TFORM8  = 'D       '           / format of field 

I'm following (or trying to follow) the explanation of the -TAB standard in Griesen et al. 2006 (PDF). (more links)

Activity

  1. astrofrog commented on Apr 20, 2017

    @astrofrog
    Member

    Note that this is also discussed in #2362 - astropy doesn't currently support -TAB I think.

  2. Cadair commented on Apr 20, 2017

    @Cadair
    Member

    This is a very important feature for ground based solar physics datasets, I would very much appreciate it working!

  3. astrofrog commented on Apr 20, 2017

    @astrofrog
    Member

    @Cadair - do you have example FITS spectra that use the -TAB convention?

  4. Cadair commented on Apr 20, 2017

    @Cadair
    Member

    No, they use something that should be represented as a non-uniformly spaced TAB but they don't actually follow the standard that would be loopy.

  5. nden commented on Apr 20, 2017

    @nden
    Contributor

    GWCS can do this

  6. Cadair commented on Apr 20, 2017

    @Cadair
    Member

    @nden yeah GWCS is my current plan. In fact I need to talk GWCS with you at some point.

  7. nden commented on Apr 20, 2017

    @nden
    Contributor

    @Cadair Email me if you want to set up a hangout or just email me your questions.

  8. Cadair commented on Apr 20, 2017

    @Cadair
    Member

    @nden will do. Need to get my cards in order first :D

  9. josePhoenix commented on Apr 20, 2017

    @josePhoenix
    ContributorAuthor

    GWCS can do this

    @nden could you elaborate?

  10. nden commented on Apr 20, 2017

    @nden
    Contributor

    gwcs is meant to be flexible in terms of what transforms it uses and hence has a different than FITS WCS representation. In general the WCS pipeline is represented as a list of steps where each step contains a starting coordinate frame and the transform to the next frame. The simplest case using a a Loookup table would be

    [('detector', LookUpTbale()),
     ('sky', None)]
    

    where LookupTable() is an instance of `modeling.models.Tabulr2D().

    I guess I should write a complete example of this in the GWCS documentation showing also how to save this to a file.

  11. parejkoj commented on Oct 4, 2019

    @parejkoj
    Contributor

    Is there a gwcs issue tracking this one? It was not immediately obvious from the gwcs docs how to create a gwcs-based -TAB FITS WCS.

  12. timj commented on Oct 31, 2019

    @timj
    Contributor

    LSST are trying to generate some data using -TAB so we have test files if people tell me where you would like one uploaded. wcsLib also has an example FITS file using -TAB for multiple axes.

  13. mcara commented on Nov 21, 2019

    @mcara
    Contributor

    In PR #9641 I implemented support for the -TAB algorithm in FITS WCS defined in WCS Paper III.

  14. mcara commented on Jan 16, 2020

    @mcara
    Contributor

    To those (still) interested: #9641 has been merged and WCS-TAB should now be supported in astropy.wcs. Please give it a try.

  15. pllim commented on Jan 16, 2020

    @pllim
    Member

    Closing as solved. Thanks, @mcara !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions