41
41
from . import measurePsf , repair , photoCal , computeExposureSummaryStats , snapCombine
42
42
43
43
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
+
44
61
class CalibrateImageConnections (pipeBase .PipelineTaskConnections ,
45
62
dimensions = ("instrument" , "visit" , "detector" )):
46
63
@@ -136,6 +153,11 @@ class CalibrateImageConnections(pipeBase.PipelineTaskConnections,
136
153
storageClass = "Catalog" ,
137
154
dimensions = ("instrument" , "visit" , "detector" ),
138
155
)
156
+ summary_metrics = connectionTypes .Output (
157
+ name = "initial_summary_metrics" ,
158
+ storageClass = "MetricMeasurementBundle" ,
159
+ dimensions = ("instrument" , "visit" , "detector" ),
160
+ )
139
161
140
162
def __init__ (self , * , config = None ):
141
163
super ().__init__ (config = config )
@@ -144,6 +166,8 @@ def __init__(self, *, config=None):
144
166
del self .psf_stars_footprints
145
167
del self .astrometry_matches
146
168
del self .photometry_matches
169
+ if config .do_create_summary_metrics is False :
170
+ del self .summary_metrics
147
171
148
172
149
173
class CalibrateImageConfig (pipeBase .PipelineTaskConfig , pipelineConnections = CalibrateImageConnections ):
@@ -255,6 +279,16 @@ class CalibrateImageConfig(pipeBase.PipelineTaskConfig, pipelineConnections=Cali
255
279
target = computeExposureSummaryStats .ComputeExposureSummaryStatsTask ,
256
280
doc = "Task to to compute summary statistics on the calibrated exposure."
257
281
)
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
+ )
258
292
259
293
def setDefaults (self ):
260
294
super ().setDefaults ()
@@ -406,6 +440,7 @@ def __init__(self, initial_stars_schema=None, **kwargs):
406
440
self .makeSubtask ("photometry" , schema = initial_stars_schema )
407
441
408
442
self .makeSubtask ("compute_summary_stats" )
443
+ self .makeSubtask ("create_summary_metrics" )
409
444
410
445
# For the butler to persist it.
411
446
self .initial_stars_schema = afwTable .SourceCatalog (initial_stars_schema )
@@ -539,7 +574,9 @@ def run(self, *, exposures, id_generator=None, result=None):
539
574
result .photometry_matches = lsst .meas .astrom .denormalizeMatches (photometry_matches ,
540
575
photometry_meta )
541
576
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 )
543
580
544
581
return result
545
582
@@ -849,3 +886,8 @@ def _summarize(self, exposure, stars, background):
849
886
# applied calibration). This needs to be checked.
850
887
summary = self .compute_summary_stats .run (exposure , stars , background )
851
888
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