()
| 116 | |
| 117 | |
| 118 | def test_removing_nodes(): |
| 119 | x = [1, 2, 3, 4, 5, 6, 7, 8] |
| 120 | wp = pywt.WaveletPacket(data=x, wavelet='db1', mode='symmetric') |
| 121 | wp.get_level(2) |
| 122 | |
| 123 | dataleafs = [n.data for n in wp.get_leaf_nodes(False)] |
| 124 | expected = np.array([[5., 13.], [-2, -2], [-1, -1], [0, 0]]) |
| 125 | |
| 126 | for i in range(4): |
| 127 | assert_allclose(dataleafs[i], expected[i, :], atol=1e-12) |
| 128 | |
| 129 | node = wp['ad'] |
| 130 | del(wp['ad']) |
| 131 | dataleafs = [n.data for n in wp.get_leaf_nodes(False)] |
| 132 | expected = np.array([[5., 13.], [-1, -1], [0, 0]]) |
| 133 | |
| 134 | for i in range(3): |
| 135 | assert_allclose(dataleafs[i], expected[i, :], atol=1e-12) |
| 136 | |
| 137 | wp.reconstruct() |
| 138 | # The reconstruction is: |
| 139 | assert_allclose(wp.reconstruct(), |
| 140 | np.array([2., 3., 2., 3., 6., 7., 6., 7.]), rtol=1e-12) |
| 141 | |
| 142 | # Restore the data |
| 143 | wp['ad'].data = node.data |
| 144 | |
| 145 | dataleafs = [n.data for n in wp.get_leaf_nodes(False)] |
| 146 | expected = np.array([[5., 13.], [-2, -2], [-1, -1], [0, 0]]) |
| 147 | |
| 148 | for i in range(4): |
| 149 | assert_allclose(dataleafs[i], expected[i, :], atol=1e-12) |
| 150 | |
| 151 | assert_allclose(wp.reconstruct(), np.arange(1, 9), rtol=1e-12) |
| 152 | |
| 153 | |
| 154 | def test_wavelet_packet_dtypes(): |
nothing calls this directly
no test coverage detected