[AstroPy] Loading wavelength from FITS spectrum
Thøger Rivera-Thorsen
trive at astro.su.se
Thu Jul 4 04:57:59 EDT 2013
I usually go:
data, header = pyfits.getdata(fitsfile, header=True)
wave = numpy.arange(data.shape[0]) * header['CDELT1'] + header['CRVAL1']
That should be about as simple as it gets :-)
Cheers,
Emil
On 2013-07-04 10:43, Éric Depagne wrote:
> 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)
> f.close()
> return x, f[0].data
>
> I'm not sure it's the best way to do so, but it works.
>
> HTH.
>
> Éric.
>
> Un clavier azerty en vaut deux
> ----------------------------------------------------------
> Éric Depagne eric at depagne.org
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
More information about the AstroPy
mailing list