Skip to content

Commit

Permalink
Merge pull request #142 from lsst/tickets/DM-35773
Browse files Browse the repository at this point in the history
DM-35773: Remove gen2 code from cp_pipe.
  • Loading branch information
erykoff committed Aug 1, 2022
2 parents 99020be + 22d1af5 commit 296245c
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 600 deletions.
3 changes: 0 additions & 3 deletions doc/lsst.cp.pipe/scripts/plotPhotonTransferCurve.py.rst

This file was deleted.

28 changes: 0 additions & 28 deletions doc/lsst.cp.pipe/tasks/lsst.cp.pipe.FindDefectsTask.rst

This file was deleted.

46 changes: 0 additions & 46 deletions doc/lsst.cp.pipe/tasks/lsst.cp.pipe.MeasureCrosstalkTask.rst

This file was deleted.

38 changes: 0 additions & 38 deletions doc/lsst.cp.pipe/tasks/lsst.cp.pipe.MeasureLinearityTask.rst

This file was deleted.

175 changes: 4 additions & 171 deletions python/lsst/cp/pipe/defects.py
Expand Up @@ -34,16 +34,13 @@
from lsst.afw import cameraGeom
from lsst.geom import Box2I, Point2I
from lsst.meas.algorithms import SourceDetectionTask
from lsst.ip.isr import IsrTask, Defects
from lsst.ip.isr import Defects
from .utils import countMaskedPixels
from lsst.pipe.tasks.getRepositoryData import DataRefListRunner
from lsst.utils.timer import timeMethod

from ._lookupStaticCalibration import lookupStaticCalibration

__all__ = ['MeasureDefectsTaskConfig', 'MeasureDefectsTask',
'MergeDefectsTaskConfig', 'MergeDefectsTask',
'FindDefectsTask', 'FindDefectsTaskConfig', ]
'MergeDefectsTaskConfig', 'MergeDefectsTask', ]


class MeasureDefectsConnections(pipeBase.PipelineTaskConnections,
Expand Down Expand Up @@ -125,7 +122,7 @@ def validate(self):
raise ValueError("nSigmaDark must be below 0.0.")


class MeasureDefectsTask(pipeBase.PipelineTask, pipeBase.CmdLineTask):
class MeasureDefectsTask(pipeBase.PipelineTask):
"""Measure the defects from one exposure.
"""

Expand Down Expand Up @@ -613,7 +610,7 @@ class MergeDefectsTaskConfig(pipeBase.PipelineTaskConfig,
)


class MergeDefectsTask(pipeBase.PipelineTask, pipeBase.CmdLineTask):
class MergeDefectsTask(pipeBase.PipelineTask):
"""Merge the defects from multiple exposures.
"""

Expand Down Expand Up @@ -709,167 +706,3 @@ def run(self, inputDefects, camera):
return pipeBase.Struct(
mergedDefects=merged,
)


class FindDefectsTaskConfig(pexConfig.Config):
measure = pexConfig.ConfigurableField(
target=MeasureDefectsTask,
doc="Task to measure single frame defects.",
)
merge = pexConfig.ConfigurableField(
target=MergeDefectsTask,
doc="Task to merge multiple defects together.",
)

isrForFlats = pexConfig.ConfigurableField(
target=IsrTask,
doc="Task to perform instrumental signature removal",
)
isrForDarks = pexConfig.ConfigurableField(
target=IsrTask,
doc="Task to perform instrumental signature removal",
)
isrMandatoryStepsFlats = pexConfig.ListField(
dtype=str,
doc=("isr operations that must be performed for valid results when using flats."
" Raises if any of these are False"),
default=['doAssembleCcd', 'doFringe']
)
isrMandatoryStepsDarks = pexConfig.ListField(
dtype=str,
doc=("isr operations that must be performed for valid results when using darks. "
"Raises if any of these are False"),
default=['doAssembleCcd', 'doFringe']
)
isrForbiddenStepsFlats = pexConfig.ListField(
dtype=str,
doc=("isr operations that must NOT be performed for valid results when using flats."
" Raises if any of these are True"),
default=['doBrighterFatter', 'doUseOpticsTransmission',
'doUseFilterTransmission', 'doUseSensorTransmission', 'doUseAtmosphereTransmission']
)
isrForbiddenStepsDarks = pexConfig.ListField(
dtype=str,
doc=("isr operations that must NOT be performed for valid results when using darks."
" Raises if any of these are True"),
default=['doBrighterFatter', 'doUseOpticsTransmission',
'doUseFilterTransmission', 'doUseSensorTransmission', 'doUseAtmosphereTransmission']
)
isrDesirableSteps = pexConfig.ListField(
dtype=str,
doc=("isr operations that it is advisable to perform, but are not mission-critical."
" WARNs are logged for any of these found to be False."),
default=['doBias']
)

ccdKey = pexConfig.Field(
dtype=str,
doc="The key by which to pull a detector from a dataId, e.g. 'ccd' or 'detector'",
default='ccd',
)
imageTypeKey = pexConfig.Field(
dtype=str,
doc="The key for the butler to use by which to check whether images are darks or flats",
default='imageType',
)


class FindDefectsTask(pipeBase.CmdLineTask):
"""Task for finding defects in sensors.
The task has two modes of operation, defect finding in raws and in
master calibrations, which work as follows.
**Master calib defect finding**
A single visit number is supplied, for which the corresponding
flat & dark will be used. This is because, at present at least,
there is no way to pass a calibration exposure ID from the command
line to a command line task.
The task retrieves the corresponding dark and flat exposures for
the supplied visit. If a flat is available the task will (be able
to) look for both bright and dark defects. If only a dark is found
then only bright defects will be sought.
All pixels above/below the specified nSigma which lie with the
specified borders for flats/darks are identified as defects.
**Raw visit defect finding**
A list of exposure IDs are supplied for defect finding. The task
will detect bright pixels in the dark frames, if supplied, and
bright & dark pixels in the flats, if supplied, i.e. if you only
supply darks you will only be given bright defects. This is done
automatically from the imageType of the exposure, so the input
exposure list can be a mix.
As with the master calib detection, all pixels above/below the
specified nSigma which lie with the specified borders for
flats/darks are identified as defects. Then, a post-processing
step is done to merge these detections, with pixels appearing in a
fraction [0..1] of the images are kept as defects and those
appearing below that occurrence-threshold are discarded.
"""

ConfigClass = FindDefectsTaskConfig
_DefaultName = "findDefects"

RunnerClass = DataRefListRunner

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.makeSubtask("measure")
self.makeSubtask("merge")

@timeMethod
def runDataRef(self, dataRefList):
"""Run the defect finding task.
Find the defects, as described in the main task docstring, from a
dataRef and a list of visit(s).
Parameters
----------
dataRefList : `list` [`lsst.daf.persistence.ButlerDataRef`]
dataRefs for the data to be checked for defects.
Returns
-------
result : `lsst.pipe.base.Struct`
Result struct with Components:
``defects``
The defects found by the task (`lsst.ip.isr.Defects`).
``exitStatus``
The exit code (`int`).
"""
dataRef = dataRefList[0]
camera = dataRef.get("camera")

singleExpDefects = []
activeChip = None
for dataRef in dataRefList:
exposure = dataRef.get("postISRCCD")
if activeChip:
if exposure.getDetector().getName() != activeChip:
raise RuntimeError("Too many input detectors supplied!")
else:
activeChip = exposure.getDetector().getName()

result = self.measure.run(exposure, camera)
singleExpDefects.append(result.outputDefects)

finalResults = self.merge.run(singleExpDefects, camera)
metadata = finalResults.mergedDefects.getMetadata()
inputDims = {'calibDate': metadata['CALIBDATE'],
'raftName': metadata['RAFTNAME'],
'detectorName': metadata['SLOTNAME'],
'detector': metadata['DETECTOR'],
'ccd': metadata['DETECTOR'],
'ccdnum': metadata['DETECTOR']}

butler = dataRef.getButler()
butler.put(finalResults.mergedDefects, "defects", inputDims)

return finalResults
55 changes: 2 additions & 53 deletions python/lsst/cp/pipe/linearity.py
Expand Up @@ -32,7 +32,7 @@
from .utils import (funcPolynomial, irlsFit)
from ._lookupStaticCalibration import lookupStaticCalibration

__all__ = ["LinearitySolveTask", "LinearitySolveConfig", "MeasureLinearityTask"]
__all__ = ["LinearitySolveTask", "LinearitySolveConfig"]


class LinearitySolveConnections(pipeBase.PipelineTaskConnections,
Expand Down Expand Up @@ -149,7 +149,7 @@ class LinearitySolveConfig(pipeBase.PipelineTaskConfig,
)


class LinearitySolveTask(pipeBase.PipelineTask, pipeBase.CmdLineTask):
class LinearitySolveTask(pipeBase.PipelineTask):
"""Fit the linearity from the PTC dataset.
"""

Expand Down Expand Up @@ -559,54 +559,3 @@ def debugFit(self, stepname, xVector, yVector, yModel, mask, ampName):
elif ans in ('x', ):
exit()
plt.close()


class MeasureLinearityConfig(pexConfig.Config):
solver = pexConfig.ConfigurableField(
target=LinearitySolveTask,
doc="Task to convert PTC data to linearity solutions.",
)


class MeasureLinearityTask(pipeBase.CmdLineTask):
"""Stand alone Gen2 linearity measurement.
This class wraps the Gen3 linearity task to allow it to be run as
a Gen2 CmdLineTask.
"""

ConfigClass = MeasureLinearityConfig
_DefaultName = "measureLinearity"

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.makeSubtask("solver")

def runDataRef(self, dataRef):
"""Run new linearity code for gen2.
Parameters
----------
dataRef : `lsst.daf.persistence.ButlerDataRef`
Input dataref for the photon transfer curve data.
Returns
-------
results : `lsst.pipe.base.Struct`
The results struct containing:
``outputLinearizer``
Final linearizer calibration (`lsst.ip.isr.Linearizer`).
``outputProvenance``
Provenance data for the new calibration
(`lsst.ip.isr.IsrProvenance`).
"""
ptc = dataRef.get('photonTransferCurveDataset')
camera = dataRef.get('camera')
inputDims = dataRef.dataId # This is the closest gen2 has.
linearityResults = self.solver.run(ptc, camera=camera, inputDims=inputDims)

inputDims['calibDate'] = linearityResults.outputLinearizer.getMetadata().get('CALIBDATE')
butler = dataRef.getButler()
butler.put(linearityResults.outputLinearizer, "linearizer", inputDims)
return linearityResults

0 comments on commit 296245c

Please sign in to comment.