|
11 | 11 | import numpy as np |
12 | 12 |
|
13 | 13 | from io import BytesIO |
14 | | -from ..volumeutils import (calculate_scale, scale_min_max, finite_range, |
15 | | - apply_read_scaling, array_to_file, array_from_file) |
| 14 | +from ..volumeutils import finite_range, apply_read_scaling, array_to_file, array_from_file |
16 | 15 | from ..casting import type_info |
17 | 16 | from ..testing import suppress_warnings |
18 | 17 |
|
| 18 | +from .test_volumeutils import _calculate_scale |
| 19 | + |
19 | 20 | from numpy.testing import (assert_array_almost_equal, assert_array_equal) |
20 | 21 |
|
21 | 22 | from nose.tools import (assert_true, assert_equal, assert_raises, |
|
26 | 27 | DEBUG = True |
27 | 28 |
|
28 | 29 |
|
29 | | -def test_scale_min_max(): |
30 | | - mx_dt = np.maximum_sctype(np.float) |
31 | | - for tp in np.sctypes['uint'] + np.sctypes['int']: |
32 | | - info = np.iinfo(tp) |
33 | | - # Need to pump up to max fp type to contain python longs |
34 | | - imin = np.array(info.min, dtype=mx_dt) |
35 | | - imax = np.array(info.max, dtype=mx_dt) |
36 | | - value_pairs = ( |
37 | | - (0, imax), |
38 | | - (imin, 0), |
39 | | - (imin, imax), |
40 | | - (1, 10), |
41 | | - (-1, -1), |
42 | | - (1, 1), |
43 | | - (-10, -1), |
44 | | - (-100, 10)) |
45 | | - for mn, mx in value_pairs: |
46 | | - # with intercept |
47 | | - scale, inter = scale_min_max(mn, mx, tp, True) |
48 | | - if mx - mn: |
49 | | - assert_array_almost_equal, (mx - inter) / scale, imax |
50 | | - assert_array_almost_equal, (mn - inter) / scale, imin |
51 | | - else: |
52 | | - assert_equal, (scale, inter), (1.0, mn) |
53 | | - # without intercept |
54 | | - if imin == 0 and mn < 0 and mx > 0: |
55 | | - (assert_raises, ValueError, |
56 | | - scale_min_max, mn, mx, tp, False) |
57 | | - continue |
58 | | - scale, inter = scale_min_max(mn, mx, tp, False) |
59 | | - assert_equal, inter, 0.0 |
60 | | - if mn == 0 and mx == 0: |
61 | | - assert_equal, scale, 1.0 |
62 | | - continue |
63 | | - sc_mn = mn / scale |
64 | | - sc_mx = mx / scale |
65 | | - assert_true, sc_mn >= imin |
66 | | - assert_true, sc_mx <= imax |
67 | | - if imin == 0: |
68 | | - if mx > 0: # numbers all +ve |
69 | | - assert_array_almost_equal, mx / scale, imax |
70 | | - else: # numbers all -ve |
71 | | - assert_array_almost_equal, mn / scale, imax |
72 | | - continue |
73 | | - if abs(mx) >= abs(mn): |
74 | | - assert_array_almost_equal, mx / scale, imax |
75 | | - else: |
76 | | - assert_array_almost_equal, mn / scale, imin |
77 | | - |
78 | | - |
79 | 30 | def test_finite_range(): |
80 | 31 | # Finite range utility function |
81 | 32 | for in_arr, res in ( |
@@ -122,26 +73,6 @@ def test_finite_range(): |
122 | 73 | assert_raises(TypeError, finite_range, a) |
123 | 74 |
|
124 | 75 |
|
125 | | -def test_calculate_scale(): |
126 | | - # Test for special cases in scale calculation |
127 | | - npa = np.array |
128 | | - # Here the offset handles it |
129 | | - res = calculate_scale(npa([-2, -1], dtype=np.int8), np.uint8, True) |
130 | | - assert_equal(res, (1.0, -2.0, None, None)) |
131 | | - # Not having offset not a problem obviously |
132 | | - res = calculate_scale(npa([-2, -1], dtype=np.int8), np.uint8, 0) |
133 | | - assert_equal(res, (-1.0, 0.0, None, None)) |
134 | | - # Case where offset handles scaling |
135 | | - res = calculate_scale(npa([-1, 1], dtype=np.int8), np.uint8, 1) |
136 | | - assert_equal(res, (1.0, -1.0, None, None)) |
137 | | - # Can't work for no offset case |
138 | | - assert_raises(ValueError, |
139 | | - calculate_scale, npa([-1, 1], dtype=np.int8), np.uint8, 0) |
140 | | - # Offset trick can't work when max is out of range |
141 | | - res = calculate_scale(npa([-1, 255], dtype=np.int16), np.uint8, 1) |
142 | | - assert_not_equal(res, (1.0, -1.0, None, None)) |
143 | | - |
144 | | - |
145 | 76 | def test_a2f_mn_mx(): |
146 | 77 | # Test array to file mn, mx handling |
147 | 78 | str_io = BytesIO() |
@@ -213,9 +144,9 @@ def test_array_file_scales(): |
213 | 144 | info = type_info(in_type) |
214 | 145 | arr[0], arr[1] = info['min'], info['max'] |
215 | 146 | if not err is None: |
216 | | - assert_raises(err, calculate_scale, arr, out_dtype, True) |
| 147 | + assert_raises(err, _calculate_scale, arr, out_dtype, True) |
217 | 148 | continue |
218 | | - slope, inter, mn, mx = calculate_scale(arr, out_dtype, True) |
| 149 | + slope, inter, mn, mx = _calculate_scale(arr, out_dtype, True) |
219 | 150 | array_to_file(arr, bio, out_type, 0, inter, slope, mn, mx) |
220 | 151 | bio.seek(0) |
221 | 152 | arr2 = array_from_file(arr.shape, out_dtype, bio) |
@@ -266,7 +197,7 @@ def check_int_a2f(in_type, out_type): |
266 | 197 | data[1] = this_max + 0j |
267 | 198 | str_io = BytesIO() |
268 | 199 | try: |
269 | | - scale, inter, mn, mx = calculate_scale(data, out_type, True) |
| 200 | + scale, inter, mn, mx = _calculate_scale(data, out_type, True) |
270 | 201 | except ValueError as e: |
271 | 202 | if DEBUG: |
272 | 203 | print(in_type, out_type, e) |
|
0 commit comments