LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Functions
lsst.meas.algorithms.testUtils Namespace Reference

Functions

def plantSources
 

Function Documentation

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

30 
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(afwGeom.PointD(int(x), int(y)))
55  thisPsfImg *= counts
56 
57  # bbox a window in our image and add the fake star image
58  imgSeg = img.Factory(img, thisPsfImg.getBBox())
59  imgSeg += thisPsfImg
60  meanSigma /= len(coordList)
61 
62  img += sky
63 
64  # add Poisson noise
65  if (addPoissonNoise):
66  numpy.random.seed(seed=1) # make results reproducible
67  imgArr = img.getArray()
68  imgArr[:] = numpy.random.poisson(imgArr)
69 
70  # bundle into a maskedimage and an exposure
71  mask = afwImage.MaskU(bbox)
72  var = img.convertFloat()
73  img -= sky
74  mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
75  exposure = afwImage.makeExposure(mimg)
76 
77  # insert an approximate psf
78  psf = SingleGaussianPsf(kwid, kwid, meanSigma)
79  exposure.setPsf(psf)
80 
81  return exposure
82 
83 
Exposure< ImagePixelT, MaskPixelT, VariancePixelT >::Ptr makeExposure(MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage, boost::shared_ptr< Wcs const > wcs=boost::shared_ptr< Wcs const >())
Definition: Exposure.h:308