1609 def calcBiasCorr(fluxLevels, imageShape, repeats=1, seed=0, addCorrelations=False,
1610 correlationStrength=0.1, maxLag=10, nSigmaClip=5, border=10, logger=None):
1611 """Calculate the bias induced when sigma-clipping non-Gaussian distributions.
1613 Fill image-pairs of the specified size with Poisson-distributed values,
1614 adding correlations as necessary. Then calculate the cross correlation,
1615 and calculate the bias induced using the cross-correlation image
1616 and the image means.
1620 fluxLevels : `list` of `int`
1621 The mean flux levels at which to simulate.
1622 Nominal values might be something like [70000, 90000, 110000]
1623 imageShape : `tuple` of `int`
1624 The shape of the image array to simulate, nx by ny pixels.
1625 repeats : `int`, optional
1626 Number of repeats to perform so that results
1627 can be averaged to improve SNR.
1628 seed : `int`, optional
1629 The random seed to use for the Poisson points.
1630 addCorrelations : `bool`, optional
1631 Whether to add brighter-fatter-like correlations to the simulated images
1632 If true, a correlation between x_{i,j} and x_{i+1,j+1} is introduced
1633 by adding a*x_{i,j} to x_{i+1,j+1}
1634 correlationStrength : `float`, optional
1635 The strength of the correlations.
1636 This is the value of the coefficient `a` in the above definition.
1637 maxLag : `int`, optional
1638 The maximum lag to work to in pixels
1639 nSigmaClip : `float`, optional
1640 Number of sigma to clip to when calculating the sigma-clipped mean.
1641 border : `int`, optional
1642 Number of border pixels to mask
1643 logger : `lsst.log.Log`, optional
1644 Logger to use. Instantiated anew if not provided.
1648 biases : `dict` [`float`, `list` of `float`]
1649 A dictionary, keyed by flux level, containing a list of the biases
1650 for each repeat at that flux level
1651 means : `dict` [`float`, `list` of `float`]
1652 A dictionary, keyed by flux level, containing a list of the average
1653 mean fluxes (average of the mean of the two images)
1654 for the image pairs at that flux level
1655 xcorrs : `dict` [`float`, `list` of `np.ndarray`]
1656 A dictionary, keyed by flux level, containing a list of the xcorr
1657 images for the image pairs at that flux level
1660 logger = lsstLog.Log.getDefaultLogger()
1662 means = {f: []
for f
in fluxLevels}
1663 xcorrs = {f: []
for f
in fluxLevels}
1664 biases = {f: []
for f
in fluxLevels}
1666 config = MakeBrighterFatterKernelTaskConfig()
1667 config.isrMandatorySteps = []
1668 config.isrForbiddenSteps = []
1669 config.nSigmaClipXCorr = nSigmaClip
1670 config.nPixBorderXCorr = border
1671 config.maxLag = maxLag
1672 task = MakeBrighterFatterKernelTask(config=config)
1674 im0 = afwImage.maskedImage.MaskedImageF(imageShape[1], imageShape[0])
1675 im1 = afwImage.maskedImage.MaskedImageF(imageShape[1], imageShape[0])
1677 random = np.random.RandomState(seed)
1679 for rep
in range(repeats):
1680 for flux
in fluxLevels:
1681 data0 = random.poisson(flux, (imageShape)).astype(float)
1682 data1 = random.poisson(flux, (imageShape)).astype(float)
1684 data0[1:, 1:] += correlationStrength*data0[: -1, : -1]
1685 data1[1:, 1:] += correlationStrength*data1[: -1, : -1]
1686 im0.image.array[:, :] = data0
1687 im1.image.array[:, :] = data1
1689 _xcorr, _means = task._crossCorrelate(im0, im1, runningBiasCorrSim=
True)
1691 means[flux].
append(_means)
1692 xcorrs[flux].
append(_xcorr)
1694 bias = xcorrs[flux][-1][1, 1]/means[flux][-1]*(1 + correlationStrength)/correlationStrength
1695 msg = f
"Simulated/expected avg. flux: {flux:.1f}, {(means[flux][-1]/2):.1f}"
1697 logger.info(f
"Bias: {bias:.6f}")
1699 bias = xcorrs[flux][-1][0, 0]/means[flux][-1]
1700 msg = f
"Simulated/expected avg. flux: {flux:.1f}, {(means[flux][-1]/2):.1f}"
1702 logger.info(f
"Bias: {bias:.6f}")
1703 biases[flux].
append(bias)
1705 return biases, means, xcorrs