42def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True):
43 """Make an exposure with stars (modelled as Gaussians)
44
45 Parameters
46 ----------
47 bbox : `lsst.geom.Box2I`
48 Parent bbox of exposure
49 kwid : `int`
50 Kernal width (and height; kernal is square)
51 sky : `float`
52 Amount of sky background (counts)
53 coordList : `list [tuple]`
54 A list of [x, y, counts, sigma] where:
55 * x,y are relative to exposure origin
56 * counts is the integrated counts for the star
57 * sigma is the Gaussian sigma in pixels
58 addPoissonNoise : `bool`
59 If True: add Poisson noise to the exposure
60 """
61
62 img = afwImage.ImageD(bbox)
63 meanSigma = 0.0
64 for coord in coordList:
65 x, y, counts, sigma = coord
66 meanSigma += sigma
67
68
69 psf = SingleGaussianPsf(kwid, kwid, sigma)
70
71
73 thisPsfImg *= counts
74
75
76 psfBox = thisPsfImg.getBBox()
77 psfBox.clip(bbox)
78 if psfBox != thisPsfImg.getBBox():
79 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
80 imgSeg = img[psfBox, afwImage.PARENT]
81 imgSeg += thisPsfImg
82 meanSigma /= len(coordList)
83
84 img += sky
85
86
87 if (addPoissonNoise):
88 np.random.seed(seed=1)
89 imgArr = img.getArray()
90 imgArr[:] = np.random.poisson(imgArr)
91
92
94 var = img.convertFloat()
95 img -= sky
96 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
98
99
100 psf = SingleGaussianPsf(kwid, kwid, meanSigma)
101 exposure.setPsf(psf)
102
103 return exposure
104
105
Represent a 2-dimensional array of bitmask pixels.
std::shared_ptr< Exposure< ImagePixelT, MaskPixelT, VariancePixelT > > makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, std::shared_ptr< geom::SkyWcs const > wcs=std::shared_ptr< geom::SkyWcs const >())
A function to return an Exposure of the correct type (cf.