Skip to content

Commit

Permalink
Add option to exclude local background in residual image (#1690) (#1691)
Browse files Browse the repository at this point in the history
* Add option to exclude local background in make_model_image() and make_residual_image()
---------

Co-authored-by: Larry Bradley <larry.bradley@gmail.com>
  • Loading branch information
m-samland and larrybradley committed Feb 13, 2024
1 parent 0016ec2 commit 7fe5ef6
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions photutils/psf/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ def __call__(self, data, *, mask=None, error=None, init_params=None):

return source_tbl

def make_model_image(self, shape, psf_shape):
def make_model_image(self, shape, psf_shape, include_localbkg=True):
"""
Create a 2D image from the fit PSF models and local background.
Expand All @@ -1040,6 +1040,11 @@ def make_model_image(self, shape, psf_shape):
The shape of region around the center of the fit model to
render in the output image.
include_localbkg : bool, optional
Whether to include the local background in the rendered
output image.
Default is True.
Returns
-------
array : 2D `~numpy.ndarray`
Expand Down Expand Up @@ -1067,11 +1072,13 @@ def make_model_image(self, shape, psf_shape):
except NoOverlapError:
continue
yy, xx = np.mgrid[slc_lg]
data[slc_lg] += (fit_model(xx, yy) + local_bkg)
data[slc_lg] += fit_model(xx, yy)
if include_localbkg:
data[slc_lg] += local_bkg

return data

def make_residual_image(self, data, psf_shape):
def make_residual_image(self, data, psf_shape, include_localbkg=True):
"""
Create a 2D residual image from the fit PSF models and local
background.
Expand All @@ -1087,6 +1094,11 @@ def make_residual_image(self, data, psf_shape):
The shape of region around the center of the fit model to
subtract.
include_localbkg : bool, optional
Whether to include the local background in the subtracted
model.
Default is True.
Returns
-------
array : 2D `~numpy.ndarray`
Expand All @@ -1095,13 +1107,15 @@ def make_residual_image(self, data, psf_shape):
"""
if isinstance(data, NDData):
residual = deepcopy(data)
residual.data[:] = self.make_residual_image(data.data, psf_shape)
residual.data[:] = self.make_residual_image(data.data, psf_shape,
include_localbkg=include_localbkg)
else:
unit = None
if isinstance(data, u.Quantity):
unit = data.unit
data = data.value
residual = self.make_model_image(data.shape, psf_shape)
residual = self.make_model_image(data.shape, psf_shape,
include_localbkg=include_localbkg)
np.subtract(data, residual, out=residual)

if unit is not None:
Expand Down

0 comments on commit 7fe5ef6

Please sign in to comment.