/usr/lib/python3/dist-packages/astroML/stats/tests/test_binned_statistic.py is in python3-astroml 0.3-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | import numpy as np
from numpy.testing import assert_array_almost_equal
from astroML.stats import \
binned_statistic, binned_statistic_2d, binned_statistic_dd
def test_1d_count():
x = np.random.random(100)
v = np.random.random(100)
count1, edges1 = binned_statistic(x, v, 'count', bins=10)
count2, edges2 = np.histogram(x, bins=10)
assert_array_almost_equal(count1, count2)
assert_array_almost_equal(edges1, edges2)
def test_1d_sum():
x = np.random.random(100)
v = np.random.random(100)
sum1, edges1 = binned_statistic(x, v, 'sum', bins=10)
sum2, edges2 = np.histogram(x, bins=10, weights=v)
assert_array_almost_equal(sum1, sum2)
assert_array_almost_equal(edges1, edges2)
def test_1d_mean():
x = np.random.random(100)
v = np.random.random(100)
stat1, edges1 = binned_statistic(x, v, 'mean', bins=10)
stat2, edges2 = binned_statistic(x, v, np.mean, bins=10)
assert_array_almost_equal(stat1, stat2)
assert_array_almost_equal(edges1, edges2)
def test_1d_median():
x = np.random.random(100)
v = np.random.random(100)
stat1, edges1 = binned_statistic(x, v, 'median', bins=10)
stat2, edges2 = binned_statistic(x, v, np.median, bins=10)
assert_array_almost_equal(stat1, stat2)
assert_array_almost_equal(edges1, edges2)
def test_2d_count():
x = np.random.random(100)
y = np.random.random(100)
v = np.random.random(100)
count1, binx1, biny1 = binned_statistic_2d(x, y, v, 'count', bins=5)
count2, binx2, biny2 = np.histogram2d(x, y, bins=5)
assert_array_almost_equal(count1, count2)
assert_array_almost_equal(binx1, binx2)
assert_array_almost_equal(biny1, biny2)
def test_2d_sum():
x = np.random.random(100)
y = np.random.random(100)
v = np.random.random(100)
sum1, binx1, biny1 = binned_statistic_2d(x, y, v, 'sum', bins=5)
sum2, binx2, biny2 = np.histogram2d(x, y, bins=5, weights=v)
assert_array_almost_equal(sum1, sum2)
assert_array_almost_equal(binx1, binx2)
assert_array_almost_equal(biny1, biny2)
def test_2d_mean():
x = np.random.random(100)
y = np.random.random(100)
v = np.random.random(100)
stat1, binx1, biny1 = binned_statistic_2d(x, y, v, 'mean', bins=5)
stat2, binx2, biny2 = binned_statistic_2d(x, y, v, np.mean, bins=5)
assert_array_almost_equal(stat1, stat2)
assert_array_almost_equal(binx1, binx2)
assert_array_almost_equal(biny1, biny2)
def test_2d_median():
x = np.random.random(100)
y = np.random.random(100)
v = np.random.random(100)
stat1, binx1, biny1 = binned_statistic_2d(x, y, v, 'median', bins=5)
stat2, binx2, biny2 = binned_statistic_2d(x, y, v, np.median, bins=5)
assert_array_almost_equal(stat1, stat2)
assert_array_almost_equal(binx1, binx2)
assert_array_almost_equal(biny1, biny2)
def test_dd_count():
X = np.random.random((100, 3))
v = np.random.random(100)
count1, edges1 = binned_statistic_dd(X, v, 'count', bins=3)
count2, edges2 = np.histogramdd(X, bins=3)
assert_array_almost_equal(count1, count2)
assert_array_almost_equal(edges1, edges2)
def test_dd_sum():
X = np.random.random((100, 3))
v = np.random.random(100)
sum1, edges1 = binned_statistic_dd(X, v, 'sum', bins=3)
sum2, edges2 = np.histogramdd(X, bins=3, weights=v)
assert_array_almost_equal(sum1, sum2)
assert_array_almost_equal(edges1, edges2)
def test_dd_mean():
X = np.random.random((100, 3))
v = np.random.random(100)
stat1, edges1 = binned_statistic_dd(X, v, 'mean', bins=3)
stat2, edges2 = binned_statistic_dd(X, v, np.mean, bins=3)
assert_array_almost_equal(stat1, stat2)
assert_array_almost_equal(edges1, edges2)
def test_dd_median():
X = np.random.random((100, 3))
v = np.random.random(100)
stat1, edges1 = binned_statistic_dd(X, v, 'median', bins=3)
stat2, edges2 = binned_statistic_dd(X, v, np.median, bins=3)
assert_array_almost_equal(stat1, stat2)
assert_array_almost_equal(edges1, edges2)
|