make_psf_model_image#
- photutils.psf.make_psf_model_image(shape, psf_model, n_sources, *, model_shape=None, min_separation=1, border_size=None, seed=0, progress_bar=False, **kwargs)[source]#
Make an example image containing PSF model images.
Source parameters are randomly generated using an optional
seed.- Parameters:
- shape2-tuple of int
The shape of the output image.
- psf_model2D
astropy.modeling.Model The PSF model. The model must have parameters named
x_0,y_0, andflux, corresponding to the center (x, y) position and flux, or it must have ‘x_name’, ‘y_name’, and ‘flux_name’ attributes that map to the x, y, and flux parameters. The model must be two-dimensional such that it accepts 2 inputs (e.g., x and y) and provides 1 output.The model is evaluated at the center of each pixel. To simulate the pixelated image of a source, the value of the model at a position must be the flux in a pixel centered at that position, as for the analytic models whose names end in
PRFand for an image-based model made from an ePSF (see Terminology).- n_sourcesint
The number of sources to generate. If
min_separationis too large, the number of requested sources may not fit within the givenshapeand therefore the number of sources generated may be less thann_sources.- model_shape
None, int, or 2-tuple of int, optional The shape around the center (x, y) position that will be used to evaluate the
psf_model. If a single integer is provided, a square shape is used. IfNone, then the shape will be determined from thepsf_modelbounding box (an error will be raised if the model does not have a bounding box).- min_separationfloat, optional
The minimum separation between the centers of two sources. Note that if the minimum separation is too large, the number of sources generated may be less than
n_sources.- border_size
None, tuple of 2 int, or int, optional The (ny, nx) size of the exclusion border around the image edges where no sources will be generated that have centers within the border region. If a single integer is provided, it will be used for both dimensions. If
None, then a border size equal to half the (y, x) size of the evaluated PSF model (taking any oversampling into account) will be used.- seedint, optional
A seed to initialize the
numpy.random.BitGenerator. IfNone, then fresh, unpredictable entropy will be pulled from the OS.- progress_barbool, optional
Whether to display a progress bar when creating the sources. The progress bar requires that the tqdm optional dependency be installed.
- **kwargsdict
Keyword arguments are accepted for additional model parameters. The values should be 2-tuples of the lower and upper bounds for the parameter range. The parameter values will be uniformly sampled over the half-open interval defined by the lower and upper bounds (i.e., the lower bound is inclusive and the upper bound is exclusive). A
fluxkeyword is mapped to the model’s flux parameter name (e.g., for models with aflux_nameattribute). If the parameter is not in the inputpsf_modelparameter names, it will be ignored. Keywords matching the model’s x and y position parameter names are also ignored because the source positions are randomly generated.
- Returns:
- data2D
ndarray The simulated image.
- table
QTable A table containing the parameters of the generated sources. It has an
'id'column with unique source IDs, columns for the x and y positions named after thepsf_modelposition parameters, and one column for each model parameter given in**kwargs, named after the model parameter. A parameter that is not given, including the flux, has no column and takes the value set inpsf_modelfor every source.
- data2D
- Warns:
AstropyUserWarningIf fewer than
n_sourcessources could be generated with the givenshapeandmin_separation.
Examples
>>> from photutils.psf import CircularGaussianPRF, make_psf_model_image >>> shape = (150, 200) >>> psf_model = CircularGaussianPRF(fwhm=3.5) >>> n_sources = 10 >>> data, params = make_psf_model_image(shape, psf_model, n_sources, ... flux=(100, 250), ... min_separation=10, ... seed=0) >>> params['x_0'].info.format = '.4f' # optional format >>> params['y_0'].info.format = '.4f' >>> params['flux'].info.format = '.4f' >>> print(params) id x_0 y_0 flux --- -------- -------- -------- 1 125.2010 72.3184 147.9522 2 57.6408 39.1380 128.1262 3 15.5391 115.4520 200.8790 4 11.0411 131.7530 129.2661 5 157.6417 43.6615 186.6532 6 175.9470 80.2172 190.3359 7 142.2274 132.7563 244.3635 8 108.0270 13.4284 110.8398 9 180.0533 106.0888 174.9959 10 158.1171 90.3260 211.6146
import matplotlib.pyplot as plt from photutils.psf import CircularGaussianPRF, make_psf_model_image shape = (150, 200) psf_model = CircularGaussianPRF(fwhm=3.5) n_sources = 10 data, params = make_psf_model_image(shape, psf_model, n_sources, flux=(100, 250), min_separation=10, seed=0) fig, ax = plt.subplots() ax.imshow(data, origin='lower')
(
Source code,png,hires.png,pdf,svg)