Skip to content

Commit

Permalink
add cosmicRayPostDiff.py
Browse files Browse the repository at this point in the history
review comments

fix typos
  • Loading branch information
kherner committed Mar 25, 2022
1 parent 12b8063 commit 63d7324
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions python/lsst/pipe/tasks/cosmicRayPostDiff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# This file is part of pipe_tasks.
#
# 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 lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import lsst.pipe.base.connectionTypes as cT
from lsst.utils.timer import timeMethod
from .repair import RepairTask


__all__ = ["CosmicRayPostDiffConfig", "CosmicRayPostDiffTask"]


class CosmicRayPostDiffConnections(pipeBase.PipelineTaskConnections,
dimensions=("instrument", "visit", "detector"),
defaultTemplates={"coaddName": "deep",
"fakesType": ""}):
exposure = cT.Input(
doc="Input difference image",
name="{fakesType}{coaddName}Diff_differenceExp",
storageClass="ExposureF",
dimensions=("instrument", "visit", "detector"),
)
repaired = cT.Output(
doc="Output subtracted image after CR run.",
name="{fakesType}{coaddName}Diff_repairedExp",
storageClass="ExposureF",
dimensions=("instrument", "visit", "detector"),
)

def adjustQuantum(self, inputs, outputs, label, dataId):
# Docstring inherited from PipelineTaskConnections
try:
return super().adjustQuantum(inputs, outputs, label, dataId)
except pipeBase.ScalarError as err:
raise pipeBase.ScalarError(
"CosmicRayPostDiffTask can at present only be run on visits that are associated with "
"exactly one exposure. Either this is not a valid exposure for this pipeline, or the "
"snap-combination step you probably want hasn't been configured to run between ISR and "
"this task (as of this writing, that would be because it hasn't been implemented yet)."
) from err


class CosmicRayPostDiffConfig(pipeBase.PipelineTaskConfig,
pipelineConnections=CosmicRayPostDiffConnections):

"""Config for CosmicRayPostDiffTask"""
repair = pexConfig.ConfigurableField(
target=RepairTask,
doc="Remove cosmic rays",
)

def setDefaults(self):
super().setDefaults()


class CosmicRayPostDiffTask(pipeBase.PipelineTask, pipeBase.CmdLineTask):
r"""Measure bright sources and use this to estimate background and PSF of an exposure
@anchor CosmicRayPostDiffTask_
@section pipe_tasks_cosmicRayPostDiff_Contents Contents
- @ref pipe_tasks_cosmicRayPostDiff_Purpose
- @ref pipe_tasks_cosmicRayPostDiff_Initialize
- @ref pipe_tasks_cosmicRayPostDiff_IO
- @ref pipe_tasks_cosmicRayPostDiff_Config
@section pipe_tasks_cosmicRayPostDiff_Purpose Description
Given an output image from image differencing:
- detect and repair cosmic rays
- At the moment this task does NOT recompute the PSF or re-do source detection.
@section pipe_tasks_cosmicRayPostDiff_Initialize Task initialisation
@copydoc \_\_init\_\_
@section pipe_tasks_cosmicRayPostDiff_IO Invoking the Task
Call the `run` method.
@section pipe_tasks_cosmicRayPostDiff_Config Configuration parameters
See @ref CosmicRayPostDiffConfig
"""

ConfigClass = CosmicRayPostDiffConfig
_DefaultName = "cosmicRayPostDiff"
RunnerClass = pipeBase.ButlerInitializedTaskRunner

def runQuantum(self, butlerQC, inputRefs, outputRefs):
inputs = butlerQC.get(inputRefs)
outputs = self.run(**inputs)
butlerQC.put(outputs, outputRefs)

def __init__(self, **kwargs):
"""Construct a CosmicRayPostDiffTask"""
super().__init__(**kwargs)
self.makeSubtask("repair")

@timeMethod
def run(self, exposure):
"""Run cosmic ray detection and repair on imageDifference outputs
Parameters
----------
exposure `lsst.afw.image.ExposureF`:
The following changes are made to the exposure,
- Blank cosmic ray mask planes, run CR detection and repair, update CR mask plane
Returns
-------
`lsst.pipe.base.Struct`:
Struct containing the input image with the CR mask plane first blanked,
and then cosmic rays detected, and the mask is updated accordingly.
The PSF model is NOT changed.
"""
# perform final repair
self.repair.run(exposure=exposure)

return pipeBase.Struct(
repaired=exposure
)

0 comments on commit 63d7324

Please sign in to comment.