LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Classes | Functions
lsst.meas.algorithms.testUtils Namespace Reference

Classes

class  MockRefcatDataId
 
class  MockRefcatDeferredDatasetHandle
 
class  MockReferenceObjectLoaderFromFiles
 

Functions

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)
 
def makeDefectList ()
 

Function Documentation

◆ makeDefectList()

def 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 148 of file testUtils.py.

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

◆ makeRandomTransmissionCurve()

def 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 104 of file testUtils.py.

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

◆ plantSources()

def 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 40 of file testUtils.py.

40def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True):
41 """Make an exposure with stars (modelled as Gaussians)
42
43 Parameters
44 ----------
45 bbox : `lsst.geom.Box2I`
46 Parent bbox of exposure
47 kwid : `int`
48 Kernal width (and height; kernal is square)
49 sky : `float`
50 Amount of sky background (counts)
51 coordList : `list [tuple]`
52 A list of [x, y, counts, sigma] where:
53 * x,y are relative to exposure origin
54 * counts is the integrated counts for the star
55 * sigma is the Gaussian sigma in pixels
56 addPoissonNoise : `bool`
57 If True: add Poisson noise to the exposure
58 """
59 # make an image with sources
60 img = afwImage.ImageD(bbox)
61 meanSigma = 0.0
62 for coord in coordList:
63 x, y, counts, sigma = coord
64 meanSigma += sigma
65
66 # make a single gaussian psf
67 psf = SingleGaussianPsf(kwid, kwid, sigma)
68
69 # make an image of it and scale to the desired number of counts
70 thisPsfImg = psf.computeImage(lsst.geom.PointD(x, y))
71 thisPsfImg *= counts
72
73 # bbox a window in our image and add the fake star image
74 psfBox = thisPsfImg.getBBox()
75 psfBox.clip(bbox)
76 if psfBox != thisPsfImg.getBBox():
77 thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
78 imgSeg = img[psfBox, afwImage.PARENT]
79 imgSeg += thisPsfImg
80 meanSigma /= len(coordList)
81
82 img += sky
83
84 # add Poisson noise
85 if (addPoissonNoise):
86 np.random.seed(seed=1) # make results reproducible
87 imgArr = img.getArray()
88 imgArr[:] = np.random.poisson(imgArr)
89
90 # bundle into a maskedimage and an exposure
91 mask = afwImage.Mask(bbox)
92 var = img.convertFloat()
93 img -= sky
94 mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
95 exposure = afwImage.makeExposure(mimg)
96
97 # insert an approximate psf
98 psf = SingleGaussianPsf(kwid, kwid, meanSigma)
99 exposure.setPsf(psf)
100
101 return exposure
102
103
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
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:454
def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True)
Definition: testUtils.py:40