我正在尝试将表面亮度轮廓拟合到银河中,或者得到一个错误,指出:找不到最佳参数:函数的调用次数已达到maxfev = 800或仅不适合数据。有人做过此事并且可以提供帮助吗?
我的代码:
from astropy.io import ascii
import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize
from astropy.io import fits
import math
#plate scale for CofC Observatory
f = 3962 #mm
p = 206265./f # arcsec/mm
p = p * 9.e-6 #arcsec/pix
finalp = p * 20 #pc/pix, sombrero = 97, ngc720 = 105, ngc6946 = 20
finalp = finalp/1000 #kpc
#importing files
data_b = ascii.read('/Users/research/Desktop/Dowd.A/Final/data/NGC6946/ngc6946_b_profile.dat')
data_g = ascii.read('/Users/research/Desktop/Dowd.A/Final/data/NGC6946/ngc6946_g_profile.dat')
data_r = ascii.read('/Users/research/Desktop/Dowd.A/Final/data/NGC6946/ngc6946_r_profile.dat')
#Converting x-axis from pixels to kpc
r_b = data_b['x']*finalp
r_g = data_g['x']*finalp
r_r = data_r['x']*finalp
y_b = data_b['y'] - 412. #final number is background, different for each filter
y_g = data_g['y'] - 1288.
y_r = data_r['y'] - 1364.
r_b = np.array(r_b)
y_b = np.array(y_b)
r_g = np.array(r_g)
y_g = np.array(y_g)
r_r = np.array(r_r)
y_r = np.array(y_r)
#fitting the model for sersic and exponential
def GaussPoly(r, munaught, beta, n0):
return munaught * np.exp(-beta*(r/re)**(1/n0))
munaught = 8 #change for each filter
beta = .001 #change for each filter
r = r_b
n0 = 1. #1 for spiral and 4 for elliptical
re = r_b[0]
nlfit, nlpcov = scipy.optimize.curve_fit(GaussPoly, r_b, y_b, p0=[munaught, beta, n0])
munaught, beta, n0 = nlfit
x600 = np.arange(0,10)
fit = GaussPoly(x600, munaught, beta, n0)
plt.plot(x600, fit, color = 'orange')
#commented out filters to see one graph at a time
plt.plot(r_b,y_b, 'b.')
plt.xlabel('Avg Radius (kpc)')
plt.ylabel('Surface Brightness (counts/pixel**2)')
plt.savefig('ngc6946_radial_profile_b')