Skip to content

Commit

Permalink
Merge branch 'tickets/DM-33327' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
yalsayyad committed Feb 19, 2022
2 parents 8a3ec76 + 4d522e8 commit 5156e21
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python/lsst/pipe/tasks/insertFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _add_fake_sources(exposure, objects, calibFluxRadius=12.0, logger=None):
fullBounds = galsim.BoundsI(bbox.minX, bbox.maxX, bbox.minY, bbox.maxY)
gsImg = galsim.Image(exposure.image.array, bounds=fullBounds)

pixScale = wcs.getPixelScale().asArcseconds()
pixScale = wcs.getPixelScale(bbox.getCenter()).asArcseconds()

for spt, gsObj in objects:
pt = wcs.skyToPixel(spt)
Expand Down Expand Up @@ -255,6 +255,12 @@ class InsertFakesConfig(PipelineTaskConfig,
default=False,
)

insertOnlyStars = pexConfig.Field(
doc="Insert only stars? True or False.",
dtype=bool,
default=False,
)

doProcessAllDataIds = pexConfig.Field(
doc="If True, all input data IDs will be processed, even those containing no fake sources.",
dtype=bool,
Expand Down Expand Up @@ -709,7 +715,7 @@ def add_to_replace_dict(new_name, depr_name, std_name):
]:
add_to_replace_dict(new_name, depr_name, std_name)
# Only handle bulge/disk params if not injecting images
if not cfg.insertImages:
if not cfg.insertImages and not cfg.insertOnlyStars:
for new_name, depr_name, std_name in [
(cfg.bulge_n_col, cfg.nBulge, 'bulge_n'),
(cfg.bulge_pa_col, cfg.paBulge, 'bulge_pa'),
Expand All @@ -729,7 +735,7 @@ def add_to_replace_dict(new_name, depr_name, std_name):
# Handling the half-light radius and axis-ratio are trickier, since we
# moved from expecting (HLR, a, b) to expecting (semimajor, axis_ratio).
# Just handle these manually.
if not cfg.insertImages:
if not cfg.insertImages and not cfg.insertOnlyStars:
if (
cfg.bulge_semimajor_col in fakeCat.columns
and cfg.bulge_axis_ratio_col in fakeCat.columns
Expand Down
29 changes: 29 additions & 0 deletions python/lsst/pipe/tasks/matchFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class MatchFakesConfig(
max=10,
)

doMatchVisit = pexConfig.Field(
dtype=bool,
default=False,
doc="Match visit to trim the fakeCat"
)


class MatchFakesTask(PipelineTask):
"""Match a pre-existing catalog of fakes to a catalog of detections on
Expand Down Expand Up @@ -132,6 +138,10 @@ def run(self, fakeCats, skyMap, diffIm, associatedDiaSources):
length of ``fakeCat``. (`pandas.DataFrame`)
"""
fakeCat = self.composeFakeCat(fakeCats, skyMap)

if self.config.doMatchVisit:
fakeCat = self.getVisitMatchedFakeCat(fakeCat, diffIm)

return self._processFakes(fakeCat, diffIm, associatedDiaSources)

def _processFakes(self, fakeCat, diffIm, associatedDiaSources):
Expand Down Expand Up @@ -211,6 +221,25 @@ def composeFakeCat(self, fakeCats, skyMap):

return pd.concat(outputCat)

def getVisitMatchedFakeCat(self, fakeCat, exposure):
"""Trim the fakeCat to select particular visit
Parameters
----------
fakeCat : `pandas.core.frame.DataFrame`
The catalog of fake sources to add to the exposure
exposure : `lsst.afw.image.exposure.exposure.ExposureF`
The exposure to add the fake sources to
Returns
-------
movingFakeCat : `pandas.DataFrame`
All fakes that belong to the visit
"""
selected = exposure.getInfo().getVisitInfo().getId() == fakeCat["visit"]

return fakeCat[selected]

def _trimFakeCat(self, fakeCat, image):
"""Trim the fake cat to about the size of the input image.
Expand Down
28 changes: 28 additions & 0 deletions python/lsst/pipe/tasks/processCcdWithFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ class ProcessCcdWithFakesConfig(PipelineTaskConfig,
doc=("Match radius for matching icSourceCat objects to sourceCat objects (pixels)"),
)

doMatchVisit = pexConfig.Field(
dtype=bool,
default=False,
doc="Match visit to trim the fakeCat"
)

calibrate = pexConfig.ConfigurableField(target=CalibrateTask,
doc="The calibration task to use.")

Expand Down Expand Up @@ -478,6 +484,9 @@ def run(self, fakeCats, exposure, skyMap, wcs=None, photoCalib=None, exposureIdI
if photoCalib is None:
photoCalib = exposure.getPhotoCalib()

if self.config.doMatchVisit:
fakeCat = self.getVisitMatchedFakeCat(fakeCat, exposure)

self.insertFakes.run(fakeCat, exposure, wcs, photoCalib)

# detect, deblend and measure sources
Expand Down Expand Up @@ -524,6 +533,25 @@ def composeFakeCat(self, fakeCats, skyMap):

return pd.concat(outputCat)

def getVisitMatchedFakeCat(self, fakeCat, exposure):
"""Trim the fakeCat to select particular visit
Parameters
----------
fakeCat : `pandas.core.frame.DataFrame`
The catalog of fake sources to add to the exposure
exposure : `lsst.afw.image.exposure.exposure.ExposureF`
The exposure to add the fake sources to
Returns
-------
movingFakeCat : `pandas.DataFrame`
All fakes that belong to the visit
"""
selected = exposure.getInfo().getVisitInfo().getId() == fakeCat["visit"]

return fakeCat[selected]

def copyCalibrationFields(self, calibCat, sourceCat, fieldsToCopy):
"""Match sources in calibCat and sourceCat and copy the specified fields
Expand Down

0 comments on commit 5156e21

Please sign in to comment.