43 """Make an exposure with stars (modelled as Gaussians)
47 bbox : `lsst.geom.Box2I`
48 Parent bbox of exposure
50 Kernal width (and height; kernal is square)
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
62 img = afwImage.ImageD(bbox)
64 for coord
in coordList:
65 x, y, counts, sigma = coord
76 psfBox = thisPsfImg.getBBox()
78 if psfBox != thisPsfImg.getBBox():
79 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
80 imgSeg = img[psfBox, afwImage.PARENT]
82 meanSigma /= len(coordList)
89 rng = np.random.Generator(np.random.MT19937(5))
90 imgArr = img.getArray()
91 imgArr[:] = rng.poisson(imgArr)
94 mask = afwImage.Mask(bbox)
95 var = img.convertFloat()
97 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
98 exposure = afwImage.makeExposure(mimg)
108 maxRadius=80.0, nRadii=30, perturb=0.05):
109 """Create a random TransmissionCurve with nontrivial spatial and
110 wavelength variation.
114 rng : numpy.random.RandomState
115 Random number generator.
116 minWavelength : float
117 Average minimum wavelength for generated TransmissionCurves (will be
119 maxWavelength : float
120 Average maximum wavelength for generated TransmissionCurves (will be
123 Number of samples in the wavelength dimension.
125 Average maximum radius for spatial variation (will be perturbed).
127 Number of samples in the radial dimension.
129 Fraction by which wavelength and radius bounds should be randomly
132 dWavelength = maxWavelength - minWavelength
134 def perturbed(x, s=perturb*dWavelength):
135 return x + 2.0*s*(rng.rand() - 0.5)
137 wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
138 radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
139 throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
142 peak0 = perturbed(0.9, 0.05)
143 start0 = perturbed(minWavelength + 0.25*dWavelength)
144 stop0 = perturbed(minWavelength + 0.75*dWavelength)
145 for i, r
in enumerate(radii):
146 mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
147 throughput[mask, i] = peak0*(1.0 - r/1000.0)
148 return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)