[AstroPy] Gaussian models fitter non-functional?
Jeff Mangum
jmangum at nrao.edu
Fri Oct 16 09:11:56 EDT 2015
Hello,
Long-time listener but first-time caller. Have been trying to use the
2D Gaussian fitting capabilities within astropy.models to fit a 2D
Gaussian to an image (in FITS format). Here is my script:
import numpy as np
import radio_beam
from astropy.modeling import models, fitting
from astropy import units as u
from astropy.io import fits
import astropy.coordinates as coord
import astropy.wcs as wcs
import matplotlib
import pylab as pl
# The following is the position of the peak in both J1 and J2, so use
# it as the starting guess
ra0 = '13h15m03.50s'
dec0 = '24d37m08.2s'
radeg = coord.Angle(ra0, unit=u.hour).degree
decdeg = coord.Angle(dec0, unit=u.degree)
# Now open the image
hdulist = fits.open('IC860CbandCarrayH2COJ1_moment0.fits')
#hdulist = fits.open('IC860KubandDarrayH2COJ2_moment0.fits')
w = wcs.WCS(hdulist[0].header, hdulist)
yy,xx = np.indices(hdulist[0].data.shape)
x0,y0 = w.wcs_world2pix(radeg, decdeg, 1)
# Now fit 2D gaussian
g_init = models.Gaussian2D(amplitude=1., x_mean=x0, y_mean=y0,
x_stddev=1, y_stddev=1)
fit_g = fitting.LevMarLSQFitter()
g = fit_g(g_init, xx, yy, hdulist[0].data)
When I look at g_init (which is where I believe the fit results should
be), I see that the fit has not moved from its initial settings. It
appears that the fitter just did not run. With Adam Ginsburg's help I
have a workaround using gaussfitter, but would certainly like to make
this work with astropy.models. Thanks!
-- Jeff
More information about the AstroPy
mailing list