astropy / photutils

Astropy package for source detection and photometry. Maintainer: @larrybradley
https://photutils.readthedocs.io
BSD 3-Clause "New" or "Revised" License
231 stars 131 forks source link

Add option to exclude negative peaks from residual/model image #1800

Closed keflavich closed 3 days ago

keflavich commented 4 days ago

Solves #1799 by making negative peaks excludable.

It's difficult to impossible for a user to do this now, since the construction of the list of fits for IterativePSFPhotometry is done within make_model_image.

pep8speaks commented 4 days ago

Hello @keflavich! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers:

Comment last updated at 2024-07-01 15:10:54 UTC
larrybradley commented 4 days ago

@keflavich To exclude negative peaks you should bound the flux parameter on the input psf_model, e.g, psf_model.flux.min = 0.

I've considered automatically excluding negative flux results, but I've only seen that occur with IterativePSFPhotometry where something has gone wrong (i.e., the source doesn't really exist). I wasn't sure whether removing them is the correct choice, since it gives the user an indication that something went wrong -- also because the user can bound the flux parameter themselves if they only want positive flux.

In https://github.com/astropy/photutils/pull/1778, I do automatically exclude fit (x, y) positions that out-of-bound during the IterativePSFPhtometry iterations because it will crash without it. The (x, y) model parameters could also be bound in the input psf_model to the image shape.

keflavich commented 4 days ago

Thanks. That makes sense as a way to prevent the fit from ever going negative.

I am seeing this show up even with "basic" PSFPhotometry. I think it has to do with a structured background.