Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-33327 (to merge): Add config options insertOnlyStars and doMatchVisit #635

Merged
merged 1 commit into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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