@@ -206,6 +206,12 @@ class MakeDirectWarpConnections(
206206 storageClass = "ImageF" ,
207207 dimensions = ("tract" , "patch" , "skymap" , "instrument" , "visit" ),
208208 )
209+ photometric_to_background_ratio_warp = Output (
210+ doc = "Warped version of the inverse of the background_to_photometric_ratio exposure." ,
211+ name = "photometric_to_background_ratio_warp" ,
212+ storageClass = "ImageF" ,
213+ dimensions = ("tract" , "patch" , "skymap" , "instrument" , "visit" ),
214+ )
209215
210216 def __init__ (self , * , config = None ):
211217 super ().__init__ (config = config )
@@ -221,6 +227,8 @@ def __init__(self, *, config=None):
221227
222228 if not config .doWarpMaskedFraction :
223229 del self .masked_fraction_warp
230+ if not config .doWarpPhotometricToBackgroundRatio :
231+ del self .photometric_to_background_ratio_warp
224232
225233 # Dynamically set output connections for noise images, depending on the
226234 # number of noise realization specified in the config.
@@ -336,6 +344,18 @@ class MakeDirectWarpConfig(
336344 doc = "Configuration for the warp that warps the mask fraction image" ,
337345 dtype = Warper .ConfigClass ,
338346 )
347+ doWarpPhotometricToBackgroundRatio = Field [bool ](
348+ doc = (
349+ "Warp the inverse of the background_to_photometric_ratio image? "
350+ "If this is True but doApplyFlatBackgroundRatio is False, an image "
351+ "of ones is warped instead."
352+ ),
353+ default = False ,
354+ )
355+ backgroundToPhotometricRatioWarper = ConfigField (
356+ doc = "Configuration for the warp that warps the background_to_photometric ratio" ,
357+ dtype = Warper .ConfigClass ,
358+ )
339359 coaddPsf = ConfigField (
340360 doc = "Configuration for CoaddPsf" ,
341361 dtype = CoaddPsfConfig ,
@@ -365,6 +385,7 @@ def setDefaults(self) -> None:
365385 self .warper .warpingKernelName = "lanczos3"
366386 self .warper .cacheSize = 0
367387 self .maskedFractionWarper .warpingKernelName = "bilinear"
388+ self .backgroundToPhotometricRatioWarper .warpingKernelName = "bilinear"
368389
369390
370391class MakeDirectWarpTask (PipelineTask ):
@@ -400,6 +421,10 @@ def __init__(self, **kwargs):
400421 self .warper = Warper .fromConfig (self .config .warper )
401422 if self .config .doWarpMaskedFraction :
402423 self .maskedFractionWarper = Warper .fromConfig (self .config .maskedFractionWarper )
424+ if self .config .doWarpPhotometricToBackgroundRatio :
425+ self .backgroundToPhotometricRatioWarper = Warper .fromConfig (
426+ self .config .backgroundToPhotometricRatioWarper
427+ )
403428
404429 def runQuantum (self , butlerQC , inputRefs , outputRefs ):
405430 # Docstring inherited.
@@ -530,6 +555,8 @@ def run(self, inputs: Mapping[int, WarpDetectorInputs], sky_info, visit_summary)
530555 final_warp = self ._prepareEmptyExposure (sky_info )
531556 if self .config .doWarpMaskedFraction :
532557 final_masked_fraction_warp = self ._prepareEmptyExposure (sky_info )
558+ if self .config .doWarpPhotometricToBackgroundRatio :
559+ final_photometric_to_background_ratio_warp = self ._prepareEmptyExposure (sky_info )
533560 final_noise_warps = {
534561 n_noise : self ._prepareEmptyExposure (sky_info )
535562 for n_noise in range (self .config .numberOfNoiseRealizations )
@@ -604,6 +631,22 @@ def run(self, inputs: Mapping[int, WarpDetectorInputs], sky_info, visit_summary)
604631 final_masked_fraction_warp .mask .getPlaneBitMask (["NO_DATA" ]),
605632 )
606633
634+ if self .config .doWarpPhotometricToBackgroundRatio :
635+ ptbr_exp = input_exposure .clone ()
636+ ptbr_exp .image .array [:, :] = 1.0
637+ ptbr_exp .mask .array [:, :] = 0
638+ ptbr_exp .variance .array [:, :] = 1.0
639+ if detector_inputs .background_to_photometric_ratio is not None :
640+ ptbr_exp .image .array [:, :] /= detector_inputs .background_to_photometric_ratio .array [:, :]
641+ btpr_warp = self .backgroundToPhotometricRatioWarper .warpExposure (
642+ target_wcs , ptbr_exp , destBBox = target_bbox
643+ )
644+ copyGoodPixels (
645+ final_photometric_to_background_ratio_warp .maskedImage ,
646+ btpr_warp .maskedImage ,
647+ final_photometric_to_background_ratio_warp .mask .getPlaneBitMask (["NO_DATA" ]),
648+ )
649+
607650 # Process and accumulate noise images.
608651 for n_noise in range (self .config .numberOfNoiseRealizations ):
609652 noise_calexp = noise_calexps [n_noise ]
@@ -660,6 +703,9 @@ def run(self, inputs: Mapping[int, WarpDetectorInputs], sky_info, visit_summary)
660703 if self .config .doWarpMaskedFraction :
661704 results .masked_fraction_warp = final_masked_fraction_warp .image
662705
706+ if self .config .doWarpPhotometricToBackgroundRatio :
707+ results .photometric_to_background_ratio_warp = final_photometric_to_background_ratio_warp .image
708+
663709 for noise_index , noise_exposure in final_noise_warps .items ():
664710 setattr (results , f"noise_warp{ noise_index } " , noise_exposure .maskedImage )
665711
0 commit comments