New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fitting width of Moffat2D and Gaussian2D models with PSFPhotometry #1670
Comments
I've modified your code to show an example of how to fit a https://gist.github.com/larrybradley/263f2c9c1a47013a38cd71c6690e8105 However, there appears to be bug when the PSF model fit fails ( There are also a few things to note. When you input an astropy model into Also, "amplitude" is not the same as "flux". Using it will give the wrong fit "flux" output values unless the input model was already normalized. Instead of mapping "flux" to "amplitude" just let Third, one important thing to keep in mind is that when fitting with the models output by I'm also planning to add a section in the documentation with these notes and an example. |
Dear Larry, thanks a lot for your detailed explanations and the code. The solution is very simple, yet it is very hard to find it without having comprehensive knowledge of various photutils components and their interactions. A few comments:
I will now wait for a day for your possible comment on my current post and will close the issue as "solved". Thanks again! |
Yes, 1 is a known bug -- the compound PSF model gets mixed up with possible PSF model grouping (which is also a compound model). For this reason, I suspect using grouping with For 2, simply do not use the For 3, you could try |
Oh, I see. If I set flux_name=None or simply omit it, the model will compute the flux based on ampl, gamma, alpha. Did not realize it was that simple. As an off-topic note - for a person like me who came from traditional C programming, it is sometimes difficult to readjust to python style. I tend to think that things are more complicated (at the user level) than they are :) Thank you again for your help. I will now close the topic. |
Closed as solved. |
I re-opened the issue just to make a comment. The updated version kind of works, but for real images which are 4000x4000 pixels, running it results in the error message (sorry the code formatiing does not work again): Traceback (most recent call last): How to reproduce - just run your notebook version with the image size set to 4000x4000. If I comment the lines psf_model.gamma_2.fixed = False the code works, but of course does not fit these parameters. I understand that the error message is about some arrays having inconsistent lengths, but other than that I am unable to say anything. |
Many thanks for letting me know! I'll take a look soon. |
This version of the code works! I have not tested it thoroughly, but running the code on a few 4000x4000 frames worked without any flaws and fitted both gamma and alpha. One strange thing, though. I removed the "flux_name=" mapping from the call to make_psf_model, so PSFPhotometry should compute flux based on the fit values of gamma, alpha, and amplitude. It does, but the value of the flux is ~2 times smaller than the value found with e.g. Gaussian PSF or measured directly within some appropriate aperture (for isolated stars). Yet, the stellar profile is reproduced well. The ratio is approximately the same for various sources so I suspect that the coefficient "2" is lost somewhere when the flux is computed. Hmm, I run the minimal working example for 100x100 frame, the ratio for most simulated stars is about 2, but for some is different. So it is not as simple as I suggested. Also, should I set
or not? The resulting fluxes in the two cases (set/omitted from the code) are different. Yet, if I e.g. increase the flux of all simulated sources and omit this line from the code, the output fluxes change. I am a bit lost here. Thanks a lot for you work! |
Hi,
I wrote a code which uses IntegratedGaussianPRF and PSFPhotometry. Works ok, but the fit is not optimal as my measured stellar profiles are non-Gaussian and are more like Moffat. So I tried to implement the Moffat2D model. It works, but it seems that only x, y, and flux (actually amplitude) are fitted and not gamma or alpha. Same with Gaussian2D - x_stddev and y_stddev are not fitted. All these parameters are set to be free in my models. With IntegratedGaussianPRF, if I set
psf_model = IntegratedGaussianPRF(flux=1, sigma=fwhm/2.355) psf_model.sigma.fixed = False
sigma of the model is fitted ok. (Yes, I know that this is not good to allow sigma to vary for all sources as the results will be biased for low S/N, what I try to do is to measure sigma for several bright sources and then use this fixed value for the final fit).
My astropy/photutils versions are
astropy 5.3.4
photutils 1.10.0
I was unable to find working examples of how to use Gaussian2D (or Moffat2D) with PSFPhotometry and would appreciate any help.
For some strange reason a working example which I tried to insert here with "code" formatting was improperly formatted. So I provide a link to the code. The code can simulate either Moffat or Gaussian stars and then fit them with either Moffat2D or Gaussian2D models. If the initial widths (gamma or x_stddev, y_stddev) for the fit models are wrong, PSFPhotometry does not adjust them.
I attach a screenshot with the results of the above code. Simulated are Gaussian stars with fwhm=3.0, fitted with initial fwhm=6.0.
The text was updated successfully, but these errors were encountered: