我一直在使用matplotlib.pyplot从Python中的fits文件绘制光谱,并获得强度与像素的关系,但是我真正需要的是将像素转换为波长。我曾见过类似的问题,使我走上了正确的路(例如similar question,RGB example),但我仍然感到迷失。
我有FITS文件,其波长在3500和6000(A)之间,且为float32格式和尺寸(53165,)。
据我了解,我需要将像素位置校准为波长。我有我的其余波长头(RESW),“步进”波长头(STW),我需要获取:
x = RESW +(像素数* STW)
并绘制它。到目前为止,这就是我在代码中得到的内容。
import os, glob from glob import glob from pylab import * from astropy.io import ascii import scipy.constants as constants import matplotlib.pylab as plt from astropy.io import fits #add directory you have your files in dir = '' #OPEN ALL FILES AND STORE THEM INTO A LIST files= glob(dir + '*.fits') for fi in (files): print(fi) name = fi[:-len('.fits')] #Remove '.fits' from the file name with fits.open(dir + fi) as hdu: hdu.info() data = hdu[0].data hdr = hdu[0].header #added to try2 step = hdr['CDELT1'] #added to try2 restw = hdr['CRVAL1'] #added to try2 #step = fits.getheader('STW') #added to try #restw = fits.getheader('RESW') #added to try spectra = restw + (data * step) #added to try plt.clf() plt.plot(spectra) plt.savefig(name + '.pdf')
我已经尝试过使用fits.getheader(''),但由于这种方式无法正常工作,我不知道在哪里放置或如何放置它。
有人可以帮忙吗?预先感谢!
我一直在使用matplotlib.pyplot从Python中的fits文件绘制光谱,并获得强度与像素的关系,但是我真正需要的是将像素转换为波长。我看过...
您有没有解决这个问题?我目前也在尝试这样做。 IRAF有一个名为“ mkmultispec”的任务,可以非常快速地完成这一任务,但是在天灾中似乎没有类似的任务。