Skip to content

Commit

Permalink
Fix overscan mean/median typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Broughton committed Oct 8, 2024
1 parent 5ed87b5 commit d300448
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
26 changes: 13 additions & 13 deletions python/lsst/ip/isr/deferredCharge.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,11 +953,11 @@ def fromTable(cls, tableList):

# Version check
if calibVersion < 1.1:
#This version might be in the wrong units (not electron), and does not
# contain the gain information to convert into a a new calibration
# version.
# This version might be in the wrong units (not electron),
# and does not contain the gain information to convert
# into a new calibration version.
raise RuntimeError(f"Using old version of CTI calibration (ver. {calibVersion} < 1.1), "
"which is no longer supported.")
"which is no longer supported.")

return cls.fromDict(inDict)

Expand Down Expand Up @@ -1054,7 +1054,8 @@ class DeferredChargeConfig(Config):
dtype=bool,
doc="If true, scale by the gain.",
default=False,
deprecated="This field is no longer used. Will be removed after v28.",
deprecated="This field is no longer used. Will be removed after v28"
"(TODO: DM-46721).",
)
zeroUnusedPixels = Field(
dtype=bool,
Expand Down Expand Up @@ -1086,7 +1087,7 @@ def run(self, exposure, ctiCalib, gains=None):
gains : `dict` [`str`, `float`]
A dictionary, keyed by amplifier name, of the gains to
use. If gains is None, the nominal gains in the amplifier
object are used if necessary.
object are used.
Returns
-------
Expand All @@ -1100,8 +1101,8 @@ def run(self, exposure, ctiCalib, gains=None):
units of electrons. If bootstrapping, the gains used
will just be 1.0. and the input/output units will stay in
adu. If the input image is in adu, the output image will be
in units of electron. If the input image is in electron, the
output image will be in electron.
in units of electrons. If the input image is in electron,
the output image will be in electron.
"""
image = exposure.getMaskedImage().image
detector = exposure.getDetector()
Expand All @@ -1116,19 +1117,18 @@ def run(self, exposure, ctiCalib, gains=None):
applyGains = True

# If we need to convert the image to electrons, check that gains
# were supplied, they should be used. If no external gains were
# supplied, use the nominal gains listed in the detector.
# were supplied. CTI should not be solved or corrected without
# supplied gains.
if applyGains:
if gains is None:
self.log.warning("No gains supplied for deferred charge correction. Using nominal gains.")
gains = {amp.getName(): amp.getGain() for amp in detector.getAmplifiers()}
raise RuntimeError("No gains supplied for deferred charge correction.")

with gainContext(exposure, image, apply=applyGains, gains=gains, isTrimmed=False):
# Both the image and the overscan are in electron units.
for amp in detector.getAmplifiers():
ampName = amp.getName()

ampImage = image[amp.getRawDataBBox()]
ampImage = image[amp.getRawBBox()]
if self.config.zeroUnusedPixels:
# We don't apply overscan subtraction, so zero these
# out for now.
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/isr/isrFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,4 +1323,4 @@ def isTrimmedImage(image, detector):
result : `bool`
True if the image is trimmed, else False.
"""
return detector.getBBox() == image.getBBox()
return detector.getBBox() == image.getBBox()
2 changes: 1 addition & 1 deletion python/lsst/ip/isr/isrMockLSST.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def amplifierAddDeferredCharge(self, exposure, amp):
# Create a fake amplifier object that contains some deferred charge
# paramters.
floatingOutputAmplifier = FloatingOutputAmplifier(
gain=1.0, # Everyhting is already in electrons.
gain=1.0, # Everything is already in electrons.
scale=driftScale,
decay_time=decayTime,
noise=0.0,
Expand Down
5 changes: 3 additions & 2 deletions python/lsst/ip/isr/isrStatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class IsrStatisticsTaskConfig(pexConfig.Config):
dtype=bool,
doc="Apply gain to the overscan region when measuring CTI statistics?",
default=True,
deprecated="This field is no longer used. Will be removed after v28.",
deprecated="This field is no longer used. Will be removed after v28 "
"(TODO: DM-46721).",
)

doBandingStatistics = pexConfig.Field(
Expand Down Expand Up @@ -365,7 +366,7 @@ def measureCti(self, inputExp, overscans, gains):
# Ensure we have the same number of overscans as amplifiers.
assert len(overscans) == len(detector.getAmplifiers())

with gainContext(inputExp, image, applyGain, gains, isTrimmed=isTrimmed:
with gainContext(inputExp, image, applyGain, gains, isTrimmed=isTrimmed):
for ampIter, amp in enumerate(detector.getAmplifiers()):
ampStats = {}
readoutCorner = amp.getReadoutCorner()
Expand Down
10 changes: 8 additions & 2 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,23 +1437,29 @@ def run(self, ccdExposure, *, camera=None, bias=None, linearizer=None,
if isinstance(overscanResults.overscanMean, float):
# Only serial overscan was run
mean = overscanResults.overscanMean
median = overscanResults.overscanMedian
sigma = overscanResults.overscanSigma
residMean = overscanResults.residualMean
residMedian = overscanResults.residualMedian
residSigma = overscanResults.residualSigma
else:
# Both serial and parallel overscan were
# run. Only report serial here.
mean = overscanResults.overscanMean[0]
median = overscanResults.overscanMedian[0]
sigma = overscanResults.overscanSigma[0]
residMean = overscanResults.residualMean[0]
residMedian = overscanResults.residualMedian[0]
residSigma = overscanResults.residualSigma[0]

self.metadata[f"FIT MEDIAN {amp.getName()}"] = mean
self.metadata[f"FIT MEDIAN {amp.getName()}"] = median
self.metadata[f"FIT MEAN {amp.getName()}"] = mean
self.metadata[f"FIT STDEV {amp.getName()}"] = sigma
self.log.debug(" Overscan stats for amplifer %s: %f +/- %f",
amp.getName(), mean, sigma)

self.metadata[f"RESIDUAL MEDIAN {amp.getName()}"] = residMean
self.metadata[f"RESIDUAL MEDIAN {amp.getName()}"] = residMedian
self.metadata[f"RESIDUAL MEAN {amp.getName()}"] = residMean
self.metadata[f"RESIDUAL STDEV {amp.getName()}"] = residSigma
self.log.debug(" Overscan stats for amplifer %s after correction: %f +/- %f",
amp.getName(), residMean, residSigma)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ip/isr/isrTaskLSST.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ def overscanCorrection(self, mode, detectorConfig, detector, badAmpDict, ccdExpo
Returns
-------
overscans : `list` [`lsst.pipe.base.Struct` or None]
Overscan measurements (always in adu).
Each result struct has components:
``imageFit``
Expand Down Expand Up @@ -1770,7 +1771,6 @@ def run(self, ccdExposure, *, dnlLUT=None, bias=None, deferredChargeCalib=None,
brighterFatterApplyGain = False
else:
brighterFatterApplyGain = True
exposureMetadata["LSST ISR UNITS"] = "electron"

if brighterFatterApplyGain and (ptc is not None) and (bfGains != gains):
# The supplied ptc should be the same as the ptc used to
Expand Down
4 changes: 3 additions & 1 deletion python/lsst/ip/isr/linearize.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ def applyLinearity(self, image, detector=None, log=None, gains=None):
self.validate(detector)

# Check if the image is trimmed.
isTrimmed = isTrimmedImage(image, detector)
isTrimmed = None
if detector:
isTrimmed = isTrimmedImage(image, detector)

numAmps = 0
numLinearized = 0
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/ip/isr/ptcDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ class PhotonTransferCurveDataset(IsrCalib):
Version 1.7 adds the `noiseList` attribute.
Version 1.8 adds the `ptcTurnoffSamplingError` attribute.
Version 1.9 standardizes PTC noise units to electron.
Version 2.0 adds the `ampOffsets`, `gainUnadjusted`, and
`gainList` attributes.
Version 2.0 deprecates the `covariancesModelNoB`, `aMatrixNoB`,
and `noiseMatrixNoB` attributes.
"""

_OBSTYPE = 'PTC'
Expand Down

0 comments on commit d300448

Please sign in to comment.