@@ -286,18 +286,14 @@ class CalibrateImageConfig(pipeBase.PipelineTaskConfig, pipelineConnections=Cali
286286 doc = "Task to perform intial background subtraction, before first detection pass." ,
287287 )
288288 psf_detection = pexConfig .ConfigurableField (
289- target = lsst . meas . algorithms . SourceDetectionTask ,
289+ target = AdaptiveThresholdDetectionTask ,
290290 doc = "Task to detect sources for PSF determination."
291291 )
292292 do_adaptive_threshold_detection = pexConfig .Field (
293293 dtype = bool ,
294294 default = True ,
295295 doc = "Implement the adaptive detection thresholding approach?" ,
296296 )
297- psf_adaptive_threshold_detection = pexConfig .ConfigurableField (
298- target = AdaptiveThresholdDetectionTask ,
299- doc = "Task to adaptively detect sources for PSF determination." ,
300- )
301297 psf_source_measurement = pexConfig .ConfigurableField (
302298 target = lsst .meas .base .SingleFrameMeasurementTask ,
303299 doc = "Task to measure sources to be used for psf estimation."
@@ -472,13 +468,8 @@ def setDefaults(self):
472468 # thresholdValue * includeThresholdMultiplier. The low thresholdValue
473469 # ensures that the footprints are large enough for the noise replacer
474470 # to mask out faint undetected neighbors that are not to be measured.
475- self .psf_detection .thresholdValue = 10.0
476- self .psf_detection .includeThresholdMultiplier = 5.0
477- # TODO investigation: Probably want False here, but that may require
478- # tweaking the background spatial scale, to make it small enough to
479- # prevent extra peaks in the wings of bright objects.
480- self .psf_detection .doTempLocalBackground = False
481- self .psf_detection .reEstimateBackground = False
471+ self .psf_detection .baseline .thresholdValue = 10.0
472+ self .psf_detection .baseline .includeThresholdMultiplier = 5.0
482473
483474 # Minimal measurement plugins for PSF determination.
484475 # TODO DM-39203: We can drop GaussianFlux and PsfFlux, if we use
@@ -622,15 +613,15 @@ def validate(self):
622613 "CalibrateImageTask.psf_subtract_background must be configured with "
623614 "doApplyFlatBackgroundRatio=True if do_illumination_correction=True."
624615 )
625- if self .psf_detection . reEstimateBackground :
616+ if getattr ( self .psf_detection , " reEstimateBackground" , False ) :
626617 if not self .psf_detection .doApplyFlatBackgroundRatio :
627618 raise pexConfig .FieldValidationError (
628619 CalibrateImageConfig .psf_detection ,
629620 self ,
630621 "CalibrateImageTask.psf_detection background must be configured with "
631622 "doApplyFlatBackgroundRatio=True if do_illumination_correction=True."
632623 )
633- if self .star_detection . reEstimateBackground :
624+ if getattr ( self .star_detection , " reEstimateBackground" , False ) :
634625 if not self .star_detection .doApplyFlatBackgroundRatio :
635626 raise pexConfig .FieldValidationError (
636627 CalibrateImageConfig .star_detection ,
@@ -643,17 +634,17 @@ def validate(self):
643634 if not os .getenv ("SATTLE_URI_BASE" ):
644635 raise pexConfig .FieldValidationError (CalibrateImageConfig .run_sattle , self ,
645636 "Sattle requested but URI environment variable not set." )
637+ if (
638+ issubclass (self .psf_detection .target , AdaptiveThresholdDetectionTask )
639+ != self .do_adaptive_threshold_detection
640+ ):
641+ raise pexConfig .FieldValidationError (
642+ CalibrateImageConfig .psf_detection , self ,
643+ "AdaptiveThresholdDetectionTask must be used for the psf_detection subtask "
644+ "if and only if do_adaptive_threshold_detection is True."
645+ )
646646
647647 if not self .do_adaptive_threshold_detection :
648- if not self .psf_detection .reEstimateBackground :
649- raise pexConfig .FieldValidationError (
650- CalibrateImageConfig .psf_detection ,
651- self ,
652- "If not using the adaptive threshold detection implementation (i.e. "
653- "config.do_adaptive_threshold_detection = False), CalibrateImageTask.psf_detection "
654- "background must be configured with "
655- "reEstimateBackground = True to maintain original behavior."
656- )
657648 if not self .star_detection .reEstimateBackground :
658649 raise pexConfig .FieldValidationError (
659650 CalibrateImageConfig .psf_detection ,
@@ -695,7 +686,6 @@ def __init__(self, initial_stars_schema=None, **kwargs):
695686 afwTable .CoordKey .addErrorFields (self .psf_schema )
696687 self .makeSubtask ("psf_detection" , schema = self .psf_schema )
697688 self .makeSubtask ("psf_source_measurement" , schema = self .psf_schema )
698- self .makeSubtask ("psf_adaptive_threshold_detection" )
699689 self .makeSubtask ("psf_measure_psf" , schema = self .psf_schema )
700690 self .makeSubtask ("psf_normalized_calibration_flux" , schema = self .psf_schema )
701691
@@ -948,11 +938,12 @@ def run(
948938 illumination_correction ,
949939 )
950940
951- result . psf_stars_footprints , result .background , _ , adaptiveDetResStruct = self ._compute_psf (
941+ psf_detections , result .background , _ = self ._compute_psf (
952942 result .exposure ,
953943 id_generator ,
954944 background_to_photometric_ratio = result .background_to_photometric_ratio ,
955945 )
946+ result .psf_stars_footprints = psf_detections .sources
956947 have_fit_psf = True
957948
958949 # Check if all centroids have been flagged. This should happen
@@ -999,7 +990,7 @@ def run(
999990 result .background ,
1000991 id_generator ,
1001992 background_to_photometric_ratio = result .background_to_photometric_ratio ,
1002- adaptiveDetResStruct = adaptiveDetResStruct ,
993+ psf_detections = psf_detections ,
1003994 num_astrometry_matches = num_astrometry_matches ,
1004995 )
1005996 psf = result .exposure .getPsf ()
@@ -1147,8 +1138,10 @@ def _compute_psf(self, exposure, id_generator, background_to_photometric_ratio=N
11471138
11481139 Returns
11491140 -------
1150- sources : `lsst.afw.table.SourceCatalog`
1151- Catalog of detected bright sources.
1141+ detections : `lsst.pipe.base.Struct`
1142+ Struct returned by the ``psf_detection`` subtask, with its
1143+ ``sources`` attribute further updated by measurement and PSF
1144+ modeling.
11521145 background : `lsst.afw.math.BackgroundList`
11531146 Background that was fit to the exposure during detection.
11541147 cell_set : `lsst.afw.math.SpatialCellSet`
@@ -1191,25 +1184,12 @@ def log_psf(msg, addToMetadata=False):
11911184 self .psf_repair .run (exposure = exposure , keepCRs = True )
11921185
11931186 table = afwTable .SourceTable .make (self .psf_schema , id_generator .make_table_id_factory ())
1194- if not self .config .do_adaptive_threshold_detection :
1195- adaptiveDetResStruct = None
1196- # Re-estimate the background during this detection step, so that
1197- # measurement uses the most accurate background-subtraction.
1198- detections = self .psf_detection .run (
1199- table = table ,
1200- exposure = exposure ,
1201- background = background ,
1202- backgroundToPhotometricRatio = background_to_photometric_ratio ,
1203- )
1204- else :
1205- initialThreshold = self .config .psf_detection .thresholdValue
1206- initialThresholdMultiplier = self .config .psf_detection .includeThresholdMultiplier
1207- adaptiveDetResStruct = self .psf_adaptive_threshold_detection .run (
1208- table , exposure ,
1209- initialThreshold = initialThreshold ,
1210- initialThresholdMultiplier = initialThresholdMultiplier ,
1211- )
1212- detections = adaptiveDetResStruct .detections
1187+ detections = self .psf_detection .run (
1188+ table = table ,
1189+ exposure = exposure ,
1190+ background = background ,
1191+ backgroundToPhotometricRatio = background_to_photometric_ratio ,
1192+ )
12131193
12141194 self .metadata ["initial_psf_positive_footprint_count" ] = detections .numPos
12151195 self .metadata ["initial_psf_negative_footprint_count" ] = detections .numNeg
@@ -1258,7 +1238,7 @@ def log_psf(msg, addToMetadata=False):
12581238
12591239 # PSF is set on exposure; candidates are returned to use for
12601240 # calibration flux normalization and aperture corrections.
1261- return detections . sources , background , psf_result .cellSet , adaptiveDetResStruct
1241+ return detections , background , psf_result .cellSet
12621242
12631243 def _measure_aperture_correction (self , exposure , bright_sources ):
12641244 """Measure and set the ApCorrMap on the Exposure, using
@@ -1290,8 +1270,8 @@ def _measure_aperture_correction(self, exposure, bright_sources):
12901270
12911271 exposure .info .setApCorrMap (ap_corr_map )
12921272
1293- def _find_stars (self , exposure , background , id_generator , background_to_photometric_ratio = None ,
1294- adaptiveDetResStruct = None , num_astrometry_matches = None ):
1273+ def _find_stars (self , exposure , background , id_generator , background_to_photometric_ratio = None , * ,
1274+ psf_detections , num_astrometry_matches ):
12951275 """Detect stars on an exposure that has a PSF model, and measure their
12961276 PSF, circular aperture, compensated gaussian fluxes.
12971277
@@ -1307,6 +1287,10 @@ def _find_stars(self, exposure, background, id_generator, background_to_photomet
13071287 background_to_photometric_ratio : `lsst.afw.image.Image`, optional
13081288 Image to convert photometric-flattened image to
13091289 background-flattened image.
1290+ psf_detections : `lsst.pipe.base.Struct`
1291+ Struct returned from the ``psf_detection`` subtask.
1292+ num_astrometry_matches : `int`
1293+ Number of astrometry matches.
13101294
13111295 Returns
13121296 -------
@@ -1321,14 +1305,14 @@ def _find_stars(self, exposure, background, id_generator, background_to_photomet
13211305 maxAdaptiveDetIter = 8
13221306 adaptiveDetIter = 0
13231307 threshFactor = 0.2
1324- if adaptiveDetResStruct is not None :
1308+ if self . config . do_adaptive_threshold_detection :
13251309 while inAdaptiveDet and adaptiveDetIter < maxAdaptiveDetIter :
13261310 inAdaptiveDet = False
13271311 adaptiveDetectionConfig = lsst .meas .algorithms .SourceDetectionConfig ()
13281312 adaptiveDetectionConfig .reEstimateBackground = False
13291313 adaptiveDetectionConfig .includeThresholdMultiplier = 2.0
13301314 psfThreshold = (
1331- adaptiveDetResStruct .thresholdValue * adaptiveDetResStruct .includeThresholdMultiplier
1315+ psf_detections .thresholdValue * psf_detections .includeThresholdMultiplier
13321316 )
13331317 adaptiveDetectionConfig .thresholdValue = max (
13341318 self .config .star_detection .thresholdValue ,
0 commit comments