You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to fit a 2d Gaussian with weights for each data point using the astropy.modeling.fitting in astropy version 1.3, python 2.7.13, scipy 0.18.1, and numpy 1.11.3. When I try this using a 1d Gaussian model everything seems to work fine, but I am encountering a shape error when I try to do it in the 2d case. The weights have the same shape (21,21) as everything else. The code I used and the error is below.
Code:
fromastropy.modelingimportmodels,fittingimportnumpyasnpdefgaussian(height, center_x, center_y, width_x, width_y):
"""Returns a gaussian function with the given parameters"""width_x=float(width_x)
width_y=float(width_y)
returnlambdax,y: height*np.exp(
-(((center_x-x)/width_x)**2+((center_y-y)/width_y)**2)/2)
Xin, Yin=np.mgrid[0:21, 0:21]
y=gaussian(10, 10, 9, 2, 3)(Xin, Yin)
#Add gaussian noise to the function with a random sigma between 0.1 and 1.1ysig=1*np.random.rand(Xin.shape[0],Xin.shape[1]) +0.1y=y+np.random.normal(0., ysig, Xin.shape)
#Fit the datagauss2d_init=models.Gaussian2D(amplitude=15, x_mean=5, y_mean=5, x_stddev=1, y_stddev=1, theta=0)
fit_gauss2d=fitting.LevMarLSQFitter()
gmod=fit_gauss2d(gauss2d_init, Xin, Yin, y,weights=1.0/ysig)
Description:
I am trying to fit a 2d Gaussian with weights for each data point using the astropy.modeling.fitting in astropy version 1.3, python 2.7.13, scipy 0.18.1, and numpy 1.11.3. When I try this using a 1d Gaussian model everything seems to work fine, but I am encountering a shape error when I try to do it in the 2d case. The weights have the same shape (21,21) as everything else. The code I used and the error is below.
Code:
Error:
The text was updated successfully, but these errors were encountered: