@@ -207,6 +207,22 @@ def test_run_2_snaps(self):
207207
208208 self ._check_run (calibrate , result )
209209
210+ def test_run_no_optionals (self ):
211+ """Test that disabling optional outputs removes them from the output
212+ struct, as appropriate.
213+ """
214+ self .config .optional_outputs = None
215+ calibrate = CalibrateImageTask (config = self .config )
216+ calibrate .astrometry .setRefObjLoader (self .ref_loader )
217+ calibrate .photometry .match .setRefObjLoader (self .ref_loader )
218+ result = calibrate .run (exposures = self .exposure )
219+
220+ self ._check_run (calibrate , result )
221+ # These are the only optional outputs that require extra computation,
222+ # the others are included in the output struct regardless.
223+ self .assertNotIn ("astrometry_matches" , result .getDict ())
224+ self .assertNotIn ("photometry_matches" , result .getDict ())
225+
210226 def test_handle_snaps (self ):
211227 calibrate = CalibrateImageTask (config = self .config )
212228 self .assertEqual (calibrate ._handle_snaps (self .exposure ), self .exposure )
@@ -216,6 +232,8 @@ def test_handle_snaps(self):
216232 calibrate ._handle_snaps ([])
217233 with self .assertRaisesRegex (RuntimeError , "Can only process 1 or 2 snaps, not 3." ):
218234 calibrate ._handle_snaps (3 * [self .exposure ])
235+ with self .assertRaisesRegex (RuntimeError , "must be either an afw Exposure" ):
236+ calibrate ._handle_snaps ("" )
219237
220238 def test_compute_psf (self ):
221239 """Test that our brightest sources are found by _compute_psf(),
@@ -541,30 +559,39 @@ def test_runQuantum_2_snaps(self):
541559 self .assertEqual (mock_run .call_args .kwargs .keys (), {"exposures" , "result" , "id_generator" })
542560
543561 def test_runQuantum_no_optional_outputs (self ):
544- config = CalibrateImageTask .ConfigClass ()
545- config .optional_outputs = None
546- task = CalibrateImageTask (config = config )
547- lsst .pipe .base .testUtils .assertValidInitOutput (task )
548-
549- quantum = lsst .pipe .base .testUtils .makeQuantum (
550- task , self .butler , self .visit_id ,
551- {"exposures" : [self .exposure0_id ],
552- "astrometry_ref_cat" : [self .htm_id ],
553- "photometry_ref_cat" : [self .htm_id ],
554- # outputs
555- "exposure" : self .visit_id ,
556- "stars" : self .visit_id ,
557- "stars_footprints" : self .visit_id ,
558- "applied_photo_calib" : self .visit_id ,
559- "background" : self .visit_id ,
560- })
561- mock_run = lsst .pipe .base .testUtils .runTestQuantum (task , self .butler , quantum )
562-
563- # Ensure the reference loaders have been configured.
564- self .assertEqual (task .astrometry .refObjLoader .name , "gaia_dr3_20230707" )
565- self .assertEqual (task .photometry .match .refObjLoader .name , "ps1_pv3_3pi_20170110" )
566- # Check that the proper kwargs are passed to run().
567- self .assertEqual (mock_run .call_args .kwargs .keys (), {"exposures" , "result" , "id_generator" })
562+ # All the possible connections: we modify this to test each one by
563+ # popping off the removed connection, then re-setting it.
564+ connections = {"exposures" : [self .exposure0_id , self .exposure1_id ],
565+ "astrometry_ref_cat" : [self .htm_id ],
566+ "photometry_ref_cat" : [self .htm_id ],
567+ # outputs
568+ "exposure" : self .visit_id ,
569+ "stars" : self .visit_id ,
570+ "stars_footprints" : self .visit_id ,
571+ "background" : self .visit_id ,
572+ "psf_stars" : self .visit_id ,
573+ "psf_stars_footprints" : self .visit_id ,
574+ "applied_photo_calib" : self .visit_id ,
575+ "initial_pvi_background" : self .visit_id ,
576+ "astrometry_matches" : self .visit_id ,
577+ "photometry_matches" : self .visit_id ,
578+ }
579+
580+ # Check that we can turn off one output at a time.
581+ for optional in ["psf_stars" , "psf_stars_footprints" , "astrometry_matches" , "photometry_matches" ]:
582+ config = CalibrateImageTask .ConfigClass ()
583+ config .optional_outputs .remove (optional )
584+ task = CalibrateImageTask (config = config )
585+ lsst .pipe .base .testUtils .assertValidInitOutput (task )
586+ # Save the removed one for the next test.
587+ temp = connections .pop (optional )
588+ # This will fail with "Error in connection ..." if we don't pop
589+ # the optional item from the connections list just above.
590+ quantum = lsst .pipe .base .testUtils .makeQuantum (task , self .butler , self .visit_id , connections )
591+ # This confirms that the outputs did skip the removed one.
592+ self .assertNotIn (optional , quantum .outputs )
593+ # Restore the one we removed for the next test.
594+ connections [optional ] = temp
568595
569596 def test_lintConnections (self ):
570597 """Check that the connections are self-consistent.
0 commit comments