LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
testUtils.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 # Copyright 2008-2013 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 import numpy
25 
26 import lsst.afw.image as afwImage
27 import lsst.afw.geom as afwGeom
28 from .algorithmsLib import SingleGaussianPsf
29 
30 def plantSources(bbox, kwid, sky, coordList, addPoissonNoise=True):
31  """Make an exposure with stars (modelled as Gaussians)
32 
33  @param bbox: parent bbox of exposure
34  @param kwid: kernel width (and height; kernel is square)
35  @param sky: amount of sky background (counts)
36  @param coordList: a list of [x, y, counts, sigma], where:
37  * x,y are relative to exposure origin
38  * counts is the integrated counts for the star
39  * sigma is the Gaussian sigma in pixels
40  @param addPoissonNoise: add Poisson noise to the exposure?
41  """
42  # make an image with sources
43  img = afwImage.ImageD(bbox)
44  meanSigma = 0.0
45  for coord in coordList:
46  x, y, counts, sigma = coord
47  meanSigma += sigma
48 
49  # make a single gaussian psf
50  psf = SingleGaussianPsf(kwid, kwid, sigma)
51 
52  # make an image of it and scale to the desired number of counts
53  thisPsfImg = psf.computeImage(afwGeom.PointD(int(x), int(y)))
54  thisPsfImg *= counts
55 
56  # bbox a window in our image and add the fake star image
57  imgSeg = img.Factory(img, thisPsfImg.getBBox())
58  imgSeg += thisPsfImg
59  meanSigma /= len(coordList)
60 
61  img += sky
62 
63  # add Poisson noise
64  if (addPoissonNoise):
65  numpy.random.seed(seed=1) # make results reproducible
66  imgArr = img.getArray()
67  imgArr[:] = numpy.random.poisson(imgArr)
68 
69  # bundle into a maskedimage and an exposure
70  mask = afwImage.MaskU(bbox)
71  var = img.convertFloat()
72  img -= sky
73  mimg = afwImage.MaskedImageF(img.convertFloat(), mask, var)
74  exposure = afwImage.makeExposure(mimg)
75 
76  # insert an approximate psf
77  psf = SingleGaussianPsf(kwid, kwid, meanSigma)
78  exposure.setPsf(psf)
79 
80  return exposure
81 
82 
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