Skip to content

Commit

Permalink
Add default types to allow fakes propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
sr525 committed Sep 23, 2021
1 parent ef555c1 commit 147febd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
5 changes: 3 additions & 2 deletions python/lsst/pipe/tasks/healSparseMapping.py
Expand Up @@ -307,7 +307,8 @@ def _pixels_to_radec(self, wcs, pixels):

class HealSparsePropertyMapConnections(pipeBase.PipelineTaskConnections,
dimensions=("tract", "band", "skymap",),
defaultTemplates={"coaddName": "deep"}):
defaultTemplates={"coaddName": "deep",
"calexpType": ""}):
input_maps = pipeBase.connectionTypes.Input(
doc="Healsparse bit-wise coadd input maps",
name="{coaddName}Coadd_inputMap",
Expand All @@ -326,7 +327,7 @@ class HealSparsePropertyMapConnections(pipeBase.PipelineTaskConnections,
)
visit_summaries = pipeBase.connectionTypes.Input(
doc="Visit summary tables with aggregated statistics",
name="visitSummary",
name="{calexpType}visitSummary",
storageClass="ExposureCatalog",
dimensions=("instrument", "visit"),
multiple=True,
Expand Down
11 changes: 11 additions & 0 deletions python/lsst/pipe/tasks/insertFakes.py
Expand Up @@ -71,6 +71,8 @@ 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()

for spt, gsObj in objects:
pt = wcs.skyToPixel(spt)
posd = galsim.PositionD(pt.x, pt.y)
Expand All @@ -81,6 +83,13 @@ def _add_fake_sources(exposure, objects, calibFluxRadius=12.0, logger=None):
mat = wcs.linearizePixelToSky(spt, geom.arcseconds).getMatrix()
gsWCS = galsim.JacobianWCS(mat[0, 0], mat[0, 1], mat[1, 0], mat[1, 1])

# This check is here because sometimes the WCS
# is multivalued and objects that should not be
# were being included.
gsPixScale = np.sqrt(gsWCS.pixelArea())
if gsPixScale < pixScale/2 or gsPixScale > pixScale*2:
continue

try:
psfArr = psf.computeKernelImage(pt).array
except InvalidParameterError:
Expand All @@ -106,6 +115,7 @@ def _add_fake_sources(exposure, objects, calibFluxRadius=12.0, logger=None):
pt
)
continue

apCorr = psf.computeApertureFlux(calibFluxRadius)
psfArr /= apCorr
gsPSF = galsim.InterpolatedImage(galsim.Image(psfArr), wcs=gsWCS)
Expand All @@ -121,6 +131,7 @@ def _add_fake_sources(exposure, objects, calibFluxRadius=12.0, logger=None):
# Note, for calexp injection, pixel is already part of the PSF and
# for coadd injection, it's incorrect to include the output pixel.
# So for both cases, we draw using method='no_pixel'.

conv.drawImage(
subImg,
add_to_image=True,
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/pipe/tasks/postprocess.py
Expand Up @@ -1328,10 +1328,10 @@ def writeConfig(self, butler, clobber=False, doBackup=True):

class MakeCcdVisitTableConnections(pipeBase.PipelineTaskConnections,
dimensions=("instrument",),
defaultTemplates={}):
defaultTemplates={"calexpType": ""}):
visitSummaryRefs = connectionTypes.Input(
doc="Data references for per-visit consolidated exposure metadata from ConsolidateVisitSummaryTask",
name="visitSummary",
name="{calexpType}visitSummary",
storageClass="ExposureCatalog",
dimensions=("instrument", "visit"),
multiple=True,
Expand Down Expand Up @@ -1417,10 +1417,10 @@ def run(self, visitSummaryRefs):

class MakeVisitTableConnections(pipeBase.PipelineTaskConnections,
dimensions=("instrument",),
defaultTemplates={}):
defaultTemplates={"calexpType": ""}):
visitSummaries = connectionTypes.Input(
doc="Per-visit consolidated exposure metadata from ConsolidateVisitSummaryTask",
name="visitSummary",
name="{calexpType}visitSummary",
storageClass="ExposureCatalog",
dimensions=("instrument", "visit",),
multiple=True,
Expand Down
32 changes: 30 additions & 2 deletions python/lsst/pipe/tasks/processCcdWithFakes.py
Expand Up @@ -70,11 +70,27 @@ class ProcessCcdWithFakesConnections(PipelineTaskConnections,
dimensions=("tract", "skymap", "instrument", "visit", "detector")
)

externalSkyWcsCatalog = cT.Input(
doc=("Per-tract, per-visit wcs calibrations. These catalogs use the detector "
"id for the catalog id, sorted on id for fast lookup."),
name="{wcsName}SkyWcsCatalog",
storageClass="ExposureCatalog",
dimensions=("instrument", "visit", "tract"),
)

photoCalib = cT.Input(
doc="Calib information for the input exposure.",
name="{photoCalibName}_photoCalib",
storageClass="PhotoCalib",
dimensions=("tract", "skymap", "instrument", "visit", "detector")
dimensions=("instrument", "visit", "detector")
)

externalPhotoCalibCatalog = cT.Input(
doc=("Per-tract, per-visit photometric calibrations. These catalogs use the "
"detector id for the catalog id, sorted on id for fast lookup."),
name="{photoCalibName}PhotoCalibCatalog",
storageClass="ExposureCatalog",
dimensions=("instrument", "visit"),
)

icSourceCat = cT.Input(
Expand Down Expand Up @@ -295,16 +311,28 @@ def runDataRef(self, dataRef):

def runQuantum(self, butlerQC, inputRefs, outputRefs):
inputs = butlerQC.get(inputRefs)
detectorId = inputs["exposure"].getInfo().getDetector().getId()

if 'exposureIdInfo' not in inputs.keys():
expId, expBits = butlerQC.quantum.dataId.pack("visit_detector", returnMaxBits=True)
inputs['exposureIdInfo'] = ExposureIdInfo(expId, expBits)

if not self.config.doApplyExternalSkyWcs:
inputs["wcs"] = inputs["exposure"].getWcs()

else:
externalSkyWcsCatalog = inputs["externalSkyWcsCatalog"]
row = externalSkyWcsCatalog.find(detectorId)
inputs["wcs"] = row.getWcs()

if not self.config.doApplyExternalPhotoCalib:
inputs["photoCalib"] = inputs["exposure"].getPhotoCalib()

else:
externalPhotoCalibCatalog = inputs["externalPhotoCalibCatalog"]
row = externalPhotoCalibCatalog.find(detectorId)
inputs["photoCalib"] = row.getPhotoCalib()

outputs = self.run(**inputs)
butlerQC.put(outputs, outputRefs)

Expand All @@ -317,7 +345,7 @@ def _makeArgumentParser(cls):
return parser

def run(self, fakeCat, exposure, wcs=None, photoCalib=None, exposureIdInfo=None, icSourceCat=None,
sfdSourceCat=None):
sfdSourceCat=None, externalSkyWcsCatalog=None, externalPhotoCalibCatalog=None):
"""Add fake sources to a calexp and then run detection, deblending and measurement.
Parameters
Expand Down

0 comments on commit 147febd

Please sign in to comment.