def get_distances(self): """ This returns the distance of each neighbor to the pixel """ D = np.zeros((self.N, self.A)) for i in xrange(self.N): pi = self.flattening.index2cell[i] for jj in xrange(self.A): j = self.neighbor_indices_flat[i, jj] pj = self.flattening.index2cell[j] dx = pi[0] - pj[0] dy = pi[1] - pj[1] dxn = dmod(dx, self.shape[0] / 2) dyn = dmod(dy, self.shape[1] / 2) d = np.hypot(dxn, dyn) D[i, jj] = d return D
def get_distances_to_area_center(self): """ This returns the distance of each neighbor to the center of the area border. This is the same thing as get_distances() only if the area center is on the nominal pixel. """ D = np.zeros((self.N, self.A)) for i in xrange(self.N): pi = self.flattening.index2cell[i] area_center = self.get_center_for_cell_area(pi) js = self.neighbor_indices_flat[i, :] pjs = self.flattening.index2cell[js] assert pjs.shape[1] == 2 dx = area_center[0] - pjs[:, 0] dy = area_center[1] - pjs[:, 1] dxn = dmod(dx, self.shape[0] / 2) dyn = dmod(dy, self.shape[1] / 2) d = np.hypot(dxn, dyn) D[i, :] = d return D