24 __all__ = [
"plantSources",
"makeRandomTransmissionCurve",
"makeDefectList"]
30 from .
import SingleGaussianPsf
34 def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True):
35 """Make an exposure with stars (modelled as Gaussians)
39 bbox : `lsst.geom.Box2I`
40 Parent bbox of exposure
42 Kernal width (and height; kernal is square)
44 Amount of sky background (counts)
45 coordList : `list [tuple]`
46 A list of [x, y, counts, sigma] where:
47 * x,y are relative to exposure origin
48 * counts is the integrated counts for the star
49 * sigma is the Gaussian sigma in pixels
50 addPoissonNoise : `bool`
51 If True: add Poisson noise to the exposure
54 img = afwImage.ImageD(bbox)
56 for coord
in coordList:
57 x, y, counts, sigma = coord
68 psfBox = thisPsfImg.getBBox()
70 if psfBox != thisPsfImg.getBBox():
71 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
72 imgSeg = img[psfBox, afwImage.PARENT]
74 meanSigma /= len(coordList)
80 np.random.seed(seed=1)
81 imgArr = img.getArray()
82 imgArr[:] = np.random.poisson(imgArr)
85 mask = afwImage.Mask(bbox)
86 var = img.convertFloat()
88 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
89 exposure = afwImage.makeExposure(mimg)
99 maxRadius=80.0, nRadii=30, perturb=0.05):
100 """Create a random TransmissionCurve with nontrivial spatial and
101 wavelength variation.
105 rng : numpy.random.RandomState
106 Random number generator.
107 minWavelength : float
108 Average minimum wavelength for generated TransmissionCurves (will be
110 maxWavelength : float
111 Average maximum wavelength for generated TransmissionCurves (will be
114 Number of samples in the wavelength dimension.
116 Average maximum radius for spatial variation (will be perturbed).
118 Number of samples in the radial dimension.
120 Fraction by which wavelength and radius bounds should be randomly
123 dWavelength = maxWavelength - minWavelength
125 def perturbed(x, s=perturb*dWavelength):
126 return x + 2.0*s*(rng.rand() - 0.5)
128 wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
129 radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
130 throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
133 peak0 = perturbed(0.9, 0.05)
134 start0 = perturbed(minWavelength + 0.25*dWavelength)
135 stop0 = perturbed(minWavelength + 0.75*dWavelength)
136 for i, r
in enumerate(radii):
137 mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
138 throughput[mask, i] = peak0*(1.0 - r/1000.0)
139 return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)
143 """Create a list of defects that can be used for testing.
147 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)