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-21308: Replace doApplyUberCal with doApplyExternal configs #245

Merged
merged 1 commit into from
Jan 25, 2020
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
3 changes: 2 additions & 1 deletion config/hsc/coaddBase.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config.doApplyUberCal = True
config.doApplyExternalPhotoCalib = True
config.doApplyExternalSkyWcs = True
3 changes: 2 additions & 1 deletion config/hsc/compareWarpAssembleCoadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# Load configs shared between assembleCoadd and makeCoaddTempExp
config.load(os.path.join(getPackageDir("obs_subaru"), "config", "hsc", "assembleCoadd.py"))

config.assembleStaticSkyModel.doApplyUberCal = True
config.assembleStaticSkyModel.doApplyExternalPhotoCalib = True
config.assembleStaticSkyModel.doApplyExternalSkyWcs = True
39 changes: 16 additions & 23 deletions python/lsst/obs/hsc/makeCoaddTempExp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from lsst.pipe.tasks.makeCoaddTempExp import MakeCoaddTempExpTask, MissingExposureError
import lsst.daf.persistence as dafPersist
import lsst.afw.image as afwImage
import numpy as np

__all__ = ["SubaruMakeCoaddTempExpTask"]
Expand Down Expand Up @@ -53,10 +52,15 @@ def getCalibratedExposure(self, dataRef, bgSubtracted):

This was copy-pasted from MakeCoaddTempExpTask, and extra step added to check
whether an additional mask is needed.
If config.doApplyUberCal, the exposure will be photometrically
calibrated via the `jointcal_photoCalib` dataset and have its SkyWcs
updated to the `jointcal_wcs`, otherwise it will be calibrated via the
Exposure's own PhotoCalib and have the original SkyWcs.

If config.doApplyExternalPhotoCalib is `True`, the photometric calibration
(`photoCalib`) is taken from `config.externalPhotoCalibName` via the
`name_photoCalib` dataset. Otherwise, the photometric calibration is
retrieved from the processed exposure. When
`config.doApplyExternalSkyWcs` is `True`,
the astrometric calibration is taken from `config.externalSkyWcsName`
with the `name_wcs` dataset. Otherwise, the astrometric calibration
is taken from the processed exposure.
"""
try:
exposure = dataRef.get(self.calexpType, immediate=True)
Expand All @@ -74,30 +78,19 @@ def getCalibratedExposure(self, dataRef, bgSubtracted):
mi += background.getImage()
del mi

if self.config.doApplyUberCal:
if self.config.useMeasMosaic:
from lsst.meas.mosaic import applyMosaicResultsExposure
# NOTE: this changes exposure in-place, updating its Calib and Wcs.
# Save the calibration error, as it gets overwritten with zero.
calibrationErr = exposure.getPhotoCalib().getCalibrationErr()
try:
applyMosaicResultsExposure(dataRef, calexp=exposure)
except dafPersist.NoResults as e:
raise MissingExposureError('Mosaic calibration not found: %s ' % str(e)) from e
photoCalib = afwImage.PhotoCalib(exposure.getPhotoCalib().getCalibrationMean(),
calibrationErr,
exposure.getBBox())
else:
photoCalib = dataRef.get("jointcal_photoCalib")
skyWcs = dataRef.get("jointcal_wcs")
exposure.setWcs(skyWcs)
if self.config.doApplyExternalPhotoCalib:
photoCalib = dataRef.get(f"{self.config.externalPhotoCalibName}_photoCalib")
exposure.setPhotoCalib(photoCalib)
else:
photoCalib = exposure.getPhotoCalib()

if self.config.doApplyExternalSkyWcs:
skyWcs = dataRef.get(f"{self.config.externalSkyWcsName}_wcs")
exposure.setWcs(skyWcs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - the exposure already has a WCS from the calexp (heh) if this doesn't happen, so it makes sense to only setWcs if we are overriding it.
Similarly, isn't it true that the exposure already has a photoCalib from the calexp? If so, then this can be simplified even further by removing the the else above (which retrieves the photoCalib from the exposure if there's no external one) and only calls setPhotoCalib if there is a new one.


exposure.maskedImage = photoCalib.calibrateImage(exposure.maskedImage,
includeScaleUncertainty=self.config.includeCalibVar)
exposure.maskedImage /= photoCalib.getCalibrationMean()
exposure.setPhotoCalib(photoCalib)
# TODO: The images will have a calibration of 1.0 everywhere once RFC-545 is implemented.
# exposure.setCalib(afwImage.Calib(1.0))
return exposure
Expand Down