make_psf_model#
- photutils.psf.make_psf_model(model, *, x_name=None, y_name=None, flux_name=None, normalize=True, dx=50, dy=50, subsample=100, use_dblquad=False)[source]#
Make a PSF model that can be used with the PSF photometry classes (
PSFPhotometry
orIterativePSFPhotometry
) from an Astropy fittable 2D model.If the
x_name
,y_name
, orflux_name
keywords are input, this function will map thosemodel
parameter names tox_0
,y_0
, orflux
, respectively.If any of the
x_name
,y_name
, orflux_name
keywords areNone
, then a new parameter will be added to the model corresponding to the missing parameter. Any new position parameters will be set to a default value of 0, and any new flux parameter will be set to a default value of 1.The output PSF model will have
x_name
,y_name
, andflux_name
attributes that contain the name of the corresponding model parameter.Note
This function is needed only in cases where the 2D PSF model does not have
x_0
,y_0
, andflux
parameters.It is not needed for any of the PSF models provided by Photutils.
- Parameters:
- model
Fittable2DModel
An Astropy fittable 2D model to use as a PSF.
- x_name
str
orNone
, optional The name of the
model
parameter that corresponds to the x center of the PSF. IfNone
, the model will be assumed to be centered at x=0, and a new model parameter calledxpos_0
will be added for the x position.- y_name
str
orNone
, optional The name of the
model
parameter that corresponds to the y center of the PSF. IfNone
, the model will be assumed to be centered at y=0, and a new parameter calledypos_1
will be added for the y position.- flux_name
str
orNone
, optional The name of the
model
parameter that corresponds to the total flux of a source. IfNone
, a new model parameter calledflux_3
will be added for model flux.- normalizebool, optional
If
True
, the inputmodel
will be integrated and rescaled so that its sum integrates to 1. This normalization occurs only once for the inputmodel
. If the total flux ofmodel
somehow depends on (x, y) position, then one will need to correct the fitted model fluxes for this effect.- dx, dyodd int, optional
The size of the integration grid in x and y for normalization. Must be odd. These keywords are ignored if
normalize
isFalse
oruse_dblquad
isTrue
.- subsampleint, optional
The subsampling factor for the integration grid along each axis for normalization. Each pixel will be sampled
subsample
xsubsample
times. This keyword is ignored ifnormalize
isFalse
oruse_dblquad
isTrue
.- use_dblquadbool, optional
If
True
, then usescipy.integrate.dblquad
to integrate the model for normalization. This is much slower than the default integration of the evaluated model, but it is more accurate. This keyword is ignored ifnormalize
isFalse
.
- model
- Returns:
- result
CompoundModel
A PSF model that can be used with the PSF photometry classes. The returned model will always be an Astropy compound model.
- result
Notes
To normalize the model, by default it is discretized on a grid of size
dx
xdy
from the model center with a subsampling factor ofsubsample
. The model is then integrated over the grid using trapezoidal integration.If the
use_dblquad
keyword is set toTrue
, then the model is integrated usingscipy.integrate.dblquad
. This is much slower than the default integration of the evaluated model, but it is more accurate. Also, note that thedblquad
integration can sometimes fail, e.g., return zero for a non-zero model. This can happen when the model function is sharply localized relative to the size of the integration interval.Examples
>>> from astropy.modeling.models import Gaussian2D >>> from photutils.psf import make_psf_model >>> model = Gaussian2D(x_stddev=2, y_stddev=2) >>> psf_model = make_psf_model(model, x_name='x_mean', y_name='y_mean') >>> print(psf_model.param_names) ('amplitude_2', 'x_mean_2', 'y_mean_2', 'x_stddev_2', 'y_stddev_2', 'theta_2', 'amplitude_3', 'amplitude_4')