[AstroPy] Loading wavelength from FITS spectrum

Éric Depagne eric at depagne.org
Thu Jul 4 04:43:19 EDT 2013

Le jeudi 4 juillet 2013 à 03:51:20, Gustavo Bragança a écrit :
> Hi,
Hi Gustavo, 

> Is there any easy way to load the values of wavelength from a FITS spectrum
> using astropy?
> I could obtain the wavelengths by using some values of the header, but I
> was wondering if there is an easy way.
I use the following code to get the wavelength and intensity:
def readspec(fitsfile):
        f = pyfits.open(fitsfile)
        cdelt1 = f[0].header['CDELT1']
        crval1 = f[0].header['CRVAL1']
        start = crval1 - f[0].header['CRPIX1'] * cdelt1
        end = start + cdelt1 * f[0].shape[0] - cdelt1/10.
        x = numpy.arange(start, end, cdelt1)
        return x, f[0].data

I'm not sure it's the best way to do so, but it works.



Un clavier azerty en vaut deux
Éric Depagne                            eric at depagne.org

More information about the AstroPy mailing list