LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Classes | Functions
lsst.meas.extensions.piff.piffPsfDeterminer Namespace Reference

Classes

class  PiffPsfDeterminerConfig
 
class  PiffPsfDeterminerTask
 

Functions

def computeWeight (maskedImage, maxSNR)
 
def applyMaxSNR (imArr, weightArr, good, maxSNR)
 

Function Documentation

◆ applyMaxSNR()

def lsst.meas.extensions.piff.piffPsfDeterminer.applyMaxSNR (   imArr,
  weightArr,
  good,
  maxSNR 
)
Rescale weight of bright stars to cap the computed SNR.

Parameters
----------
imArr : `ndarray`
    Signal (image) array of stamp.
weightArr : `ndarray`
    Weight map array.  May be rescaled in place.
good : `ndarray`
    Index array of pixels to use when computing SNR.
maxSNR : `float`
    Threshold for adjusting variance plane implementing maximum SNR.

Definition at line 100 of file piffPsfDeterminer.py.

100 def applyMaxSNR(imArr, weightArr, good, maxSNR):
101  """Rescale weight of bright stars to cap the computed SNR.
102 
103  Parameters
104  ----------
105  imArr : `ndarray`
106  Signal (image) array of stamp.
107  weightArr : `ndarray`
108  Weight map array. May be rescaled in place.
109  good : `ndarray`
110  Index array of pixels to use when computing SNR.
111  maxSNR : `float`
112  Threshold for adjusting variance plane implementing maximum SNR.
113  """
114  # We define the SNR value following Piff. Here's the comment from that
115  # code base explaining the calculation.
116  #
117  # The S/N value that we use will be the weighted total flux where the
118  # weight function is the star's profile itself. This is the maximum S/N
119  # value that any flux measurement can possibly produce, which will be
120  # closer to an in-practice S/N than using all the pixels equally.
121  #
122  # F = Sum_i w_i I_i^2
123  # var(F) = Sum_i w_i^2 I_i^2 var(I_i)
124  # = Sum_i w_i I_i^2 <--- Assumes var(I_i) = 1/w_i
125  #
126  # S/N = F / sqrt(var(F))
127  #
128  # Note that if the image is pure noise, this will produce a "signal" of
129  #
130  # F_noise = Sum_i w_i 1/w_i = Npix
131  #
132  # So for a more accurate estimate of the S/N of the actual star itself, one
133  # should subtract off Npix from the measured F.
134  #
135  # The final formula then is:
136  #
137  # F = Sum_i w_i I_i^2
138  # S/N = (F-Npix) / sqrt(F)
139  F = np.sum(weightArr[good]*imArr[good]**2, dtype=float)
140  Npix = np.sum(good)
141  SNR = 0.0 if F < Npix else (F-Npix)/np.sqrt(F)
142  # rescale weight of bright stars. Essentially makes an error floor.
143  if SNR > maxSNR:
144  factor = (maxSNR / SNR)**2
145  weightArr[good] *= factor
146 
147 
def applyMaxSNR(imArr, weightArr, good, maxSNR)

◆ computeWeight()

def lsst.meas.extensions.piff.piffPsfDeterminer.computeWeight (   maskedImage,
  maxSNR 
)
Derive a weight map without Poisson variance component due to signal.

Parameters
----------
maskedImage : `afw.image.MaskedImage`
    PSF candidate postage stamp
maxSNR : `float`
    Maximum SNR applying variance floor.

Returns
-------
weightArr : `ndarry`
    Array to use for weight.

Definition at line 69 of file piffPsfDeterminer.py.

69 def computeWeight(maskedImage, maxSNR):
70  """Derive a weight map without Poisson variance component due to signal.
71 
72  Parameters
73  ----------
74  maskedImage : `afw.image.MaskedImage`
75  PSF candidate postage stamp
76  maxSNR : `float`
77  Maximum SNR applying variance floor.
78 
79  Returns
80  -------
81  weightArr : `ndarry`
82  Array to use for weight.
83  """
84  imArr = maskedImage.image.array
85  varArr = maskedImage.variance.array
86  good = (varArr != 0) & np.isfinite(varArr) & np.isfinite(imArr)
87 
88  # Fit a straight line to variance vs (sky-subtracted) signal.
89  # The evaluate that line at zero signal to get an estimate of the
90  # signal-free variance.
91  fit = np.polyfit(imArr[good], varArr[good], deg=1)
92  # fit is [1/gain, sky_var]
93  weightArr = np.zeros_like(imArr, dtype=float)
94  weightArr[good] = 1./fit[1]
95 
96  applyMaxSNR(imArr, weightArr, good, maxSNR)
97  return weightArr
98 
99