Skip to content

Commit 581b620

Browse files
authored
Merge pull request #2135 from larrybradley/psf-docstrings
Add docstrings for make_model_image and make_residual_image methods
2 parents 74e2eec + 826741a commit 581b620

File tree

2 files changed

+113
-3
lines changed

2 files changed

+113
-3
lines changed

photutils/psf/iterative.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,34 @@ def _get_model_image_params(self):
691691

692692
def make_model_image(self, shape, *, psf_shape=None,
693693
include_localbkg=False):
694+
"""
695+
Create a model image from the fit results.
696+
697+
Parameters
698+
----------
699+
shape : 2-tuple of int
700+
The shape (ny, nx) of the output image.
694701
702+
psf_shape : 2-tuple of int, optional
703+
The shape (ny, nx) of the PSF model to be rendered. If
704+
`None`, the shape of the PSF model is determined by the
705+
``fit_shape`` parameter.
706+
707+
include_localbkg : bool, optional
708+
Whether to include the local background in the model image.
709+
Default is `False`.
710+
711+
Returns
712+
-------
713+
image : `~numpy.ndarray`
714+
The model image.
715+
716+
Raises
717+
------
718+
ValueError
719+
If no results are available. Please run the
720+
`IterativePSFPhotometry` instance first.
721+
"""
695722
if not self.fit_results:
696723
msg = ('No results available. Please run the '
697724
'IterativePSFPhotometry instance first.')
@@ -706,7 +733,34 @@ def make_model_image(self, shape, *, psf_shape=None,
706733

707734
def make_residual_image(self, data, *, psf_shape=None,
708735
include_localbkg=False):
736+
"""
737+
Create a residual image from the fit results.
709738
739+
Parameters
740+
----------
741+
data : 2D `~numpy.ndarray`
742+
The data image.
743+
744+
psf_shape : 2-tuple of int, optional
745+
The shape (ny, nx) of the PSF model to be rendered. If
746+
`None`, the shape of the PSF model is determined by the
747+
``fit_shape`` parameter.
748+
749+
include_localbkg : bool, optional
750+
Whether to include the local background in the model image
751+
that is subtracted from the data. Default is `False`.
752+
753+
Returns
754+
-------
755+
image : `~numpy.ndarray`
756+
The residual image.
757+
758+
Raises
759+
------
760+
ValueError
761+
If no results are available. Please run the
762+
`IterativePSFPhotometry` instance first.
763+
"""
710764
if not self.fit_results:
711765
msg = ('No results available. Please run the '
712766
'IterativePSFPhotometry instance first.')

photutils/psf/photometry.py

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class for more information.
369369
"""
370370

371371
# Default value for parameter initialization (invalid sources)
372-
DEFAULT_PARAM_VALUE = np.nan
372+
_DEFAULT_PARAM_VALUE = np.nan
373373

374374
def __init__(self, psf_model, fit_shape, *, finder=None, grouper=None,
375375
fitter=None, fitter_maxiters=100, xy_bounds=None,
@@ -489,7 +489,7 @@ def _init_model_param_storage(self, n_sources):
489489
for model_param in model_params:
490490
# initialize all parameters with np.nan (for invalid sources)
491491
param_data[model_param] = np.full(n_sources,
492-
self.DEFAULT_PARAM_VALUE)
492+
self._DEFAULT_PARAM_VALUE)
493493
param_data[f'{model_param}_fixed'] = [None] * n_sources
494494
param_data[f'{model_param}_bounds'] = [None] * n_sources
495495

@@ -523,7 +523,7 @@ def _cache_fitted_parameters(self, row_index, model):
523523
template_model = self.psf_model
524524
for param_name in template_model.param_names:
525525
# Set all parameters to np.nan for invalid sources
526-
param_data[param_name][row_index] = self.DEFAULT_PARAM_VALUE
526+
param_data[param_name][row_index] = self._DEFAULT_PARAM_VALUE
527527

528528
template_param = getattr(template_model, param_name)
529529
param_data[f'{param_name}_fixed'][row_index] = (
@@ -1803,6 +1803,34 @@ def _get_model_image_params(self):
18031803

18041804
def make_model_image(self, shape, *, psf_shape=None,
18051805
include_localbkg=False):
1806+
"""
1807+
Create a model image from the fit results.
1808+
1809+
Parameters
1810+
----------
1811+
shape : 2-tuple of int
1812+
The shape (ny, nx) of the output image.
1813+
1814+
psf_shape : 2-tuple of int, optional
1815+
The shape (ny, nx) of the PSF model to be rendered. If
1816+
`None`, the shape of the PSF model is determined by the
1817+
``fit_shape`` parameter.
1818+
1819+
include_localbkg : bool, optional
1820+
Whether to include the local background in the model image.
1821+
Default is `False`.
1822+
1823+
Returns
1824+
-------
1825+
image : `~numpy.ndarray`
1826+
The model image.
1827+
1828+
Raises
1829+
------
1830+
ValueError
1831+
If no results are available. Please run the `PSFPhotometry`
1832+
instance first.
1833+
"""
18061834
if self.results is None:
18071835
msg = ('No results available. Please run the PSFPhotometry '
18081836
'instance first.')
@@ -1817,6 +1845,34 @@ def make_model_image(self, shape, *, psf_shape=None,
18171845

18181846
def make_residual_image(self, data, *, psf_shape=None,
18191847
include_localbkg=False):
1848+
"""
1849+
Create a residual image from the fit results.
1850+
1851+
Parameters
1852+
----------
1853+
data : 2D `~numpy.ndarray`
1854+
The data image.
1855+
1856+
psf_shape : 2-tuple of int, optional
1857+
The shape (ny, nx) of the PSF model to be rendered. If
1858+
`None`, the shape of the PSF model is determined by the
1859+
``fit_shape`` parameter.
1860+
1861+
include_localbkg : bool, optional
1862+
Whether to include the local background in the model image
1863+
that is subtracted from the data. Default is `False`.
1864+
1865+
Returns
1866+
-------
1867+
image : `~numpy.ndarray`
1868+
The residual image.
1869+
1870+
Raises
1871+
------
1872+
ValueError
1873+
If no results are available. Please run the `PSFPhotometry`
1874+
instance first.
1875+
"""
18201876
if self.results is None:
18211877
msg = ('No results available. Please run the PSFPhotometry '
18221878
'instance first.')

0 commit comments

Comments
 (0)