def get_inverse_matrix(self, dst, srcs): ''' Inverse matrix to solve linear equations ''' src_obj = self.src_obj dst_obj = self.dst_obj mat_size = self.mat_size amat = np.zeros((mat_size, mat_size), 'f8') src_local_xyzs = src_obj.xyzs[srcs] r0 = self.get_r0(srcs) func = lambda r: sqrt(r*r + r0*r0) # multiquadratic for i in xrange(mat_size): for j in xrange(mat_size): r = angle(src_local_xyzs[i], src_local_xyzs[j]) amat[i,j] = func(r) try: invmat = np.linalg.inv(amat) except Exception, e: print str(e) print 'dst', dst print 'srcs', srcs print 'amat', amat print 'r0', r0 sys.exit()
def get_r0(self, srcs): ''' Define r0 with average distance between src points ''' src_obj = self.src_obj distances = list() for src1 in srcs: for src2 in srcs: if src1 != src2: xyz1 = src_obj.xyzs[src1] xyz2 = src_obj.xyzs[src2] distances.append( angle(xyz1, xyz2) ) return np.average(distances)
def get_src_address(self, dst): src_obj = self.src_obj dst_obj = self.dst_obj mat_size = self.mat_size idxs = set( src_obj.get_surround_idxs(*dst_obj.latlons[dst]) ) while len(idxs) < mat_size: if -1 in idxs: idxs.remove(-1) for idx in idxs.copy(): nidxs = set( src_obj.get_neighbors(idx) ) if -1 in nidxs: nidxs.remove(-1) idxs.update(nidxs) # sort along distance dst_xyz = dst_obj.xyzs[dst] sorted_idxs = sorted(idxs, key=lambda idx:angle(dst_xyz, src_obj.xyzs[idx])) return sorted_idxs[:mat_size] # list