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
Arun Kannawadi authored and sr525 committed Nov 14, 2019
1 parent 728bddb commit a239e99
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 24 deletions.
25 changes: 25 additions & 0 deletions bin.src/insertFakeSources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2016 LSST/AURA
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from lsst.pipe.tasks.insertFakeSources import InsertFakeSourcesTask

InsertFakeSourcesTask.parseAndRun()
25 changes: 25 additions & 0 deletions bin.src/insertFakes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2016 LSST/AURA
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from lsst.pipe.tasks.insertFakes import InsertFakesTask

InsertFakesTask.parseAndRun()
25 changes: 25 additions & 0 deletions bin.src/processCcdWithFakes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python
#
# LSST Data Management System
# Copyright 2008, 2009, 2010 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
from lsst.pipe.tasks.processCcdWithFakes import ProcessCcdWithFakesTask

ProcessCcdWithFakesTask.parseAndRun()
35 changes: 14 additions & 21 deletions python/lsst/pipe/tasks/insertFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import lsst.pipe.base as pipeBase

from lsst.pipe.base import CmdLineTask, PipelineTask, PipelineTaskConfig, PipelineTaskConnections
import lsst.pipe.base.connectionTyes as cT
import lsst.pipe.base.connectionTypes as cT
from lsst.pex.exceptions import LogicError, InvalidParameterError
from lsst.coadd.utils.coaddDataIdContainer import ExistingCoaddDataIdContainer
from lsst.geom import SpherePoint, radians, Box2D
Expand All @@ -46,27 +46,28 @@ class InsertFakesConnections(PipelineTaskConnections, defaultTemplates={"CoaddNa

image = cT.Input(
doc="Image into which fakes are to be added.",
nameTemplate="{CoaddName}Coadd",
name="{CoaddName}Coadd",
storageClass="ExposureF",
dimensions=("tract", "patch", "abstract_filter", "skymap")
)

fakeCat = cT.Input(
doc="Catalog of fake sources to draw inputs from.",
nameTemplate="{CoaddName}Coadd_fakeSourceCat",
name="{CoaddName}Coadd_fakeSourceCat",
storageClass="Parquet",
dimensions=("tract", "skymap")
)

imageWithFakes = cT.Output(
doc="Image with fake sources added.",
nameTemplate="fakes_{CoaddName}Coadd",
name="fakes_{CoaddName}Coadd",
storageClass="ExposureF",
dimensions=("tract", "patch", "abstract_filter", "skymap")
)


class InsertFakesConfig(PipelineTaskConfig):
class InsertFakesConfig(PipelineTaskConfig,
pipelineConnections=InsertFakesConnections):
"""Config for inserting fake sources
Notes
Expand Down Expand Up @@ -387,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 @@ -405,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 @@ -446,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 @@ -466,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 @@ -497,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
7 changes: 4 additions & 3 deletions python/lsst/pipe/tasks/processCcdWithFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


class ProcessCcdWithFakesConnections(PipelineTaskConnections, dimensions=("instrument", "visit", "detector"),
defaultTemplates={}):
defaultTemplates={"CoaddName": "deep"}):

exposure = cT.Input(
doc="Exposure into which fakes are to be added.",
Expand All @@ -54,7 +54,7 @@ class ProcessCcdWithFakesConnections(PipelineTaskConnections, dimensions=("instr

fakeCat = cT.Input(
doc="Catalog of fake sources to draw inputs from.",
nameTemplate="{CoaddName}Coadd_fakeSourceCat",
name="{CoaddName}Coadd_fakeSourceCat",
storageClass="Parquet",
dimensions=("tract", "skymap")
)
Expand Down Expand Up @@ -88,7 +88,8 @@ class ProcessCcdWithFakesConnections(PipelineTaskConnections, dimensions=("instr
)


class ProcessCcdWithFakesConfig(PipelineTaskConfig):
class ProcessCcdWithFakesConfig(PipelineTaskConfig,
pipelineConnections=ProcessCcdWithFakesConnections):
"""Config for inserting fake sources
Notes
Expand Down

0 comments on commit a239e99

Please sign in to comment.