[AstroPy] Gaussian models fitter non-functional?

Giuliano Iorio giuliano.iorio at unibo.it
Fri Oct 16 10:42:26 EDT 2015


It is really strange, I have used intensivly the 2D Gaussian fitting this last month and I have never had this kind of problem. I do not know gaussfitter and i usually work directly on the numpy array index of the image, instead to use the coordinate and the wcs utility. To definitevely exclude some bugs or errors in the steps before the fit, I suggest you to try to not use the coordinate of the peak, but instead find it with np.argmax

Cheers,
Giuliano
> Il giorno 16 ott 2015, alle ore 16:23, Jeff Mangum <jmangum at nrao.edu> ha scritto:
> 
> Hello Guiliano,
> 
>> On 10/16/15 9:47 AM, Giuliano Iorio wrote:
>> Hi Jeff,
>> this is the kind of staff that usually happens if the position of the initial guess is too far away the right one. Did you plot the contour of the fitted gaussian on the image?
> 
> Yes.  The initial guess I give the fitter is right on the peak.
> 
>> It can be also that the image is too noisy around the target to fit. I usually use only a little subarray around the target, then I search the position of the maximum and I set the initial guess of xo and yo to its position. After I normalize all the subarray to the value of the maximum and cut all the signal below a certain threshold (usually 0.1).
>> In this way I am able to obtain a robust fit also in very noisy map.
> 
> The final signal-to-noise on peak is more than 100:1.  Note that I have used gaussfitter to solve this problem using the same inputs as I tried to use with astropy.models, and that worked beautifully.
> 
> -- Jeff
> 
>> 
>> best regards,
>> Giuliano
>>> Il giorno 16 ott 2015, alle ore 15:29, Steve Crawford <crawford at saao.ac.za> ha scritto:
>>> 
>>> 
>>> 
>>> Hi Jeff--
>>> 
>>> The fitted model will not be in g_init (this remains unchanged), but in g.   If you take a look in g, you should be able to see the fitted results.
>>> 
>>> Cheers
>>> Steve
>>> 
>>> ----- Original Message -----
>>> From: "Jeff Mangum" <jmangum at nrao.edu>
>>> To: astropy at scipy.org
>>> Sent: Friday, October 16, 2015 3:11:56 PM
>>> Subject: [AstroPy] Gaussian models fitter non-functional?
>>> 
>>> 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
>>> _______________________________________________
>>> AstroPy mailing list
>>> AstroPy at scipy.org
>>> https://mail.scipy.org/mailman/listinfo/astropy
>>> 
>>> !DSPAM:5620f7a993681466218807!
>>> 
>>> 
>>> _______________________________________________
>>> AstroPy mailing list
>>> AstroPy at scipy.org
>>> https://mail.scipy.org/mailman/listinfo/astropy
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> https://mail.scipy.org/mailman/listinfo/astropy
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy



More information about the AstroPy mailing list