def runOffPolyISCE(offField): ''' Estimate polynomial here. ''' inArr = np.array(offField.unpackOffsets()) x = inArr[:, 0] y = inArr[:, 2] dx = inArr[:, 1] dy = inArr[:, 3] sig = inArr[:, 4] obj = Offsetpoly() obj.setLocationAcross(list(x)) obj.setLocationDown(list(y)) obj.setSNR(list(sig)) obj.setOffset(list(dy)) obj.offsetpoly() val = obj.offsetPoly # print('Range: ', val) azpol = Polynomial(rangeOrder=2, azimuthOrder=2) azpol.setCoeffs([[val[0], val[1], val[4]], [val[2], val[3]], [val[5]]]) obj.setOffset(list(dx)) obj.offsetpoly() val = obj.offsetPoly # print('Azimuth: ', val) rgpol = Polynomial(rangeOrder=2, azimuthOrder=2) rgpol.setCoeffs([[val[0], val[1], val[4]], [val[2], val[3]], [val[5]]]) return azpol, rgpol
def runOffPoly(offField): ''' Estimate polynomial here. ''' inArr = np.array(offField.unpackOffsets()) x = inArr[:, 0] y = inArr[:, 2] dx = inArr[:, 1] dy = inArr[:, 3] sig = inArr[:, 4] snr = 1.0 + 1.0 / sig xOrder = 2 yOrder = 2 #####Normalization factors ymin = np.min(y) ynorm = np.max(y) - ymin if ynorm == 0: ynorm = 1.0 yoff = np.int(np.round(np.mean(dy))) y = (y - ymin) / ynorm xmin = np.min(x) xnorm = np.max(x) - xmin if xnorm == 0: xnorm = 1.0 x = (x - xmin) / xnorm arrList = [] for ii in range(yOrder + 1): yfact = np.power(y, ii) for jj in range(yOrder + 1 - ii): temp = np.power(x, jj) * yfact arrList.append(temp.reshape((temp.size, 1))) A = np.hstack(arrList) A = A / snr[:, None] b = dy / snr val, res, rank, eigs = np.linalg.lstsq(A, b, rcond=1.0e-12) print('Az Chi : ', np.sqrt(res / (1.0 * len(b)))) azpol = Polynomial(rangeOrder=2, azimuthOrder=2) azpol.setCoeffs([val[0:3], val[3:5], val[5:]]) azpol._meanRange = xmin azpol._normRange = xnorm azpol._meanAzimuth = ymin azpol._normAzimuth = ynorm b = dx / snr val, res, rank, eigs = np.linalg.lstsq(A, b, rcond=1.0e-12) print('Rg chi : ', np.sqrt(res / (1.0 * len(b)))) rgpol = Polynomial(rangeOrder=2, azimuthOrder=2) rgpol.setCoeffs([val[0:3], val[3:5], val[5:]]) rgpol._meanRange = xmin rgpol._normRange = xnorm rgpol._meanAzimuth = ymin rgpol._normAzimuth = ynorm return azpol, rgpol