Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions python/lsst/pipe/tasks/skyCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@
from lsst.afw.math import BackgroundMI, binImage
from lsst.daf.butler import DeferredDatasetHandle
from lsst.pex.config import Config, ConfigField, ConfigurableField, Field
from lsst.pipe.base import PipelineTask, PipelineTaskConfig, PipelineTaskConnections, Struct
from lsst.pipe.base import (
AlgorithmError,
AnnotatedPartialOutputsError,
PipelineTask,
PipelineTaskConfig,
PipelineTaskConnections,
Struct,
)
from lsst.pipe.base.connectionTypes import Input, Output, PrerequisiteInput
from lsst.pipe.tasks.background import (
FocalPlaneBackground,
Expand Down Expand Up @@ -258,7 +265,15 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
outputRefs.skyCorr, [ref.dataId["detector"] for ref in outputRefs.skyCorr], detectorOrder
)
inputs = butlerQC.get(inputRefs)
outputs = self.run(**inputs)
try:
outputs = self.run(**inputs)
except AlgorithmError as e:
error = AnnotatedPartialOutputsError.annotate(
e,
self, # type: ignore
log=self.log,
)
raise error from e
butlerQC.put(outputs, outputRefs)

def run(self, calExps, calBkgs, skyFrames, camera, backgroundToPhotometricRatioHandles=[]):
Expand Down Expand Up @@ -606,11 +621,7 @@ def _validateBgModel(self, bgModelID, bgModel, config):

thresh = config.minFrac * spArea
if np.all(bgModelArray < thresh):
raise RuntimeError(
f"No background model superpixels are more than {100*config.minFrac}% filled. "
"Try decreasing the minFrac configuration parameter, optimizing the subset of detectors "
"being processed, or increasing the number of detectors being processed."
)
raise NoUsableBackgroundSuperpixelsError(bgModelID, config.minFrac)

with warnings.catch_warnings():
warnings.filterwarnings("ignore", r"invalid value encountered")
Expand Down Expand Up @@ -671,3 +682,21 @@ def _fitSkyFrame(self, calExps, masks, skyCorrs, skyFrames, backgroundToPhotomet
skyCorr.append(newBgData)
self.log.info("Sky frame subtracted with a scale factor of %.5f", scale)
return scale


class NoUsableBackgroundSuperpixelsError(AlgorithmError):
def __init__(self, bgModelID: str, minFrac: float):
self.bgModelID = bgModelID
self.minFrac = float(minFrac)
message = (
f"No background model superpixels in {bgModelID} are more than {100 * self.minFrac:.1f}% filled. "
"Try decreasing the minFrac configuration parameter, optimizing the subset of detectors "
"being processed, or increasing the number of detectors being processed."
)
super().__init__(message)

@property
def metadata(self) -> dict:
return {
"bgModelID": self.bgModelID,
}