def main(): #test_generateEllGaussianImage("ellGaussianTest_0.01.fits") print commons.getTriWeight([0,0], [0, 3], [4, 0], [2,1]) return 0
def getLensOperator(mappingDict, srcBrightNess): dim = len(mappingDict) L = np.zeros((dim, 2*dim)) imgPointList = mappingDict.keys() srcPointList = mappingDict.values() srcPosition = [] firstOrderWeightList = [] secondOrderWeightList = [] Hsy1 = np.zeros((dim, dim)) Hsy2 = np.zeros((dim, dim)) d = np.zeros(dim) normV = [[] for i in range(dim)] #srcBrightNess = np.ones(dim) varList = [] RTR = np.zeros((2*dim, 2*dim)) for i in range(dim): imgX, imgY = imgPointList[i] srcX, srcY, imgBrightNess, type, var = srcPointList[i] srcPosition.append((srcX, srcY)) varList.append(var) d[i] = imgBrightNess if type=='o': if (imgX, imgY-1) in imgPointList and (imgX, imgY+1) in imgPointList and (imgX+1, imgY) in imgPointList: Hsy1[i][i]=1 Hsy2[i][i]=1 w1Index = imgPointList.index((imgX, imgY-1)) w2Index = imgPointList.index((imgX, imgY+1)) w3Index = imgPointList.index((imgX+1, imgY)) A = (mappingDict[(imgX,imgY-1)][0], mappingDict[(imgX,imgY-1)][1]) B = (mappingDict[(imgX,imgY+1)][0], mappingDict[(imgX,imgY+1)][1]) C = (mappingDict[(imgX+1,imgY)][0], mappingDict[(imgX+1,imgY)][1]) L[i][w1Index], L[i][w2Index],L[i][w3Index] = commons.getTriWeight(A,B,C, (srcX, srcY)) # update the normV An = (A[0], A[1], srcBrightNess[w1Index]) Bn = (B[0], B[1], srcBrightNess[w2Index]) Cn = (C[0], C[1], srcBrightNess[w3Index]) n0, n1, n2 = commons.getNormVectors(An, Bn, Cn) normV[w1Index].append((n0, n1, n2)) normV[w2Index].append((n0, n1, n2)) normV[w3Index].append((n0, n1, n2)) firstOrderWeightList.append((w1Index, w2Index, w3Index, L[i][w1Index], L[i][w2Index],L[i][w3Index])) else: L[i][i] =1 firstOrderWeightList.append((i, i, i , 1/3.,1/3.,1/3.)) if type=='v': L[i][i] =1 firstOrderWeightList.append((i, i, i , 1/3.,1/3.,1/3.)) if (imgX-1, imgY-1) in imgPointList and (imgX-1, imgY+1) in imgPointList and (imgX+1, imgY-1) in imgPointList and (imgX+1, imgY+1) in imgPointList: wAIndex = imgPointList.index((imgX-1, imgY-1)) wBIndex = imgPointList.index((imgX-1, imgY+1)) wCIndex = imgPointList.index((imgX+0, imgY+0)) wDIndex = imgPointList.index((imgX+1, imgY-1)) wEIndex = imgPointList.index((imgX+1, imgY+1)) A = (mappingDict[(imgX-1,imgY-1)][0], mappingDict[(imgX-1,imgY-1)][1]) B = (mappingDict[(imgX-1,imgY+1)][0], mappingDict[(imgX-1,imgY+1)][1]) C = (mappingDict[(imgX+0,imgY+0)][0], mappingDict[(imgX+0,imgY+0)][1]) D = (mappingDict[(imgX+1,imgY-1)][0], mappingDict[(imgX+1,imgY-1)][1]) E = (mappingDict[(imgX+1,imgY+1)][0], mappingDict[(imgX+1,imgY+1)][1]) Hsy1[i][wAIndex], Hsy1[i][wBIndex], Hsy1[i][wCIndex], Hsy1[i][wDIndex],Hsy1[i][wEIndex],\ Hsy2[i][wAIndex], Hsy2[i][wBIndex], Hsy2[i][wCIndex], Hsy2[i][wDIndex],Hsy2[i][wEIndex] = commons.getPentWeigth(A, B, C, D, E) HsTHs = scipy.sparse.coo_matrix(Hsy1.transpose())*scipy.sparse.coo_matrix(Hsy1) + \ scipy.sparse.coo_matrix(Hsy2.transpose())*scipy.sparse.coo_matrix(Hsy2) HsTHs = HsTHs.toarray() #Hs = np.linalg.cholesky(tt) for i in range(dim): for j in range(dim): RTR[i][j] = HsTHs[i][j] # Diagonal covariance matrix: C = commons.listToDiagonalMatrix(varList) normV = commons.getMeanNorm(normV) return srcPosition, srcPointList, commons.sMatrix(L), normV, C, firstOrderWeightList, d, RTR, HsTHs, imgPointList