LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Functions
lsst.meas.algorithms.testUtils Namespace Reference

Classes

class  MockRefcatDataId
 
class  MockReferenceObjectLoaderFromFiles
 
class  MockReferenceObjectLoaderFromMemory
 

Functions

 plantSources (bbox, kwid, sky, coordList, addPoissonNoise=True)
 
 makeRandomTransmissionCurve (rng, minWavelength=4000.0, maxWavelength=7000.0, nWavelengths=200, maxRadius=80.0, nRadii=30, perturb=0.05)
 
 makeDefectList ()
 

Function Documentation

◆ makeDefectList()

lsst.meas.algorithms.testUtils.makeDefectList ( )
Create a list of defects that can be used for testing.

Returns
-------
defectList = `list` [`lsst.meas.algorithms.Defect`]
    The list of defects.

Definition at line 150 of file testUtils.py.

150def makeDefectList():
151 """Create a list of defects that can be used for testing.
152
153 Returns
154 -------
155 defectList = `list` [`lsst.meas.algorithms.Defect`]
156 The list of defects.
157 """
158 defectList = [Defect(lsst.geom.Box2I(lsst.geom.Point2I(962, 0),
159 lsst.geom.Extent2I(2, 4611))),
160 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1316, 0),
161 lsst.geom.Extent2I(2, 4611))),
162 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1576, 0),
163 lsst.geom.Extent2I(4, 4611))),
164 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1626, 0),
165 lsst.geom.Extent2I(2, 4611))),
166 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1994, 252),
167 lsst.geom.Extent2I(2, 4359))),
168 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1426, 702),
169 lsst.geom.Extent2I(2, 3909))),
170 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1526, 1140),
171 lsst.geom.Extent2I(2, 3471))),
172 Defect(lsst.geom.Box2I(lsst.geom.Point2I(856, 2300),
173 lsst.geom.Extent2I(2, 2311))),
174 Defect(lsst.geom.Box2I(lsst.geom.Point2I(858, 2328),
175 lsst.geom.Extent2I(2, 65))),
176 Defect(lsst.geom.Box2I(lsst.geom.Point2I(859, 2328),
177 lsst.geom.Extent2I(1, 56))),
178 Defect(lsst.geom.Box2I(lsst.geom.Point2I(844, 2796),
179 lsst.geom.Extent2I(4, 1814))),
180 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1366, 2804),
181 lsst.geom.Extent2I(2, 1806))),
182 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1766, 3844),
183 lsst.geom.Extent2I(2, 766))),
184 Defect(lsst.geom.Box2I(lsst.geom.Point2I(1872, 4228),
185 lsst.geom.Extent2I(2, 382))),
186 ]
187
188 return defectList
189
190
An integer coordinate rectangle.
Definition Box.h:55

◆ makeRandomTransmissionCurve()

lsst.meas.algorithms.testUtils.makeRandomTransmissionCurve ( rng,
minWavelength = 4000.0,
maxWavelength = 7000.0,
nWavelengths = 200,
maxRadius = 80.0,
nRadii = 30,
perturb = 0.05 )
Create a random TransmissionCurve with nontrivial spatial and
wavelength variation.

Parameters
----------
rng : numpy.random.RandomState
    Random number generator.
minWavelength : float
    Average minimum wavelength for generated TransmissionCurves (will be
    randomly perturbed).
maxWavelength : float
    Average maximum wavelength for generated TransmissionCurves (will be
    randomly perturbed).
nWavelengths : int
    Number of samples in the wavelength dimension.
maxRadius : float
    Average maximum radius for spatial variation (will be perturbed).
nRadii : int
    Number of samples in the radial dimension.
perturb: float
    Fraction by which wavelength and radius bounds should be randomly
    perturbed.

Definition at line 106 of file testUtils.py.

107 maxRadius=80.0, nRadii=30, perturb=0.05):
108 """Create a random TransmissionCurve with nontrivial spatial and
109 wavelength variation.
110
111 Parameters
112 ----------
113 rng : numpy.random.RandomState
114 Random number generator.
115 minWavelength : float
116 Average minimum wavelength for generated TransmissionCurves (will be
117 randomly perturbed).
118 maxWavelength : float
119 Average maximum wavelength for generated TransmissionCurves (will be
120 randomly perturbed).
121 nWavelengths : int
122 Number of samples in the wavelength dimension.
123 maxRadius : float
124 Average maximum radius for spatial variation (will be perturbed).
125 nRadii : int
126 Number of samples in the radial dimension.
127 perturb: float
128 Fraction by which wavelength and radius bounds should be randomly
129 perturbed.
130 """
131 dWavelength = maxWavelength - minWavelength
132
133 def perturbed(x, s=perturb*dWavelength):
134 return x + 2.0*s*(rng.rand() - 0.5)
135
136 wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
137 radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
138 throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
139 # throughput will be a rectangle in wavelength, shifting to higher wavelengths and shrinking
140 # in height with radius, going to zero at all bounds.
141 peak0 = perturbed(0.9, 0.05)
142 start0 = perturbed(minWavelength + 0.25*dWavelength)
143 stop0 = perturbed(minWavelength + 0.75*dWavelength)
144 for i, r in enumerate(radii):
145 mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
146 throughput[mask, i] = peak0*(1.0 - r/1000.0)
147 return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)
148
149

◆ plantSources()

lsst.meas.algorithms.testUtils.plantSources ( bbox,
kwid,
sky,
coordList,
addPoissonNoise = True )
Make an exposure with stars (modelled as Gaussians)

Parameters
----------
bbox : `lsst.geom.Box2I`
    Parent bbox of exposure
kwid : `int`
    Kernal width (and height; kernal is square)
sky : `float`
    Amount of sky background (counts)
coordList : `list [tuple]`
    A list of [x, y, counts, sigma] where:
        * x,y are relative to exposure origin
        * counts is the integrated counts for the star
        * sigma is the Gaussian sigma in pixels
addPoissonNoise : `bool`
    If True: add Poisson noise to the exposure

Definition at line 42 of file testUtils.py.

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 # make an image with sources
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 # make a single gaussian psf
69 psf = SingleGaussianPsf(kwid, kwid, sigma)
70
71 # make an image of it and scale to the desired number of counts
72 thisPsfImg = psf.computeImage(lsst.geom.PointD(x, y))
73 thisPsfImg *= counts
74
75 # bbox a window in our image and add the fake star image
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 # add Poisson noise
87 if (addPoissonNoise):
88 np.random.seed(seed=1) # make results reproducible
89 imgArr = img.getArray()
90 imgArr[:] = np.random.poisson(imgArr)
91
92 # bundle into a maskedimage and an exposure
93 mask = afwImage.Mask(bbox)
94 var = img.convertFloat()
95 img -= sky
96 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
97 exposure = afwImage.makeExposure(mimg)
98
99 # insert an approximate psf
100 psf = SingleGaussianPsf(kwid, kwid, meanSigma)
101 exposure.setPsf(psf)
102
103 return exposure
104
105
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:81
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.
Definition Exposure.h:484