EPSFBuilder#
- class photutils.psf.EPSFBuilder(*, oversampling=4, shape=None, smoothing_kernel='quartic', sigma_clip=<default: SigmaClip(sigma=3.0, maxiters=10)>, recentering_func=<function centroid_com>, recentering_boxsize=(5, 5), recentering_maxiters=20, center_accuracy=0.001, fitter=None, fit_shape=5, fitter_maxiters=100, maxiters=10, progress_bar=True)[source]#
Bases:
objectClass to build an effective PSF (ePSF).
See Anderson and King 2000 (PASP 112, 1360) and Anderson 2016 (WFC3 ISR 2016-12) for details.
- Parameters:
- oversamplingint or array_like (int)
The integer oversampling factor(s) of the output ePSF relative to the input
starsalong each axis. Ifoversamplingis a scalar then it will be used for both axes. Ifoversamplinghas two elements, they must be in(y, x)order.- shapefloat, tuple of two floats, or
None, optional The (ny, nx) shape of the output ePSF. If the input shape is even along any axis, it will be made odd by adding one. If the
shapeisNone, it will be derived from the sizes of the inputstarsand the ePSFoversamplingfactor. The output ePSF will always have odd sizes along both axes to ensure a well-defined central pixel.- smoothing_kernel{‘quartic’, ‘quadratic’}, 2D
ndarray, orNone The smoothing kernel to apply to the ePSF during each iteration step. The predefined
'quartic'and'quadratic'kernels are derived from fourth and second degree polynomials, respectively. Alternatively, a custom 2D array can be input. IfNonethen no smoothing will be performed.- sigma_clip
astropy.stats.SigmaClipinstance, optional A
SigmaClipobject that defines the sigma clipping parameters used to determine which pixels are ignored when stacking the ePSF residuals in each iteration step. IfNonethen no sigma clipping will be performed.- recentering_funccallable, optional
A callable object that is used to calculate the centroid of a 2D array. The callable must accept a 2D
ndarray, have amaskkeyword and optionally anerrorkeyword. The callable object must return a tuple of (x, y) centroids.- recentering_boxsizefloat or tuple of two floats, optional
The size (in pixels) of the box used to calculate the centroid of the ePSF during each build iteration. The size is in the input star (i.e., undersampled) pixel space; it is automatically scaled by the oversampling factor when applied to the oversampled ePSF grid. If a single integer number is provided, then a square box will be used. If two values are provided, then they must be in
(ny, nx)order.recentering_boxsizemust have odd values and be greater than or equal to 3 for both axes.- recentering_maxitersint, optional
The maximum number of recentering iterations to perform during each ePSF build iteration.
- center_accuracyfloat, optional
The desired accuracy for the centers of stars. The building iterations will stop if the centers of all the stars change by less than
center_accuracypixels between iterations. All stars must meet this condition for the building iterations to stop.- fitter
FitterorEPSFFitter, optional A
Fitterobject used to fit the ePSF to stars. IfNone, then the defaultTRFLSQFitterwill be used.Deprecated since version 3.0: Passing an
EPSFFitterinstance is deprecated; use thefitter,fit_shape, andfitter_maxitersparameters instead.- fit_shapeint, tuple of int, or
None, optional The size (in pixels) of the box centered on the star to be used for ePSF fitting. This allows using only a small number of central pixels of the star (i.e., where the star is brightest) for fitting. If
fit_shapeis a scalar then a square box of sizefit_shapewill be used. Iffit_shapehas two elements, they must be in(ny, nx)order.fit_shapemust have odd values and be greater than or equal to 3 for both axes. IfNone, the fitter will use the entire star image.- fitter_maxitersint, optional
The maximum number of iterations in which the
fitteris called for each star. The value can be increased if the fit is not converging. This parameter is passed to thefitterif it supports themaxiterparameter and ignored otherwise.- maxitersint, optional
The maximum number of ePSF building iterations to perform.
- progress_barbool, option
Whether to print the progress bar during the build iterations. The progress bar requires that the tqdm optional dependency be installed.
Methods Summary
__call__(stars)Build an ePSF from input stars.
build_epsf(stars, *[, epsf])Build iteratively an ePSF from star cutouts.
Methods Documentation
- __call__(stars)[source]#
Build an ePSF from input stars.
- Parameters:
- stars
EPSFStars The stars used to build the ePSF.
- stars
- Returns:
- result
EPSFBuildResult The result of the ePSF building process.
- result
- build_epsf(stars, *, epsf=None)[source]#
Build iteratively an ePSF from star cutouts.
This method builds an ePSF from an initial model when
epsfis provided, or from scratch whenepsfisNone. In the latter case, it is equivalent to invoking anEPSFBuilderinstance on the inputstars.- Parameters:
- Returns:
- result
EPSFBuildResultor tuple The ePSF building results. Returns an
EPSFBuildResultobject with detailed information about the building process. For backward compatibility, the result can be unpacked as a tuple:(epsf, fitted_stars) = epsf_builder(stars).
- result
Notes
The structured result object contains: - epsf: The final constructed ePSF - fitted_stars: Stars with updated centers/fluxes - iterations: Number of iterations performed - converged: Whether convergence was achieved - final_center_accuracy: Final center movement accuracy - n_excluded_stars: Number of stars excluded due to fit failures - excluded_star_indices: Indices of excluded stars