<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks Larry. Sorry I’m coming up to speed on this somewhat haltingly. I’m an amateur astrophotographer (some of my images <a href="https://www.flickr.com/photos/jbw/albums/72157631316034648" class="">here</a>), as well as a software engineer, and I’m working on an image-cataloging program that, among other things monitors exposures as they are captured and reports things like FHWM, estimated SNR, any correlated PSF elongation, etc., to help tune a capture session. Astropy has been an absolute boon for this effort.<div class=""><br class=""></div><div class="">From what I can see the 2D-Gaussian fit in find_peaks() is in the dev release, which I’ll upgrade to shortly, but it doesn’t seem to report mean or std-devs or orientation of the fitted model, which I think I need for some of the above. </div><div class=""><br class=""></div><div class="">So, the trick would be to use find_peaks() to get the centroid and then create cut-outs around them that I give to the fitting & modeling functions in astropy, is that right? Or simply use detect_sources() + segment_properties() to get the cut-outs and covariance matrix from their image-moment analysis to seed the 2D Moffat fit, or whichever model I might use. How different would you expect say a Gaussian 2D model’s centroids & orientation & standard deviations be from the segment_properties() figures on the same source?<br class=""><div class=""><br class=""></div><div class="">I do hope I’m not overstepping things here as an amateur bugging you guys for help. </div><div class=""><br class=""></div><div class="">Best,</div><div class="">John.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 22, 2015, at 9:19 AM, Larry Bradley <<a href="mailto:lbradley@stsci.edu" class="">lbradley@stsci.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi John,<div class=""><br class=""></div><div class="">Just to clarify, the morphological properties calculated by photutils.segment_properties() are derived from the 2D image moments of the source (within the defined segment) -- 2D Gaussian fits are not used there. Photutils also has a local peak finder (photutils.find_peaks()), which does have an option to use a 2D Gaussian fit for better precision.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Larry</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Oct 22, 2015 at 12:08 PM, John Wainwright <span dir="ltr" class=""><<a href="mailto:johnw@lyric.com" target="_blank" class="">johnw@lyric.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Thanks Erik, and sorry, I should have found those. I realize now I was asking relative to the detect_sources() and segment_properties() functions in the <a href="http://photutils.readthedocs.org/en/latest/index.html" target="_blank" class="">photutils</a> affiliate package, which I think use a 2D Gaussian fit to generate the basic morphological properties I've been getting. Presumably, I could use the centroids from that data as peak seeds for a Moffat2D model fit.<div class=""><br class=""></div><div class="">Thanks again,</div><div class="">John.</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Oct 20, 2015, at 7:01 AM, Erik Bray <<a href="mailto:embray@stsci.edu" target="_blank" class="">embray@stsci.edu</a>> wrote:</div><br class=""><div class="">On 10/19/2015 05:56 PM, John Wainwright wrote:<br class=""><blockquote type="cite" class="">Just on the topic of PSF fitting, is there any plan to implement Moffat PSF<br class="">models? I'm trying to replicate some of the PSF fitting<br class=""><<a href="http://pixinsight.com/doc/tools/DynamicPSF/DynamicPSF.html" target="_blank" class="">http://pixinsight.com/doc/tools/DynamicPSF/DynamicPSF.html</a>> capabilities found<br class="">in PixInsight <<a href="http://pixinsight.com/" target="_blank" class="">http://pixinsight.com/</a>> which provides excellent Moffat modeling<br class="">support.<br class=""></blockquote><br class="">Well, there are are already these implementations:<br class=""><br class=""><a href="http://docs.astropy.org/en/latest/api/astropy.modeling.functional_models.Moffat1D.html#astropy.modeling.functional_models.Moffat1D" target="_blank" class="">http://docs.astropy.org/en/latest/api/astropy.modeling.functional_models.Moffat1D.html#astropy.modeling.functional_models.Moffat1D</a><br class=""><br class=""><a href="http://docs.astropy.org/en/latest/api/astropy.modeling.functional_models.Moffat2D.html#astropy.modeling.functional_models.Moffat2D" target="_blank" class="">http://docs.astropy.org/en/latest/api/astropy.modeling.functional_models.Moffat2D.html#astropy.modeling.functional_models.Moffat2D</a><br class=""><br class="">So you can check how they compare. You can also always add your own version:<br class=""><br class=""><a href="http://docs.astropy.org/en/latest/modeling/new.html" target="_blank" class="">http://docs.astropy.org/en/latest/modeling/new.html</a><br class=""><br class=""><br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Oct 19, 2015, at 11:45 AM, Jeff Mangum <<a href="mailto:jmangum@nrao.edu" target="_blank" class="">jmangum@nrao.edu</a><br class=""><mailto:<a href="mailto:jmangum@nrao.edu" target="_blank" class="">jmangum@nrao.edu</a>>> wrote:<br class=""><br class="">Thanks for the responses. Adam Ginsburg and I iterated a bit on this problem<br class="">and found that the issue was the fact that the image I was fitting contained<br class="">nans. Once I removed the nans the gaussian fit routine works. Note that if<br class="">the fitter in astropy.models is not able to handle images with nans, then<br class="">perhaps it should issue a warning.<br class=""><br class="">-- Jeff<br class=""><br class="">On 10/19/15 11:00 AM, Erik Bray wrote:<br class=""><blockquote type="cite" class="">On 10/16/2015 09:47 AM, Giuliano Iorio wrote:<br class=""><blockquote type="cite" class=""><br class="">Hi Jeff,<br class="">this is the kind of staff that usually happens if the position of the<br class="">initial guess is too far away the right one. Did you plot the contour of the<br class="">fitted gaussian on the image?<br class="">It can be also that the image is too noisy around the target to fit. I<br class="">usually use only a little subarray around the target, then I search the<br class="">position of the maximum and I set the initial guess of xo and yo to its<br class="">position. After I normalize all the subarray to the value of the maximum and<br class="">cut all the signal below a certain threshold (usually 0.1).<br class="">In this way I am able to obtain a robust fit also in very noisy map.<br class=""></blockquote><br class="">I agree pretty much with all of Giuliano's advice. And again it might help<br class="">to exclude data outside a smaller subarray. Without actually seeing the data<br class="">it's hard to provide much other advice.<br class=""><br class="">Have you tried a different optimizer? There are a couple other non-linear<br class="">fitters in the package and some have different sensitivities to initial<br class="">conditions. But it's certainly not "non-functional".<br class=""><br class="">Erik<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">Hi Jeff--<br class=""><br class="">The fitted model will not be in g_init (this remains unchanged), but in g.<br class=""> If you take a look in g, you should be able to see the fitted results.<br class=""><br class="">Cheers<br class="">Steve<br class=""><br class="">----- Original Message -----<br class="">From: "Jeff Mangum" <<a href="mailto:jmangum@nrao.edu" target="_blank" class="">jmangum@nrao.edu</a> <mailto:<a href="mailto:jmangum@nrao.edu" target="_blank" class="">jmangum@nrao.edu</a>>><br class="">To: <a href="mailto:astropy@scipy.org" target="_blank" class="">astropy@scipy.org</a> <mailto:<a href="mailto:astropy@scipy.org" target="_blank" class="">astropy@scipy.org</a>><br class="">Sent: Friday, October 16, 2015 3:11:56 PM<br class="">Subject: [AstroPy] Gaussian models fitter non-functional?<br class=""><br class="">Hello,<br class=""><br class="">Long-time listener but first-time caller. Have been trying to use the<br class="">2D Gaussian fitting capabilities within astropy.models to fit a 2D<br class="">Gaussian to an image (in FITS format). Here is my script:<br class=""><br class="">import numpy as np<br class="">import radio_beam<br class="">from astropy.modeling import models, fitting<br class="">from astropy import units as u<br class="">from <a href="http://astropy.io/" target="_blank" class="">astropy.io</a> import fits<br class="">import astropy.coordinates as coord<br class="">import astropy.wcs as wcs<br class="">import matplotlib<br class="">import pylab as pl<br class=""><br class=""># The following is the position of the peak in both J1 and J2, so use<br class=""># it as the starting guess<br class="">ra0 = '13h15m03.50s'<br class="">dec0 = '24d37m08.2s'<br class=""><br class="">radeg = coord.Angle(ra0, unit=u.hour).degree<br class="">decdeg = coord.Angle(dec0, unit=u.degree)<br class=""><br class=""># Now open the image<br class="">hdulist = fits.open('IC860CbandCarrayH2COJ1_moment0.fits')<br class="">#hdulist = fits.open('IC860KubandDarrayH2COJ2_moment0.fits')<br class="">w = wcs.WCS(hdulist[0].header, hdulist)<br class=""><br class="">yy,xx = np.indices(hdulist[0].data.shape)<br class=""><br class="">x0,y0 = w.wcs_world2pix(radeg, decdeg, 1)<br class=""><br class=""># Now fit 2D gaussian<br class="">g_init = models.Gaussian2D(amplitude=1., x_mean=x0, y_mean=y0,<br class="">x_stddev=1, y_stddev=1)<br class="">fit_g = fitting.LevMarLSQFitter()<br class="">g = fit_g(g_init, xx, yy, hdulist[0].data)<br class=""><br class=""><br class="">When I look at g_init (which is where I believe the fit results should<br class="">be), I see that the fit has not moved from its initial settings. It<br class="">appears that the fitter just did not run. With Adam Ginsburg's help I<br class="">have a workaround using gaussfitter, but would certainly like to make<br class="">this work with astropy.models. Thanks!<br class=""><br class="">-- Jeff<br class=""></blockquote></blockquote></blockquote></blockquote></blockquote><br class="">_______________________________________________<br class="">AstroPy mailing list<br class=""><a href="mailto:AstroPy@scipy.org" target="_blank" class="">AstroPy@scipy.org</a><br class=""><a href="https://mail.scipy.org/mailman/listinfo/astropy" target="_blank" class="">https://mail.scipy.org/mailman/listinfo/astropy</a><br class=""><br class=""></div></blockquote></div><br class=""></div></div><br class="">_______________________________________________<br class="">
AstroPy mailing list<br class="">
<a href="mailto:AstroPy@scipy.org" class="">AstroPy@scipy.org</a><br class="">
<a href="https://mail.scipy.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank" class="">https://mail.scipy.org/mailman/listinfo/astropy</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">AstroPy mailing list<br class=""><a href="mailto:AstroPy@scipy.org" class="">AstroPy@scipy.org</a><br class="">https://mail.scipy.org/mailman/listinfo/astropy<br class=""></div></blockquote></div><br class=""></div></div></body></html>