Skip to content

Commit f78e4ec

Browse files
committed
Add summary metric creation to calibrateImage.py
1 parent 1e125bf commit f78e4ec

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

python/lsst/pipe/tasks/calibrateImage.py

+43-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@
4141
from . import measurePsf, repair, photoCal, computeExposureSummaryStats, snapCombine
4242

4343

44+
class _EmptyTargetTask(pipeBase.PipelineTask):
45+
"""
46+
This is a placeholder target for CreateSummaryMetrics and must be retargeted at runtime.
47+
CreateSummaryMetrics should target an analysis tool task, but that would, at the time
48+
of writing, result in a circular import.
49+
50+
As a result, this class should not be used for anything else.
51+
"""
52+
ConfigClass = pipeBase.PipelineTaskConfig
53+
54+
def __init__(self, **kwargs) -> None:
55+
raise NotImplementedError(
56+
"doCreateSummaryMetrics is set to True, in which case "
57+
"createSummaryMetrics must be retargeted."
58+
)
59+
60+
4461
class CalibrateImageConnections(pipeBase.PipelineTaskConnections,
4562
dimensions=("instrument", "visit", "detector")):
4663

@@ -136,6 +153,11 @@ class CalibrateImageConnections(pipeBase.PipelineTaskConnections,
136153
storageClass="Catalog",
137154
dimensions=("instrument", "visit", "detector"),
138155
)
156+
summary_metrics = connectionTypes.Output(
157+
name="initial_summary_metrics",
158+
storageClass="MetricMeasurementBundle",
159+
dimensions=("instrument", "visit", "detector"),
160+
)
139161

140162
def __init__(self, *, config=None):
141163
super().__init__(config=config)
@@ -144,6 +166,8 @@ def __init__(self, *, config=None):
144166
del self.psf_stars_footprints
145167
del self.astrometry_matches
146168
del self.photometry_matches
169+
if config.do_create_summary_metrics is False:
170+
del self.summary_metrics
147171

148172

149173
class CalibrateImageConfig(pipeBase.PipelineTaskConfig, pipelineConnections=CalibrateImageConnections):
@@ -255,6 +279,16 @@ class CalibrateImageConfig(pipeBase.PipelineTaskConfig, pipelineConnections=Cali
255279
target=computeExposureSummaryStats.ComputeExposureSummaryStatsTask,
256280
doc="Task to to compute summary statistics on the calibrated exposure."
257281
)
282+
do_create_summary_metrics = pexConfig.Field(
283+
dtype=bool,
284+
default=False,
285+
doc="Run the subtask to create summary metrics, and then write those metrics."
286+
)
287+
create_summary_metrics = pexConfig.ConfigurableField(
288+
target=_EmptyTargetTask,
289+
doc="Subtask to create metrics from the summary stats. This must be retargeted, likely to an"
290+
"analysis_tools task such as CalexpSummaryMetrics."
291+
)
258292

259293
def setDefaults(self):
260294
super().setDefaults()
@@ -406,6 +440,7 @@ def __init__(self, initial_stars_schema=None, **kwargs):
406440
self.makeSubtask("photometry", schema=initial_stars_schema)
407441

408442
self.makeSubtask("compute_summary_stats")
443+
self.makeSubtask("create_summary_metrics")
409444

410445
# For the butler to persist it.
411446
self.initial_stars_schema = afwTable.SourceCatalog(initial_stars_schema)
@@ -539,7 +574,9 @@ def run(self, *, exposures, id_generator=None, result=None):
539574
result.photometry_matches = lsst.meas.astrom.denormalizeMatches(photometry_matches,
540575
photometry_meta)
541576

542-
self._summarize(result.exposure, result.stars_footprints, result.background)
577+
result.summary_metrics = self._summarize(result.exposure,
578+
result.stars_footprints,
579+
result.background)
543580

544581
return result
545582

@@ -849,3 +886,8 @@ def _summarize(self, exposure, stars, background):
849886
# applied calibration). This needs to be checked.
850887
summary = self.compute_summary_stats.run(exposure, stars, background)
851888
exposure.info.setSummaryStats(summary)
889+
890+
summaryMetrics = None
891+
if self.config.do_create_summary_metrics:
892+
summaryMetrics = self.create_summary_metrics.run(data=summary.__dict__).metrics
893+
return summaryMetrics

0 commit comments

Comments
 (0)