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-43563: Add flat correction placeholder. #316

Merged
merged 2 commits into from
Apr 3, 2024
Merged
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
55 changes: 55 additions & 0 deletions python/lsst/ip/isr/isrTaskLSST.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,28 @@ class IsrTaskLSSTConfig(pipeBase.PipelineTaskConfig,
default=True,
)

# Flat correction.
doFlat = pexConfig.Field(
aferte marked this conversation as resolved.
Show resolved Hide resolved
dtype=bool,
doc="Apply flat field correction.",
default=True,
)
flatScalingType = pexConfig.ChoiceField(
dtype=str,
doc="The method for scaling the flat on the fly.",
default='USER',
allowed={
"USER": "Scale by flatUserScale",
"MEAN": "Scale by the inverse of the mean",
"MEDIAN": "Scale by the inverse of the median",
},
)
flatUserScale = pexConfig.Field(
dtype=float,
doc="If flatScalingType is 'USER' then scale flat by this amount; ignored otherwise.",
default=1.0,
)

# Calculate image quality statistics?
doStandardStatistics = pexConfig.Field(
dtype=bool,
Expand Down Expand Up @@ -1137,6 +1159,30 @@ def doLinearize(self, detector):
return self.config.doLinearize and \
detector.getAmplifiers()[0].getLinearityType() != NullLinearityType

def flatCorrection(self, exposure, flatExposure, invert=False):
"""Apply flat correction in place.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to process.
flatExposure : `lsst.afw.image.Exposure`
Flat exposure of the same size as ``exposure``.
invert : `Bool`, optional
If True, unflatten an already flattened image.

See Also
--------
lsst.ip.isr.isrFunctions.flatCorrection
"""
isrFunctions.flatCorrection(
maskedImage=exposure.getMaskedImage(),
flatMaskedImage=flatExposure.getMaskedImage(),
scalingType=self.config.flatScalingType,
userScale=self.config.flatUserScale,
invert=invert
)

def makeBinnedImages(self, exposure):
"""Make visualizeVisit style binned exposures.

Expand Down Expand Up @@ -1190,6 +1236,8 @@ def run(self, *, ccdExposure, dnlLUT=None, bias=None, deferredChargeCalib=None,
exposureMetadata["LSST CALIB DATE BFK"] = self.extractCalibDate(bfKernel)
if self.config.doDark:
exposureMetadata["LSST CALIB DATE DARK"] = self.extractCalibDate(dark)
if self.config.doFlat:
exposureMetadata["LSST CALIB DATE FLAT"] = self.extractCalibDate(flat)

# First we mark which amplifiers are completely bad from defects.
badAmpDict = self.maskFullDefectAmplifiers(ccdExposure, detector, defects)
Expand Down Expand Up @@ -1320,6 +1368,13 @@ def run(self, *, ccdExposure, dnlLUT=None, bias=None, deferredChargeCalib=None,
bfKernelOut, bfGains = self.getBrighterFatterKernel(detector, bfKernel)
ccdExposure = self.applyBrighterFatterCorrection(ccdExposure, flat, dark, bfKernelOut, bfGains)

if self.config.doFlat:
# Input units: electrons
self.log.info("Applying flat correction.")
# Placeholder while the LSST flat procedure is done.
# The flat here would be a background flat.
self.flatCorrection(ccdExposure, flat)
aferte marked this conversation as resolved.
Show resolved Hide resolved

# Calculate standard image quality statistics
if self.config.doStandardStatistics:
metadata = ccdExposure.getMetadata()
Expand Down