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-19393: Delegate to StrayLightTask subclasses to load their data. #86

Merged
merged 1 commit into from
Apr 23, 2019
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
24 changes: 20 additions & 4 deletions python/lsst/ip/isr/isrTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@ def readIsrData(self, dataRef, rawExposure):
- ``atmosphereTransmission`` : `lsst.afw.image.TransmissionCurve`
A ``TransmissionCurve`` that represents the throughput of the
atmosphere, assumed to be spatially constant.
- ``strayLightData`` : `object`
An opaque object containing calibration information for
stray-light correction. If `None`, no correction will be
performed.

Raises
------
Expand Down Expand Up @@ -928,6 +932,11 @@ def readIsrData(self, dataRef, rawExposure):
sensorTransmission = None
atmosphereTransmission = None

if self.config.doStrayLight:
strayLightData = self.strayLight.readIsrData(dataRef, rawExposure)
else:
strayLightData = None

# Struct should include only kwargs to run()
return pipeBase.Struct(bias=biasExposure,
linearizer=linearizer,
Expand All @@ -941,14 +950,15 @@ def readIsrData(self, dataRef, rawExposure):
filterTransmission=filterTransmission,
sensorTransmission=sensorTransmission,
atmosphereTransmission=atmosphereTransmission,
strayLightData=strayLightData
)

@pipeBase.timeMethod
def run(self, ccdExposure, camera=None, bias=None, linearizer=None, crosstalkSources=None,
dark=None, flat=None, bfKernel=None, defects=None, fringes=None,
opticsTransmission=None, filterTransmission=None,
sensorTransmission=None, atmosphereTransmission=None,
detectorNum=None, isGen3=False
detectorNum=None, strayLightData=None, isGen3=False,
):
"""!Perform instrument signature removal on an exposure.

Expand Down Expand Up @@ -1013,6 +1023,9 @@ def run(self, ccdExposure, camera=None, bias=None, linearizer=None, crosstalkSou
The integer number for the detector to process.
isGen3 : bool, optional
Flag this call to run() as using the Gen3 butler environment.
strayLightData : `object`, optional
Opaque object containing calibration information for stray-light
correction. If `None`, no correction will be performed.

Returns
-------
Expand Down Expand Up @@ -1234,9 +1247,12 @@ def run(self, ccdExposure, camera=None, bias=None, linearizer=None, crosstalkSou
self.debugView(ccdExposure, "doFringe")

if self.config.doStrayLight:
self.log.info("Applying stray light correction.")
self.strayLight.run(ccdExposure)
self.debugView(ccdExposure, "doStrayLight")
if strayLightData is not None:
self.log.info("Applying stray light correction.")
self.strayLight.run(ccdExposure, strayLightData)
self.debugView(ccdExposure, "doStrayLight")
else:
self.log.debug("Skipping stray light correction: no data found for this image.")

if self.config.doFlat:
self.log.info("Applying flat correction.")
Expand Down
38 changes: 34 additions & 4 deletions python/lsst/ip/isr/straylight.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,44 @@ class StrayLightTask(Task):
"""
ConfigClass = StrayLightConfig

def run(self, exposure, **kwargs):
def readIsrData(self, dataRef, rawExposure):
"""Read and return calibration products relevant for correcting
stray light in the given exposure.

Parameters
----------
dataRef : `daf.persistence.butlerSubset.ButlerDataRef`
Butler reference of the detector data to be processed
rawExposure : `afw.image.Exposure`
The raw exposure that will later be corrected with the
retrieved calibration data; should not be modified in this
method.

Returns
-------
straylightData : `object`, optional
An opaque object that should be passed as the second argument to
the `run` method. If `None`, no stray light correction will be
performed for the given image. Any other object (e.g. `True`)
may be used to signal that stray light correction should be
performed even if there is nothing to read.

Notes
-----
This method will be called only when `IsrTask` is run by the Gen2
Middleware (i.e. CmdLineTask).
"""
return None

def run(self, exposure, strayLightData):
"""Correct stray light.

Parameters
----------
exposure : `lsst.afw.image.Exposure`
Exposure to correct.

strayLightData : `object`, optional
An opaque object that contains any calibration data used to
correct for stray light.
"""
self.log.info("The generic StrayLightTask does not correct anything.")
return
raise NotImplementedError("Must be implemented by subclasses.")