105.4. Synthetic source injection#
105.4. Synthetic source injection¶
For the Rubin Science Platform at data.lsst.cloud.
Data Release: Data Preview 2
Container Size: large
LSST Science Pipelines version: r30.0.11
Last verified to run: 2026-11-16
Repository: github.com/lsst/tutorial-notebooks
DOI: 10.11578/rubin/dc.20250909.20
Learning objective: Use LSST Science Pipelines tools to inject synthetic sources into a deep coadd image.
LSST data products: deep_coadd
Packages: lsst.source.injection, lsst.images, lsst.daf.butler, lsst.geom
Credit: Originally developed by Jeff Carlin in collaboration with Lee Kelvin and the Rubin Community Science Team. Much of the material is based on the documentation for the LSST source_injection package. Please consider acknowledging them if this notebook is used for the preparation of journal articles, software releases, or other notebooks.
Get Support: Everyone is encouraged to ask questions or raise issues in the Support Category of the Rubin Community Forum. Rubin staff will respond to all questions posted there.
Warning: This tutorial works with a
deep_coaddas anlsst.imagesCellCoaddobject (https://images.lsst.io/). However, the source injection task in the current recommended version of the LSST Science Pipelines requires anExposureFobject, which is being deprecated in favor oflsst.imagesobjects. Thedeep_coaddis therefore converted to anExposureFonly for the injection step itself (Section 4.1). Future versions of the LSST Science Pipelines are expected to support injection directly into aCellCoadd.
1. Introduction¶
This notebook demonstrates the use of the source_injection package from the LSST Science Pipelines to inject artificial sources (stars and galaxies) into images using the images' measured point-spread function, WCS, and photometric calibration. Sources can be injected into images produced during various stages of Pipelines processing, including visit-level images (e.g., visit_images), any dataset with a datasetType of Exposure (e.g., post_isr_image), and coadd images (e.g., deep_coadds). This notebook demonstrates injection into a deep_coadd. The driver that both creates and injects synthetic sources into images is based on Galsim, enabling injection of many types of sources, including stars, a variety of parameterized galaxy models, and postage stamp images.
Injecting directly into a deep_coadd is fast and convenient, and the injected sources are rendered with the coadd's own PSF. The most realistic approach, however, is to inject sources into the individual exposures and then build coadds from them, so that the injected sources go through the same processing as the real ones.
This notebook teaches some basics of using the source_injection package to insert artificial sources into images. Read the extensive documentation for more details and examples. Furthermore, the Galsim documentation provides much more detail on the types of sources that can be injected.
Related tutorials: The 105-series notebook tutorials about detecting and measuring sources and forced photometry.
1.1. Import packages¶
Import numpy, a fundamental package for scientific computing with arrays in Python
(numpy.org), and
matplotlib, a comprehensive library for data visualization
(matplotlib.org;
matplotlib gallery). Tools from Astropy will be used to read a FITS image, and work with Tables, sky coordinates, and units.
From the lsst package, import the butler, the Image class from lsst.images (images.lsst.io), lsst.geom for the sky position used to look up the skymap, the lsst.source.injection package to inject synthetic sources into images, and image display functions from the LSST Science Pipelines (pipelines.lsst.io).
import numpy as np
import matplotlib.pyplot as plt
from lsst.daf.butler import Butler
from lsst.images import Image
import lsst.afw.display as afwDisplay
import lsst.geom as geom
from astropy.io import fits
from astropy.table import Table, vstack
from astropy.coordinates import SkyCoord, Angle
import astropy.units as u
from lsst.source.injection import generate_injection_catalog
from lsst.source.injection import CoaddInjectConfig, CoaddInjectTask
1.2. Define parameters and functions¶
Set afwDisplay to use matplotlib.
afwDisplay.setDefaultBackend("matplotlib")
Create an instance of the butler pointing to the DP2 repository and collection, and assert it exists.
butler = Butler("dp2", collections="dp2")
assert butler is not None
2. Retrieve an image¶
2.1. Select a deep_coadd¶
Identify the deep coadd that contains a particular sky position, to inject sources into.
Coadds are divided into tracts and patches of a skymap.
Neighboring patches overlap slightly at their edges, so a butler query for patches that overlap a position can return a patch for which that position lies near the edge.
Instead, retrieve the skymap from the butler and use it to find the tract and patch whose inner region (i.e., excluding the overlaps) contains the position.
Define the position, near the center of the ECDFS field, and the band.
ra = 53.076
dec = -28.110
band = 'r'
Find the tract and patch that contain the position.
skymap_name = 'lsst_cells_v2'
skymap = butler.get('skyMap', skymap=skymap_name)
coord = geom.SpherePoint(ra, dec, geom.degrees)
tract_info = skymap.findTract(coord)
patch_info = tract_info.findPatch(coord)
tract = tract_info.getId()
patch = tract_info.getSequentialPatchIndex(patch_info)
print('tract: ', tract, ' patch: ', patch)
tract: 5063 patch: 15
Retrieve the $r$-band deep_coadd for this tract and patch.
By default, the butler returns a deep_coadd as an lsst.images CellCoadd object.
Print its type and its pixel units.
deep_coadd = butler.get('deep_coadd', skymap=skymap_name, tract=tract, patch=patch, band=band)
print(type(deep_coadd))
print('Pixel units: ', deep_coadd.unit)
<class 'lsst.images.cells._coadd.CellCoadd'> Pixel units: nJy
2.1.1. Extract the image center and dimensions¶
To generate synthetic sources to inject into the image, the coordinates and size of its bounding box are necessary.
Use the image's bounding box (bbox) and its sky projection (sky_projection, which maps pixel coordinates to sky coordinates and back) to extract the central (RA, Dec) coordinate, as an Astropy SkyCoord, and the image size in degrees.
The size is computed as the angular separation between pixels on opposite edges of the image.
Also print the bounding box and the type of PSF.
The bounding box does not start at pixel (0, 0): the pixel coordinates of a coadd are those of the whole tract, and the patch is positioned within it.
DP2 coadds are cell-based: each patch is divided into small cells, each with its own PSF model, and these are combined into a CellPointSpreadFunction.
bbox = deep_coadd.bbox
proj = deep_coadd.sky_projection
cen = proj.pixel_to_sky(x=bbox.x.center, y=bbox.y.center)
left = proj.pixel_to_sky(x=bbox.x.min, y=bbox.y.center)
right = proj.pixel_to_sky(x=bbox.x.max, y=bbox.y.center)
bottom = proj.pixel_to_sky(x=bbox.x.center, y=bbox.y.min)
top = proj.pixel_to_sky(x=bbox.x.center, y=bbox.y.max)
width = float(left.separation(right).deg)
height = float(bottom.separation(top).deg)
imsize = (width, height)
print('Image center in (RA, Dec): ', cen.ra.deg, cen.dec.deg)
print('Size of deep_coadd in degrees: ', imsize)
print('Bounding box: ', bbox)
print('PSF type: ', type(deep_coadd.psf).__name__)
Image center in (RA, Dec): 52.9930589718291 -28.103914179832266 Size of deep_coadd in degrees: (0.1832677364776037, 0.18325843387875684) Bounding box: [y=2850:6150, x=14850:18150] PSF type: CellPointSpreadFunction
3. Make a catalog of synthetic sources¶
Having retrieved a deep_coadd to inject into, now set up a simple synthetic source catalog.
3.1. Make a catalog of galaxies and stars¶
The source_injection package provides tools to create catalogs of synthetic sources. Here, use the generate_injection_catalog function to create the sources to inject.
Injection catalogs are defined in sky coordinates (RA, Dec), so a catalog can be injected into any image that overlaps it. Here, define the catalog to cover the coadd patch.
Set inject_size, the half-width of the region in which sources are placed, to 90% of half the patch width as determined above, so that sources are not placed right at the patch edges.
Lines of constant RA converge toward the poles, so a given angular distance on the sky corresponds to a larger range in RA by a factor of $1/\cos({\rm Dec})$; apply this factor to the RA limits so that the sources span the full width of the patch.
inject_size = 0.9 * imsize[0] / 2
ra_c = cen.ra.deg
dec_c = cen.dec.deg
ra_half = inject_size / np.cos(np.radians(dec_c))
ra_lim = [float(ra_c - ra_half), float(ra_c + ra_half)]
dec_lim = [float(dec_c - inject_size), float(dec_c + inject_size)]
print('RA limits: ', ra_lim)
print('Dec limits: ', dec_lim)
RA limits: [52.89956506163442, 53.08655288202378] Dec limits: [-28.18638466124719, -28.021443698417343]
3.1.1. Galaxies¶
The simplest form of a galaxy in Galsim is parameterized by a Sersic model: $I(r) = I_e~{\rm exp}\{-b_n [(\frac{r}{r_e})^{1/n}-1]\}$, which defines the shape of the galaxy's light profile as a function of radius (r) in terms of the "Sersic index" (n) and the "half-light radius" ($r_e$). (Note that $n = 1$ corresponds to an exponential profile.)
The above equation results in a circular galaxy. To create elongated (elliptical) Sersic profiles, additionally specify the minor-to-major axis ratio (q) with a rotation angle (beta).
generate_injection_catalog will automatically generate sources with all possible permutations of the parameters you provide. For example, the cell below specifies "number=2" to create 2 synthetic galaxies, but then specifies a single magnitude (mag), 3 values of Sersic index (n), 3 values of axis ratio (q), 2 values of beta, and a single value for half_light_radius. This should result in $2*1*3*3*2*1 = 36$ different combinations of those parameters.
Finally, provide the minimum and maximum RA and Dec coordinates in degrees defined above. In this case, generate_injection_catalog will randomly select positions within those limits.
my_injection_catalog_galaxies = generate_injection_catalog(
ra_lim=ra_lim,
dec_lim=dec_lim,
number=2,
seed='3210',
source_type="Sersic",
mag=[15.0],
n=[1, 2, 4],
q=[0.9, 0.5, 0.1],
beta=[31.0, 144.0],
half_light_radius=[5.0],
)
lsst.source.injection.utils._generate_injection_catalog INFO: Generated an injection catalog containing 36 sources: 18 combinations repeated 2 times.
3.1.2. Stars¶
Using a similar method, create a catalog of stars to be injected. Specify 7 values of magnitude, with 7 instances, which will result in 49 stars.
my_injection_catalog_stars = generate_injection_catalog(
ra_lim=ra_lim,
dec_lim=dec_lim,
number=7,
seed='432',
mag=[19.0, 19.5, 20.0, 20.5, 21.0, 21.5, 22.0],
source_type="Star",
)
lsst.source.injection.utils._generate_injection_catalog INFO: Generated an injection catalog containing 49 sources: 7 combinations repeated 7 times.
my_injection_catalog_stars['injection_id'] += 1000
inject_cat = vstack([my_injection_catalog_galaxies, my_injection_catalog_stars])
Inspect the catalog.
inject_cat
| injection_id | ra | dec | source_type | mag | n | q | beta | half_light_radius |
|---|---|---|---|---|---|---|---|---|
| int64 | float64 | float64 | str6 | float64 | int64 | float64 | float64 | float64 |
| 0 | 53.07747750078901 | -28.13143118232056 | Sersic | 15.0 | 1 | 0.9 | 31.0 | 5.0 |
| 1 | 52.966453482432826 | -28.029615773166338 | Sersic | 15.0 | 1 | 0.9 | 31.0 | 5.0 |
| 10 | 52.90801978856115 | -28.052015163180265 | Sersic | 15.0 | 1 | 0.9 | 144.0 | 5.0 |
| 11 | 52.90217641917398 | -28.174193654165336 | Sersic | 15.0 | 1 | 0.9 | 144.0 | 5.0 |
| 20 | 53.03657391507883 | -28.1395764150529 | Sersic | 15.0 | 1 | 0.5 | 31.0 | 5.0 |
| 21 | 52.98398359059433 | -28.119213333222056 | Sersic | 15.0 | 1 | 0.5 | 31.0 | 5.0 |
| 30 | 52.948923374271324 | -28.045906238631012 | Sersic | 15.0 | 1 | 0.5 | 144.0 | 5.0 |
| 31 | 53.013200437530166 | -28.0479425468141 | Sersic | 15.0 | 1 | 0.5 | 144.0 | 5.0 |
| 40 | 52.91386315794832 | -28.09477763502504 | Sersic | 15.0 | 1 | 0.1 | 31.0 | 5.0 |
| 41 | 53.05410402324034 | -28.03979731408176 | Sersic | 15.0 | 1 | 0.1 | 31.0 | 5.0 |
| 50 | 53.0248871763045 | -28.033688389532507 | Sersic | 15.0 | 1 | 0.1 | 144.0 | 5.0 |
| 51 | 53.007357068143 | -28.168084729616083 | Sersic | 15.0 | 1 | 0.1 | 144.0 | 5.0 |
| 60 | 53.068712446708254 | -28.176229962348422 | Sersic | 15.0 | 2 | 0.9 | 31.0 | 5.0 |
| 61 | 52.919706527335485 | -28.15790318870066 | Sersic | 15.0 | 2 | 0.9 | 31.0 | 5.0 |
| 70 | 53.04826065385317 | -28.16197580506683 | Sersic | 15.0 | 2 | 0.9 | 144.0 | 5.0 |
| 71 | 52.93139326610982 | -28.14364903141907 | Sersic | 15.0 | 2 | 0.9 | 144.0 | 5.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1044 | 52.989979113507545 | -28.084238047246544 | Star | 21.0 | -- | -- | -- | -- |
| 1045 | 52.960762266571706 | -28.133109443640574 | Star | 21.0 | -- | -- | -- | -- |
| 1046 | 52.914015311474365 | -28.04147557540177 | Star | 21.0 | -- | -- | -- | -- |
| 1050 | 53.004587536975464 | -28.135145751823657 | Star | 21.5 | -- | -- | -- | -- |
| 1051 | 52.90232857270003 | -28.10460112907739 | Star | 21.5 | -- | -- | -- | -- |
| 1052 | 53.01919596044338 | -28.08627435542963 | Star | 21.5 | -- | -- | -- | -- |
| 1053 | 52.94907552779737 | -28.031294034486347 | Star | 21.5 | -- | -- | -- | -- |
| 1054 | 52.96660563595887 | -28.047584499951025 | Star | 21.5 | -- | -- | -- | -- |
| 1055 | 53.063021230847134 | -28.0374029590356 | Star | 21.5 | -- | -- | -- | -- |
| 1056 | 53.016274275749794 | -28.110710053626644 | Star | 21.5 | -- | -- | -- | -- |
| 1060 | 53.07470796962147 | -28.165690374569927 | Star | 22.0 | -- | -- | -- | -- |
| 1061 | 53.04256943799205 | -28.14125467637291 | Star | 22.0 | -- | -- | -- | -- |
| 1062 | 52.96952732065245 | -28.092383279978883 | Star | 22.0 | -- | -- | -- | -- |
| 1063 | 53.00166585228188 | -28.127000519091318 | Star | 22.0 | -- | -- | -- | -- |
| 1064 | 53.02796101452413 | -28.07405650633112 | Star | 22.0 | -- | -- | -- | -- |
| 1065 | 53.077629654315054 | -28.1819808400346 | Star | 22.0 | -- | -- | -- | -- |
| 1066 | 52.9081719420872 | -28.16365406638684 | Star | 22.0 | -- | -- | -- | -- |
3.2. Add a postage stamp image entry¶
In addition to parameterized sources of many types, a postage-stamp image (for example, an output image from a simulation) can also be injected. This can be any image; the only requirement is that it must be in FITS format and have a valid WCS. This notebook demonstrates injection of an SDSS g-band image of the galaxy PGC 038749 downloaded from the NASA/IPAC Extragalactic Database (NED).
Load the image, then display it to see what it depicts:
stamp_path = '/rubin/cst_repos/tutorial-notebooks-data/data/'
stamp_img_hdu = fits.open(stamp_path + 'PGC_038749_I_g_bbl2011.fits')
fig = plt.figure()
plt.subplot()
im = plt.imshow(stamp_img_hdu[0].data, cmap='gray', vmin=-20.0, vmax=100, origin='lower')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
Figure 1: The SDSS g-band image of PGC 038749 displayed in grayscale, with axes in pixel coordinates.
Add a postage stamp entry into the injection catalog, using vstack to add an astropy Table containing a single row. Specify its position, magnitude, and source_type of Stamp, in addition to the filename of the image to inject. (It is fine to leave unnecessary columns empty.)
my_injection_catalog_stamp = Table(
{
'injection_id': [9999],
'ra': [cen.ra.deg + 0.01],
'dec': [cen.dec.deg - 0.01],
'source_type': ['Stamp'],
'mag': [14.8],
'stamp': [stamp_path + 'PGC_038749_I_g_bbl2011.fits'],
}
)
inject_cat = vstack([inject_cat, my_injection_catalog_stamp])
Option to view the injection catalog:
# inject_cat
4. Inject sources into an image¶
In Section 3, a catalog specifying the synthetic sources to inject was created.
Now run the task from source_injection that injects sources into the deep_coadd that was retrieved earlier, using the point spread function (PSF), photometric calibration, and WCS (World Coordinate System) of the deep_coadd.
In the RSP’s current recommended version of the LSST Science Pipelines, the injection task requires its input image to be an ExposureF, and its PSF, WCS, and photometric calibration to be the legacy lsst.afw objects that an ExposureF carries, rather than their lsst.images equivalents.
Convert the deep_coadd to an ExposureF just before injection, use it only for the injection, and convert the injected image back to an lsst.images Image afterward.
4.1. Convert the deep coadd to an ExposureF¶
Use the to_legacy method of the CellCoadd to create an ExposureF version of the deep_coadd.
The ExposureF carries the coadd's PSF (as a StitchedPsf, the legacy equivalent of the CellPointSpreadFunction), WCS, and photometric calibration.
The injection task edits its input image in place.
Setting copy=True makes the ExposureF an independent copy of the pixel data, so that the original deep_coadd is not modified by the injection and can be compared with the injected image later in this notebook.
legacy_coadd = deep_coadd.to_legacy(copy=True)
print(type(legacy_coadd))
<class 'lsst.afw.image._exposure.ExposureF'>
4.2. Instantiate the injection classes¶
First, instantiate the CoaddInjectConfig class. The CoaddInjectConfig class is where configuration of the injection task occurs, allowing for modifications to be made to how the task operates.
Then, after one configuration change (described below), instantiate the CoaddInjectTask, using inject_config as the configuration argument.
Note: More generally, depending on the dataset type being injected into, use the appropriate option from the following list:
from lsst.source.injection import CoaddInjectConfig, CoaddInjectTask
from lsst.source.injection import ExposureInjectConfig, ExposureInjectTask
from lsst.source.injection import VisitInjectConfig, VisitInjectTask
Both ExposureInject and VisitInject accept dimensions of ("instrument", "visit", "detector"). They differ in that ExposureInject takes a post_isr_image exposure (i.e., a raw image that has had "instrument signature removal," or ISR, applied, and no further processing) as an input, while VisitInject expects to operate on a visit_image (an image that has been astrometrically and photometrically calibrated to an external source).
inject_config = CoaddInjectConfig()
Before injecting, the task estimates the relationship between pixel flux and pixel variance in the image, so that it can update the variance plane to account for the injected sources.
To do so, it ignores pixels flagged in any of the mask planes listed in the configuration parameter bad_mask_names.
The default list was designed for single-epoch images and includes mask planes, such as CROSSTALK, that a deep_coadd does not have, and requesting a mask plane that does not exist raises an error.
Keep only the planes that the ExposureF version of the coadd has.
Note that the injection task works with the legacy (ExposureF) mask plane names, which differ for some planes from the names used by lsst.images: for example, INTRP and CR in the ExposureF correspond to INTERPOLATED and COSMIC_RAY in the CellCoadd.
Print both sets of names to compare them.
legacy_mask_planes = legacy_coadd.mask.getMaskPlaneDict().keys()
print('CellCoadd mask planes: ', sorted(deep_coadd.mask.schema.names))
print('ExposureF mask planes: ', sorted(legacy_mask_planes))
print('Default bad_mask_names: ', list(inject_config.bad_mask_names))
inject_config.bad_mask_names = [name for name in inject_config.bad_mask_names
if name in legacy_mask_planes]
print('Updated bad_mask_names: ', list(inject_config.bad_mask_names))
CellCoadd mask planes: ['CLIPPED', 'COSMIC_RAY', 'DETECTED', 'DETECTION_EDGE', 'INEXACT_PSF', 'INTERPOLATED', 'NO_DATA', 'REJECTED', 'SATURATED'] ExposureF mask planes: ['BAD', 'CLIPPED', 'CR', 'DETECTED', 'DETECTED_NEGATIVE', 'EDGE', 'INEXACT_PSF', 'INTRP', 'NO_DATA', 'REJECTED', 'SAT', 'STREAK', 'SUSPECT', 'VIGNETTED'] Default bad_mask_names: ['BAD', 'CR', 'CROSSTALK', 'INTRP', 'NO_DATA', 'SAT', 'SUSPECT', 'UNMASKEDNAN'] Updated bad_mask_names: ['BAD', 'CR', 'INTRP', 'NO_DATA', 'SAT', 'SUSPECT']
Instantiate the CoaddInjectTask with the updated configuration.
inject_task = CoaddInjectTask(config=inject_config)
4.3. Run the source_injection task¶
Execute the run method of the inject_task.
The run method needs the following inputs:
- the input injection catalog
- the input image, here the
ExposureFversion of thedeep_coadd - the PSF of the input image
- the WCS information
- the photometric calibration information
The PSF, WCS, and photo_calib inputs are taken from the ExposureF version of the deep_coadd.
The inject task provides two outputs:
- the output exposure with sources injected
- the output source injection catalog
The output source injection catalog contains the input sources, with some additional columns describing the outcome of the injection. Note that this catalog is NOT the science catalog containing the full suite of LSST Science Pipelines outputs. To get that, this source injected image would need to be processed by additional Science Pipelines tasks.
Run the source injection task and extract the "output_exposure" and "output_catalog":
injected_output = inject_task.run(
injection_catalogs=inject_cat,
input_exposure=legacy_coadd,
psf=legacy_coadd.psf,
photo_calib=legacy_coadd.photoCalib,
wcs=legacy_coadd.wcs,
)
injected_exposure = injected_output.output_exposure
injected_catalog = injected_output.output_catalog
lsst.coaddInjectTask INFO: Retrieved 86 injection sources from 86 HTM trixels.
lsst.coaddInjectTask INFO: Catalog cleaning removed 0 of 86 sources; 86 remaining for catalog checking.
lsst.coaddInjectTask INFO: Catalog checking flagged 0 of 86 sources; 86 remaining for source generation.
lsst.coaddInjectTask INFO: Adding INJECTED and INJECTED_CORE mask planes to the exposure.
lsst.coaddInjectTask INFO: Generating 86 injection sources consisting of 3 unique types: Sersic(36), DeltaFunction(49), Stamp(1).
lsst.coaddInjectTask INFO: Injected 86 of 86 potential sources. 0 sources flagged and skipped.
A GalSimFFTSizeWarning may appear. GalSim draws extended sources using a Fast Fourier Transform (FFT), and very extended, highly elongated profiles (such as the $n = 4$, $q = 0.1$ Sersic galaxies, with a half-light radius of 5 arcseconds) can require a large FFT.
This is a warning rather than an error: the source is still drawn, at the cost of temporarily using more memory.
A source that could not be drawn at all would instead be flagged with FFT_SIZE_ERROR.
Option to view the output injection catalog:
# injected_catalog
The output exposure is an ExposureF.
Convert its image plane back to an lsst.images Image, with the same pixel units and sky projection as the deep_coadd, for the rest of this notebook.
The Image shares its pixel data with the ExposureF, rather than copying it.
injected_image = Image.from_legacy(injected_exposure.image,
unit=deep_coadd.unit,
sky_projection=deep_coadd.sky_projection)
print(type(injected_image))
print('Bounding box: ', injected_image.bbox)
<class 'lsst.images._image.Image'> Bounding box: [y=2850:6150, x=14850:18150]
4.4. Compare the images before and after injection¶
Display the images in separate panels with afwDisplay, and compare them to confirm that the sources have been injected.
afwDisplay accepts lsst.images objects directly, and uses the image's sky projection as its WCS, so the axes are labeled in RA and Dec.
fig, ax = plt.subplots(1, 2, figsize=(10, 6), dpi=150)
plt.sca(ax[0])
display0 = afwDisplay.Display(frame=fig)
display0.scale('linear', 'zscale')
display0.mtv(deep_coadd.image)
plt.title('deep_coadd')
plt.sca(ax[1])
display1 = afwDisplay.Display(frame=fig)
display1.scale('linear', 'zscale')
display1.mtv(injected_image)
plt.title('injected deep_coadd')
plt.tight_layout()
plt.show()
Figure 2: The
deep_coaddbefore (left) and after (right) synthetic source injection. Thezscalealgorithm sets the display range based on the noise in the image.
Zoom in on the injected postage stamp image.
Use the bbox_from_sky_circle method of the CellCoadd to compute the bounding box of a circle on the sky, centered on the stamp's (RA, Dec), with a radius of 50 arcseconds (250 pixels).
Setting clip=True clips the bounding box to the patch, in case the circle extends past the patch edge.
stamp_coord = SkyCoord(ra=my_injection_catalog_stamp['ra'][0],
dec=my_injection_catalog_stamp['dec'][0], unit='deg')
stamp_bbox = deep_coadd.bbox_from_sky_circle(stamp_coord, Angle(50, u.arcsec), clip=True)
print(stamp_bbox)
[y=4070:4571, x=16091:16592]
Display the same region of the coadd before and after injection.
Indexing an lsst.images image with a bounding box (e.g., deep_coadd.image[stamp_bbox]) interprets the box in the image's own pixel coordinates, here those of the tract, and returns a new Image covering that region.
fig, ax = plt.subplots(1, 2, figsize=(10, 6), dpi=150)
plt.sca(ax[0])
display0 = afwDisplay.Display(frame=fig)
display0.scale('linear', 'zscale')
display0.mtv(deep_coadd.image[stamp_bbox])
plt.title('deep_coadd')
plt.sca(ax[1])
display1 = afwDisplay.Display(frame=fig)
display1.scale('linear', 'zscale')
display1.mtv(injected_image[stamp_bbox])
plt.title('injected deep_coadd')
plt.tight_layout()
plt.show()
Figure 3: Zoom-in of the injected stamp. The stamp appears inside a faint rectangle. A postage stamp is injected in its entirety, including its own sky noise and any residual background, so the edges of the stamp are visible wherever its noise is larger than that of the image it is injected into. Ideally, postage stamps for injection should be noiseless models, or carefully background-subtracted images.