|
11 | 11 | import nibabel as nib
|
12 | 12 | import numpy as np
|
13 | 13 | from nibabel.cmdline.utils import *
|
14 |
| -from nibabel.cmdline.diff import get_headers_diff, display_diff, main, get_data_md5_diff |
| 14 | +from nibabel.cmdline.diff import get_headers_diff, display_diff, main, get_data_md5_diff, get_data_diff |
15 | 15 | from os.path import (join as pjoin)
|
16 | 16 | from nibabel.testing import data_path
|
17 | 17 | from collections import OrderedDict
|
@@ -116,6 +116,36 @@ def test_get_data_diff():
|
116 | 116 | for f in ('standard.nii.gz', 'standard.nii.gz')]
|
117 | 117 | assert_equal(get_data_md5_diff(test_names), [])
|
118 | 118 |
|
| 119 | + # testing the maximum relative and absolute differences' different use cases |
| 120 | + test_array = np.arange(16).reshape(4, 4) |
| 121 | + test_array_2 = np.arange(1, 17).reshape(4, 4) |
| 122 | + test_array_3 = np.arange(2, 18).reshape(4, 4) |
| 123 | + test_array_4 = np.arange(100).reshape(10, 10) |
| 124 | + test_array_5 = np.arange(64).reshape(8, 8) |
| 125 | + |
| 126 | + # same shape, 2 files |
| 127 | + assert_equal(get_data_diff([test_array, test_array_2]), |
| 128 | + OrderedDict([('DATA(diff 1:)', [None, OrderedDict([('abs', 1), ('rel', 2.0)])])])) |
| 129 | + |
| 130 | + # same shape, 3 files |
| 131 | + assert_equal(get_data_diff([test_array, test_array_2, test_array_3]), |
| 132 | + OrderedDict([('DATA(diff 1:)', [None, OrderedDict([('abs', 1), ('rel', 2.0)]), |
| 133 | + OrderedDict([('abs', 2), ('rel', 2.0)])]), |
| 134 | + ('DATA(diff 2:)', [None, None, |
| 135 | + OrderedDict([('abs', 1), ('rel', 0.66666666666666663)])])])) |
| 136 | + |
| 137 | + # same shape, 2 files, modified maximum abs/rel |
| 138 | + assert_equal(get_data_diff([test_array, test_array_2], max_abs=2, max_rel=2), OrderedDict()) |
| 139 | + |
| 140 | + # different shape, 2 files |
| 141 | + assert_equal(get_data_diff([test_array_2, test_array_4]), |
| 142 | + OrderedDict([('DATA(diff 1:)', [None, {'CMP': 'incompat'}])])) |
| 143 | + |
| 144 | + # different shape, 3 files |
| 145 | + assert_equal(get_data_diff([test_array_4, test_array_5, test_array_2]), |
| 146 | + OrderedDict([('DATA(diff 1:)', [None, {'CMP': 'incompat'}, {'CMP': 'incompat'}]), |
| 147 | + ('DATA(diff 2:)', [None, None, {'CMP': 'incompat'}])])) |
| 148 | + |
119 | 149 |
|
120 | 150 | def test_main():
|
121 | 151 | test_names = [pjoin(data_path, f)
|
|
0 commit comments