28 from .
import SingleGaussianPsf
32 def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True):
33 """Make an exposure with stars (modelled as Gaussians)
35 @param bbox: parent bbox of exposure
36 @param kwid: kernel width (and height; kernel is square)
37 @param sky: amount of sky background (counts)
38 @param coordList: a list of [x, y, counts, sigma], where:
39 * x,y are relative to exposure origin
40 * counts is the integrated counts for the star
41 * sigma is the Gaussian sigma in pixels
42 @param addPoissonNoise: add Poisson noise to the exposure?
45 img = afwImage.ImageD(bbox)
47 for coord
in coordList:
48 x, y, counts, sigma = coord
59 psfBox = thisPsfImg.getBBox()
61 if psfBox != thisPsfImg.getBBox():
62 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
63 imgSeg = img[psfBox, afwImage.PARENT]
65 meanSigma /= len(coordList)
71 np.random.seed(seed=1)
72 imgArr = img.getArray()
73 imgArr[:] = np.random.poisson(imgArr)
76 mask = afwImage.Mask(bbox)
77 var = img.convertFloat()
79 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
80 exposure = afwImage.makeExposure(mimg)
90 maxRadius=80.0, nRadii=30, perturb=0.05):
91 """Create a random TransmissionCurve with nontrivial spatial and
96 rng : numpy.random.RandomState
97 Random number generator.
99 Average minimum wavelength for generated TransmissionCurves (will be
101 maxWavelength : float
102 Average maximum wavelength for generated TransmissionCurves (will be
105 Number of samples in the wavelength dimension.
107 Average maximum radius for spatial variation (will be perturbed).
109 Number of samples in the radial dimension.
111 Fraction by which wavelength and radius bounds should be randomly
114 dWavelength = maxWavelength - minWavelength
116 def perturbed(x, s=perturb*dWavelength):
117 return x + 2.0*s*(rng.rand() - 0.5)
119 wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
120 radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
121 throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
124 peak0 = perturbed(0.9, 0.05)
125 start0 = perturbed(minWavelength + 0.25*dWavelength)
126 stop0 = perturbed(minWavelength + 0.75*dWavelength)
127 for i, r
in enumerate(radii):
128 mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
129 throughput[mask, i] = peak0*(1.0 - r/1000.0)
130 return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)
134 """Create a list of defects that can be used for testing.
138 defectList = `list` [`lsst.meas.algorithms.Defect`]