[AstroPy] Loading wavelength from FITS spectrum

David Berry d.berry at jach.hawaii.edu
Thu Jul 4 08:21:50 EDT 2013


On 4 July 2013 13:20, David Berry <d.berry at jach.hawaii.edu> wrote:
> Using pyast (http://dsberry.github.io/starlink/pyast.html) you can do
> it like this:
>
>
> import pyfits
> import starlink.Atl as Atl
>
> hdulist = pyfits.open( 'test.fit' )
> frameset,encoding = Atl.readfitswcs( hdulist )
> wcsvalues = frameset.trangrid( 1, hdulist[0].shape[0] )
>
>
>
> This assumes your FITS file has only one axis. If you have more axes
> (RA, Dec axes for instance), you need additionally to use mapsplit to
> split off the mapping for the spectral axis from the complete
> n-dimensional FrameSet:
>
> import pyfits
> import starlink.Atl as Atl
>
> # The one-based index of the spectral axis
> spectralaxis = 1
>
> # Read the FITS headers and get an AST FrameSet describing the
> # full WCS.
> hdulist = pyfits.open( 'test.fit' )
> frameset,encoding = Atl.readfitswcs( hdulist )
>
> # Split off the Mapping that describes just the spectral axis.
> wcsaxis,specmap = frameset.mapsplit( spectralaxis )
>
> # Use this Mapping to generate a list of spectral axis values
> # corresponding to pixel 1, 2, 3...
> wcsvalues = specmap.trangrid( 1, hdulist[0].shape[pixelaxis-1] )

Doh!   That final "pixelaxis-1" should be "spectralaxis-1".

David



More information about the AstroPy mailing list