2 from astropy.io
import fits
16 doc=
"Size of margin at edge that should not be added")
18 doc=
"Seed for random number generator")
20 allowed={
'dsersic':
'double sersic galaxies added',
21 'sersic':
'single sersic galaxies added',
22 'real':
'real HST galaxy images added'},
23 doc=
'type of GalSim galaxies to add')
25 otherwise a random subset of nGal from the catalog""", default=0)
29 ConfigClass = RandomGalSimFakesConfig
32 BaseFakeSourcesTask.__init__(self, **kwargs)
33 print(
"RNG seed:", self.
config.seed)
38 def run(self, exposure, background):
40 self.
log.
info(
"Adding fake random galaxies")
41 psf = exposure.getPsf()
42 psfBBox = psf.computeImage().getBBox()
43 minMargin =
int(np.floor(
max(psfBBox.getWidth(), psfBBox.getHeight())/2)) + 1
44 md = exposure.getMetadata()
45 expBBox = exposure.getBBox()
46 scalingMatrix = np.array([[0.0, 1.0], [1.0, 0.0]]) / exposure.getWcs().pixelScale().asArcseconds()
54 for igal, gal
in doGal:
61 flux = exposure.getCalib().getFlux(
float(gal[
'mag']))
63 raise KeyError(
"No mag column in %s table"%self.
config.galList)
67 if self.
config.margin
is not None:
68 margin = self.
config.margin
71 bboxI = (exposure.getBBox(lsst.afw.image.PARENT))
74 x = self.
rng.flat(bboxD.getMinX(), bboxD.getMaxX())
75 y = self.
rng.flat(bboxD.getMinY(), bboxD.getMaxY())
79 galArray = makeFake.makeGalaxy(flux, gal, psfImage.getArray(), self.
config.galType,
80 transform=scalingMatrix)
81 galImage = lsst.afw.image.ImageF(galArray.astype(np.float32))
82 galBBox = galImage.getBBox(lsst.afw.image.PARENT)
84 x - galBBox.getWidth()/2.0 + 0.5,
85 y - galBBox.getHeight()/2.0 + 0.5,
87 galBBox = galImage.getBBox(lsst.afw.image.PARENT)
90 if expBBox.contains(galImage.getBBox(lsst.afw.image.PARENT))
is False:
91 newBBox = galImage.getBBox(lsst.afw.image.PARENT)
93 self.
log.
info(
"Cropping FAKE%d from %s to %s"%(galident,
str(galBBox),
str(newBBox)))
94 galImage = galImage.Factory(galImage, newBBox, lsst.afw.image.PARENT)
97 galMaskedImage = lsst.afw.image.MaskedImageF(galImage)
99 mask = galMaskedImage.getMask()
102 md.set(
"FAKE%d" % gal[
'ID'],
"%.3f, %.3f" % (x, y))
103 self.
log.
info(
"Adding fake at: %.1f,%.1f" % (x, y))
107 subMaskedImage = exposure.getMaskedImage().
Factory(exposure.getMaskedImage(),
108 galMaskedImage.getBBox(lsst.afw.image.PARENT),
109 lsst.afw.image.PARENT)
110 subMaskedImage += galMaskedImage
def run(self, exposure, background)
A floating-point coordinate rectangle geometry.
def __init__(self, kwargs)
daf::base::PropertySet * set
std::shared_ptr< ImageT > offsetImage(ImageT const &image, float dx, float dy, std::string const &algorithmName="lanczos5", unsigned int buffer=0)
Return an image offset by (dx, dy) using the specified algorithm.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
daf::base::PropertyList * list
A class that can be used to generate sequences of random numbers according to a number of different a...