def func(dtype): d1 = distance(shape, center=center, scale=scale, dtype=dtype) d2 = _distance_slow(shape, center, scale, dtype) assert_same(d1, ref) assert_same(d2, ref) distance(shape, center=center, scale=scale, dtype=dtype, out=d1) _distance_slow(shape, center, scale, dtype, d2) assert_same(d1, ref) assert_same(d2, ref)
def integrated_profile_slow(input, center=None, scale=1, bin=1): d = distance(input.shape, center=center, scale=scale) m = int(np.max(d)) x = np.ndarray(m + 1) y = np.ndarray(m + 1) for i in range(m + 1): x[i] = (i + 1) * bin y[i] = np.sum(input[d < x[i]]) return x * scale, y * scale**2
def profile_slow(input, center=None, scale=1., bin=1.): d = distance(input.shape, center=center, scale=scale) d /= bin d = d.astype(int) m = int(np.max(d)) p = np.ndarray(m + 1) n = np.zeros(m + 1, int) for i in range(m + 1): mask = d == i p[i] = np.mean(input[mask]) n[i] = np.sum(mask) return p, n
def test_integrated_profile(): def integrated_profile_slow(input, center=None, scale=1, bin=1): d = distance(input.shape, center=center, scale=scale) m = int(np.max(d)) x = np.ndarray(m + 1) y = np.ndarray(m + 1) for i in range(m + 1): x[i] = (i + 1) * bin y[i] = np.sum(input[d < x[i]]) return x * scale, y * scale**2 d = distance((10, 20)) bin = 2 center = (4, 5) scale = 0.4 x, y = integrated_profile(d, bin=bin, center=center, scale=scale) x_ref, y_ref = integrated_profile_slow(d, bin=bin, center=center, scale=scale) assert_same(x, x_ref[0:y.size]) assert_same(y, y_ref[0:y.size])
def test_profile(): def profile_slow(input, center=None, scale=1., bin=1.): d = distance(input.shape, center=center, scale=scale) d /= bin d = d.astype(int) m = int(np.max(d)) p = np.ndarray(m + 1) n = np.zeros(m + 1, int) for i in range(m + 1): mask = d == i p[i] = np.mean(input[mask]) n[i] = np.sum(mask) return p, n d = distance((10, 20)) center = (4, 5) scale = 0.4 bin = 2 x, y, n = profile(d, center=center, scale=scale, bin=bin, histogram=True) y_ref, n_ref = profile_slow(d, center=center, scale=scale, bin=bin) assert_same(y, y_ref[0:y.size]) assert_same(n, n_ref[0:n.size])