问题描述
我有 3 个数据文件;波长/像素、计数/像素和背景/像素。每个数据文件有多个订单(订单总数 = 35)。我已经为每个订单拟合了多项式并绘制了结果。然而,我需要一个结合所有结果的图,而不是 35 个图。我曾尝试使用 .append
填充一个空数组,但我无法使用它来绘制组合结果。这是我绘制每个订单的代码。有人能指出我如何结合这些结果的正确方向吗?提前致谢。
# =============================================================================
# Load libraries
# =============================================================================
from astropy.io import fits
import matplotlib.pyplot as plt
import numpy as np
# =============================================================================
# Load data
# =============================================================================
counts_image = ("counts.fits")
wavelength_image = ("wavelength.fits")
background_image = ("backgound.fits")
# =============================================================================
# Open as fits files
# =============================================================================
sp = fits.open(counts_image)
sp_w = fits.open(wavelength_image)
sp_b = fits.open(background_image)
# =============================================================================
# Array data
# =============================================================================
counts_data = np.array(sp[0].data)
wave_data = np.array(sp_w[0].data)
background_data = np.array(sp_b[0].data)
# =============================================================================
# Order-by-order
# =============================================================================
order = 0
while order < 34:
# =============================================================================
counts = counts_data[order]
wave = wave_data[order]
background = background_data[order]
# =============================================================================
# Fitting
# =============================================================================
z = Fit(wave,counts)
# =============================================================================
# Wavelength range
# =============================================================================
wavespread = max(wave) - min(wave)
wavecenter = wave - min(wave) - wavespread/2.
# =============================================================================
# Normalize
# =============================================================================
norm = counts/max(counts)
# =============================================================================
# Make a function based on those polynomial coefficients
# =============================================================================
cfit = np.poly1d(z)
# =============================================================================
# Plot the original
#==============================================================================
plt.figure()
plt.plot(wavecenter,norm)
# =============================================================================
# Continuum fit
# =============================================================================
plt.plot(wavecenter,cfit(wavecenter))
fitted = norm/cfit(wavecenter)
# =============================================================================
plt.figure()
plt.plot(wave,fitted)
plt.ylim([0,1.1])
plt.xlim([min(wave),max(wave)])
# =============================================================================
# End while loop
# =============================================================================
ord += 1
# =============================================================================
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)