LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Functions
lsst.meas.algorithms.testUtils Namespace Reference

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

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

◆ 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 98 of file testUtils.py.

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

◆ 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 34 of file testUtils.py.

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