-
Notifications
You must be signed in to change notification settings - Fork 264
RF+ENH: nib-diff - allow to specify absolute and/or relative maximal diff to tolerate #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cd5a741
018eceb
833b4df
9b123f6
1e33ea7
76ca32f
0aa6370
d057249
76ee358
034c276
19fcdd5
93c7bb6
cd85e09
716b1c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
import nibabel as nib | ||
import numpy as np | ||
from nibabel.cmdline.utils import * | ||
from nibabel.cmdline.diff import get_headers_diff, display_diff, main, get_data_diff | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of us has managed to make this file executable, please undo:
|
||
from nibabel.cmdline.diff import get_headers_diff, display_diff, main, get_data_hash_diff, get_data_diff | ||
from os.path import (join as pjoin) | ||
from nibabel.testing import data_path | ||
from collections import OrderedDict | ||
|
@@ -96,9 +96,9 @@ def test_display_diff(): | |
("bitpix", [np.array(8).astype(dtype="uint8"), np.array(16).astype(dtype="uint8")]) | ||
]) | ||
|
||
expected_output = "These files are different.\n" + "Field hellokitty.nii.gz" \ | ||
" " \ | ||
"privettovarish.nii.gz \n" \ | ||
expected_output = "These files are different.\n" + "Field/File 1:hellokitty.nii.gz" \ | ||
" " \ | ||
"2:privettovarish.nii.gz \n" \ | ||
"datatype " \ | ||
"2 " \ | ||
"4 \n" \ | ||
|
@@ -114,7 +114,37 @@ def test_get_data_diff(): | |
# testing for identical files specifically as md5 may vary by computer | ||
test_names = [pjoin(data_path, f) | ||
for f in ('standard.nii.gz', 'standard.nii.gz')] | ||
assert_equal(get_data_diff(test_names), []) | ||
assert_equal(get_data_hash_diff(test_names), []) | ||
|
||
# testing the maximum relative and absolute differences' different use cases | ||
test_array = np.arange(16).reshape(4, 4) | ||
test_array_2 = np.arange(1, 17).reshape(4, 4) | ||
test_array_3 = np.arange(2, 18).reshape(4, 4) | ||
test_array_4 = np.arange(100).reshape(10, 10) | ||
test_array_5 = np.arange(64).reshape(8, 8) | ||
|
||
# same shape, 2 files | ||
assert_equal(get_data_diff([test_array, test_array_2]), | ||
OrderedDict([('DATA(diff 1:)', [None, OrderedDict([('abs', 1), ('rel', 2.0)])])])) | ||
|
||
# same shape, 3 files | ||
assert_equal(get_data_diff([test_array, test_array_2, test_array_3]), | ||
OrderedDict([('DATA(diff 1:)', [None, OrderedDict([('abs', 1), ('rel', 2.0)]), | ||
OrderedDict([('abs', 2), ('rel', 2.0)])]), | ||
('DATA(diff 2:)', [None, None, | ||
OrderedDict([('abs', 1), ('rel', 0.66666666666666663)])])])) | ||
|
||
# same shape, 2 files, modified maximum abs/rel | ||
assert_equal(get_data_diff([test_array, test_array_2], max_abs=2, max_rel=2), OrderedDict()) | ||
|
||
# different shape, 2 files | ||
assert_equal(get_data_diff([test_array_2, test_array_4]), | ||
OrderedDict([('DATA(diff 1:)', [None, {'CMP': 'incompat'}])])) | ||
|
||
# different shape, 3 files | ||
assert_equal(get_data_diff([test_array_4, test_array_5, test_array_2]), | ||
OrderedDict([('DATA(diff 1:)', [None, {'CMP': 'incompat'}, {'CMP': 'incompat'}]), | ||
('DATA(diff 2:)', [None, None, {'CMP': 'incompat'}])])) | ||
|
||
|
||
def test_main(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,10 +72,10 @@ def check_nib_diff_examples(): | |
fnames = [pjoin(DATA_PATH, f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same here about permissions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please clarify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jk I got it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good ;) |
||
for f in ('standard.nii.gz', 'example4d.nii.gz')] | ||
code, stdout, stderr = run_command(['nib-diff'] + fnames, check_code=False) | ||
checked_fields = ["Field", "regular", "dim_info", "dim", "datatype", "bitpix", "pixdim", "slice_end", | ||
checked_fields = ["Field/File", "regular", "dim_info", "dim", "datatype", "bitpix", "pixdim", "slice_end", | ||
"xyzt_units", "cal_max", "descrip", "qform_code", "sform_code", "quatern_b", | ||
"quatern_c", "quatern_d", "qoffset_x", "qoffset_y", "qoffset_z", "srow_x", | ||
"srow_y", "srow_z", "DATA(md5)"] | ||
"srow_y", "srow_z", "DATA(md5)", "DATA(diff 1:)"] | ||
for item in checked_fields: | ||
assert_true(item in stdout) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ndarray
I assume means a data block equivalent to one loaded withnib.load().get_fdata()
or similar?