Skip to content
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

[bug] model does not fit correctly when the image is not normalized #11

Open
kunzaatko opened this issue Apr 3, 2022 · 4 comments
Open

Comments

@kunzaatko
Copy link

Hi! Like your work!
There is a slight problem when trying to fit a model to bead image in practice... The optimization without specifying the amp parameter does not work with real bead images, because they are usually not normalized to (0,1). For example, I have this image of a bead:
unnormalized_bead

and the fitted gaussian PSF model gives:
unnormalized_fit

When I normalize the bead image by

bead .-= minimum(bead)
bead ./= maximum(bead)

then the image looks like this:
normalized_bead

and the fitted gaussian PSF model looks like this:
normalized_fit

Which is a much better fit.
Note, that just specifying the amp = 1 parameter would not help in this case, because it makes the optimization much more likely to land at a local optimum. This could be solved only by setting the amp parameter very close to the true value. Here is the result when optimizing against amp also with the same bead:
unnormalized_fit_with_amp

@kunzaatko
Copy link
Author

The best way to approach this would probably be to predefine the amp before the fitting to maximum(im) or to fit a normalized image.

@kunzaatko
Copy link
Author

kunzaatko commented Apr 3, 2022

Alternatively, it could be only noted in the docs so that users are cautious
.

@mileslucas
Copy link
Member

I'm not sure this is a bug, like you said if you want to fit the amplitude, you need to specify it, otherwise you could do

func_kwargs = (;amps=fixed_amp_value)
PSFModels.fit(...; func_kwargs=func_kwargs)

Alternatively, it could be only noted in the docs so that users are cautious

PRs are welcome! As a note, by the way, all of the astropy PSF models require an amplitude, and don't make any assumptions about normalized or unnormalized data, the same as we do here. Are there other tools you are used to that "automatically" apply these pre-processing steps? If, so, I'd be interested in checking them out!

@kunzaatko
Copy link
Author

Right.., I think bug was not the right word. It is just that the 'default' method for fitting does not adhere to the probably most frequent use of it... That is that fitting the normalized PSF model into a most surely unnormalized view into the image. Right? I will go through the docs and add some comment about this. With that, I think that it would be settled. Would that be OK?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants