193 ) -> CorrelationMatrix:
194 """Determine correlation coefficients between pixels
196 This is the concrete routine that does the computation.
200 maskedImage : `~lsst.afw.image.MaskedImage`
201 Image for which to determine the variance rescaling factor.
202 refMaskedImage : `~lsst.afw.image.MaskedImage`
203 Image from which to determine which pixels to mask.
207 corr_matrix : `CorrelationMatrix`
208 Correlation matrix of the maskedImage.
210 maskVal = refMaskedImage.mask.getPlaneBitMask(self.config.maskPlanes)
212 ((refMaskedImage.mask.array & maskVal) == 0)
213 & np.isfinite(refMaskedImage.image.array)
214 & np.isfinite(refMaskedImage.variance.array)
215 & (refMaskedImage.variance.array > 0)
218 nGood = np.sum(isGood)
220 "Number of selected background pixels: %d of %d.", nGood, isGood.size
225 with warnings.catch_warnings():
226 warnings.simplefilter(
"ignore", category=RuntimeWarning)
227 normalized_arr = maskedImage.image.array / np.sqrt(
228 maskedImage.variance.array
230 normalized_arr[~isGood] = np.nan
232 corr_matrix = np.empty(
233 (self.config.size + 1, self.config.size + 1), dtype=np.float32
236 for dx, dy
in itertools.product(
237 range(self.config.size + 1), range(self.config.size + 1)
239 sliceX = slice(
None, -dx)
if dx != 0
else slice(
None,
None)
240 sliceY = slice(
None, -dy)
if dy != 0
else slice(
None,
None)
241 arr1 = normalized_arr[sliceX, sliceY]
243 sliceX = slice(dx,
None)
if dx != 0
else slice(
None,
None)
244 sliceY = slice(dy,
None)
if dy != 0
else slice(
None,
None)
245 arr2 = normalized_arr[sliceX, sliceY]
247 if self.config.subtractEmpiricalMean:
248 arr1 -= np.nanmean(arr1)
249 arr2 -= np.nanmean(arr2)
250 if self.config.scaleEmpiricalVariance:
253 arr1 /= np.nanmean(arr1**2) ** 0.5
254 arr2 /= np.nanmean(arr2**2) ** 0.5
256 cov = np.nanmean(arr1 * arr2)
260 cov *= 1.0 + 0.5 * (1 - cov**2) / (~np.isnan(arr1 * arr2)).sum()
262 corr_matrix[dx, dy] = cov