Skip to content

Commit

Permalink
Implement amp-to-amp offset correction task
Browse files Browse the repository at this point in the history
This commit adds a placeholder amp offset task which is not implemented
here, and instead should be retargeted by a camera specific version.
  • Loading branch information
leeskelvin committed Apr 27, 2021
1 parent fb99f82 commit c0084ae
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 2 deletions.
86 changes: 86 additions & 0 deletions python/lsst/ip/isr/ampOffset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This file is part of ip_isr.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# import os

import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
from lsst.meas.algorithms import (SubtractBackgroundTask, SourceDetectionTask)


class AmpOffsetConfig(pexConfig.Config):
"""Configuration parameters for AmpOffsetTask.
"""
ampEdgeInset = pexConfig.Field(
doc="Number of pixels the amp edge strip is inset from the amp edge. A thin strip of pixels running "
"parallel to the edge of the amp is used to characterize the average flux level at the amp edge.",
dtype=int,
default=5,
)
ampEdgeWidth = pexConfig.Field(
doc="Pixel width of the amp edge strip, starting at ampEdgeInset and extending inwards.",
dtype=int,
default=64,
)
ampEdgeMinFrac = pexConfig.Field(
doc="Minimum allowed fraction of viable pixel rows along an amp edge. No amp-to-amp step estimate "
"will be generated for amp edges that do not have at least this fraction of unmasked pixel rows.",
dtype=float,
default=0.5,
)
ampEdgeMaxStep = pexConfig.Field(
doc="Maximum allowed amp-to-amp step value. If a measured amp-to-amp step value is larger than this, "
"the result will be discarded and therefore not used to determine amp offset piston corrections.",
dtype=float,
default=5.0,
)
ampEdgeWindow = pexConfig.Field(
doc="Size of the sliding window used to generate rolling average amp-edge step values.",
dtype=int,
default=512,
)
background = pexConfig.ConfigurableField(
doc="An initial background estimation step run prior to amp offset calculation.",
target=SubtractBackgroundTask,
)
detection = pexConfig.ConfigurableField(
doc="Source detection to add temporary detection footprints prior to amp offset calculation.",
target=SourceDetectionTask,
)


class AmpOffsetTask(pipeBase.Task):
"""Calculate and apply amp offset corrections to an exposure.
"""
ConfigClass = AmpOffsetConfig
_DefaultName = "isrAmpOffset"

def run(self, exposure):
"""Calculate amp-to-amp step values, determine corrective piston
pedestals for each amp, and update the input exposure in-place. This
task is currently not implemented, and should be retargeted by a camera
specific version.
Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to be corrected for any amp-to-amp offsets.
"""
raise NotImplementedError("Amp offset task should be retargeted by a camera specific version.")
20 changes: 18 additions & 2 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from .overscan import OverscanCorrectionTask
from .straylight import StrayLightTask
from .vignette import VignetteTask
from .ampOffset import AmpOffsetTask
from lsst.daf.butler import DimensionGraph


Expand Down Expand Up @@ -433,7 +434,6 @@ class IsrTaskConfig(pipeBase.PipelineTaskConfig,
target=OverscanCorrectionTask,
doc="Overscan subtraction task for image segments.",
)

overscanFitType = pexConfig.ChoiceField(
dtype=str,
doc="The method for fitting the overscan bias level.",
Expand Down Expand Up @@ -752,6 +752,17 @@ class IsrTaskConfig(pipeBase.PipelineTaskConfig,
default=True,
)

# Amp offset correction.
doAmpOffset = pexConfig.Field(
doc="Calculate and apply amp-to-amp offset corrections?",
dtype=bool,
default=False,
)
ampOffset = pexConfig.ConfigurableField(
doc="Amp-to-amp offset correction task.",
target=AmpOffsetTask,
)

# Initial CCD-level background statistics options.
doMeasureBackground = pexConfig.Field(
dtype=bool,
Expand All @@ -771,7 +782,6 @@ class IsrTaskConfig(pipeBase.PipelineTaskConfig,
)

# Interpolation options.

doInterpolate = pexConfig.Field(
dtype=bool,
doc="Interpolate masked pixels?",
Expand Down Expand Up @@ -943,6 +953,7 @@ def __init__(self, **kwargs):
self.makeSubtask("masking")
self.makeSubtask("overscan")
self.makeSubtask("vignette")
self.makeSubtask("ampOffset")

def runQuantum(self, butlerQC, inputRefs, outputRefs):
inputs = butlerQC.get(inputRefs)
Expand Down Expand Up @@ -1679,6 +1690,11 @@ def run(self, ccdExposure, *, camera=None, bias=None, linearizer=None,

self.roughZeroPoint(ccdExposure)

# correct for amp offsets within the CCD
if self.config.doAmpOffset:
self.log.info("Correcting amp offsets.")
self.ampOffset.run(ccdExposure)

if self.config.doMeasureBackground:
self.log.info("Measuring background level.")
self.measureBackground(ccdExposure, self.config.qa)
Expand Down

0 comments on commit c0084ae

Please sign in to comment.