astropy:属性错误无法导入拟合

时间:2017-03-31 08:34:34

标签: python curve-fitting astropy

我想使用astropy来拟合我的代码光谱:

from astropy.io import fits
from astropy.modeling import models, fitting
import math
import numpy as np
import pylab as plb
import matplotlib.pyplot as plt
#after opening  the fits file and reading its data pixel by pixel
# fitting for the spectra at a pixel
x = velocity
y = ant_tem
g_init = models.Gaussian1D(amplitude=1., mean=0, stddev=1.)
f1 = fitting.NonLinearLSQFitter()
g = f1(g_init, x,y)
# Plot the data with the best-fit model
plt.figure(figsize=(8,5))
plt.plot(x, y, 'ko')
plt.plot(x, g(x), 'r-', lw=2, label='Gaussian')
plt.xlabel('Velocity')
plt.ylabel('Antenne Temperature')
plt.legend(loc=2)

` 但是我的代码给了我以下错误:

in <module>
    f1 = fitting.NonLinearLSQFitter().
AttributeError: 'module' object has no attribute 'NonLinearLSQFitter'
Please suggest what should i do?

1 个答案:

答案 0 :(得分:2)

您正在使用astropy 0.3或更早版本的文档 NonLinearLSQFitter已在天蝎座0.4及更高版本中重命名为LevMarLSQFitter。请改用它。