4141import lsst .meas .base .tests
4242import lsst .pipe .base .testUtils
4343from lsst .pipe .tasks .calibrateImage import CalibrateImageTask
44+ from lsst .analysis .tools .tasks import CalexpSummaryAnalysisTask
45+ from lsst .analysis .tools .atools import CalexpSummaryMetrics
46+ from lsst .analysis .tools .interfaces import MetricMeasurementBundle
4447import lsst .utils .tests
4548
4649
@@ -138,6 +141,10 @@ def setUp(self):
138141 # Something about this test dataset prefers a larger threshold here.
139142 self .config .star_selector ["science" ].unresolved .maximum = 0.2
140143
144+ self .config .do_create_summary_metrics = True
145+ self .config .create_summary_metrics .retarget (CalexpSummaryAnalysisTask )
146+ self .config .create_summary_metrics .atools .initial_pvi_metrics = CalexpSummaryMetrics
147+
141148 def _check_run (self , calibrate , result ):
142149 """Test the result of CalibrateImage.run().
143150
@@ -162,6 +169,27 @@ def _check_run(self, calibrate, result):
162169 self .assertFloatsAlmostEqual (summary .ra , self .sky_center .getRa ().asDegrees (), rtol = 1e-7 )
163170 self .assertFloatsAlmostEqual (summary .dec , self .sky_center .getDec ().asDegrees (), rtol = 1e-7 )
164171
172+ # Check that the summary metrics are reasonable.
173+ metrics = result .summary_metrics
174+ if self .config .do_create_summary_metrics :
175+ self .assertIsInstance (metrics , MetricMeasurementBundle )
176+
177+ for metric in metrics ['initial_pvi_metrics' ]:
178+ if metric .metric_name .metric == 'psfSigma' :
179+ self .assertFloatsAlmostEqual (metric .quantity .value , 2.0 , rtol = 1e-2 )
180+ if metric .metric_name .metric == 'ra' :
181+ self .assertFloatsAlmostEqual (
182+ metric .quantity .value ,
183+ self .sky_center .getRa ().asDegrees (),
184+ rtol = 1e-7 )
185+ if metric .metric_name .metric == 'dec' :
186+ self .assertFloatsAlmostEqual (
187+ metric .quantity .value ,
188+ self .sky_center .getDec ().asDegrees (),
189+ rtol = 1e-7 )
190+ else :
191+ self .assertIsNone (metrics )
192+
165193 # Should have finite sky coordinates in the afw and astropy catalogs.
166194 self .assertTrue (np .isfinite (result .stars_footprints ["coord_ra" ]).all ())
167195 self .assertTrue (np .isfinite (result .stars ["coord_ra" ]).all ())
@@ -212,6 +240,7 @@ def test_run_no_optionals(self):
212240 struct, as appropriate.
213241 """
214242 self .config .optional_outputs = None
243+ self .config .do_create_summary_metrics = False
215244 calibrate = CalibrateImageTask (config = self .config )
216245 calibrate .astrometry .setRefObjLoader (self .ref_loader )
217246 calibrate .photometry .match .setRefObjLoader (self .ref_loader )
@@ -480,6 +509,10 @@ def setUp(self):
480509 "initial_photometry_match_detector" ,
481510 {"instrument" , "visit" , "detector" },
482511 "Catalog" )
512+ butlerTests .addDatasetType (self .repo ,
513+ "initial_summary_metrics" ,
514+ {"instrument" , "visit" , "detector" },
515+ "MetricMeasurementBundle" )
483516
484517 # dataIds
485518 self .exposure0_id = self .repo .registry .expandDataId (
@@ -520,6 +553,7 @@ def test_runQuantum(self):
520553 "initial_pvi_background" : self .visit_id ,
521554 "astrometry_matches" : self .visit_id ,
522555 "photometry_matches" : self .visit_id ,
556+ "summary_metrics" : self .visit_id ,
523557 })
524558 mock_run = lsst .pipe .base .testUtils .runTestQuantum (task , self .butler , quantum )
525559
@@ -549,6 +583,7 @@ def test_runQuantum_2_snaps(self):
549583 "initial_pvi_background" : self .visit_id ,
550584 "astrometry_matches" : self .visit_id ,
551585 "photometry_matches" : self .visit_id ,
586+ "summary_metrics" : self .visit_id ,
552587 })
553588 mock_run = lsst .pipe .base .testUtils .runTestQuantum (task , self .butler , quantum )
554589
@@ -575,6 +610,7 @@ def test_runQuantum_no_optional_outputs(self):
575610 "initial_pvi_background" : self .visit_id ,
576611 "astrometry_matches" : self .visit_id ,
577612 "photometry_matches" : self .visit_id ,
613+ "summary_metrics" : self .visit_id ,
578614 }
579615
580616 # Check that we can turn off one output at a time.
@@ -621,6 +657,7 @@ def test_runQuantum_exception(self):
621657 "initial_pvi_background" : self .visit_id ,
622658 "astrometry_matches" : self .visit_id ,
623659 "photometry_matches" : self .visit_id ,
660+ "summary_metrics" : self .visit_id ,
624661 })
625662
626663 # A generic exception should raise directly.
0 commit comments