LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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)
 

Function Documentation

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

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

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