Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0d33ba9806+23fb6b1458,g0fba68d861+c03ca182fa,g1e78f5e6d3+6885d38a10,g1ec0fe41b4+f8df4a5e9d,g1fd858c14a+1f896281a9,g35bb328faa+fcb1d3bbc8,g4af146b050+32dc2822d5,g4d2262a081+2d16baa2ff,g53246c7159+fcb1d3bbc8,g5a012ec0e7+6ce3c67fb7,g60b5630c4e+23fb6b1458,g67b6fd64d1+b5a8974b5d,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+4e9c20b633,g8852436030+17127e6d9c,g89139ef638+b5a8974b5d,g9125e01d80+fcb1d3bbc8,g94187f82dc+23fb6b1458,g989de1cb63+b5a8974b5d,g9f33ca652e+b775bc0ddd,g9f7030ddb1+0d26baa418,ga2b97cdc51+23fb6b1458,ga44b1db4f6+f3405f2437,gabe3b4be73+1e0a283bba,gabf8522325+a9d2faf463,gb1101e3267+1c10e8ebae,gb58c049af0+f03b321e39,gb89ab40317+b5a8974b5d,gcf25f946ba+17127e6d9c,gd6cbbdb0b4+ace4583378,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+551b1246a4,ge278dab8ac+fa73091e6d,ge410e46f29+b5a8974b5d,gf67bdafdda+b5a8974b5d,gfe06eef73a+62ba25d42b,v29.0.0.rc5
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 151 of file testUtils.py.

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

108 maxRadius=80.0, nRadii=30, perturb=0.05):
109 """Create a random TransmissionCurve with nontrivial spatial and
110 wavelength variation.
111
112 Parameters
113 ----------
114 rng : numpy.random.RandomState
115 Random number generator.
116 minWavelength : float
117 Average minimum wavelength for generated TransmissionCurves (will be
118 randomly perturbed).
119 maxWavelength : float
120 Average maximum wavelength for generated TransmissionCurves (will be
121 randomly perturbed).
122 nWavelengths : int
123 Number of samples in the wavelength dimension.
124 maxRadius : float
125 Average maximum radius for spatial variation (will be perturbed).
126 nRadii : int
127 Number of samples in the radial dimension.
128 perturb: float
129 Fraction by which wavelength and radius bounds should be randomly
130 perturbed.
131 """
132 dWavelength = maxWavelength - minWavelength
133
134 def perturbed(x, s=perturb*dWavelength):
135 return x + 2.0*s*(rng.rand() - 0.5)
136
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)
140 # throughput will be a rectangle in wavelength, shifting to higher wavelengths and shrinking
141 # in height with radius, going to zero at all bounds.
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)
149
150

◆ 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 # Make results predictable over different numpy versions.
89 rng = np.random.Generator(np.random.MT19937(5))
90 imgArr = img.getArray()
91 imgArr[:] = rng.poisson(imgArr)
92
93 # bundle into a maskedimage and an exposure
94 mask = afwImage.Mask(bbox)
95 var = img.convertFloat()
96 img -= sky
97 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
98 exposure = afwImage.makeExposure(mimg)
99
100 # insert an approximate psf
101 psf = SingleGaussianPsf(kwid, kwid, meanSigma)
102 exposure.setPsf(psf)
103
104 return exposure
105
106
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:82
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