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

Reject negative fluxes? #1799

Open keflavich opened 3 days ago

keflavich commented 3 days ago

Fitted PSF photometry fluxes can go negative.

Can we include a mechanism to reject them using public methods?

Right now, you can reject them, but it requires modifying a private method. You need this if you're interested in using the residual image or model image. Example:

phot = PSFPhotometry()
result = phot(data)
bad = result['flux_fit'] <= 0
result = result[~bad]
phot._fit_models = [mod for mod, ok in zip(phot._fit_models, ~bad) if ok]
keflavich commented 2 days ago

I'm also not sure that works, since make_model_image uses _fit_model_params, but that doesn't exist for the PSFPhotometry instances I'm playing with.

keflavich commented 2 days ago

with latest photutils, should be:

phot = PSFPhotometry()
result = phot(data)
bad = result['flux_fit'] <= 0
result = result[~bad]
phot._fit_model_params = phot._fit_model_params[~bad]
keflavich commented 1 day ago

Quoting @larrybradley from https://github.com/astropy/photutils/pull/1800#issuecomment-2200314737:

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