Skip to content

Commit

Permalink
Replace the use of lists with generators
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkannawadi committed Nov 14, 2019
1 parent b070bc6 commit 05bfd66
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions python/lsst/pipe/tasks/insertFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ def trim(row):

return fakeCat[fakeCat.apply(trim, axis=1)]


def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image):
"""Make images of fake galaxies using GalSim.
Expand All @@ -389,10 +388,10 @@ def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image
photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
Photometric calibration to be used to calibrate the fake sources
Returns
Yields
-------
galImages : `list`
A list of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
galImages : `generator`
A generator of tuples of `lsst.afw.image.exposure.exposure.ExposureF` and
`lsst.geom.Point2D` of their locations.
Notes
Expand All @@ -407,8 +406,6 @@ def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image
attached to the config options.
"""

galImages = []

self.log.info("Making %d fake galaxy images" % len(fakeCat))

for (index, row) in fakeCat.iterrows():
Expand Down Expand Up @@ -448,9 +445,7 @@ def mkFakeGalsimGalaxies(self, fakeCat, band, photoCalib, pixelScale, psf, image
except (galsim.errors.GalSimFFTSizeError, MemoryError):
continue

galImages.append((afwImage.ImageF(galIm), xy))

return galImages
yield (afwImage.ImageF(galIm), xy)

def mkFakeStars(self, fakeCat, band, photoCalib, psf, image):

Expand All @@ -468,15 +463,13 @@ def mkFakeStars(self, fakeCat, band, photoCalib, psf, image):
photoCalib : `lsst.afw.image.photoCalib.PhotoCalib`
Photometric calibration to be used to calibrate the fake sources
Returns
Yields
-------
starImages : `list`
A list of tuples of `lsst.afw.image.ImageF` of fake stars and
starImages : `generator`
A generator of tuples of `lsst.afw.image.ImageF` of fake stars and
`lsst.geom.Point2D` of their locations.
"""

starImages = []

self.log.info("Making %d fake star images" % len(fakeCat))

for (index, row) in fakeCat.iterrows():
Expand All @@ -499,9 +492,7 @@ def mkFakeStars(self, fakeCat, band, photoCalib, psf, image):
flux = 0

starIm *= flux
starImages.append((starIm.convertF(), xy))

return starImages
yield ((starIm.convertF(), xy))

def cleanCat(self, fakeCat):
"""Remove rows from the fakes catalog which have HLR = 0 for either the buldge or disk component
Expand Down Expand Up @@ -531,8 +522,8 @@ def addFakeSources(self, image, fakeImages, sourceType):
----------
image : `lsst.afw.image.exposure.exposure.ExposureF`
The image into which the fake sources should be added
fakeImages : `list`
A list of tuples of `lsst.afw.image.ImageF` and `lsst.geom.Point2D,
fakeImages : `typing.Iterator`
An iterator of tuples [`lsst.afw.image.ImageF`, `lsst.geom.Point2D`],
the images and the locations they are to be inserted at.
sourceType : `str`
The type (star/galaxy) of fake sources input
Expand Down

0 comments on commit 05bfd66

Please sign in to comment.