@@ -522,7 +522,11 @@ def update_background_stats(self, summary, background):
522
522
Parameters
523
523
----------
524
524
summary : `lsst.afw.image.ExposureSummaryStats`
525
- Summary object to update in-place.
525
+ Summary object to update in-place. This method adds/updates the
526
+ following fields:
527
+ - `skyBg`: Median sky background value across background models.
528
+ - `skyBgNormRange`: Normalized range (max - min / median) of the
529
+ combined sky background, used to quantify spatial variation.
526
530
background : `lsst.afw.math.BackgroundList` or `None`
527
531
Background model. If `None`, all fields that depend on the
528
532
background will be reset (generally to NaN).
@@ -535,11 +539,31 @@ def update_background_stats(self, summary, background):
535
539
as well.
536
540
"""
537
541
if background is not None :
538
- bgStats = (bg [0 ].getStatsImage ().getImage ().array
539
- for bg in background )
540
- summary .skyBg = float (sum (np .median (bg [np .isfinite (bg )]) for bg in bgStats ))
542
+ bgStats = []
543
+ for bg in background :
544
+ statsImageF = bg [0 ].getStatsImage ().getImage ()
545
+ bgArray = statsImageF .array
546
+ bgArray [~ np .isfinite (bgArray )] = np .nan
547
+ bgStats .append (bgArray )
548
+ summary .skyBg = float (sum (np .nanmedian (bg ) for bg in bgStats ))
549
+ shapes = [arr .shape for arr in bgStats ]
550
+ if len (set (shapes )) != 1 :
551
+ raise RuntimeError (
552
+ f"BackgroundList images from background models have different shapes: { shapes } "
553
+ )
554
+ skyBgSumImage = np .sum (np .stack (bgStats ), axis = 0 )
555
+
556
+ median = np .nanmedian (skyBgSumImage )
557
+ if median != 0 and np .isfinite (median ):
558
+ summary .skyBgNormRange = float (
559
+ (np .nanmax (skyBgSumImage ) - np .nanmin (skyBgSumImage )) / median
560
+ )
561
+ else :
562
+ summary .skyBgNormRange = float ("nan" )
541
563
else :
542
564
summary .skyBg = float ("nan" )
565
+ summary .skyBgNormRange = float ("nan" )
566
+ breakpoint ()
543
567
544
568
def update_masked_image_stats (self , summary , masked_image ):
545
569
"""Compute summary-statistic fields that depend on the masked image
0 commit comments