28 from .
import SingleGaussianPsf
32 def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True):
33 """Make an exposure with stars (modelled as Gaussians)
37 bbox : `lsst.geom.Box2I`
38 Parent bbox of exposure
40 Kernal width (and height; kernal is square)
42 Amount of sky background (counts)
43 coordList : `list [tuple]`
44 A list of [x, y, counts, sigma] where:
45 * x,y are relative to exposure origin
46 * counts is the integrated counts for the star
47 * sigma is the Gaussian sigma in pixels
48 addPoissonNoise : `bool`
49 If True: add Poisson noise to the exposure
52 img = afwImage.ImageD(bbox)
54 for coord
in coordList:
55 x, y, counts, sigma = coord
66 psfBox = thisPsfImg.getBBox()
68 if psfBox != thisPsfImg.getBBox():
69 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
70 imgSeg = img[psfBox, afwImage.PARENT]
72 meanSigma /= len(coordList)
78 np.random.seed(seed=1)
79 imgArr = img.getArray()
80 imgArr[:] = np.random.poisson(imgArr)
83 mask = afwImage.Mask(bbox)
84 var = img.convertFloat()
86 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
87 exposure = afwImage.makeExposure(mimg)
97 maxRadius=80.0, nRadii=30, perturb=0.05):
98 """Create a random TransmissionCurve with nontrivial spatial and
103 rng : numpy.random.RandomState
104 Random number generator.
105 minWavelength : float
106 Average minimum wavelength for generated TransmissionCurves (will be
108 maxWavelength : float
109 Average maximum wavelength for generated TransmissionCurves (will be
112 Number of samples in the wavelength dimension.
114 Average maximum radius for spatial variation (will be perturbed).
116 Number of samples in the radial dimension.
118 Fraction by which wavelength and radius bounds should be randomly
121 dWavelength = maxWavelength - minWavelength
123 def perturbed(x, s=perturb*dWavelength):
124 return x + 2.0*s*(rng.rand() - 0.5)
126 wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
127 radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
128 throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
131 peak0 = perturbed(0.9, 0.05)
132 start0 = perturbed(minWavelength + 0.25*dWavelength)
133 stop0 = perturbed(minWavelength + 0.75*dWavelength)
134 for i, r
in enumerate(radii):
135 mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
136 throughput[mask, i] = peak0*(1.0 - r/1000.0)
137 return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)
141 """Create a list of defects that can be used for testing.
145 defectList = `list` [`lsst.meas.algorithms.Defect`]
Encapsulate information about a bad portion of a detector.
Represent a PSF as a circularly symmetrical Gaussian.
def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True)
def makeRandomTransmissionCurve(rng, minWavelength=4000.0, maxWavelength=7000.0, nWavelengths=200, maxRadius=80.0, nRadii=30, perturb=0.05)