26 """Create an elliptical Gaussian. 31 An array containing the x coordinates the Gaussian will be evaluated on. 32 most likely the result of a numpy.indices call 34 An array containing the y coordinates the Gaussian will be evaluated on. 35 most likely the result of a numpy.indices call 37 The value the resulting Gaussian will have when summed over all pixels. 39 The central position of the Gaussian in the x direction 41 The central position of the Gaussian in the y direction 43 The variance of the Gaussian about the muX position 45 The covariance of the Gaussian in x and y 47 The variance of the Gaussian about the muY position 51 Gaussian : 2D numpy array 52 The Gaussian array generated from the input values 55 rho = varXY/(varX**0.5*varY**0.5)
57 psf = np.exp(-1/(2*(1-rho**2)) *
58 ((x-muX)**2/varX+(y - muY)**2/varY -
59 2*rho*(x-muX)*(y-muY)/(varX**0.5*varY**0.5)))
66 """ Propagate pixel uncertainties to uncertainties in weighted moments 70 imShape : tuple(float, float) 71 The shape of image for which weighted moments have been calculated 73 An iterable object with six elements corresponding to the moments used 74 in the weighted moment calculation, scale, mean in x, mean in y, variance 75 in x, covariance between x and y, and variance in y. 77 Uncertainty in the pixel value. This is a single value, as this routine 78 assumes errors are background dominated, and uncorrelated 82 covarianceMatrix : 2D 6x6 numpy array of floats 83 This is the covariance matrix on the measured moments with uncertainties 84 propagated from pixel uncertainties 86 yInd, xInd = np.indices(imShape)
88 sigmaImage = np.eye(weightImage.size)*uncertanty
89 MomentWeightMatrix = np.zeros((6, weightImage.size))
91 weightImageFlat = weightImage.flatten()
92 xIndFlat = xInd.flatten()
93 yIndFlat = yInd.flatten()
95 MomentWeightMatrix[0] = weightImageFlat
96 MomentWeightMatrix[1] = weightImageFlat*xIndFlat
97 MomentWeightMatrix[2] = weightImageFlat*yIndFlat
98 MomentWeightMatrix[3] = weightImageFlat*xIndFlat**2
99 MomentWeightMatrix[4] = weightImageFlat*xIndFlat*yIndFlat
100 MomentWeightMatrix[5] = weightImageFlat*yIndFlat**2
102 return np.dot(MomentWeightMatrix, np.dot(sigmaImage, np.transpose(MomentWeightMatrix)))
106 """ Calculate weighted moments of the input image with the given weight array 110 image : 2D numpy array of floats 111 This is the input postage stamp of a source for which the weighted moments are 113 W : 2D numpy array of floats 114 Array of floats that are used as weights when calculating moments on the input 115 image. Array must be the same shape image 119 moments : 6 element numpy array 120 These are the weighted moments as measured from the input image in the order of 121 0th, 1st X, 1st Y, 2nd X, 2nd XY, 2nd Y 125 AssertionError: Raises if the input arrays are not the same shape 127 assert image.shape == W.shape,
"Input image and weight array must be the same shape" 129 yInd, xInd = np.indices(image.shape)
132 zero = np.sum(image*weightImage)
133 oneX = np.sum(image*weightImage*xInd)
134 oneY = np.sum(image*weightImage*yInd)
135 twoX = np.sum(image*weightImage*xInd**2)
136 twoXY = np.sum(image*weightImage*xInd*yInd)
137 twoY = np.sum(image*weightImage*yInd**2)
139 return np.array((zero, oneX, oneY, twoX, twoXY, twoY)), weightImage
def buildUncertanty(imShape, W, uncertanty)
def measureMoments(image, W)
def makeGaussian(x, y, scale, muX, muY, varX, varXY, varY)