-1

i want to use astropy for fitting spectra my code is:

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)

` But my code is giving me the following error:

in <module>
    f1 = fitting.NonLinearLSQFitter().
AttributeError: 'module' object has no attribute 'NonLinearLSQFitter'
Please suggest what should i do?
sasha
  • 29
  • 5
  • You're using astropy 0.3 or earlier documentation. NonLinearLSQFitter has been renamed LevMarLSQFitter in astropy 0.4. Use that instead. –  Mar 31 '17 at 08:54

1 Answers1

2

You're using astropy 0.3 or earlier documentation.
NonLinearLSQFitter has been renamed LevMarLSQFitter in astropy 0.4 and later. Use that instead.