LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
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 133 of file testUtils.py.

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

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

89 def makeRandomTransmissionCurve(rng, minWavelength=4000.0, maxWavelength=7000.0, nWavelengths=200,
90  maxRadius=80.0, nRadii=30, perturb=0.05):
91  """Create a random TransmissionCurve with nontrivial spatial and
92  wavelength variation.
93 
94  Parameters
95  ----------
96  rng : numpy.random.RandomState
97  Random number generator.
98  minWavelength : float
99  Average minimum wavelength for generated TransmissionCurves (will be
100  randomly perturbed).
101  maxWavelength : float
102  Average maximum wavelength for generated TransmissionCurves (will be
103  randomly perturbed).
104  nWavelengths : int
105  Number of samples in the wavelength dimension.
106  maxRadius : float
107  Average maximum radius for spatial variation (will be perturbed).
108  nRadii : int
109  Number of samples in the radial dimension.
110  perturb: float
111  Fraction by which wavelength and radius bounds should be randomly
112  perturbed.
113  """
114  dWavelength = maxWavelength - minWavelength
115 
116  def perturbed(x, s=perturb*dWavelength):
117  return x + 2.0*s*(rng.rand() - 0.5)
118 
119  wavelengths = np.linspace(perturbed(minWavelength), perturbed(maxWavelength), nWavelengths)
120  radii = np.linspace(0.0, perturbed(maxRadius, perturb*maxRadius), nRadii)
121  throughput = np.zeros(wavelengths.shape + radii.shape, dtype=float)
122  # throughput will be a rectangle in wavelength, shifting to higher wavelengths and shrinking
123  # in height with radius, going to zero at all bounds.
124  peak0 = perturbed(0.9, 0.05)
125  start0 = perturbed(minWavelength + 0.25*dWavelength)
126  stop0 = perturbed(minWavelength + 0.75*dWavelength)
127  for i, r in enumerate(radii):
128  mask = np.logical_and(wavelengths >= start0 + r, wavelengths <= stop0 + r)
129  throughput[mask, i] = peak0*(1.0 - r/1000.0)
130  return afwImage.TransmissionCurve.makeRadial(throughput, wavelengths, radii)
131 
132 

◆ plantSources()

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

@param bbox: parent bbox of exposure
@param kwid: kernel width (and height; kernel is square)
@param sky: amount of sky background (counts)
@param coordList: 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
@param addPoissonNoise: add Poisson noise to the exposure?

Definition at line 32 of file testUtils.py.

32 def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True):
33  """Make an exposure with stars (modelled as Gaussians)
34 
35  @param bbox: parent bbox of exposure
36  @param kwid: kernel width (and height; kernel is square)
37  @param sky: amount of sky background (counts)
38  @param coordList: a list of [x, y, counts, sigma], where:
39  * x,y are relative to exposure origin
40  * counts is the integrated counts for the star
41  * sigma is the Gaussian sigma in pixels
42  @param addPoissonNoise: add Poisson noise to the exposure?
43  """
44  # make an image with sources
45  img = afwImage.ImageD(bbox)
46  meanSigma = 0.0
47  for coord in coordList:
48  x, y, counts, sigma = coord
49  meanSigma += sigma
50 
51  # make a single gaussian psf
52  psf = SingleGaussianPsf(kwid, kwid, sigma)
53 
54  # make an image of it and scale to the desired number of counts
55  thisPsfImg = psf.computeImage(lsst.geom.PointD(x, y))
56  thisPsfImg *= counts
57 
58  # bbox a window in our image and add the fake star image
59  psfBox = thisPsfImg.getBBox()
60  psfBox.clip(bbox)
61  if psfBox != thisPsfImg.getBBox():
62  thisPsfImg = thisPsfImg[psfBox, afwImage.PARENT]
63  imgSeg = img[psfBox, afwImage.PARENT]
64  imgSeg += thisPsfImg
65  meanSigma /= len(coordList)
66 
67  img += sky
68 
69  # add Poisson noise
70  if (addPoissonNoise):
71  np.random.seed(seed=1) # make results reproducible
72  imgArr = img.getArray()
73  imgArr[:] = np.random.poisson(imgArr)
74 
75  # bundle into a maskedimage and an exposure
76  mask = afwImage.Mask(bbox)
77  var = img.convertFloat()
78  img -= sky
79  mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
80  exposure = afwImage.makeExposure(mimg)
81 
82  # insert an approximate psf
83  psf = SingleGaussianPsf(kwid, kwid, meanSigma)
84  exposure.setPsf(psf)
85 
86  return exposure
87 
88 
lsst::afw::image::Mask
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:77
lsst::meas::algorithms.testUtils.plantSources
def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True)
Definition: testUtils.py:32
lsst::afw::image::makeExposure
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:442
lsst::geom::Point< int, 2 >
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst::meas::algorithms.testUtils.makeDefectList
def makeDefectList()
Definition: testUtils.py:133
lsst::geom::Extent< int, 2 >
lsst::meas::algorithms.testUtils.makeRandomTransmissionCurve
def makeRandomTransmissionCurve(rng, minWavelength=4000.0, maxWavelength=7000.0, nWavelengths=200, maxRadius=80.0, nRadii=30, perturb=0.05)
Definition: testUtils.py:89