Skip to content

Commit

Permalink
Add doProcessAllDataIds insertFakes config option
Browse files Browse the repository at this point in the history
  • Loading branch information
leeskelvin committed Aug 24, 2020
1 parent 3be7e53 commit d249cd7
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions python/lsst/pipe/tasks/insertFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ class InsertFakesConfig(PipelineTaskConfig,
default=False,
)

doProcessAllDataIds = pexConfig.Field(
doc="If True, all input data IDs will be processed, even those containing no fake sources.",
dtype=bool,
default=False,
)


class InsertFakesTask(PipelineTask, CmdLineTask):
"""Insert fake objects into images.
Expand Down Expand Up @@ -334,37 +340,40 @@ def run(self, fakeCat, image, wcs, photoCalib):
psf = image.getPsf()
pixelScale = wcs.getPixelScale().asArcseconds()

if len(fakeCat) == 0:
errMsg = "No fakes found for this dataRef."
raise RuntimeError(errMsg)

if isinstance(fakeCat[self.config.sourceType].iloc[0], str):
galCheckVal = "galaxy"
starCheckVal = "star"
elif isinstance(fakeCat[self.config.sourceType].iloc[0], bytes):
galCheckVal = b"galaxy"
starCheckVal = b"star"
elif isinstance(fakeCat[self.config.sourceType].iloc[0], (int, float)):
galCheckVal = 1
starCheckVal = 0
else:
raise TypeError("sourceType column does not have required type, should be str, bytes or int")
if len(fakeCat) > 0:
if isinstance(fakeCat[self.config.sourceType].iloc[0], str):
galCheckVal = "galaxy"
starCheckVal = "star"
elif isinstance(fakeCat[self.config.sourceType].iloc[0], bytes):
galCheckVal = b"galaxy"
starCheckVal = b"star"
elif isinstance(fakeCat[self.config.sourceType].iloc[0], (int, float)):
galCheckVal = 1
starCheckVal = 0
else:
raise TypeError("sourceType column does not have required type, should be str, bytes or int")

if not self.config.insertImages:
if self.config.doCleanCat:
fakeCat = self.cleanCat(fakeCat, starCheckVal)
if not self.config.insertImages:
if self.config.doCleanCat:
fakeCat = self.cleanCat(fakeCat, starCheckVal)

galaxies = (fakeCat[self.config.sourceType] == galCheckVal)
galImages = self.mkFakeGalsimGalaxies(fakeCat[galaxies], band, photoCalib, pixelScale, psf, image)
galaxies = (fakeCat[self.config.sourceType] == galCheckVal)
galImages = self.mkFakeGalsimGalaxies(fakeCat[galaxies], band, photoCalib, pixelScale, psf,
image)

stars = (fakeCat[self.config.sourceType] == starCheckVal)
starImages = self.mkFakeStars(fakeCat[stars], band, photoCalib, psf, image)
else:
galImages, starImages = self.processImagesForInsertion(fakeCat, wcs, psf, photoCalib, band,
pixelScale)

stars = (fakeCat[self.config.sourceType] == starCheckVal)
starImages = self.mkFakeStars(fakeCat[stars], band, photoCalib, psf, image)
image = self.addFakeSources(image, galImages, "galaxy")
image = self.addFakeSources(image, starImages, "star")
elif len(fakeCat) == 0 and self.config.doProcessAllDataIds:
self.log.warn("No fakes found for this dataRef; forcing fakes output.")
else:
galImages, starImages = self.processImagesForInsertion(fakeCat, wcs, psf, photoCalib, band,
pixelScale)
raise RuntimeError("No fakes found for this dataRef.")

image = self.addFakeSources(image, galImages, "galaxy")
image = self.addFakeSources(image, starImages, "star")
resultStruct = pipeBase.Struct(imageWithFakes=image)

return resultStruct
Expand Down

0 comments on commit d249cd7

Please sign in to comment.